Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp57031lqe; Fri, 5 Apr 2024 12:27:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV+Q/mymm4uwf4/f48mGdmGBJOKHHuAdY4eAzpkk8NrrC5TBSjh9tkk6Unne7FZnSGqF5zzdllIwWaxS/iBM17PgWbBNpAywBJjz21EJw== X-Google-Smtp-Source: AGHT+IFpWWSfYNrnwAg7ylxtGM2YYjMdjHRFr0rPGe/WT6JF/TlghCGkaL9bgMi53tw4C8HkjaYd X-Received: by 2002:a50:931d:0:b0:568:1882:651f with SMTP id m29-20020a50931d000000b005681882651fmr1469805eda.25.1712345237839; Fri, 05 Apr 2024 12:27:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712345237; cv=pass; d=google.com; s=arc-20160816; b=f+iLWo2vJ1ZFENChtToyjUYq00kYrVXk0KT2N5ptVt6kGOHRPrkjiaqPfXtZrhRE4v e6rVr1shVM5c6BT27yHdnb24BYIMDbg4iAytzqiLilemFpeNo1Zs46uUSSipzUfUArtZ 2ukm+LM94LRqVdEo8+ucyxZ4/nsoRydJj7qwr+Ydh2XoMNVNunvP7udMjd8icdwx/V9A K4nYZnw/JOtPSBWzDwhKpkvH48tdzyXI5jl3I5831jWEadcQf//lI7sjOElTAtxXrGqb /4hZrKRdbF4XCLKyNMF3764GuMH5WCM5aeRqKZlIXpuIDqBteIDeRmvmZyX1hDJknUQI kHTw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=UMHG5WAqDsP+/+fZR/YsyFb3zl/RkAxZvjPf1Xgd3JA=; fh=SA1N00ejnQGJFWvUV0JYq1JY0QlarnxM40iBsNLeZKc=; b=EpzpIoUWqoXBiLuUza4DiJnBGC665CAfGU9faGaqbS44VBBAOxhD9Ukdv5V8mL3exx L9ZG/vy6u5/LX9QAbv0CWW6hQ62jI0PvLmkTWhst7zjWFprT1SlhJuU9/k75Y0blMPxn bQNNqdzyNr7yvHJxaYp2HDa0oGqtVb51rt8rnfxjs1lSI8x/Pdkvjc+WftjXRd12/eIt GQsqrQ97PF/wMKP9mKWpJY6qrX1Dkz+FfrDGeM1kzWIxrglU7/Wu6C13kVqrb4XDejjh C+lo7PGrCiVUbUUDeMdGWgLbwdcZdbhJX93artR5GOlgFW4HLQH7mgglO+3V5OHfEUL2 N2sQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=IezP4Cxa; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-133332-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-133332-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id h16-20020a056402281000b00568b4af7206si1029484ede.482.2024.04.05.12.27.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Apr 2024 12:27:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-133332-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=IezP4Cxa; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-133332-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-133332-linux.lists.archive=gmail.com@vger.kernel.org" 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 79BDA1F21565 for ; Fri, 5 Apr 2024 16:22:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2739D16F82C; Fri, 5 Apr 2024 16:22:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="IezP4Cxa" Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 4A0AA16C858; Fri, 5 Apr 2024 16:22:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712334130; cv=none; b=u9uM3U8XQA3/XKjto0S+lFdW7QGKQVCOvOnuZCu6Kra/iUbuppUbum6ZyummRyS9Ijlv6rbE4ZaCkewVcXkUdYakNoEngwD1f7AnB13SylEJNyuYNMEfHpczM9TvanNbRn7N13vX9dtnOJ/O0oqaLQrZ7W7hQaKuf5yxJQDBUIo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712334130; c=relaxed/simple; bh=BKLget3zVcch6Et1v/4ZsurOnV/ojVhkQsDlcqhq99g=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=lrlBtEmyMrO5dsC7q26XIO4g8G/vbTZKJQMMUZgDVjxm4zKGmVMBokDMDdNVIUia4Zczh4oj1TL9GI+15sPx+qkS+b3AHGinD7cP7kZTeGnzpfOcT4/Ip9OgZRPM/WTTCrWrVnjGxCnj2s0s+nfbMpJauN9AlpQdcOGHVJCzSS8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=IezP4Cxa; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Sender:Reply-To:Content-ID:Content-Description; bh=UMHG5WAqDsP+/+fZR/YsyFb3zl/RkAxZvjPf1Xgd3JA=; b=IezP4Cxa2GSeMtKTsc4nkfg149 6o1VZoolrIuNOna/Ier+kLUe/J0RT6Yo19xdrqGYCfe3diE7QqLPOgrGt6NvXvZpmmlkx+RIgj0XX NY6Ov2kVU7G0wRjqp94kOWxaXjbpcZa6hc2uJz7Bfkh5ql8UJrWf04XBdG7egq/1DRaEd7JcNbLwD GqNyvupMWZX6+VlxZMJlwdGGLyElKMB3uMloQinDDNP7rE1vlCI4OqFVRqlkZr4PsaefX4gZ0KWCI zZamjeGvdxPMNqdXLCuULWKLFTosrqimp4NGNHqdPcRqH/CHVQD3/NuKBp2NNYo33hnxMVymUobRI IrDXeHmQ==; Received: from [50.53.2.121] (helo=[192.168.254.15]) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsmKH-00000007yld-21UJ; Fri, 05 Apr 2024 16:22:01 +0000 Message-ID: <5628d83f-cc05-46b4-997a-2309701d3a77@infradead.org> Date: Fri, 5 Apr 2024 09:22:00 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] Add MO(mod objs) variable to process ext modules with subdirs To: Valerii Chernous , 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 References: <20240405100140.1394290-1-vchernou@cisco.com> Content-Language: en-US From: Randy Dunlap In-Reply-To: <20240405100140.1394290-1-vchernou@cisco.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Hi-- On 4/5/24 3:01 AM, Valerii Chernous wrote: > 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 separating source and build separate > 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 failed. > Providing "MO" variable and using "override" directive with declaring > "src" variable solve the problem 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..63e1a71a3b9a 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 artifatcs directories artifacts > +(KBUILD_EXTMOD + KBUILD_EXTMOD_SRC), KBUILD_EXTMOD working as output > +artifacts directory directory. > > Setting "M=..." takes precedence over KBUILD_EXTMOD. > > +KBUILD_EXTMOD_SRC > +------------- Extend the underline to the same length as the title. > +Set the external module source directory in case when separate module > +sources and build artifacts directories required. Working in pair with are required. or are used. > +KBUILD_EXTMOD. If KBUILD_EXTMOD_SRC is set then KBUILD_EXTMOD working as works as or is used as > +module build artifacts directory 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..135be2fc798e 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 an external module build artifacts drop an > + should be placed into specific dir() ). > + This parameter optional, without it "M" working as parameter is optional. Without it "M" works as both > + source provider and build output location 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)/: -- #Randy