]> granicus.if.org Git - esp-idf/commitdiff
build system: Refactor component.mk to not need component_common.mk
authorAngus Gratton <angus@espressif.com>
Thu, 10 Nov 2016 02:20:55 +0000 (13:20 +1100)
committerAngus Gratton <angus@espressif.com>
Thu, 10 Nov 2016 04:52:22 +0000 (15:52 +1100)
New makefile component_wrapper.mk allows some variables to be set
before component.mk is evaluated. This properly fixes problems with
sdkconfig being hard to access in all phases of the build.

Including component_common.mk is no longer necessary and will print a
deprecation warning for components which use it.

31 files changed:
components/bootloader/Makefile.projbuild
components/bootloader/src/main/component.mk
components/bt/component.mk
components/driver/component.mk
components/esp32/component.mk
components/expat/component.mk
components/freertos/component.mk
components/json/component.mk
components/log/component.mk
components/lwip/component.mk
components/mbedtls/component.mk
components/newlib/component.mk
components/nghttp/component.mk
components/nvs_flash/component.mk
components/openssl/component.mk
components/spi_flash/component.mk
components/tcpip_adapter/component.mk
components/vfs/component.mk
components/wpa_supplicant/component.mk
components/xtensa-debug-module/component.mk
examples/01_hello_world/main/component.mk
examples/02_blink/main/component.mk
examples/03_http_request/main/component.mk
examples/04_https_request/main/component.mk
examples/05_ble_adv/main/component.mk
examples/06_sntp/main/component.mk
make/common.mk
make/component_common.mk
make/component_wrapper.mk [new file with mode: 0644]
make/project.mk
make/project_config.mk

index 5bcd77b36fc728906286ca87db2670fa3a0df8ab..c03288d107cfa81c0257454c6c8c2e395ed590e0 100644 (file)
@@ -20,7 +20,7 @@ BOOTLOADER_MAKE=+$(MAKE) -C $(BOOTLOADER_COMPONENT_PATH)/src \
 
 .PHONY: bootloader-clean bootloader-flash bootloader $(BOOTLOADER_BIN)
 
-$(BOOTLOADER_BIN):
+$(BOOTLOADER_BIN): $(SDKCONFIG_MAKEFILE)
        $(Q) $(BOOTLOADER_MAKE) $@
 
 bootloader-clean:
index bd1dcf4d9035b5c56770ddc2b21563c84a9a82c3..01b07b949831113ff42c3043408c8eb52cf1bd9b 100644 (file)
@@ -1,12 +1,9 @@
 #
-# Main Makefile. This is basically the same as a component makefile.
+# Main bootloader Makefile.
 #
-# This Makefile should, at the very least, just include $(IDF_PATH)/make/component_common.mk. By default, 
-# this will take the sources in the src/ directory, compile them and link them into 
-# lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable,
-# please read the esp-idf build system document if you need to do this.
+# This is basically the same as a component makefile, but in the case of the bootloader
+# we pull in bootloader-specific linker arguments.
 #
 
 COMPONENT_ADD_LDFLAGS := -L $(COMPONENT_PATH) -lmain -T esp32.bootloader.ld -T $(IDF_PATH)/components/esp32/ld/esp32.rom.ld
 
-include $(IDF_PATH)/make/component_common.mk
index 5addee2ceb25f1fc0d7b8ebb83a1f369f7f97c22..91620ddc14a74f541980836595fd42efb86113df 100644 (file)
@@ -12,8 +12,6 @@ COMPONENT_ADD_LDFLAGS := -lbt -L $(COMPONENT_PATH)/lib \
                            $(addprefix -l,$(LIBS)) \
                           $(LINKER_SCRIPTS)
 
-include $(IDF_PATH)/make/component_common.mk
-
 ALL_LIB_FILES := $(patsubst %,$(COMPONENT_PATH)/lib/lib%.a,$(LIBS))
 $(COMPONENT_LIBRARY): $(ALL_LIB_FILES)
 
index a19b131ef5e07474a439d476c136aaaa55ff646e..a208f6ae20f312894b9dd413866ad6b041a88763 100644 (file)
@@ -1,14 +1,8 @@
 #
 # Component Makefile
 #
-# This Makefile should, at the very least, just include $(SDK_PATH)/make/component.mk. By default, 
-# this will take the sources in this directory, compile them and link them into 
-# lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable,
-# please read the SDK documents if you need to do this.
-#
 
 COMPONENT_ADD_INCLUDEDIRS := include
 
 COMPONENT_PRIV_INCLUDEDIRS := include/driver
 
-include $(IDF_PATH)/make/component_common.mk
index 7e22b651832bf8151aa6bbf4b6f8ed3976a7362b..3866d3e4b94a2db7f8d6a3aa1d471d9690d23cf4 100644 (file)
@@ -1,12 +1,6 @@
 #
 # Component Makefile
 #
-# This Makefile should, at the very least, just include $(IDF_PATH)/make/component_common.mk. By default, 
-# this will take the sources in this directory, compile them and link them into 
-# lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable,
-# please read the esp-idf build system document if you need to do this.
-#
--include include/config/auto.conf
 
 COMPONENT_SRCDIRS := . hwcrypto
 
@@ -21,8 +15,6 @@ COMPONENT_ADD_LDFLAGS := -lesp32 \
                           -L $(COMPONENT_PATH)/ld \
                           $(LINKER_SCRIPTS)
 
-include $(IDF_PATH)/make/component_common.mk
-
 ALL_LIB_FILES := $(patsubst %,$(COMPONENT_PATH)/lib/lib%.a,$(LIBS))
 
 # automatically trigger a git submodule update
@@ -44,8 +36,6 @@ $(COMPONENT_LIBRARY): $(ALL_LIB_FILES)
 # saves us from having to add the target to a Makefile.projbuild
 $(COMPONENT_LIBRARY): esp32_out.ld
 
