]> granicus.if.org Git - esp-idf/commitdiff
make: Add macro to test for & try to fix up files required for submodules
authorAngus Gratton <angus@espressif.com>
Mon, 12 Sep 2016 07:48:40 +0000 (17:48 +1000)
committerAngus Gratton <angus@espressif.com>
Mon, 12 Sep 2016 08:00:20 +0000 (18:00 +1000)
Now applied to both esptool.py & esp32 wifi libs

components/esp32/Makefile
components/esptool_py/Makefile.projbuild
make/common.mk

index 2331f286c6b0fa3e6a8d9ffb645de4740216dace..d67f50211c4115414329293a0bddef2466e1ade0 100644 (file)
@@ -37,14 +37,9 @@ include $(IDF_PATH)/make/component.mk
 
 ALL_LIB_FILES := $(patsubst %,$(COMPONENT_PATH)/lib/lib%.a,$(LIBS))
 
-# The binary libraries are in a git submodule, so this target will
-# be invoked if any modules are missing (probably because
-# git submodule update --init needs to be run).
-$(ALL_LIB_FILES):
-       $(Q) [ -d ${IDF_PATH}/.git ] || ( @echo "ERROR: Missing libraries in esp32 component. esp-idf must be cloned from git to work."; exit 1 )
-       $(Q) [ -x $(which git) ] || ( @echo "ERROR: Missing libraries in esp32 component. Need to run 'git submodule update --init' in esp-idf root directory."; exit 1 )
-       @echo "Warning: Missing libraries in components/esp32/lib/ submodule. Going to try running 'git submodule update --init' in esp-idf root directory..."
-       cd ${IDF_PATH} && git submodule update --init
+# automatically trigger a git submodule update
+# if any libraries are missing
+$(eval $(call SubmoduleRequiredForFiles,$(ALL_LIB_FILES)))
 
 # adding $(ALL_LIB_FILES) as a build dependency here is a hack to make
 # sure they get evaluated. Once TW6630 lands and we have library file
index 4ddb51e6ac07ca6f00eb7d035fed163511d4807c..971192937914df8876ed9af0e3c15d4d43729c6f 100644 (file)
@@ -9,7 +9,8 @@ PYTHON ?= $(call dequote,$(CONFIG_PYTHON))
 # to invoke esptool.py (with or without serial port args)
 #
 # NB: esptool.py lives in the sdk/bin directory not the component directory
-ESPTOOLPY := $(PYTHON) $(COMPONENT_PATH)/esptool/esptool.py --chip esp32
+ESPTOOLPY_SRC := $(COMPONENT_PATH)/esptool/esptool.py
+ESPTOOLPY := $(PYTHON) $(ESPTOOLPY_SRC) --chip esp32
 ESPTOOLPY_SERIAL := $(ESPTOOLPY) --port $(ESPPORT) --baud $(ESPBAUD)
 
 # the no-stub argument is temporary until esptool.py fully supports compressed uploads
@@ -17,12 +18,14 @@ ESPTOOLPY_WRITE_FLASH=$(ESPTOOLPY_SERIAL) $(if $(CONFIG_ESPTOOLPY_COMPRESSED),--
 
 ESPTOOL_ALL_FLASH_ARGS += $(CONFIG_APP_OFFSET) $(APP_BIN)
 
-$(APP_BIN): $(APP_ELF)
+$(APP_BIN): $(APP_ELF) $(ESPTOOLPY_SRC)
        $(Q) $(ESPTOOLPY) elf2image -o $@ $<
 
-flash: all_binaries
+flash: all_binaries $(ESPTOOLPY_SRC)
        @echo "Flashing project app to $(CONFIG_APP_OFFSET)..."
        $(Q) $(ESPTOOLPY_WRITE_FLASH) $(ESPTOOL_ALL_FLASH_ARGS)
 
-app-flash: $(APP_BIN)
+app-flash: $(APP_BIN) $(ESPTOOLPY_SRC)
        $(Q) $(ESPTOOLPY_WRITE_FLASH) $(CONFIG_APP_OFFSET) $(APP_BIN)
+
+$(eval $(call SubmoduleRequiredForFiles,$(ESPTOOLPY_SRC)))
index 7f372cc3051be550a2b317817fed644c503afbe3..adae46738e9e9163a0ec10cccbbbbcf0cc75528d 100644 (file)
@@ -49,6 +49,23 @@ summary := @echo
 details := @true
 endif
 
+# Pseudo-target to handle the case where submodules need to be
+# re-initialised.
+#
+# $(eval $(call SubmoduleRequiredForFiles,FILENAMES)) to create a target that
+# automatically runs 'git submodule update --init' if those files
+# are missing, and fails if this is not possible.
+define SubmoduleRequiredForFiles
+$(1):
+       @echo "WARNING: Missing submodule for $$@..."
+       $(Q) [ -d ${IDF_PATH}/.git ] || ( echo "ERROR: esp-idf must be cloned from git to work."; exit 1)
+       $(Q) [ -x $(which git) ] || ( echo "ERROR: Need to run 'git submodule --init' in esp-idf root directory."; exit 1)
+       @echo "Attempting 'git submodule update --init' in esp-idf root directory..."
+       cd ${IDF_PATH} && git submodule update --init
+endef
+
+
+
 # General make utilities
 
 # convenience variable for printing an 80 asterisk wide separator line