diff --git a/components/bootloader/Makefile.projbuild b/components/bootloader/Makefile.projbuild index 0af467de47..35be94e4a3 100644 --- a/components/bootloader/Makefile.projbuild +++ b/components/bootloader/Makefile.projbuild @@ -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 diff --git a/components/esptool_py/Makefile.projbuild b/components/esptool_py/Makefile.projbuild index d00158c7f9..b5992a4d96 100644 --- a/components/esptool_py/Makefile.projbuild +++ b/components/esptool_py/Makefile.projbuild @@ -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 diff --git a/make/common.mk b/make/common.mk index c0487d2737..605b8ab862 100644 --- a/make/common.mk +++ b/make/common.mk @@ -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 diff --git a/make/project_config.mk b/make/project_config.mk index a32c74a380..187d1ac282 100644 --- a/make/project_config.mk +++ b/make/project_config.mk @@ -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