From patchwork Wed Jun 6 06:36:10 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 163271 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 46608B6EF3 for ; Wed, 6 Jun 2012 17:07:15 +1000 (EST) Received: from localhost ([::1]:44795 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ScAKm-00063o-Us for incoming@patchwork.ozlabs.org; Wed, 06 Jun 2012 03:07:12 -0400 Received: from eggs.gnu.org ([208.118.235.92]:39283) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sc9rQ-0003pL-D4 for qemu-devel@nongnu.org; Wed, 06 Jun 2012 02:36:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sc9rM-0002A2-8f for qemu-devel@nongnu.org; Wed, 06 Jun 2012 02:36:51 -0400 Received: from mail-pz0-f45.google.com ([209.85.210.45]:46266) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sc9rL-00028G-Vq for qemu-devel@nongnu.org; Wed, 06 Jun 2012 02:36:48 -0400 Received: by mail-pz0-f45.google.com with SMTP id v2so9050351dad.4 for ; Tue, 05 Jun 2012 23:36:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=pUHi7lfh09lF1sM0jiOJGigxfhZbBFRIW2XWLtvDFSw=; b=MFKErLb1ET0l8LNJfnvPewCcA0/tgPz4Xj5UcI2Soua0dyxB3+A9RDIPGFUi0Mlts2 VROXYbvGzesU52H/0V1sktlylJW24JDOriLBIO/q1GveIKNsIE6zSaH1So6YObHq+erv 8LU74fMBNIX3Aq+5WzMCLMVLuFAzS/GrB5r4sq1sM4pGWFYGegkVp1igri7vClM45APM tgoR69xqmnky+pFtR7IQnh21jYOBAlmir0hNI5VlR6DFE3pAfofkq/Fazpelm0P8BGrb LWGhOiME8SWbwA/5rym4WeKhkIvIdEJDH0z+mzIMTqo8+xhcS24lI4bALpIBX88hPJhb el8Q== Received: by 10.68.230.105 with SMTP id sx9mr3613752pbc.114.1338964606577; Tue, 05 Jun 2012 23:36:46 -0700 (PDT) Received: from yakj.usersys.redhat.com.usersys.redhat.com (p40081-ipngn402hodogaya.kanagawa.ocn.ne.jp. [180.23.161.81]) by mx.google.com with ESMTPS id py5sm1479093pbb.1.2012.06.05.23.36.43 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 05 Jun 2012 23:36:45 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 6 Jun 2012 08:36:10 +0200 Message-Id: <1338964592-22223-4-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.10.1 In-Reply-To: <1338964592-22223-1-git-send-email-pbonzini@redhat.com> References: <1338964592-22223-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.210.45 Cc: anthony@codemonkey.ws Subject: [Qemu-devel] [PATCH v2 03/25] build: add rules for nesting X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@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 | 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