From 33ca8874d4b401bd167e86d8abb1e6667496f8cf Mon Sep 17 00:00:00 2001 From: Jeroen Domburg Date: Wed, 13 Dec 2017 15:48:49 +0800 Subject: [PATCH] Add support for Makefile.componentbuild files --- docs/api-guides/build-system.rst | 10 ++++++++++ make/component_wrapper.mk | 27 ++++++++++++++++++++++++++- make/project.mk | 1 + 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/docs/api-guides/build-system.rst b/docs/api-guides/build-system.rst index 2ef47a468..31debb431 100644 --- a/docs/api-guides/build-system.rst +++ b/docs/api-guides/build-system.rst @@ -321,6 +321,7 @@ Second Level: Component Makefiles ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - Each call to a component makefile goes via the ``$(IDF_PATH)/make/component_wrapper.mk`` wrapper makefile. +- This component wrapper includes all component ``Makefile.componentbuild`` files, making any recipes, variables etc in these files available to every component. - The ``component_wrapper.mk`` is called with the current directory set to the component build directory, and the ``COMPONENT_MAKEFILE`` variable is set to the absolute path to ``component.mk``. - ``component_wrapper.mk`` sets default values for all `component variables`, then includes the `component.mk` file which can override or modify these. - If ``COMPONENT_OWNBUILDTARGET`` and ``COMPONENT_OWNCLEANTARGET`` are not defined, default build and clean targets are created for the component's source files and the prerequisite ``COMPONENT_LIBRARY`` static library file. @@ -390,6 +391,15 @@ configuration options at the top-level of menuconfig, rather than inside the "Co Take care when adding configuration values in this file, as they will be included across the entire project configuration. Where possible, it's generally better to create a KConfig file for `component configuration`. + +Makefile.componentbuild +^^^^^^^^^^^^^^^^^^^^^^^ + +For components that e.g. include tools to generate source files from other files, it is necessary to be able to add recipes, macros or variable definitions +into the component build process of every components. This is done by having a ``Makefile.componentbuild`` in a component directory. This file gets included +in ``component_wrapper.mk``, before the ``component.mk`` of the component is included. As with the Makefile.projbuild, take care with these files: as they're +included in each component build, a ``Makefile.componentbuild`` error may only show up when compiling an entirely different component. + Configuration-Only Components ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/make/component_wrapper.mk b/make/component_wrapper.mk index cc0afaa05..e43e82a51 100644 --- a/make/component_wrapper.mk +++ b/make/component_wrapper.mk @@ -73,11 +73,36 @@ COMPONENT_SUBMODULES ?= ################################################################################ # 2) Include the component.mk for the specific component (COMPONENT_MAKEFILE) to -# override variables & optionally define custom targets. +# override variables & optionally define custom targets. Also include global +# component makefiles. ################################################################################ + +# Include any Makefile.componentbuild file letting components add +# configuration at the global component level + +# Save component_path; we pass it to the called Makefile.componentbuild +# as COMPILING_COMPONENT_PATH, and we use it to restore the current +# COMPONENT_PATH later. +COMPILING_COMPONENT_PATH := $(COMPONENT_PATH) + +define includeCompBuildMakefile +$(if $(V),$(info including $(1)/Makefile.componentbuild...)) +COMPONENT_PATH := $(1) +include $(1)/Makefile.componentbuild +endef +$(foreach componentpath,$(COMPONENT_PATHS), \ + $(if $(wildcard $(componentpath)/Makefile.componentbuild), \ + $(eval $(call includeCompBuildMakefile,$(componentpath))))) + +#Restore COMPONENT_PATH to what it was +COMPONENT_PATH := $(COMPILING_COMPONENT_PATH) + + +# Include component.mk for this component. include $(COMPONENT_MAKEFILE) + ################################################################################ # 3) Set variables that depend on values that may changed by component.mk ################################################################################ diff --git a/make/project.mk b/make/project.mk index a15b7d301..d2eefad7b 100644 --- a/make/project.mk +++ b/make/project.mk @@ -154,6 +154,7 @@ export COMPONENTS # 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 cd,$(COMPONENT_DIRS),$(wildcard $(dir $(cd))$(comp) $(cd)/$(comp))))) +export COMPONENT_PATHS TEST_COMPONENTS ?= TESTS_ALL ?=