From patchwork Thu Mar 21 08:23:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Khlebnikov X-Patchwork-Id: 2311451 Return-Path: X-Original-To: patchwork-linux-kbuild@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 717F840213 for ; Thu, 21 Mar 2013 08:24:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757610Ab3CUIYZ (ORCPT ); Thu, 21 Mar 2013 04:24:25 -0400 Received: from mail-la0-f49.google.com ([209.85.215.49]:55636 "EHLO mail-la0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757919Ab3CUIXL (ORCPT ); Thu, 21 Mar 2013 04:23:11 -0400 Received: by mail-la0-f49.google.com with SMTP id fs13so4548944lab.8 for ; Thu, 21 Mar 2013 01:23:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:subject:to:from:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-type :content-transfer-encoding; bh=Cg009FQ+Iphe/miLdFAGoaBctUCEqMpH0PxPxWefdpU=; b=VtY+LC+NXcNTKtJqyMzrhnpBY3hIpBnVYtkuHvb00lz/Mo7eO2A9D2Nl/0xEkg7dP0 ztEkBYkwGLwwmdzJtqYjW2oU4OeUbf6u1AXkPFeeRVTcu/iRUA68zYhWdq9/Z92OcwYB RPNezbpXc8XR261PnLoSGymskVzh3CB5qKhmuNjztE2fGVL63bf4Vu5SfrjbJtZSSFxp D+hDp2H135L1SySTsnc8Scm79vTGRCAFGlltF2Q0a7IBuXBdGQDdphYBvUB2Wm6fRtcq zvNbtkEU4TziF2gwsDvRY/X/KfCjmjh3kKV6R/RSU3Gm7O4v9nqItTqCuYU4NQjHP4+G Y9Mw== X-Received: by 10.112.34.200 with SMTP id b8mr11137506lbj.3.1363854189332; Thu, 21 Mar 2013 01:23:09 -0700 (PDT) Received: from localhost (swsoft-msk-nat.sw.ru. [195.214.232.10]) by mx.google.com with ESMTPS id t17sm2100846lam.9.2013.03.21.01.23.07 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 21 Mar 2013 01:23:08 -0700 (PDT) Subject: [PATCH RFC 3/5] kconfig: simplity linking cross-module glue objects To: Michal Marek , Andrew Morton , linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org From: Konstantin Khlebnikov Cc: Tejun Heo , Greg Kroah-Hartman , Richard Cochran Date: Thu, 21 Mar 2013 12:23:05 +0400 Message-ID: <20130321082305.21557.69305.stgit@zurg> In-Reply-To: <20130321082256.21557.68351.stgit@zurg> References: <20130321082256.21557.68351.stgit@zurg> User-Agent: StGit/0.15 MIME-Version: 1.0 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org This patch adds some synax sugar for makefiles to simplify conditional linking cross-module glue objects into composite modules. For example: there two tristate config options MODULE_A and MODULE_B. Module-B wants to use some code from Module-A. Code of Module-A is available from Module-B if MODULE_A=y or if MODULE_A=m and MODULE_B=m. This patch allows to write this construction in makefile: obj-$(CONFIG_MODULE_A) += module_a.o obj-$(CONFIG_MODULE_B) += module_b.o module_b-y += core_b.o module_b-$(CONFIG_MODULE_A) += glue_a_b.o After that glue_a_b will be linked into module_b.o iff module-A is available. Objects from module_b-m will be linked only if CONFIG_MODULE_B=m. Signed-off-by: Konstantin Khlebnikov Cc: Andrew Morton Cc: Michal Marek Cc: linux-kbuild@vger.kernel.org --- Documentation/kbuild/makefiles.txt | 14 ++++++++++++++ scripts/Makefile.build | 16 ++++++++++++---- scripts/Makefile.lib | 8 ++++---- 3 files changed, 30 insertions(+), 8 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/Documentation/kbuild/makefiles.txt b/Documentation/kbuild/makefiles.txt index 5198b74..dcdf424 100644 --- a/Documentation/kbuild/makefiles.txt +++ b/Documentation/kbuild/makefiles.txt @@ -224,6 +224,20 @@ more details, with real examples. kbuild will build an ext2.o file for you out of the individual parts and then link this into built-in.o, as you would expect. + Kbuild also includes objects listed in variable $(-m) + if it builds composite objects as module (obj-m) and ignores them + for built-in modules (obj-y). This allows to implement flexible + dependence between two modules. + + Example: + obj-$(CONFIG_MODULE_A) += module_a.o + obj-$(CONFIG_MODULE_B) += module_b.o + module_b-y += core_b.o + module_b-$(CONFIG_MODULE_A) += glue_a_b.o + + In this example, glue_a_b.o will be used only if module_a is available + from module_b, this is true if CONFIG_MODULE_A=y or they both are =m. + --- 3.4 Objects which export symbols No special notation is required in the makefiles for diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 0e801c3..1c89dbf 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -421,16 +421,24 @@ endif # -objs := # or # -y := -link_multi_deps = \ +# or (for modules) +# -m := +link_multi_deps-y = \ $(filter $(addprefix $(obj)/, \ $($(subst $(obj)/,,$(@:.o=-objs))) \ $($(subst $(obj)/,,$(@:.o=-y)))), $^) - + +link_multi_deps-m = \ +$(filter $(addprefix $(obj)/, \ +$($(subst $(obj)/,,$(@:.o=-objs))) \ +$($(subst $(obj)/,,$(@:.o=-y))) \ +$($(subst $(obj)/,,$(@:.o=-m)))), $^) + quiet_cmd_link_multi-y = LD $@ -cmd_link_multi-y = $(LD) $(ld_flags) -r -o $@ $(link_multi_deps) $(cmd_secanalysis) +cmd_link_multi-y = $(LD) $(ld_flags) -r -o $@ $(link_multi_deps-y) $(cmd_secanalysis) quiet_cmd_link_multi-m = LD [M] $@ -cmd_link_multi-m = $(cmd_link_multi-y) +cmd_link_multi-m = $(LD) $(ld_flags) -r -o $@ $(link_multi_deps-m) $(cmd_secanalysis) # We would rather have a list of rules like # foo.o: $(foo-objs) diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 07125e6..b1ce3e4 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -48,14 +48,14 @@ subdir-ym := $(sort $(subdir-y) $(subdir-m)) # if $(foo-objs) exists, foo.o is a composite object multi-used-y := $(sort $(foreach m,$(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m)))) -multi-used-m := $(sort $(foreach m,$(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m)))) +multi-used-m := $(sort $(foreach m,$(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))), $(m)))) multi-used := $(multi-used-y) $(multi-used-m) single-used-m := $(sort $(filter-out $(multi-used-m),$(obj-m))) # Build list of the parts of our composite objects, our composite # objects depend on those (obviously) multi-objs-y := $(foreach m, $(multi-used-y), $($(m:.o=-objs)) $($(m:.o=-y))) -multi-objs-m := $(foreach m, $(multi-used-m), $($(m:.o=-objs)) $($(m:.o=-y))) +multi-objs-m := $(foreach m, $(multi-used-m), $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))) multi-objs := $(multi-objs-y) $(multi-objs-m) # $(subdir-obj-y) is the list of objects in $(obj-y) which uses dir/ to @@ -67,7 +67,7 @@ obj-dirs := $(dir $(multi-objs) $(subdir-obj-y)) # Replace multi-part objects by their individual parts, look at local dir only real-objs-y := $(foreach m, $(filter-out $(subdir-obj-y), $(obj-y)), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m))) $(extra-y) -real-objs-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m))) +real-objs-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m)),$(m))) # Add subdir path @@ -163,7 +163,7 @@ dtc_cpp_flags = -Wp,-MD,$(depfile) -nostdinc \ # Finds the multi-part object the current object will be linked into modname-multi = $(sort $(foreach m,$(multi-used),\ - $(if $(filter $(subst $(obj)/,,$*.o), $($(m:.o=-objs)) $($(m:.o=-y))),$(m:.o=)))) + $(if $(filter $(subst $(obj)/,,$*.o), $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$(m:.o=)))) ifdef REGENERATE_PARSERS