Received: by 2002:ab2:5182:0:b0:1f4:61d5:3ad4 with SMTP id x2csp68564lqi; Fri, 5 Apr 2024 09:57:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUU9Tv8U4NFuzgYgtS1aRJJuA3VTCxI2n93FrW+Dfyw4+G5i8MrflCNZuefkGSb5cerCUdi/16NkCiLkKuBBPqHKBEC5LeerUkf+dGIYQ== X-Google-Smtp-Source: AGHT+IG+9ShrXlTH6Oninbhaqj7FaUg+R8Ia6JacIko1sYjZZsFP9DDHN9XCyyWl5XxrfVVDM0Z5 X-Received: by 2002:a05:6214:230a:b0:699:271b:26b with SMTP id gc10-20020a056214230a00b00699271b026bmr2034961qvb.60.1712336259971; Fri, 05 Apr 2024 09:57:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712336259; cv=pass; d=google.com; s=arc-20160816; b=v6/OydlPVaTm3DUruuVlQU7IXpmmbb78Elc0yC3XJXoir+YhLksLrlDLYrVXTEPbXT aFZEFIWtJWR+FibdAPsYmoAsD92ZXREISkyfE2y5izSdyQ9PUysDePzES5X2fZPBv+eo YvZ/h+iqeukuWnHr0Id/MBw89PsoBO+DC+G/cbavyU/GUDt5/byDhHSS/4s3k30cHBbb FbiuX+GaquvJwSulL+z2/kVaEDsbL+PyN/6cGiL6+7voDrUK8JmZiwbONcBbXOWF8Owj TD15n0LZdB6kEilhEFJtjWnQ7bKFPKykqfbi8EGzLFij6I6XyFYfwVsA231WiZlQ/Mgx qWYA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:ironport-hdrordr:ironport-data:dkim-signature; bh=3giUsTCXvDdhR8jWae0EY/dEresrV+oTZ2G7M/vJy6c=; fh=J088JOqP4pb0CtQG6ZZRNJBug/jrvhRZLg0RGzURcqQ=; b=RO+qVNNqv6JukDiesqlL2dZbj26HL5mMQgFCtKpgoHN+FQ6vfvGfYlTb05qB028VY3 PPqdSHHVN6nC+yjLIHgghQ1XPpo47ttEirZe/ree8CJOfNXZgBzcM5AFvZ9Ds0EJKg20 v7jQV2oUnbg4Ejpralv2wms0Wa8qxSkn48YLjf4EjbjetpLr20ezC8HUqtocSFLOpGhJ ovPlJI2fRZJ6Pv/5vyNTTW0LqAg6/u0lM7BwJpAvAjrip9C0nKE2yO96PvO4iPAKgQE1 uc7Jkw+gtC/6i3G7DqA0bbYgHljCSkagkWpmduelShuBtYF3LpV0wvXAvvxoYeurhf4T 1hTg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@cisco.com header.s=iport header.b=GZil8yxZ; arc=pass (i=1 spf=pass spfdomain=cisco.com dkim=pass dkdomain=cisco.com dmarc=pass fromdomain=cisco.com); spf=pass (google.com: domain of linux-kernel+bounces-133374-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-133374-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=cisco.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id dr8-20020a05621408e800b006992fc40294si2122651qvb.266.2024.04.05.09.57.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Apr 2024 09:57:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-133374-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@cisco.com header.s=iport header.b=GZil8yxZ; arc=pass (i=1 spf=pass spfdomain=cisco.com dkim=pass dkdomain=cisco.com dmarc=pass fromdomain=cisco.com); spf=pass (google.com: domain of linux-kernel+bounces-133374-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-133374-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=cisco.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 881461C22B69 for ; Fri, 5 Apr 2024 16:57:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5EBB6171E42; Fri, 5 Apr 2024 16:57:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=cisco.com header.i=@cisco.com header.b="GZil8yxZ" Received: from rcdn-iport-3.cisco.com (rcdn-iport-3.cisco.com [173.37.86.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 32075171670; Fri, 5 Apr 2024 16:57:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=173.37.86.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712336243; cv=none; b=agilDD7Gtp48oap7kTEEUCKXSe94vl1HtapMJGcypbfpN6ATC6cD9j+hg2I/fzE/p+zDuca6KOFBJWjFf7q38viyoyoWShUGAAxFL6ZPhU1YGkcTPlRsfT3ac0bJWLOcuR+q/8LnY+omVmpzYCiRYGCdLvcz9tCG/m9gtBpt6No= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712336243; c=relaxed/simple; bh=qXuwMCT+b3u9KeSmgIWHdfGEQJkVakqVWx1OHSggAVc=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=OTWYo4Xvyio89CY3z8I7wz2K0IfIxXnq9CSkQPfLoCMxZEr/tnaKTpn9SWpBmhAcs6kWolHZ+NZYx/mvrnp5sQdgb7oPP2nEYu0UZcuvBJSIe98nqzzTAiScDS9dY3WbHGuQ4C7mvs2rcFTMF3w5rHigilSVAXunpYQ/mu9Y/sQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=cisco.com; spf=pass smtp.mailfrom=cisco.com; dkim=pass (1024-bit key) header.d=cisco.com header.i=@cisco.com header.b=GZil8yxZ; arc=none smtp.client-ip=173.37.86.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=cisco.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cisco.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cisco.com; i=@cisco.com; l=5348; q=dns/txt; s=iport; t=1712336241; x=1713545841; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=3giUsTCXvDdhR8jWae0EY/dEresrV+oTZ2G7M/vJy6c=; b=GZil8yxZYaGeOBquPdcMgrOOUrPOdYxPovcnhbPlhzVyM0gcdJWcP3Ja FHv5BCt4rZtyzyeSXIvb/iLWbckFToSlkRvT3ZjeHgPVglxe3pAPYReC4 evt2ma2oLohpcoOpO9HB8x4zr8MyD8hdIx6DhKEPT8I6XWPtRgRdIIQ4s M=; X-CSE-ConnectionGUID: y+8OyqXeSbCm8u+1be0NQg== X-CSE-MsgGUID: 94PtCkYcR2SQXvekIlsO8w== X-IPAS-Result: =?us-ascii?q?A0CQAQByLBBmmJ1dJa1aHgEBCxIMggQLg0BWQUiWPItzh?= =?us-ascii?q?ySKc4ElA1YPAQEBDzETBAEBhQaIEwImNgcOAQIEAQEBAQMCAwEBAQEBAQEBB?= =?us-ascii?q?gEBBQEBAQIBBwUUAQEBAQEBAQEeGQUQDieFbQ2GXDYBRoE9ARKDAAGCXwIBr?= =?us-ascii?q?zeCLIEB3i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1KXZ+UCaC3ICQzoHb8Yp3Oc9QiYg2 0Ohm8zvQzpirNW9T3OW8bOdthu8OyEOKWJEaDJsZQ0M/9nqpqkwgwjJQ9IlF7S65vXwECr5w zGQqzkWhLgJi8MPkaKh8jj6bymEvJPFSEs+4R/aGzzj5QJib4njbIutgbTG0RpeBJfaHn6Qp UgJoMK16bATTsiHmXSreepYSdlF+M25GDHbhFduGbwo+DKs52OvcOhsDNdWeh4B3iEsJ2aBX aPDhT698qO/K5dDUEOaS5i6B8Jvxq/6GJG7EPvVddFJJJN2cWdrHR2Ch2bOgAgBc2B1zcnT3 Kt3l+73Ux727ow8kVKLqx81i+ND+8zH7Tq7qWrH5xqmy6GCQ3WeVK0INlCDBshgs/re+liIr 4kEapTUo/m6bAEYSnSHmWL0BQ1bRUXX+binwyCqXrfafVo4Qj1J5wH5mON8J+SJYJi5Zs+To yniARUHoLYOrXbGMg6NImtyc6/iWI03rHQwe0QR0aWAhRAejXKUxP5HLfMfJOB/nMQ6lK4cZ 6deIa2oXK8QIgkrDhxAN/ERWqQ4KkTy7e9PVgL4CAUCk2lIHFCZqo69JVSxpEHjzEOf7KMDn lFp7SuDKbJreuioJJ++hC6Hp79pgUUgpQ== IronPort-HdrOrdr: A9a23:iv3EfqidPvTrOZA32Mc6VzlGxHBQXtUji2hC6mlwRA09TyVXra yTdZMgpH3JYVkqNk3I9errBEDiewK+yXcK2+gs1N6ZNWGMhILCFu5fBOXZrgEIMheOk9K1rZ 0BT0C7Y+eAamSTSq3BkW2FL+o= X-Talos-CUID: 9a23:jYhC4WGjIgr8Sop2qmJ2tx4zC9kVf0bX53KAPgzhA2sxboSaHAo= X-Talos-MUID: =?us-ascii?q?9a23=3AMDdUjg1PETgcMmjvAPmjJes04TUjsviWFGsOoJ4?= =?us-ascii?q?84fK9BTJ9OBaZlxPnXdpy?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-AV: E=Sophos;i="6.07,181,1708387200"; d="scan'208";a="206922865" Received: from rcdn-core-6.cisco.com ([173.37.93.157]) by rcdn-iport-3.cisco.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Apr 2024 16:56:12 +0000 Received: from sjc-ads-1541.cisco.com (sjc-ads-1541.cisco.com [171.70.59.233]) by rcdn-core-6.cisco.com (8.15.2/8.15.2) with ESMTP id 435GuBC2023239; Fri, 5 Apr 2024 16:56:11 GMT From: Valerii Chernous To: Masahiro Yamada , Nathan Chancellor , Nicolas Schier Cc: xe-linux-external@cisco.com, Jonathan Corbet , linux-kbuild@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3] Add MO(mod objs) variable to process ext modules with subdirs Date: Fri, 5 Apr 2024 09:56:08 -0700 Message-Id: <20240405165610.1537698-1-vchernou@cisco.com> X-Mailer: git-send-email 2.35.6 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Auto-Response-Suppress: DR, OOF, AutoReply X-Outbound-SMTP-Client: 171.70.59.233, sjc-ads-1541.cisco.com X-Outbound-Node: rcdn-core-6.cisco.com The change allow to build external modules with nested makefiles. With current unofficial way(using "src" variable) it is possible to build external(out of tree) kernel module with separate source and build artifacts dirs but with nested makefiles it doesn't work properly. Build system trap to recursion inside makefiles, artifacts output dir path grow with each iteration until exceed max path len and build failed. Providing "MO" variable and using "override" directive with declaring "src" variable solves the problem Usage example: make -C KERNEL_SOURCE_TREE MO=BUILD_OUT_DIR M=EXT_MOD_SRC_DIR modules Cc: xe-linux-external@cisco.com Cc: Valerii Chernous Signed-off-by: Valerii Chernous --- Documentation/kbuild/kbuild.rst | 14 +++++++++++++- Documentation/kbuild/modules.rst | 16 +++++++++++++++- Makefile | 17 +++++++++++++++++ scripts/Makefile.build | 7 +++++++ 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/Documentation/kbuild/kbuild.rst b/Documentation/kbuild/kbuild.rst index 9c8d1d046ea5..81413ddba2ad 100644 --- a/Documentation/kbuild/kbuild.rst +++ b/Documentation/kbuild/kbuild.rst @@ -121,10 +121,22 @@ Setting "V=..." takes precedence over KBUILD_VERBOSE. KBUILD_EXTMOD ------------- Set the directory to look for the kernel source when building external -modules. +modules. In case of using separate sources and module artifacts directories +(KBUILD_EXTMOD + KBUILD_EXTMOD_SRC), KBUILD_EXTMOD working as output +artifacts directory. Setting "M=..." takes precedence over KBUILD_EXTMOD. +KBUILD_EXTMOD_SRC +----------------- +Set the external module source directory in case when separate module +sources and build artifacts directories are used. Working in pair with +KBUILD_EXTMOD. If KBUILD_EXTMOD_SRC is set then KBUILD_EXTMOD is used as +module build artifacts directory. + +Setting "MO=..." takes precedence over KBUILD_EXTMOD. +Setting "M=..." takes precedence over KBUILD_EXTMOD_SRC. + KBUILD_OUTPUT ------------- Specify the output directory when building the kernel. diff --git a/Documentation/kbuild/modules.rst b/Documentation/kbuild/modules.rst index a1f3eb7a43e2..b6c30e76b314 100644 --- a/Documentation/kbuild/modules.rst +++ b/Documentation/kbuild/modules.rst @@ -79,6 +79,14 @@ executed to make module versioning work. The kbuild system knows that an external module is being built due to the "M=" option given in the command. + To build an external module with separate src and artifacts dirs use:: + + $ make -C M=$PWD MO= + + The kbuild system knows that an external module with separate sources + and build artifacts dirs is being built due to the "M=" and + "MO=" options given in the command. + To build against the running kernel use:: $ make -C /lib/modules/`uname -r`/build M=$PWD @@ -93,7 +101,7 @@ executed to make module versioning work. ($KDIR refers to the path of the kernel source directory.) - make -C $KDIR M=$PWD + make -C $KDIR M=$PWD MO= -C $KDIR The directory where the kernel source is located. @@ -106,6 +114,12 @@ executed to make module versioning work. directory where the external module (kbuild file) is located. + MO= + Informs kbuild that external module build artifacts + should be placed into specific dir(). + Parameter is optional. Without it "M" works as both + source provider and build output location. + 2.3 Targets =========== diff --git a/Makefile b/Makefile index 4bef6323c47d..3d45a41737a6 100644 --- a/Makefile +++ b/Makefile @@ -142,6 +142,7 @@ ifeq ("$(origin M)", "command line") KBUILD_EXTMOD := $(M) endif +define kbuild_extmod_check_TEMPLATE $(if $(word 2, $(KBUILD_EXTMOD)), \ $(error building multiple external modules is not supported)) @@ -152,9 +153,25 @@ $(foreach x, % :, $(if $(findstring $x, $(KBUILD_EXTMOD)), \ ifneq ($(filter %/, $(KBUILD_EXTMOD)),) KBUILD_EXTMOD := $(shell dirname $(KBUILD_EXTMOD).) endif +endef +$(eval $(call kbuild_extmod_check_TEMPLATE)) export KBUILD_EXTMOD +# Use make M=src_dir MO=ko_dir or set the environment variables: +# KBUILD_EXTMOD_SRC, KBUILD_EXTMOD to specify separate directories of +# external module sources and build artifacts. +ifeq ("$(origin MO)", "command line") +ifeq ($(KBUILD_EXTMOD),) + $(error Ext module objects without module sources is not supported)) +endif +KBUILD_EXTMOD_SRC := $(KBUILD_EXTMOD) +KBUILD_EXTMOD := $(MO) +$(eval $(call kbuild_extmod_check_TEMPLATE)) +endif + +export KBUILD_EXTMOD_SRC + # backward compatibility KBUILD_EXTRA_WARN ?= $(KBUILD_ENABLE_EXTRA_GCC_CHECKS) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index baf86c0880b6..a293950e2e07 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -3,7 +3,14 @@ # Building # ========================================================================== +ifeq ($(KBUILD_EXTMOD_SRC),) src := $(obj) +else ifeq ($(KBUILD_EXTMOD),$(obj)) +override src := $(KBUILD_EXTMOD_SRC) +else +src_subdir := $(patsubst $(KBUILD_EXTMOD)/%,%,$(obj)) +override src := $(KBUILD_EXTMOD_SRC)/$(src_subdir) +endif PHONY := $(obj)/ $(obj)/: -- 2.35.6