Patchwork [03/24] add rules for nesting

login
register
mail settings
Submitter Paolo Bonzini
Date June 3, 2012, 12:25 p.m.
Message ID <1338726358-30681-4-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/162497/
State New
Headers show

Comments

Paolo Bonzini - June 3, 2012, 12:25 p.m.
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 <pbonzini@redhat.com>
---
 rules.mak |   21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

Patch

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