-# .. is BUILD_DIR_BASE here, as component makefiles
-# are evaluated with CWD=component build dir
 esp32_out.ld: $(COMPONENT_PATH)/ld/esp32.ld ../include/sdkconfig.h
        $(CC) -I ../include -C -P -x c -E $< -o $@
 
index 907b358a87d735ba57b5e034509e7c0f40fc6f93..0ee1199d1b056bac6cb0484826defa3aa9b2c408 100644 (file)
@@ -1,15 +1,9 @@
 #
 # Component Makefile
 #
-# This Makefile should, at the very least, just include $(SDK_PATH)/Makefile. By default, 
-# this will take the sources in this directory, compile them and link them into 
-# lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable,
-# please read the SDK documents if you need to do this.
-#
 COMPONENT_ADD_INCLUDEDIRS := port/include include/expat
 
 COMPONENT_SRCDIRS := library port
 
 CFLAGS += -Wno-unused-function -DHAVE_EXPAT_CONFIG_H
 
-include $(IDF_PATH)/make/component_common.mk
index 6702d1b95cd31684dbbb76fd405ba454c1f7d9d3..0240ea235f49bae3cb3df85b957c630e30a60347 100644 (file)
@@ -6,4 +6,3 @@ COMPONENT_ADD_LDFLAGS = -l$(COMPONENT_NAME) -Wl,--undefined=uxTopUsedPriority
 COMPONENT_ADD_INCLUDEDIRS := include
 COMPONENT_PRIV_INCLUDEDIRS := include/freertos
 
-include $(IDF_PATH)/make/component_common.mk
index 311a902f9994e884ffa2c8ffe8bdc258d3f21921..2dd6ea8b87dc89ff53146b34bd2ea6d21723dd32 100644 (file)
@@ -1,13 +1,7 @@
 #
 # Component Makefile
 #
-# This Makefile should, at the very least, just include $(SDK_PATH)/Makefile. By default, 
-# this will take the sources in this directory, compile them and link them into 
-# lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable,
-# please read the SDK documents if you need to do this.
-#
 COMPONENT_ADD_INCLUDEDIRS := include port/include
 
 COMPONENT_SRCDIRS := library port
 
-include $(IDF_PATH)/make/component_common.mk
index ef497a7ecb7e313f663f73ec12da22b16648340c..c2c4c03a1a6e2dc2a6bd58c0dd72d89d61b5d89d 100755 (executable)
@@ -1,3 +1,5 @@
-COMPONENT_ADD_INCLUDEDIRS := include
+#
+# Component Makefile
+#
+# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
 
-include $(IDF_PATH)/make/component_common.mk
index 5d1502004784c6adf091c5c48e117ba4e9826dd0..49fc644ae4b68a20a94192e6d61a829056d18ccd 100644 (file)
@@ -8,4 +8,3 @@ COMPONENT_SRCDIRS := api apps/sntp apps core/ipv4 core/ipv6 core netif port/free
 
 CFLAGS += -Wno-address -Wno-unused-variable -Wno-unused-but-set-variable
 
-include $(IDF_PATH)/make/component_common.mk
index 98838d4d7b36a32c32ee27e821ed2d03b2f074ae..bd7209a926f6105d1db1bc2e2d2aa074bfa7e35f 100644 (file)
@@ -6,4 +6,3 @@ COMPONENT_ADD_INCLUDEDIRS := port/include include
 
 COMPONENT_SRCDIRS := library port
 
-include $(IDF_PATH)/make/component_common.mk
index 0648946c20a322b256bfb44a9857f71810e39294..4f567242b6ee8b16e9b970cd77a382a9b02b0068 100644 (file)
@@ -2,4 +2,3 @@ COMPONENT_ADD_LDFLAGS := $(COMPONENT_PATH)/lib/libc.a $(COMPONENT_PATH)/lib/libm
 
 COMPONENT_ADD_INCLUDEDIRS := include platform_include
 
-include $(IDF_PATH)/make/component_common.mk
index a4dca5cf70ebb64b20ffbbb2236a755fa0aa00b3..d2cd0455f524810daef5b218b21ac045f31ca6ba 100644 (file)
@@ -5,5 +5,3 @@
 COMPONENT_ADD_INCLUDEDIRS := port/include include
 
 COMPONENT_SRCDIRS := library port
-
-include $(IDF_PATH)/make/component_common.mk
\ No newline at end of file
index 02ff8cf038a121a842e7f20bffae12b59224300a..a905ca689eeada9e41d5bd921f6c3e0bf370e136 100755 (executable)
@@ -6,4 +6,3 @@ COMPONENT_ADD_INCLUDEDIRS := include
 
 COMPONENT_SRCDIRS := src
 
-include $(IDF_PATH)/make/component_common.mk
index 2dfcc6b38d94bca3474e79f3335a926db3866c0d..be40549d20718c57b75e987507377a1908c41cd3 100644 (file)
@@ -7,4 +7,3 @@ COMPONENT_PRIV_INCLUDEDIRS := include/internal include/platform include/openssl
 
 COMPONENT_SRCDIRS := library platform
 
-include $(IDF_PATH)/make/component_common.mk
index 459da06419acc2550863331d3012df5af10fec26..d511eedb8ed2f10bc4ac46037463a0854362d86e 100755 (executable)
@@ -5,4 +5,3 @@ ifdef IS_BOOTLOADER_BUILD
 COMPONENT_OBJS := spi_flash_rom_patch.o
 endif
 
-include $(IDF_PATH)/make/component_common.mk
index a57ae0b12b8a39c85037cf23f9213dcd1c0b7914..c2c4c03a1a6e2dc2a6bd58c0dd72d89d61b5d89d 100755 (executable)
@@ -1,5 +1,5 @@
 #
 # Component Makefile
 #
+# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
 
