[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 03/29] build: add rules for nesting
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PATCH v3 03/29] build: add rules for nesting |
Date: |
Thu, 7 Jun 2012 09:39:48 +0200 |
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 <address@hidden>
---
rules.mak | 39 +++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/rules.mak b/rules.mak
index efef6f2..f65283c 100644
--- a/rules.mak
+++ b/rules.mak
@@ -73,3 +73,42 @@ 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
+
+obj := .
+old-nested-dirs :=
+
+define push-var
+$(eval save-$2-$1 = $(value $1))
+$(eval $1 :=)
+endef
+
+define pop-var
+$(eval subdir-$2-$1 := $(if $(filter $2,$(save-$2-$1)),$(addprefix $2,$($1))))
+$(eval $1 = $(value save-$2-$1) $$(subdir-$2-$1))
+$(eval save-$2-$1 :=)
+endef
+
+define unnest-dir
+$(foreach var,$(nested-vars),$(call push-var,$(var),$1/))
+$(eval obj := $(obj)/$1)
+$(eval include $(SRC_PATH)/$1/Makefile.objs)
+$(eval obj := $(patsubst %/$1,%,$(obj)))
+$(foreach var,$(nested-vars),$(call pop-var,$(var),$1/))
+endef
+
+define unnest-vars-1
+$(eval nested-dirs := $(filter-out \
+ $(old-nested-dirs), \
+ $(sort $(foreach var,$(nested-vars), $(filter %/, $($(var)))))))
+$(if $(nested-dirs),
+ $(foreach dir,$(nested-dirs),$(call unnest-dir,$(patsubst %/,%,$(dir))))
+ $(eval old-nested-dirs := $(old-nested-dirs) $(nested-dirs))
+ $(call unnest-vars-1))
+endef
+
+define unnest-vars
+$(call unnest-vars-1)
+$(foreach var,$(nested-vars),$(eval $(var) := $(filter-out %/, $($(var)))))
+endef
--
1.7.10.1
- [Qemu-devel] [PULL v3 00/29] per-directory Makefile.objs snippets, limit vpath (ab)use, Paolo Bonzini, 2012/06/07
- [Qemu-devel] [PATCH v3 10/29] build: move other target-*/ objects to nested Makefile.objs, Paolo Bonzini, 2012/06/07
- [Qemu-devel] [PATCH v3 11/29] build: move rules for nesting to Makefile.objs, Paolo Bonzini, 2012/06/07
- [Qemu-devel] [PATCH v3 13/29] build: move block/ objects to nested Makefile.objs, Paolo Bonzini, 2012/06/07
- [Qemu-devel] [PATCH v3 12/29] build: adapt qom/Makefile and move it to Makefile.objs, Paolo Bonzini, 2012/06/07
- [Qemu-devel] [PATCH v3 14/29] build: move net/ objects to nested Makefile.objs, Paolo Bonzini, 2012/06/07
- [Qemu-devel] [PATCH v3 21/29] build: move target-independent hw/ objects to nested Makefile.objs, Paolo Bonzini, 2012/06/07