This adds the 'magic' rules that take care of subdirectories. The subdirectory makefiles in the source tree are not complete; they only define some variables (listed in nested-vars) according to the configuration.
The magic rules descend into subdirectory makefiles and gather the evaluated values of those variables. The values from all subdirectories are joined together, each prefixed with the subdirectory name, and used by the "real" makefiles. Signed-off-by: Paolo Bonzini <pbonz...@redhat.com> --- rules.mak | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/rules.mak b/rules.mak index efef6f2..3126c8c 100644 --- a/rules.mak +++ b/rules.mak @@ -73,3 +73,24 @@ TRACETOOL=$(PYTHON) $(SRC_PATH)/scripts/tracetool.py # will delete the target of a rule if commands exit with a nonzero exit status .DELETE_ON_ERROR: + +# magic to descend into other directories + +save-var = $(eval $2 = $(value $1))$(eval $1 :=) +restore-var = $(eval $1 = $(value $2))$(eval $2 :=) + +define unnest-var-1 +$(eval nested-dirs := $(patsubst %, $3%, $(filter %/, $2))) +$(eval all-files += $(patsubst %, $3%, $(filter-out %/, $2))) +$(foreach nested-dir,$(nested-dirs), + $(foreach var,$(nested-vars),$(call save-var,$(var),save-$(nested-dir)-$(var))) + $(eval include $(SRC_PATH)/$(nested-dir)Makefile) + $(call unnest-var-1,$1,$($1),$(nested-dir)) + $(foreach var,$(nested-vars),$(call restore-var,$(var),save-$(nested-dir)-$(var)))) +endef + +define unnest-var +$(eval all-files :=) +$(call unnest-var-1,$1,$($1),) +$(eval $1 := $$(all-files)) +endef -- 1.7.10.1