-include $(IDF_PATH)/make/component_common.mk
index fccf88db8adf9552c287e84eed0e698434f9bd5f..c2c4c03a1a6e2dc2a6bd58c0dd72d89d61b5d89d 100755 (executable)
@@ -1 +1,5 @@
-include $(IDF_PATH)/make/component_common.mk
+#
+# Component Makefile
+#
+# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
+
index cb6b06652f17611062c941281252d13133c02915..b01eb83be9bd15cdfd719c181a4e0b22ad32b992 100644 (file)
@@ -2,5 +2,3 @@ COMPONENT_ADD_INCLUDEDIRS := include port/include
 COMPONENT_SRCDIRS := src/crypto
 
 CFLAGS += -DEMBEDDED_SUPP -D__ets__ -Wno-strict-aliasing
-
-include $(IDF_PATH)/make/component_common.mk
index a57ae0b12b8a39c85037cf23f9213dcd1c0b7914..308f64f0ea1ef4187292c39ff36c1475a022389b 100755 (executable)
@@ -1,5 +1,4 @@
 #
 # Component Makefile
 #
-
-include $(IDF_PATH)/make/component_common.mk
+# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
index 24356f23ed2e292e153170d8edda3dd5dce430aa..4d3b30caf379ffdb14a2840a82052a8286201fae 100644 (file)
@@ -1,10 +1,5 @@
 #
 # Main Makefile. This is basically the same as a component makefile.
 #
-# This Makefile should, at the very least, just include $(SDK_PATH)/make/component_common.mk. By default, 
-# this will take the sources in the src/ directory, compile them and link them into 
-# lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable,
-# please read the ESP-IDF documents if you need to do this.
-#
+# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
 
-include $(IDF_PATH)/make/component_common.mk
index 24356f23ed2e292e153170d8edda3dd5dce430aa..b4fa72791c7423f91fa017f0f94775c22ea2c7cc 100644 (file)
@@ -1,10 +1,4 @@
 #
 # Main Makefile. This is basically the same as a component makefile.
 #
-# This Makefile should, at the very least, just include $(SDK_PATH)/make/component_common.mk. By default, 
-# this will take the sources in the src/ directory, compile them and link them into 
-# lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable,
-# please read the ESP-IDF documents if you need to do this.
-#
-
-include $(IDF_PATH)/make/component_common.mk
+# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
index 24356f23ed2e292e153170d8edda3dd5dce430aa..b4fa72791c7423f91fa017f0f94775c22ea2c7cc 100644 (file)
@@ -1,10 +1,4 @@
 #
 # Main Makefile. This is basically the same as a component makefile.
 #
-# This Makefile should, at the very least, just include $(SDK_PATH)/make/component_common.mk. By default, 
-# this will take the sources in the src/ directory, compile them and link them into 
-# lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable,
-# please read the ESP-IDF documents if you need to do this.
-#
-
-include $(IDF_PATH)/make/component_common.mk
+# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
index 24356f23ed2e292e153170d8edda3dd5dce430aa..4d3b30caf379ffdb14a2840a82052a8286201fae 100644 (file)
@@ -1,10 +1,5 @@
 #
 # Main Makefile. This is basically the same as a component makefile.
 #
-# This Makefile should, at the very least, just include $(SDK_PATH)/make/component_common.mk. By default, 
-# this will take the sources in the src/ directory, compile them and link them into 
-# lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable,
-# please read the ESP-IDF documents if you need to do this.
-#
+# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
 
-include $(IDF_PATH)/make/component_common.mk
index 24356f23ed2e292e153170d8edda3dd5dce430aa..b4fa72791c7423f91fa017f0f94775c22ea2c7cc 100644 (file)
@@ -1,10 +1,4 @@
 #
 # Main Makefile. This is basically the same as a component makefile.
 #
-# This Makefile should, at the very least, just include $(SDK_PATH)/make/component_common.mk. By default, 
-# this will take the sources in the src/ directory, compile them and link them into 
-# lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable,
-# please read the ESP-IDF documents if you need to do this.
-#
-
-include $(IDF_PATH)/make/component_common.mk
+# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
index 24356f23ed2e292e153170d8edda3dd5dce430aa..b4fa72791c7423f91fa017f0f94775c22ea2c7cc 100644 (file)
@@ -1,10 +1,4 @@
 #
 # Main Makefile. This is basically the same as a component makefile.
 #
-# This Makefile should, at the very least, just include $(SDK_PATH)/make/component_common.mk. By default, 
-# this will take the sources in the src/ directory, compile them and link them into 
-# lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable,
-# please read the ESP-IDF documents if you need to do this.
-#
-
-include $(IDF_PATH)/make/component_common.mk
+# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
index 6183cfbc464058147318d742130c316cba8f9765..779811f1ad7df10680fafce31bb17759651b368e 100644 (file)
@@ -1,7 +1,15 @@
-# Functionality common to both top-level project makefile
-# and component makefiles
+# Functionality common to both top-level project makefile (project.mk)
+# and component makefiles (component_wrapper.mk)
 #
 
+# Include project config makefile, if it exists.
+#
+# (Note that we only rebuild this makefile automatically for some
+# targets, see project_config.mk for details.)
+SDKCONFIG_MAKEFILE ?= $(abspath $(BUILD_DIR_BASE)/include/config/auto.conf)
+-include $(SDKCONFIG_MAKEFILE)
+export SDKCONFIG_MAKEFILE  # sub-makes (like bootloader) will reuse this path
+
 #Handling of V=1/VERBOSE=1 flag
 #
 # if V=1, $(summary) does nothing and $(details) will echo extra details
index a9598a23ba3f6140eab50b813627aba20bcbde7c..32af3c7c06fa640896898ee81ad03c2950ebc27e 100644 (file)
@@ -1,135 +1,3 @@
-# Component common makefile
-#
-# This Makefile gets included in the Makefile of all the components to set the correct include paths etc.
-# PWD is the build directory of the component and the top Makefile is the one in the
-# component source dir.
-#
-# The way the Makefile differentiates between those two is by looking at the environment
-# variable PROJECT_PATH. If this is set (to the basepath of the project), we're building a
-# component and its Makefile has included this makefile. If not, we're building the entire project.
-#
+$(warning Deprecated feature: It is no longer necessary to include component_common.mk.)
+$(warning The line "include $$(IDF_PATH)/make/component_common.mk" can be removed from component.mk files.)
 
