]> granicus.if.org Git - esp-idf/commitdiff
build system: Fix bug where erase_flash was always invoked for flash
authorAngus Gratton <angus@espressif.com>
Thu, 22 Dec 2016 05:32:19 +0000 (16:32 +1100)
committerAngus Gratton <angus@espressif.com>
Thu, 22 Dec 2016 05:37:28 +0000 (16:37 +1100)
Order-only prerequisites do not work for phony targets!

components/bootloader/Makefile.projbuild
components/esptool_py/Makefile.projbuild
make/common.mk
make/project_config.mk

index 0af467de472c04ef5e4caf45778f647ae803aec4..35be94e4a39b5630b33999c22d4af50001349aa0 100644 (file)
@@ -43,7 +43,7 @@ bootloader: $(BOOTLOADER_BIN)
 
 ESPTOOL_ALL_FLASH_ARGS += $(BOOTLOADER_OFFSET) $(BOOTLOADER_BIN)
 
-bootloader-flash: $(BOOTLOADER_BIN) | erase_flash
+bootloader-flash: $(BOOTLOADER_BIN) $(call prereq_if_explicit,erase_flash)
        $(ESPTOOLPY_WRITE_FLASH) 0x1000 $^
 
 else ifdef CONFIG_SECURE_BOOTLOADER_ONE_TIME_FLASH
index d00158c7f9d66801e7f2e00a9d2baa968241933e..b5992a4d963cf9c7c1f24b651404dfa73a8c1bd1 100644 (file)
@@ -43,14 +43,14 @@ APP_BIN_UNSIGNED ?= $(APP_BIN)
 $(APP_BIN_UNSIGNED): $(APP_ELF) $(ESPTOOLPY_SRC)
        $(ESPTOOLPY) elf2image $(ESPTOOL_FLASH_OPTIONS) $(ESPTOOL_ELF2IMAGE_OPTIONS) -o $@ $<
 
-flash: all_binaries $(ESPTOOLPY_SRC) | erase_flash
+flash: all_binaries $(ESPTOOLPY_SRC) $(call prereq_if_explicit,erase_flash)
        @echo "Flashing binaries to serial port $(ESPPORT) (app at offset $(CONFIG_APP_OFFSET))..."
 ifdef CONFIG_SECURE_BOOT_ENABLED
        @echo "(Secure boot enabled, so bootloader not flashed automatically. See 'make bootloader' output)"
 endif
        $(ESPTOOLPY_WRITE_FLASH) $(ESPTOOL_ALL_FLASH_ARGS)
 
-app-flash: $(APP_BIN) $(ESPTOOLPY_SRC) | erase_flash
+app-flash: $(APP_BIN) $(ESPTOOLPY_SRC) $(call prereq_if_explicit,erase_flash)
        @echo "Flashing app to serial port $(ESPPORT), offset $(CONFIG_APP_OFFSET)..."
        $(ESPTOOLPY_WRITE_FLASH) $(CONFIG_APP_OFFSET) $(APP_BIN)
 
@@ -58,7 +58,8 @@ app-flash: $(APP_BIN) $(ESPTOOLPY_SRC) | erase_flash
 # at the project level as long as qualified path
 COMPONENT_SUBMODULES += $(COMPONENT_PATH)/esptool
 
-.PHONY: erase_flash
 erase_flash:
        @echo "Erasing entire flash..."
        $(ESPTOOLPY_SERIAL) erase_flash
+
+.PHONY: erase_flash
index c0487d27378e00d6ee4fa6bb3866e87e4409ba00..605b8ab862916a16cd34310fb0496aa83c273f88 100644 (file)
@@ -54,3 +54,17 @@ endef
 define resolvepath
 $(foreach dir,$(1),$(if $(filter /%,$(dir)),$(dir),$(subst //,/,$(2)/$(dir))))
 endef
+
+
+# macro to include a target only if it's on the list of targets that make
+# was invoked with
+#
+# This allows you to have something like an "order-only phony prerequisite",
+# ie a prerequisite that determines an order phony targets have to run in.
+#
+# Because normal order-only prerequisites don't work with phony targets.
+#
+# example $(call prereq_if_explicit,erase_flash)
+define prereq_if_explicit
+$(filter $(1),$(MAKECMDGOALS))
+endef
index a32c74a380a5dd0016b05b1250bf0660cbc96c16..187d1ac28257ad43577b1929e6296bf013c94ff8 100644 (file)
@@ -26,7 +26,7 @@ menuconfig: $(KCONFIG_TOOL_DIR)/mconf $(IDF_PATH)/Kconfig
        $(KCONFIG_TOOL_ENV) $(KCONFIG_TOOL_DIR)/mconf $(IDF_PATH)/Kconfig
 
 ifeq ("$(wildcard $(SDKCONFIG))","")
-ifeq ("$(filter defconfig,$(MAKECMDGOALS))","")
+ifeq ("$(call prereq_if_explicit,defconfig)","")
 # if not configuration is present and defconfig is not a target, run makeconfig
 $(SDKCONFIG): menuconfig
 else