From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:41803) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sb9sz-0008Qr-PP for qemu-devel@nongnu.org; Sun, 03 Jun 2012 08:26:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sb9sy-0001Sb-2c for qemu-devel@nongnu.org; Sun, 03 Jun 2012 08:26:21 -0400 Received: from mail-pz0-f45.google.com ([209.85.210.45]:46026) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sb9sx-0001Ic-P0 for qemu-devel@nongnu.org; Sun, 03 Jun 2012 08:26:19 -0400 Received: by mail-pz0-f45.google.com with SMTP id v2so5107465dad.4 for ; Sun, 03 Jun 2012 05:26:18 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Sun, 3 Jun 2012 14:25:37 +0200 Message-Id: <1338726358-30681-4-git-send-email-pbonzini@redhat.com> In-Reply-To: <1338726358-30681-1-git-send-email-pbonzini@redhat.com> References: <1338726358-30681-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 03/24] add rules for nesting List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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 --- 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