-#
-# This Makefile requires the environment variable IDF_PATH to be set
-# to the top-level directory where ESP-IDF is located (the directory
-# containing this 'make' directory).
-#
-
-ifeq ("$(PROJECT_PATH)","")
-$(error Make was invoked from $(CURDIR). However please do not run make from the sdk or a component directory; invoke make from the project directory. See the ESP-IDF README for details.)
-endif
-
-# Find the path to the component
-COMPONENT_PATH := $(abspath $(dir $(firstword $(MAKEFILE_LIST))))
-export COMPONENT_PATH
-
-include $(IDF_PATH)/make/common.mk
-
-#Some of these options are overridable by the component's component.mk Makefile
-
-#Name of the component
-COMPONENT_NAME ?= $(lastword $(subst /, ,$(realpath $(COMPONENT_PATH))))
-
-#Absolute path of the .a file
-COMPONENT_LIBRARY := lib$(COMPONENT_NAME).a
-
-#Source dirs a component has. Default to root directory of component.
-COMPONENT_SRCDIRS ?= .
-
-#Object files which need to be linked into the library
-#By default we take all .c/.S files in the component directory.
-ifeq ("$(COMPONENT_OBJS)", "")
-#Find all source files in all COMPONENT_SRCDIRS
-COMPONENT_OBJS := $(foreach compsrcdir,$(COMPONENT_SRCDIRS),$(patsubst %.c,%.o,$(wildcard $(COMPONENT_PATH)/$(compsrcdir)/*.c)))
-COMPONENT_OBJS += $(foreach compsrcdir,$(COMPONENT_SRCDIRS),$(patsubst %.cpp,%.o,$(wildcard $(COMPONENT_PATH)/$(compsrcdir)/*.cpp)))
-COMPONENT_OBJS += $(foreach compsrcdir,$(COMPONENT_SRCDIRS),$(patsubst %.S,%.o,$(wildcard $(COMPONENT_PATH)/$(compsrcdir)/*.S)))
-#Make relative by removing COMPONENT_PATH from all found object paths
-COMPONENT_OBJS := $(patsubst $(COMPONENT_PATH)/%,%,$(COMPONENT_OBJS))
-endif
-
-#By default, include only the include/ dir.
-COMPONENT_ADD_INCLUDEDIRS ?= include
-COMPONENT_ADD_LDFLAGS ?= -l$(COMPONENT_NAME)
-
-#If we're called to compile something, we'll get passed the COMPONENT_INCLUDES
-#variable with all the include dirs from all the components in random order. This
-#means we can accidentally grab a header from another component before grabbing our own.
-#To make sure that does not happen, re-order the includes so ours come first.
-OWN_INCLUDES:=$(abspath $(addprefix $(COMPONENT_PATH)/,$(COMPONENT_ADD_INCLUDEDIRS) $(COMPONENT_PRIV_INCLUDEDIRS)))
-COMPONENT_INCLUDES := $(OWN_INCLUDES) $(filter-out $(OWN_INCLUDES),$(COMPONENT_INCLUDES))
-
-# macro to generate relative paths inside component_project_vars.mk, whenever possible
-# ie put literal $(IDF_PATH), $(PROJECT_PATH) and $(BUILD_DIR_BASE) into the generated
-# makefiles where possible.
-#
-# This means if directories move (breaking absolute paths), don't need to 'make clean'
-define MakeRelativePath
-$(subst $(IDF_PATH),$$(IDF_PATH),$(subst $(PROJECT_PATH),$$(PROJECT_PATH),$(subst $(BUILD_DIR_BASE),\$$(BUILD_DIR_BASE),$(1))))
-endef
-
-# This target generates component_project_vars.mk for the
-# component. This is used to take component.mk variables
-# COMPONENT_ADD_INCLUDEDIRS, COMPONENT_ADD_LDFLAGS and
-# COMPONENT_DEPENDS and inject those into the project makefile.
-#
-# The target here has no dependencies, as the parent target in
-# project.mk evaluates dependencies before calling down to here. See
-# GenerateComponentTargets macro in project.mk.
-#
-# If you are thinking of editing the output of this makefile for a
-# component-specific feature, please don't! What you want is a
-# Makefile.projbuild for your component (see docs/build-system.rst for more.)
-component_project_vars.mk::
-       $(details) "Building component project variables list $(abspath $@)"
-       @echo '# Automatically generated build file. Do not edit.' > $@
-       @echo 'COMPONENT_INCLUDES += $(call MakeRelativePath,$(addprefix $(COMPONENT_PATH)/,$(COMPONENT_ADD_INCLUDEDIRS)))' >> $@
-       @echo 'COMPONENT_LDFLAGS += $(call MakeRelativePath,$(COMPONENT_ADD_LDFLAGS))' >> $@
-       @echo '$(COMPONENT_NAME)-build: $(addsuffix -build,$(COMPONENT_DEPENDS))' >> $@
-
-#Targets for build/clean. Use builtin recipe if component Makefile
-#hasn't defined its own.
-ifeq ("$(COMPONENT_OWNBUILDTARGET)", "")
-build: $(COMPONENT_LIBRARY)
-       @mkdir -p $(COMPONENT_SRCDIRS)
-
-#Build the archive. We remove the archive first, otherwise ar will get confused if we update
-#an archive when multiple filenames have the same name (src1/test.o and src2/test.o)
-$(COMPONENT_LIBRARY): $(COMPONENT_OBJS)
-       $(summary) AR $@
-       $(Q) rm -f $@
-       $(Q) $(AR) cru $@ $(COMPONENT_OBJS)
-endif
-
-CLEAN_FILES = $(COMPONENT_LIBRARY) $(COMPONENT_OBJS) $(COMPONENT_OBJS:.o=.d) $(COMPONENT_EXTRA_CLEAN) component_project_vars.mk
-
-ifeq ("$(COMPONENT_OWNCLEANTARGET)", "")
-clean:
-       $(summary) RM $(CLEAN_FILES)
-       $(Q) rm -f $(CLEAN_FILES)
-endif
-
-#Include all dependency files already generated
--include $(COMPONENT_OBJS:.o=.d)
-
-#This pattern is generated for each COMPONENT_SRCDIR to compile the files in it.
-define GenerateCompileTargets
-# $(1) - directory containing source files, relative to $(COMPONENT_PATH)
-$(1)/%.o: $$(COMPONENT_PATH)/$(1)/%.c | $(1)
-       $$(summary) CC $$@
-       $$(Q) $$(CC) $$(CFLAGS) $(CPPFLAGS) $$(addprefix -I ,$$(COMPONENT_INCLUDES)) $$(addprefix -I ,$$(COMPONENT_EXTRA_INCLUDES)) -I$(1) -c $$< -o $$@
-
-$(1)/%.o: $$(COMPONENT_PATH)/$(1)/%.cpp | $(1)
-       $$(summary) CXX $$@
-       $$(Q) $$(CXX) $$(CXXFLAGS) $(CPPFLAGS) $$(addprefix -I,$$(COMPONENT_INCLUDES)) $$(addprefix -I,$$(COMPONENT_EXTRA_INCLUDES)) -I$(1) -c $$< -o $$@
-
-$(1)/%.o: $$(COMPONENT_PATH)/$(1)/%.S | $(1)
-       $$(summary) AS $$@
-       $$(Q) $$(CC) $$(CFLAGS) $(CPPFLAGS) $$(addprefix -I ,$$(COMPONENT_INCLUDES)) $$(addprefix -I ,$$(COMPONENT_EXTRA_INCLUDES)) -I$(1) -c $$< -o $$@
-
-# CWD is build dir, create the build subdirectory if it doesn't exist
-$(1):
-       @mkdir -p $(1)
-endef
-
-#Generate all the compile target recipes
-$(foreach srcdir,$(COMPONENT_SRCDIRS), $(eval $(call GenerateCompileTargets,$(srcdir))))
diff --git a/make/component_wrapper.mk b/make/component_wrapper.mk
new file mode 100644 (file)
index 0000000..68efe0d
--- /dev/null
@@ -0,0 +1,169 @@
+# Component wrapper makefile
+#
+# This makefile gets called recursively from the project make, once for each component.
+# COMPONENT_MAKEFILE is set to point at the component.mk file for the component itself,
+# which is included as part of this process (after default variables are defined).
+#
+# This makefile comprises multiple stages, marked in blocked comments below.
+#
+# CWD is the build directory of the component.
+
+ifeq ("$(PROJECT_PATH)","")
+$(error Make was invoked from $(CURDIR). However please do not run make from the sdk or a component directory; invoke make from the project directory. See the ESP-IDF README for details.)
+endif
+
+
+################################################################################
+# 1) Set default variables for the component build (including configuration
+#      loaded from sdkconfig.)
+################################################################################
+
+# Find the path to the component
+COMPONENT_PATH := $(abspath $(dir $(COMPONENT_MAKEFILE)))
+export COMPONENT_PATH
+
+# COMPONENT_BUILD_DIR is otherwise known as CWD for the build
+COMPONENT_BUILD_DIR := $(abspath .)
+
+# include elements common to both project & component makefiles
+# (includes project configuration set via menuconfig)
+include $(IDF_PATH)/make/common.mk
+
+# Some of the following defaults may be overriden by the component's component.mk makefile,
+# during the next step:
+
+# Name of the component
+COMPONENT_NAME := $(lastword $(subst /, ,$(realpath $(COMPONENT_PATH))))
+
+# Absolute path of the .a file
+COMPONENT_LIBRARY = lib$(COMPONENT_NAME).a
+
+# Source dirs a component has. Default to root directory of component.
+COMPONENT_SRCDIRS = .
+
+# By default, include only the include/ dir.
+COMPONENT_ADD_INCLUDEDIRS = include
+COMPONENT_ADD_LDFLAGS = -l$(COMPONENT_NAME)
+
+
+################################################################################
+# 2) Include the component.mk for the specific component (COMPONENT_MAKEFILE) to
+#     override variables & optionally define custom targets.
+################################################################################
+
+include $(COMPONENT_MAKEFILE)
+
+
+################################################################################
+# 3) Set variables that depend on values that may changed by component.mk
+################################################################################
+
+# Object files which need to be linked into the library
+# By default we take all .c, .cpp & .S files in COMPONENT_SRCDIRS.
+ifeq ("$(COMPONENT_OBJS)", "")
+# Find all source files in all COMPONENT_SRCDIRS
+COMPONENT_OBJS := $(foreach compsrcdir,$(COMPONENT_SRCDIRS),$(patsubst %.c,%.o,$(wildcard $(COMPONENT_PATH)/$(compsrcdir)/*.c)))
+COMPONENT_OBJS += $(foreach compsrcdir,$(COMPONENT_SRCDIRS),$(patsubst %.cpp,%.o,$(wildcard $(COMPONENT_PATH)/$(compsrcdir)/*.cpp)))
+COMPONENT_OBJS += $(foreach compsrcdir,$(COMPONENT_SRCDIRS),$(patsubst %.S,%.o,$(wildcard $(COMPONENT_PATH)/$(compsrcdir)/*.S)))
+# Make relative by removing COMPONENT_PATH from all found object paths
+COMPONENT_OBJS := $(patsubst $(COMPONENT_PATH)/%,%,$(COMPONENT_OBJS))
+endif
+
+# If we're called to compile something, we'll get passed the COMPONENT_INCLUDES
+# variable with all the include dirs from all the components in random order. This
+# means we can accidentally grab a header from another component before grabbing our own.
+# To make sure that does not happen, re-order the includes so ours come first.
+OWN_INCLUDES:=$(abspath $(addprefix $(COMPONENT_PATH)/,$(COMPONENT_ADD_INCLUDEDIRS) $(COMPONENT_PRIV_INCLUDEDIRS)))
+COMPONENT_INCLUDES := $(OWN_INCLUDES) $(filter-out $(OWN_INCLUDES),$(COMPONENT_INCLUDES))
+
+
+################################################################################
+# 4) Define a target to generate component_project_vars.mk Makefile which
+# contains common per-component settings which are included directly in the
+# top-level project make
+################################################################################
+
+# macro to generate variable-relative paths inside component_project_vars.mk, whenever possible
+# ie put literal $(IDF_PATH), $(PROJECT_PATH) and $(BUILD_DIR_BASE) into the generated
+# makefiles where possible.
+#
+# This means if directories move (breaking absolute paths), don't need to 'make clean'
+define MakeVariablePath
+$(subst $(IDF_PATH),$$(IDF_PATH),$(subst $(PROJECT_PATH),$$(PROJECT_PATH),$(subst $(BUILD_DIR_BASE),\$$(BUILD_DIR_BASE),$(1))))
+endef
+
+# component_project_vars.mk target for the component. This is used to
+# take component.mk variables COMPONENT_ADD_INCLUDEDIRS,
+# COMPONENT_ADD_LDFLAGS and COMPONENT_DEPENDS and inject those into
+# the project make pass.
+#
+# The target here has no dependencies, as the parent target in
+# project.mk evaluates dependencies before calling down to here. See
+# GenerateComponentTargets macro in project.mk.
+#
+# If you are thinking of editing the output of this target for a
+# component-specific feature, please don't! What you want is a
+# Makefile.projbuild for your component (see docs/build-system.rst for
+# more.)
+component_project_vars.mk::
+       $(details) "Building component project variables list $(abspath $@)"
+       @echo '# Automatically generated build file. Do not edit.' > $@
+       @echo 'COMPONENT_INCLUDES += $(call MakeVariablePath,$(addprefix $(COMPONENT_PATH)/,$(COMPONENT_ADD_INCLUDEDIRS)))' >> $@
+       @echo 'COMPONENT_LDFLAGS += $(call MakeVariablePath,$(COMPONENT_ADD_LDFLAGS))' >> $@
+       @echo '$(COMPONENT_NAME)-build: $(addsuffix -build,$(COMPONENT_DEPENDS))' >> $@
+
+
+################################################################################
+# 5) If COMPONENT_OWNBUILDTARGET / COMPONENT_OWNCLEANTARGET is not set by component.mk,
+#      define default build, clean, etc. targets
+################################################################################
+
+# If COMPONENT_OWNBUILDTARGET is not set, define a phony build target and
+# a COMPONENT_LIBRARY link target.
+ifeq ("$(COMPONENT_OWNBUILDTARGET)", "")
+.PHONY: build
+build: $(COMPONENT_LIBRARY)
+       @mkdir -p $(COMPONENT_SRCDIRS)
+
+# Build the archive. We remove the archive first, otherwise ar will get confused if we update
+# an archive when multiple filenames have the same name (src1/test.o and src2/test.o)
+$(COMPONENT_LIBRARY): $(COMPONENT_OBJS)
+       $(summary) AR $@
+       $(Q) rm -f $@
+       $(Q) $(AR) cru $@ $(COMPONENT_OBJS)
+endif
+
+# If COMPONENT_OWNCLEANTARGET is not set, define a phony clean target
+ifeq ("$(COMPONENT_OWNCLEANTARGET)", "")
+CLEAN_FILES = $(COMPONENT_LIBRARY) $(COMPONENT_OBJS) $(COMPONENT_OBJS:.o=.d) $(COMPONENT_EXTRA_CLEAN) component_project_vars.mk
+.PHONY: clean
+clean:
+       $(summary) RM $(CLEAN_FILES)
+       $(Q) rm -f $(CLEAN_FILES)
+endif
+
+# Include all dependency files already generated
+-include $(COMPONENT_OBJS:.o=.d)
+
+# This pattern is generated for each COMPONENT_SRCDIR to compile the files in it.
+define GenerateCompileTargets
+# $(1) - directory containing source files, relative to $(COMPONENT_PATH)
+$(1)/%.o: $$(COMPONENT_PATH)/$(1)/%.c | $(1)
+       $$(summary) CC $$@
+       $$(Q) $$(CC) $$(CFLAGS) $$(CPPFLAGS) $$(addprefix -I ,$$(COMPONENT_INCLUDES)) $$(addprefix -I ,$$(COMPONENT_EXTRA_INCLUDES)) -I$(1) -c $$< -o $$@
+
+$(1)/%.o: $$(COMPONENT_PATH)/$(1)/%.cpp | $(1)
+       $$(summary) CXX $$@
+       $$(Q) $$(CXX) $$(CXXFLAGS) $$(CPPFLAGS) $$(addprefix -I,$$(COMPONENT_INCLUDES)) $$(addprefix -I,$$(COMPONENT_EXTRA_INCLUDES)) -I$(1) -c $$< -o $$@
+
+$(1)/%.o: $$(COMPONENT_PATH)/$(1)/%.S | $(1)
+       $$(summary) AS $$@
+       $$(Q) $$(CC) $$(CPPFLAGS) $$(addprefix -I ,$$(COMPONENT_INCLUDES)) $$(addprefix -I ,$$(COMPONENT_EXTRA_INCLUDES)) -I$(1) -c $$< -o $$@
+
+# CWD is build dir, create the build subdirectory if it doesn't exist
+$(1):
+       @mkdir -p $(1)
+endef
+
+# Generate all the compile target patterns
+$(foreach srcdir,$(COMPONENT_SRCDIRS), $(eval $(call GenerateCompileTargets,$(srcdir))))
index 17d9e99c0ce83c1302ef71d1bc1041ac18b56fc5..f9cf20a3295454e24ecf856902d5addc9057e321 100644 (file)
@@ -48,80 +48,73 @@ PROJECT_PATH := $(abspath $(dir $(firstword $(MAKEFILE_LIST))))
 export PROJECT_PATH
 endif
 
-COMMON_MAKEFILES := $(abspath $(IDF_PATH)/make/project.mk $(IDF_PATH)/make/common.mk $(IDF_PATH)/make/component_common.mk)
+# A list of the "common" makefiles, to use as a target dependency
+COMMON_MAKEFILES := $(abspath $(IDF_PATH)/make/project.mk $(IDF_PATH)/make/common.mk $(IDF_PATH)/make/component_wrapper.mk)
 export COMMON_MAKEFILES
 
-#The directory where we put all objects/libraries/binaries. The project Makefile can
-#configure this if needed.
+# The directory where we put all objects/libraries/binaries. The project Makefile can
+# configure this if needed.
 BUILD_DIR_BASE ?= $(PROJECT_PATH)/build
 export BUILD_DIR_BASE
 
-ifndef IS_BOOTLOADER_BUILD
-# Include project config file, if it exists.
-# (bootloader build doesn't need this, config is exported from top-level)
-#
-# (Note that we only rebuild auto.conf automatically for some targets,
-# see project_config.mk for details.)
-#
-SDKCONFIG_MAKEFILE := $(BUILD_DIR_BASE)/include/config/auto.conf
--include $(SDKCONFIG_MAKEFILE)
-export $(filter CONFIG_%,$(.VARIABLES))
-endif
-
-#Component directories. These directories are searched for components.
-#The project Makefile can override these component dirs, or define extra component directories.
+# Component directories. These directories are searched for components.
+# The project Makefile can override these component dirs, or define extra component directories.
 COMPONENT_DIRS ?= $(PROJECT_PATH)/components $(EXTRA_COMPONENT_DIRS) $(IDF_PATH)/components
 export COMPONENT_DIRS
 
-#The project Makefile can define a list of components, but if it does not do this we just take
-#all available components in the component dirs.
+# Source directories of the project itself (a special, project-specific component.) Defaults to only "main".
+SRCDIRS ?= main
+
+# The project Makefile can define a list of components, but if it does not do this we just take
+# all available components in the component dirs.
 ifeq ("$(COMPONENTS)","")
-#Find all component names. The component names are the same as the
-#directories they're in, so /bla/components/mycomponent/ -> mycomponent. We later use
-#the COMPONENT_DIRS bit to find back the component path.
+# Find all component names. The component names are the same as the
+# directories they're in, so /bla/components/mycomponent/ -> mycomponent. We then use
+# COMPONENT_DIRS to build COMPONENT_PATHS with the full path to each component.
 COMPONENTS := $(foreach dir,$(COMPONENT_DIRS),$(wildcard $(dir)/*))
 COMPONENTS := $(sort $(foreach comp,$(COMPONENTS),$(lastword $(subst /, ,$(comp)))))
 endif
 export COMPONENTS
 
-#Sources default to only "main"
-SRCDIRS ?= main
-
-#Here, we resolve and add all the components and source paths into absolute paths.
-#If a component exists in multiple COMPONENT_DIRS, we take the first match.
-#WARNING: These directories paths must be generated WITHOUT a trailing / so we
-#can use $(notdir x) to get the component name.
+# Resolve all of COMPONENTS into absolute paths in COMPONENT_PATHS.
+#
+# If a component name exists in multiple COMPONENT_DIRS, we take the first match.
+#
+# NOTE: These paths must be generated WITHOUT a trailing / so we
+# can use $(notdir x) to get the component name.
 COMPONENT_PATHS := $(foreach comp,$(COMPONENTS),$(firstword $(foreach dir,$(COMPONENT_DIRS),$(wildcard $(dir)/$(comp)))))
 COMPONENT_PATHS += $(abspath $(SRCDIRS))
 
-#A component is buildable if it has a component.mk makefile; we assume that a
-# 'make -C $(component dir) -f component.mk build' results in a lib$(componentname).a
+# A component is buildable if it has a component.mk makefile in it
 COMPONENT_PATHS_BUILDABLE := $(foreach cp,$(COMPONENT_PATHS),$(if $(wildcard $(cp)/component.mk),$(cp)))
 
-# Assemble global list of include dirs (COMPONENT_INCLUDES), and
-# LDFLAGS args (COMPONENT_LDFLAGS) supplied by each component.
+# Initialise a project-wide list of include dirs (COMPONENT_INCLUDES),
+# and LDFLAGS args (COMPONENT_LDFLAGS) supplied by each component.
+#
+# These variables are built up via the component_project_vars.mk
+# generated makefiles (one per component).
 COMPONENT_INCLUDES :=
 COMPONENT_LDFLAGS :=
 
-# include paths for generated "component project variables" targets with
-# COMPONENT_INCLUDES, COMPONENT_LDFLAGS & dependency targets
+# COMPONENT_PROJECT_VARS is the list of component_project_vars.mk generated makefiles
+# for each component.
+#
+# Including $(COMPONENT_PROJECT_VARS) builds the COMPONENT_INCLUDES,
+# COMPONENT_LDFLAGS variables and also targets for any inter-component
+# dependencies.
 #
-# See component_project_vars.mk target in component_common.mk
+# See the component_project_vars.mk target in component_wrapper.mk
 COMPONENT_PROJECT_VARS := $(addsuffix /component_project_vars.mk,$(notdir $(COMPONENT_PATHS_BUILDABLE)))
 COMPONENT_PROJECT_VARS := $(addprefix $(BUILD_DIR_BASE)/,$(COMPONENT_PROJECT_VARS))
 include $(COMPONENT_PROJECT_VARS)
 
-#Also add project include path, for top-level includes
+# Also add top-level project include path, for top-level includes
 COMPONENT_INCLUDES += $(abspath $(BUILD_DIR_BASE)/include/)
 
 export COMPONENT_INCLUDES
-export COMPONENT_LDFLAGS
-
-#Make sure submakes can also use this.
-export PROJECT_PATH
 
-#Include functionality common to both project & component
--include $(IDF_PATH)/make/common.mk
+# Set variables common to both project & component
+include $(IDF_PATH)/make/common.mk
 
 # Set default LDFLAGS
 
@@ -198,15 +191,15 @@ CXXFLAGS := $(strip \
 
 export CFLAGS CPPFLAGS CXXFLAGS
 
-#Set host compiler and binutils
+# Set host compiler and binutils
 HOSTCC := $(CC)
 HOSTLD := $(LD)
 HOSTAR := $(AR)
 HOSTOBJCOPY := $(OBJCOPY)
 export HOSTCC HOSTLD HOSTAR HOSTOBJCOPY
 
-#Set target compiler. Defaults to whatever the user has
-#configured as prefix + yer olde gcc commands
+# Set target compiler. Defaults to whatever the user has
+# configured as prefix + ye olde gcc commands
 CC := $(call dequote,$(CONFIG_TOOLPREFIX))gcc
 CXX := $(call dequote,$(CONFIG_TOOLPREFIX))c++
 LD := $(call dequote,$(CONFIG_TOOLPREFIX))ld
@@ -230,10 +223,10 @@ COMPONENT_PATH := $(1)
 endef
 $(foreach componentpath,$(COMPONENT_PATHS),$(eval $(call includeProjBuildMakefile,$(componentpath))))
 
-ifndef IS_BOOTLOADER_BUILD
 # once we know component paths, we can include the config generation targets
 #
 # (bootloader build doesn't need this, config is exported from top-level)
+ifndef IS_BOOTLOADER_BUILD
 include $(IDF_PATH)/make/project_config.mk
 endif
 
@@ -265,12 +258,14 @@ $(BUILD_DIR_BASE):
 #
 # Is recursively expanded by the GenerateComponentTargets macro
 define ComponentMake
-$(Q) +$(MAKE) -C $(BUILD_DIR_BASE)/$(2) -f $(1)/component.mk COMPONENT_PATH=$(1) COMPONENT_BUILD_DIR=$(BUILD_DIR_BASE)/$(2)
+$(Q) +$(MAKE) -C $(BUILD_DIR_BASE)/$(2) -f $(IDF_PATH)/make/component_wrapper.mk COMPONENT_MAKEFILE=$(1)/component.mk
 endef
 
-define GenerateComponentTargets
+# Generate top-level component-specific targets for each component
 # $(1) - path to component dir
 # $(2) - name of component
+#
+define GenerateComponentTargets
 .PHONY: $(2)-build $(2)-clean
 
 $(2)-build:
@@ -289,10 +284,19 @@ $(BUILD_DIR_BASE)/$(2):
 $(BUILD_DIR_BASE)/$(2)/lib$(2).a: $(2)-build
        $(details) "Target '$$^' responsible for '$$@'" # echo which build target built this file
 
-# add a target to generate the component_project_vars.mk files
-# that are used to inject variables into project make pass (see
-# component_project_vars.mk target in component_common.mk).
-$(BUILD_DIR_BASE)/$(2)/component_project_vars.mk: $(1)/component.mk $(COMMON_MAKEFILES) $(SDKCONFIG) | $(BUILD_DIR_BASE)/$(2)
+# add a target to generate the component_project_vars.mk files that
+# are used to inject variables into project make pass (see matching
+# component_project_vars.mk target in component_wrapper.mk).
+#
+# If any component_project_vars.mk file is out of date, the make
+# process will call this target to rebuild it and then restart.
+#
+# Note: $(SDKCONFIG) is a normal prereq as we need to rebuild these
+# files whenever the config changes. $(SDKCONFIG_MAKEFILE) is an
+# order-only prereq because if it hasn't been rebuilt, we need to
+# build it first - but including it as a normal prereq can lead to
+# infinite restarts as the conf process will keep updating it.
+$(BUILD_DIR_BASE)/$(2)/component_project_vars.mk: $(1)/component.mk $(COMMON_MAKEFILES) $(SDKCONFIG) | $(BUILD_DIR_BASE)/$(2) $(SDKCONFIG_MAKEFILE)
        $(call ComponentMake,$(1),$(2)) component_project_vars.mk
 endef
 
index 555086fb8d0730b590699bc59e5263f9360fab40..09cec2e0bed31abeeceb6a49921678e6ac143386 100644 (file)
@@ -42,7 +42,7 @@ defconfig: $(KCONFIG_TOOL_DIR)/mconf $(IDF_PATH)/Kconfig $(BUILD_DIR_BASE)
 # Work out of whether we have to build the Kconfig makefile
 # (auto.conf), or if we're in a situation where we don't need it
 NON_CONFIG_TARGETS := clean %-clean help menuconfig defconfig
-AUTO_CONF_REGEN_TARGET := $(BUILD_DIR_BASE)/include/config/auto.conf
+AUTO_CONF_REGEN_TARGET := $(SDKCONFIG_MAKEFILE)
 
 # disable AUTO_CONF_REGEN_TARGET if all targets are non-config targets
 # (and not building default target)
@@ -50,7 +50,7 @@ ifneq ("$(MAKECMDGOALS)","")
 ifeq ($(filter $(NON_CONFIG_TARGETS), $(MAKECMDGOALS)),$(MAKECMDGOALS))
 AUTO_CONF_REGEN_TARGET :=
 # dummy target
-$(BUILD_DIR_BASE)/include/config/auto.conf:
+$(SDKCONFIG_MAKEFILE):
 endif
 endif