From patchwork Tue Sep 17 14:16:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13806197 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 F228117A918; Tue, 17 Sep 2024 14:17:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582654; cv=none; b=Z9aTTsWQ3C7uobKJkMPsxAv4f5JwlONR3qjOfMTin4Pfo2jFw00YdWoZSkLObMee5YI/wC7arctfPAir4l5N/BboSDkCk411DWrtd/KWQWLJcLjTOSh5J/MSAqPlaCghQXcPYCvnrGO5Y7VWUo6swM80/3A21axAokt2rdx/jjE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582654; c=relaxed/simple; bh=GKorpVSUF9hPEdB9ymdQzxEwHHwAdZIW5qqmtDYc5C4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NQr3qw81eYvGHViuNGdRStT2D6YloeN8q+fKFQx8PLt6lyOal29Ekt4FSlwAHgd2q7lb1U5PL+s2RtFevcJxpRE1s8+EGLI9xNjXDT+qmo0FN6Kejn8JKqHE85FUnQjHd5BEUENvmp0ipM7web5VBq6uR3pK+ZRa/2RpUT+pVf8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fV67669S; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fV67669S" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D504DC4CECD; Tue, 17 Sep 2024 14:17:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726582653; bh=GKorpVSUF9hPEdB9ymdQzxEwHHwAdZIW5qqmtDYc5C4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fV67669SoEfCdMzvPe0nT1FhMAqa+yt3j6JOM4c2H4eQDv2fgYSx7MKqcWzUtiMks dt8YKP2m+wCvYY0yqeNLLH8eDBUjon6woZ2fPMf+kDY5BTkQAQSi1mXZEATmhxDs/5 /OAodKIuxy8kM7sA3856Bp6YRDTq5Lh062SBcXTFySlWiq3W1c0jsvajIYXXdwG4u/ 5642QIx9ciVyqgWK2BxKA0U65KgdjP4ru1+3W95Q9nuyOSkVAUO9Jzlc4uMvTXeIrG Sj5GAypokuRbe8BPBf/l1xW6SVkJPOTnvVFVuSnH+sY5JoVCGW8c0SWe3U5on0zAhv oStCLYKEZToyA== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Miguel Ojeda , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Nathan Chancellor , Nicolas Schier , Masahiro Yamada Subject: [PATCH 01/23] kbuild: doc: update the description about Kbuild/Makefile split Date: Tue, 17 Sep 2024 23:16:29 +0900 Message-ID: <20240917141725.466514-2-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240917141725.466514-1-masahiroy@kernel.org> References: <20240917141725.466514-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The phrase "In newer versions of the kernel" was added by commit efdf02cf0651 ("Documentation/kbuild: major edit of modules.txt sections 1-4"). This feature is no longer new, so remove it and update the paragraph. Example 3 was written 20 years ago. [1] There is no need to note about backward compatibility with such an old build system. Remove Example 3 entirely. [1]: https://git.kernel.org/pub/scm/linux/kernel/git/history/history.git/commit/?id=65e433436b5794ae056d22ddba60fe9194bba007 Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- Documentation/kbuild/modules.rst | 38 +++----------------------------- 1 file changed, 3 insertions(+), 35 deletions(-) diff --git a/Documentation/kbuild/modules.rst b/Documentation/kbuild/modules.rst index 131863142cbb..1014a275a7e1 100644 --- a/Documentation/kbuild/modules.rst +++ b/Documentation/kbuild/modules.rst @@ -224,10 +224,9 @@ module 8123.ko, which is built from the following files:: 3.2 Separate Kbuild File and Makefile ------------------------------------- - In newer versions of the kernel, kbuild will first look for a - file named "Kbuild," and only if that is not found, will it - then look for a makefile. Utilizing a "Kbuild" file allows us - to split up the makefile from example 1 into two files: + Kbuild will first look for a file named "Kbuild", and if it is not + found, it will then look for "Makefile". Utilizing a "Kbuild" file + allows us to split up the "Makefile" from example 1 into two files: Example 2:: @@ -250,37 +249,6 @@ module 8123.ko, which is built from the following files:: consisting of several hundred lines, and here it really pays off to separate the kbuild part from the rest. - The next example shows a backward compatible version. - - Example 3:: - - --> filename: Kbuild - obj-m := 8123.o - 8123-y := 8123_if.o 8123_pci.o 8123_bin.o - - --> filename: Makefile - ifneq ($(KERNELRELEASE),) - # kbuild part of makefile - include Kbuild - - else - # normal makefile - KDIR ?= /lib/modules/`uname -r`/build - - default: - $(MAKE) -C $(KDIR) M=$$PWD - - # Module specific targets - genbin: - echo "X" > 8123_bin.o_shipped - - endif - - Here the "Kbuild" file is included from the makefile. This - allows an older version of kbuild, which only knows of - makefiles, to be used when the "make" and kbuild parts are - split into separate files. - 3.3 Binary Blobs ---------------- From patchwork Tue Sep 17 14:16:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13806198 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 EBC4317C9A7; Tue, 17 Sep 2024 14:17:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582656; cv=none; b=M5ozGpkalMn59j+0mPxYabqUNw0xmUJg9wtNlpD+/Zz2X8Kkd4sQp/nE+6wpyXLOXU2M6vhbVgBJ4Ik/gyL/Yo0ZXQiLTlw2QGR8wRfvaupPi3NtPj1rpo5iEgDY8elXuVQNANrQzhQiHzabTAp+4CyheSEqNYdBU0hhBs4exzE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582656; c=relaxed/simple; bh=i2X5CGYdAQj7D1JJrAj+pHMkEjk/Y29Sea8SsHGcNkc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R3XTlbBtNvkqz9omgrvAI0nN5TmmSjBf+2xF9IqgnPysjWlCwBkbXIrPgs+RaPme8oSlmYmEQvoY6F5fCosOKBzKpIlEF1Uq1CyjVedUGTjCuNSkVhl8KorruTcee5UibwI7ezC0kVRjAttSrrPtL+FjV2aPSZvdWZ4LFxn1sow= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=m6XnzA1K; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="m6XnzA1K" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05B93C4CED5; Tue, 17 Sep 2024 14:17:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726582655; bh=i2X5CGYdAQj7D1JJrAj+pHMkEjk/Y29Sea8SsHGcNkc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m6XnzA1Kr+++5Y87VdLgXLoTj/dUyyCb+Zm9bmNchVmR+/82UL82qpdL9dbTc5NRs QNKeS0/aHzdNNeaeq1tzedAlR3TuzR0ipNT4pe7xRUS/Iztm8Kyf9sypjgAkxGWRGL Pc7sUqpk5LEprT9pLAXK7f4K8GMOgYKBShFzX8iYF+eZii1H5ATAryf0iDJffA8o+v cRUMsx9koLMYfll6/9cEhBDmiokM9fzRXMw9BBKsYOofqW11cDct+fEVbvmczKIBe5 3SdCv6CiCu3zGpV0G0G46yxwTa7j0ZRrd//Z5uP/9ZgocUhyV/mQOLfNICinSXuP9G R2wjU/pFdxgSQ== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Miguel Ojeda , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Nathan Chancellor , Nicolas Schier , Masahiro Yamada Subject: [PATCH 02/23] kbuild: doc: remove description about grepping CONFIG options Date: Tue, 17 Sep 2024 23:16:30 +0900 Message-ID: <20240917141725.466514-3-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240917141725.466514-1-masahiroy@kernel.org> References: <20240917141725.466514-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This description was added 20 years ago [1]. It does not convey any useful information except for a feeling of nostalgia. [1]: https://git.kernel.org/pub/scm/linux/kernel/git/history/history.git/commit/?id=65e433436b5794ae056d22ddba60fe9194bba007 Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- Documentation/kbuild/modules.rst | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Documentation/kbuild/modules.rst b/Documentation/kbuild/modules.rst index 1014a275a7e1..268ebbd2ab74 100644 --- a/Documentation/kbuild/modules.rst +++ b/Documentation/kbuild/modules.rst @@ -521,9 +521,3 @@ build. ext2-y := balloc.o bitmap.o dir.o ext2-$(CONFIG_EXT2_FS_XATTR) += xattr.o - - External modules have traditionally used "grep" to check for - specific `CONFIG_` settings directly in .config. This usage is - broken. As introduced before, external modules should use - kbuild for building and can therefore use the same methods as - in-tree modules when testing for `CONFIG_` definitions. From patchwork Tue Sep 17 14:16:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13806199 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2CAE618594F; Tue, 17 Sep 2024 14:17:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582658; cv=none; b=nKmTvDAn7sSrCBvtV1+BuSqGG6rbTP/SDM7t6RxDxG4i9j+hgbZqlvQWCAF9OZuIU0QknzI7dQsDEIxBjismJVa18mqzzN9YtGHyFCvDh6E8NWZHT2WQTF9chro7REJ34m/NaooTl4KHgzDIPyaQCANqWqlrtiiPIldL49fPCDg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582658; c=relaxed/simple; bh=mEQ0ucDdLUQliMtanUxk44g5JWErCiGrOMyYhL1jU8I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=amXN8rxx+6+nJVy+M5GTDnPSaFvMP342KQnVZyLkvpTtnWO6Y3/h7hG/JsvKkWB07KOL0UP+vSYonH7rQNtedq2IL7bDkRVo6XcRUO303T0VQar7e9Xy8IuXR7r6FCns9X2vkHvsMMadkWG/ssJm9jk6FVDn6HmF4x3tTmLz0Mo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ToA62I3D; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ToA62I3D" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 11942C4CECD; Tue, 17 Sep 2024 14:17:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726582657; bh=mEQ0ucDdLUQliMtanUxk44g5JWErCiGrOMyYhL1jU8I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ToA62I3DlVO5DsXeJCBgIqatkpRCPrEwx6J1aXJONw2xm9MUakM5NkaltIugwb7lc +KakMreO0NvbKPS0KLviMBXvUzL/j+Eh3r6O6ExQPdz5wkyNYotS73jNpm0LsQZz7I Kh2mKbev4qC4PefI7yP3yO1ulWguqONEdA3FruhDY9Ysoo/YZHZT9aixi8y6wHS/s9 ORphFAFmWYbK8P++ahlH2Er9J8GxSUIpaxtpHVZif+lcs08ypQhtl7GrXWbFu701uH rF3XWxTruIdrberKoFTa2Ivl5b9wjEoBA2D3GjobqUOZS3uV90pAAZHgGaUvnxuW3R yJlp/gb80RNAA== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Miguel Ojeda , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Nathan Chancellor , Nicolas Schier , Masahiro Yamada Subject: [PATCH 03/23] kbuild: doc: remove outdated description of the limitation on -I usage Date: Tue, 17 Sep 2024 23:16:31 +0900 Message-ID: <20240917141725.466514-4-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240917141725.466514-1-masahiroy@kernel.org> References: <20240917141725.466514-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Kbuild used to manipulate header search paths, enforcing the odd limitation of "no space after -I". Commit cdd750bfb1f7 ("kbuild: remove 'addtree' and 'flags' magic for header search paths") stopped doing that. This limitation no longer exists. Instead, you need to accurately specify the header search path. (In this case, $(src)/include) Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- Documentation/kbuild/modules.rst | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Documentation/kbuild/modules.rst b/Documentation/kbuild/modules.rst index 268ebbd2ab74..7eceb9a65e9c 100644 --- a/Documentation/kbuild/modules.rst +++ b/Documentation/kbuild/modules.rst @@ -328,13 +328,9 @@ according to the following rule: --> filename: Kbuild obj-m := 8123.o - ccflags-y := -Iinclude + ccflags-y := -I $(src)/include 8123-y := 8123_if.o 8123_pci.o 8123_bin.o - Note that in the assignment there is no space between -I and - the path. This is a limitation of kbuild: there must be no - space present. - 4.3 Several Subdirectories -------------------------- From patchwork Tue Sep 17 14:16:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13806200 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 396DA18757D; Tue, 17 Sep 2024 14:17:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582660; cv=none; b=fuyzplkj8YNFMZbxix20w+b47oc8u0h3f9FskL8T4/Bu1ePIRY/rOBPzzZinR+PlBExQXilJ/JADQJY4gG5M0o2A7hVV54eUTaoxlS/G3cBICDkF4s3molCUBLE5tF5zt+q9NaCq/DvwqgXd+S5sZV/00tEgUaBflWlBJmgE3x0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582660; c=relaxed/simple; bh=M5hwbxGmb3kFIwBUjhm/vKr9Jp1vcsNIkcx9cZ1dz/U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P1FTPIcdYxrhSnK/f9YC8sgAWubMADudVJvLFXxkYFCsz5BhDXaYJW6WXeOL6c9AGBTOEe87Agiwq/2KlcnIjwhbLNci7LrpK+lOLouBYmc7+67YZhMdJFLNPJHENyuVhjnkM8Kxx8A0Zz+b8KhOtduB5RWimuaZl595VdLmU40= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MWc/OAQJ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MWc/OAQJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F4BEC4CECF; Tue, 17 Sep 2024 14:17:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726582659; bh=M5hwbxGmb3kFIwBUjhm/vKr9Jp1vcsNIkcx9cZ1dz/U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MWc/OAQJOTgPjXBC/zSjUa4v5+Mr++4m5gzJFVPj/+Z1TxHe9TfkRecHrs3e0f7Le ++eq01SBf39lsPA5zraelQ1Q2NGhtMEm9OZYIL9/JWpMFg22Bv1S5KhF34flw3TIEt eY8YMhAa3+YEl555Fh67Oza/yuOGH1jKbwAEP1/JVSFcK8Pk876xxFxJbr5SCfvncG dS9ib/pTO/wkUQ889CJyYMIl5s4NO090BckwTlHLZE/DMQPDKlm4TBXeRC4UZTi13C Q3wn0S1VZhNh2vGQzoZeLpMjNEYqmIxyQRlKrWaSC3AVhiVs/LV5H8lQlT7j4DYrbZ B4OPqFAnY/QYg== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Miguel Ojeda , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Nathan Chancellor , Nicolas Schier , Masahiro Yamada Subject: [PATCH 04/23] kbuild: doc: remove the description about shipped files Date: Tue, 17 Sep 2024 23:16:32 +0900 Message-ID: <20240917141725.466514-5-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240917141725.466514-1-masahiroy@kernel.org> References: <20240917141725.466514-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The use of shipped files is discouraged in the upstream kernel these days. [1] Downstream Makefiles have the freedom to use shipped files or other options to handle binaries, but this is not what should be advertised in the upstream document. [1]: https://lore.kernel.org/all/CAHk-=wgSEi_ZrHdqr=20xv+d6dr5G895CbOAi8ok+7-CQUN=fQ@mail.gmail.com/ Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- Documentation/kbuild/modules.rst | 35 +++----------------------------- 1 file changed, 3 insertions(+), 32 deletions(-) diff --git a/Documentation/kbuild/modules.rst b/Documentation/kbuild/modules.rst index 7eceb9a65e9c..1afa6b1b4090 100644 --- a/Documentation/kbuild/modules.rst +++ b/Documentation/kbuild/modules.rst @@ -180,7 +180,6 @@ module 8123.ko, which is built from the following files:: 8123_if.c 8123_if.h 8123_pci.c - 8123_bin.o_shipped <= Binary blob 3.1 Shared Makefile ------------------- @@ -198,7 +197,7 @@ module 8123.ko, which is built from the following files:: ifneq ($(KERNELRELEASE),) # kbuild part of makefile obj-m := 8123.o - 8123-y := 8123_if.o 8123_pci.o 8123_bin.o + 8123-y := 8123_if.o 8123_pci.o else # normal makefile @@ -207,10 +206,6 @@ module 8123.ko, which is built from the following files:: default: $(MAKE) -C $(KDIR) M=$$PWD - # Module specific targets - genbin: - echo "X" > 8123_bin.o_shipped - endif The check for KERNELRELEASE is used to separate the two parts @@ -232,7 +227,7 @@ module 8123.ko, which is built from the following files:: --> filename: Kbuild obj-m := 8123.o - 8123-y := 8123_if.o 8123_pci.o 8123_bin.o + 8123-y := 8123_if.o 8123_pci.o --> filename: Makefile KDIR ?= /lib/modules/`uname -r`/build @@ -240,35 +235,11 @@ module 8123.ko, which is built from the following files:: default: $(MAKE) -C $(KDIR) M=$$PWD - # Module specific targets - genbin: - echo "X" > 8123_bin.o_shipped - The split in example 2 is questionable due to the simplicity of each file; however, some external modules use makefiles consisting of several hundred lines, and here it really pays off to separate the kbuild part from the rest. -3.3 Binary Blobs ----------------- - - Some external modules need to include an object file as a blob. - kbuild has support for this, but requires the blob file to be - named _shipped. When the kbuild rules kick in, a copy - of _shipped is created with _shipped stripped off, - giving us . This shortened filename can be used in - the assignment to the module. - - Throughout this section, 8123_bin.o_shipped has been used to - build the kernel module 8123.ko; it has been included as - 8123_bin.o:: - - 8123-y := 8123_if.o 8123_pci.o 8123_bin.o - - Although there is no distinction between the ordinary source - files and the binary file, kbuild will pick up different rules - when creating the object file for the module. - 3.4 Building Multiple Modules ============================= @@ -329,7 +300,7 @@ according to the following rule: obj-m := 8123.o ccflags-y := -I $(src)/include - 8123-y := 8123_if.o 8123_pci.o 8123_bin.o + 8123-y := 8123_if.o 8123_pci.o 4.3 Several Subdirectories -------------------------- From patchwork Tue Sep 17 14:16:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13806201 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 F0F74178397; Tue, 17 Sep 2024 14:17:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582662; cv=none; b=QviSODDb49UyiLyL52Ta7oNwrnhoqTnWcotWTJ1eu4EvDCF7IBqYfkcRaVNqao7kFXIyeiv0RpD32eqhnRGGlo4oSav7T7OrVRMNzMFdLSj07iOX4yf4QzyDgw8xeevHw1ayMpcwfsFypU89cjIxAdnPXFD1pEywsPm/g58UKi8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582662; c=relaxed/simple; bh=zOKWLWOiEYUwJiA94nx2gJuvgncyH0kFTF0myUNTP9U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gNRuaQRCq3ivusGiFEBE0RyGN9GXJY8P02EGGmw2HKdQ3tKXliAqa+OzWW9yoDOTO/EwkuFRRDlisTCN4hKkUsXfT+RTXGU0MzCcwBXKfK9xxo1hIWa1EmPvsSXbl6qUscr4qFdZTk9YoT2o7pvR24cpsmB4WXwlg/vm4jxot0g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NRkSmNbJ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NRkSmNbJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E3BFC4CECE; Tue, 17 Sep 2024 14:17:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726582661; bh=zOKWLWOiEYUwJiA94nx2gJuvgncyH0kFTF0myUNTP9U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NRkSmNbJuo3Hq9ZTl320PZn/MO+WmCugD2N6q31nRrCb16Ne1BdOLsPzdPaBrjphn +cTQcD48Ad5XjpNwkIQn3PtgNL5CHssJnHoy23ym60aEu1MgoNDhjftZ29YvHQNlIs yKLR6yrLc3Yi53Ls7yQwNkW1FZZGzFxr3/Deb05iUmDd2Bqh9qZHcVjNlEn6otEQNj dxonGv/z9mJyZDSZK/jnCgc6rbTMB0TWZhR8iZOnCImU13KK2ujhWWkGxzHN2cbz+w kzdhqjbvLN0jODN0E6VJreNegwxvPr8tYsUdgCHvwfHwKWQhi0/ceJrVi/4OpZSnvE L4E9DcPKIhayg== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Miguel Ojeda , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Nathan Chancellor , Nicolas Schier , Masahiro Yamada Subject: [PATCH 05/23] kbuild: doc: describe the -C option precisely for external module builds Date: Tue, 17 Sep 2024 23:16:33 +0900 Message-ID: <20240917141725.466514-6-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240917141725.466514-1-masahiroy@kernel.org> References: <20240917141725.466514-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Building external modules is typically done using this command: $ make -C M= Here, refers to the output directory where the kernel was built, not the kernel source directory. When the kernel is built in-tree, there is no ambiguity, as the output directory and the source directory are the same. If the kernel was built in a separate build directory, should be the kernel output directory. Otherwise, Kbuild cannot locate necessary build artifacts such as the .config file, etc. This has been the method for building external modules based on the kernel compiled in a separate directory for over 20 years. [1] If you pass the kernel source directory to the -C option, you must also specify the kernel build directory using the O= option. This approach works as well, though it results in a slightly longer command: $ make -C O= M= Some people mistakenly believe that O= should point to a separate output directory for external modules when used together with M=. This commit adds more clarification to Documentation/kbuild/kbuild.rst. [1]: https://git.kernel.org/pub/scm/linux/kernel/git/history/history.git/commit/?id=e321b2ec2eb2993b3d0116e5163c78ad923e3c54 Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier Reviewed-by: Nicolas Schier --- Documentation/kbuild/kbuild.rst | 5 +++++ Documentation/kbuild/modules.rst | 9 ++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Documentation/kbuild/kbuild.rst b/Documentation/kbuild/kbuild.rst index 9c8d1d046ea5..716f6fb70829 100644 --- a/Documentation/kbuild/kbuild.rst +++ b/Documentation/kbuild/kbuild.rst @@ -129,6 +129,11 @@ KBUILD_OUTPUT ------------- Specify the output directory when building the kernel. +This variable can also be used to point to the kernel output directory when +building external modules using kernel build artifacts in a separate build +directory. Please note that this does NOT specify the output directory for the +external modules themselves. + The output directory can also be specified using "O=...". Setting "O=..." takes precedence over KBUILD_OUTPUT. diff --git a/Documentation/kbuild/modules.rst b/Documentation/kbuild/modules.rst index 1afa6b1b4090..a80bff699e77 100644 --- a/Documentation/kbuild/modules.rst +++ b/Documentation/kbuild/modules.rst @@ -74,7 +74,7 @@ executed to make module versioning work. The command to build an external module is:: - $ make -C M=$PWD + $ make -C M=$PWD The kbuild system knows that an external module is being built due to the "M=" option given in the command. @@ -91,12 +91,15 @@ executed to make module versioning work. 2.2 Options =========== - ($KDIR refers to the path of the kernel source directory.) + ($KDIR refers to the path of the kernel source directory, or the path + of the kernel output directory if the kernel was built in a separate + build directory.) make -C $KDIR M=$PWD -C $KDIR - The directory where the kernel source is located. + The directory that contains the kernel and relevant build + artifacts used for building an external module. "make" will actually change to the specified directory when executing and will change back when finished. From patchwork Tue Sep 17 14:16:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13806202 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 3C70B189503; Tue, 17 Sep 2024 14:17:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582664; cv=none; b=to9qUWRDqqvHFvr5Of66CiZX1asrrNZq4SFbykINtMs3pc4G1jk+YY9bbrUzpQbgm18Lzk6EI6PzfQruBsz3xFgCPICh/4tPMqrKwatfYi4D1h7PwgTKIzvtv4oWu08DwjEIz084Drs1Gw4wYrXFauJccKh7D8eqXDKI5UYWj2c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582664; c=relaxed/simple; bh=BrRTM809vvzXSKo1ggTymNEipDQUHfKnrRRZ0fYJjww=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U4jYgtNLDzdUDaHioAHIaNJRPgIM+44QvleiPd9ma7u2xLUoeLgsa3etCVsnheskmkp/AB4uQWCTAtXX8wkRQ56YhMfZLw8Qf5ZQ4kWaqPQJQOn9do8pmSc0LM5eAzt0zK4vjbxUL7AN6dYc0S+wyzAKOPm4J8Q4fHN/C+cN7ZY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XMPLBvWH; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XMPLBvWH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 349B6C4CECE; Tue, 17 Sep 2024 14:17:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726582663; bh=BrRTM809vvzXSKo1ggTymNEipDQUHfKnrRRZ0fYJjww=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XMPLBvWH6B6t01Pd2ofS+HINpciwcG7dp1EW/GNH5X96HxWtY9mkj8hjjQ71N3t8S f7ABnyosJfuVdxgOEE7JtX1VkO/dF0uBtZfxwzdIvBRnO8sIzNqcNwlws33v8vxIaA QKteJFRnMhmxb9CjGJydlXDDSxB5yCyd+oToaKvVY4gkgCLVOAlOGQaUiEZaw+DGi1 YQikz0kq9Er2JUG8n9JskP6EIia5MOxREqkMHRMm7Oet+uLFZIZIpviooFtqQRawF0 f33y8D9qdC9Q96+SgAl00Q4/k9ylvCDvLCT+8Rpnxyn8DyyDeQqBzpCI5Tr+svSQfT KbOU8ZW/mQVkg== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Miguel Ojeda , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Nathan Chancellor , Nicolas Schier , Masahiro Yamada Subject: [PATCH 06/23] kbuild: doc: replace "gcc" in external module description Date: Tue, 17 Sep 2024 23:16:34 +0900 Message-ID: <20240917141725.466514-7-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240917141725.466514-1-masahiroy@kernel.org> References: <20240917141725.466514-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Avoid "gcc" since it is not the only compiler supported by Kbuild. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- Documentation/kbuild/modules.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/kbuild/modules.rst b/Documentation/kbuild/modules.rst index a80bff699e77..3a6e7bdc0889 100644 --- a/Documentation/kbuild/modules.rst +++ b/Documentation/kbuild/modules.rst @@ -38,7 +38,7 @@ This document describes how to build an out-of-tree kernel module. "kbuild" is the build system used by the Linux kernel. Modules must use kbuild to stay compatible with changes in the build infrastructure and -to pick up the right flags to "gcc." Functionality for building modules +to pick up the right flags to the compiler. Functionality for building modules both in-tree and out-of-tree is provided. The method for building either is similar, and all modules are initially developed and built out-of-tree. @@ -284,7 +284,7 @@ according to the following rule: #include - kbuild will add options to "gcc" so the relevant directories + kbuild will add options to the compiler so the relevant directories are searched. 4.2 Single Subdirectory From patchwork Tue Sep 17 14:16:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13806203 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 4619F18A6CC; Tue, 17 Sep 2024 14:17:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582666; cv=none; b=k2iUKGj+HUTGLdtsb/Ry4bPithXgoNgMq3xVXWue2XjzNFo8M23FJYd39raqSqQQHV0aGYAwWtpIi2W/yxsZtNKIYFPVI33o0W1O+/IjACkBNz0Y9EgIm8Req6h4llzgFq14t3rFZcS7IyP8ZyO/HPje8XgZfImkYGDpHHKPKVs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582666; c=relaxed/simple; bh=+9PNpuHsdm7Ec9+L5pNvm1cAeo6Z5ZSpTWnrQWR6nsc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k1sf6F2hXZRI2ioKLgbyykpJG7on1UvyGD1IeDQO7eIMtyOA8nAog++qWz8rFpBchjIAbjxjMt0KLfkgAb3+zCzUGSIZ97vpc/C4VMS0eS1J3ceY4XZ9/XFc9ePYf8Rgv+UoZoK2rleGSpwN7eC/kcBdOz5OE87DEUoQOvy2gNA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BTwPRpGA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BTwPRpGA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 599BAC4CEC5; Tue, 17 Sep 2024 14:17:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726582666; bh=+9PNpuHsdm7Ec9+L5pNvm1cAeo6Z5ZSpTWnrQWR6nsc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BTwPRpGA7aRIKVZP6gJs11R258Rf/4UU5zer3t5jnekFkSwXESj29OVdiDU/GaxO2 MGXEMJ3GY74WkfZvQAoHTmqCPhQ1kjiv8t6ml/Bx5Qi+d6TZZsq3VLTO71dFuP0KuP sdsGbbBQ9KigJp/IYxzNR5ybSkuJwlrD2OXPGuYtxUR9KxZDOxGLKNLGMvdZEPeHNM oVimC+mEmgUx9Qtskna0HwMwrkJU2QbnD9OREkncCoVmoh6FSmWRxs3UyriKXtJPX1 k2NpB6dXd8WoM/0fXiTXMRGdsYaEK7nE5UkFY+3aQJQrhnDHMPBfMIe7FNDu12LiD4 u1BxdQA/VnPiA== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Miguel Ojeda , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Nathan Chancellor , Nicolas Schier , Masahiro Yamada Subject: [PATCH 07/23] kbuild: remove unnecessary prune of rust/alloc for rustfmt Date: Tue, 17 Sep 2024 23:16:35 +0900 Message-ID: <20240917141725.466514-8-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240917141725.466514-1-masahiroy@kernel.org> References: <20240917141725.466514-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Commit 9d0441bab775 ("rust: alloc: remove our fork of the `alloc` crate") removed the rust/alloc/ directory. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier Acked-by: Miguel Ojeda --- Makefile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Makefile b/Makefile index 35b8392d2bef..5b16e0605a77 100644 --- a/Makefile +++ b/Makefile @@ -1741,9 +1741,7 @@ PHONY += rustfmt rustfmtcheck # We `grep` afterwards in order to remove the directory entry itself. rustfmt: $(Q)find $(abs_srctree) -type f -name '*.rs' \ - -o -path $(abs_srctree)/rust/alloc -prune \ -o -path $(abs_objtree)/rust/test -prune \ - | grep -Fv $(abs_srctree)/rust/alloc \ | grep -Fv $(abs_objtree)/rust/test \ | grep -Fv generated \ | xargs $(RUSTFMT) $(rustfmt_flags) From patchwork Tue Sep 17 14:16:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13806204 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 AC34917AE11; Tue, 17 Sep 2024 14:17:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582668; cv=none; b=khsyr2voekBkXaHxW0IwbRKEdC8Jzo5UgHG21HaJf1q1Vk1Lg96SCa82LDnMhgnLRO94ymYutFwYLLBuUN8w/KCwSotENSGQBJxHjx35w8dYVZoydeJrUdsP1MySSrnWV1OnGapP/DidCzXj/Lfjlx8059lJ1T+iWS6vW+Myj0U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582668; c=relaxed/simple; bh=n8IL6UM3AlOmJPnvqYyhhURelp40V5xK3Ka0wCaa2Q8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fUxUkpRhnMRWfoynG+WtYJk/1Hp8pCXfL0wYuGvXRRYFTvTH1IwnpEoSKcm2Vm4u7xmbiBqYCtkN+7ZAdo2z3syg3hhTZn6LGs5mvsftasOLzso6iFzbiWM6cz0MXOgQbF8v5aJDJN90r3tZcDVJhJZdYlFbvYnXZ3y+/3X+wug= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tbWqWCsX; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tbWqWCsX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B188FC4CECD; Tue, 17 Sep 2024 14:17:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726582668; bh=n8IL6UM3AlOmJPnvqYyhhURelp40V5xK3Ka0wCaa2Q8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tbWqWCsXC+BMGDSCr1VxGr9145xEILy0CqXIockESg7e+uDliCAdp6aWgKYYtTPXa jRw1khQ8xp3jkiUDjqi01iIBmDhQx8vBChhrcNMuve/BqYQzKwCXQ5yKLGNsOu8zdk mcZx7mqV4e1H4TAHWwfXai+ILxNk4EQJD30nOI/twKx8/gBCiUlfKm6npi/Uffr1Cd SP41JPqy3gjab5DlV24aPr7ogjc6dyJntjG63bDJcZe9fThoJCIu0I5zHRIwBl7PZW leoUd2dHWyvsvsC6iQzDjWNaUwVGCtGiyeATybuSpqIa/cQeTwlli0WGqv/zA1Tb6v 0JyFgAzA+ZUmw== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Miguel Ojeda , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Nathan Chancellor , Nicolas Schier , Masahiro Yamada Subject: [PATCH 08/23] kbuild: simplify find command for rustfmt Date: Tue, 17 Sep 2024 23:16:36 +0900 Message-ID: <20240917141725.466514-9-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240917141725.466514-1-masahiroy@kernel.org> References: <20240917141725.466514-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The current 'find' command does not prune the rust/test directory itself, requiring an additional 'grep -Fv' command to exclude it. This is cumbersome. The correct use of the -prune option can be seen in the 'make clean' rule. [Current command] $ find . -type f -name '*.rs' -o -path ./rust/test -prune | wc 70 70 1939 $ find . -type f -name '*.rs' -o -path ./rust/test -prune | grep rust/test ./rust/test [Improved command] $ find . -path ./rust/test -prune -o -type f -name '*.rs' -print | wc 69 69 1927 $ find . -path ./rust/test -prune -o -type f -name '*.rs' -print | grep rust/test With the improved 'find' command, the grep command is no longer needed. There is also no need to use the absolute path, so $(abs_srctree) can be replaced with $(srctree). The pruned directory rust/test must be prefixed with $(srctree) instead of $(objtree). Otherwise, 'make O=... rustfmt' would visit the stale rust/test directory remaining in the source tree. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier Acked-by: Miguel Ojeda --- Makefile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 5b16e0605a77..4992b2895dd5 100644 --- a/Makefile +++ b/Makefile @@ -1740,9 +1740,8 @@ PHONY += rustfmt rustfmtcheck # when matching, which is a problem when e.g. `srctree` is `..`. # We `grep` afterwards in order to remove the directory entry itself. rustfmt: - $(Q)find $(abs_srctree) -type f -name '*.rs' \ - -o -path $(abs_objtree)/rust/test -prune \ - | grep -Fv $(abs_objtree)/rust/test \ + $(Q)find $(srctree) -path $(srctree)/rust/test -prune \ + -o -type f -name '*.rs' -print \ | grep -Fv generated \ | xargs $(RUSTFMT) $(rustfmt_flags) From patchwork Tue Sep 17 14:16:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13806205 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 EA01E18E02B; Tue, 17 Sep 2024 14:17:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582671; cv=none; b=esbi+WBjPqkSi8XZiFVbc5FCsX7v1moCDgoS7IdXDzVTNVk+OF9OXTvM4oTFrQ89mU8VwHNid3kGtlvYV6sX97RNSlEkREMzJ7KQV1Q/p6OykqconY2N4lL3vvqH5nB3S9KhYHwOx63PzUdGv/2tsiS20I/fQFFvcj9LLD7DP5s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582671; c=relaxed/simple; bh=v1w8q5fANzCuOIlI91VhLyPWmXzboTXSVo9AD3A2I0k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gWL9+SmtmiSR4o4aMNUnH6wMx0p91RvxN5cMX3RIV2jw3lPtw3OubdR3+sssKLAafRlUU2IZeS58NYorTP+o6dF3oipB6tZ/jplNPbOCyLvxjTG0Fwf2+de+AXf8q9PmYBakga0niVJ12ZvjEyiQlp60/a6UhxIyvuLB+zt0jmo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OzXSvH7r; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OzXSvH7r" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF7B6C4CECF; Tue, 17 Sep 2024 14:17:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726582670; bh=v1w8q5fANzCuOIlI91VhLyPWmXzboTXSVo9AD3A2I0k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OzXSvH7r9H0jhAg4LT7kVq5RXbI35nkRhJGKkXRly5yEfNWsBdbvPgUHU7IlyGhAO QVBBVtiHOOx3uHXcDtzFx3XxQG/45Evv+0lyk/+jFkC1+o7JEIl/2XSTqIUMKB/CFc U+RtU0nExBesrp01FEjrF11s8NcAxd0KRj23l+YjQXZz9ZZlIc2f32FMkxBX7uy7fC 4JdlA8K2Yi9DXKdZ/64iXxtenQ8JW8IQgOAS7Ez5v7TQxUk1nnYdlyoWhjqEtHyNN4 JUnlkMxB24d6ZImIqqBdHU0xeFLcwiFYjVpD7go804uAUgGg1r9R+iZMHIiJ7TPT2f 69PyiXzsHlKCg== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Miguel Ojeda , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Nathan Chancellor , Nicolas Schier , Masahiro Yamada Subject: [PATCH 09/23] speakup: use SPKDIR=$(src) to specify the source directory Date: Tue, 17 Sep 2024 23:16:37 +0900 Message-ID: <20240917141725.466514-10-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240917141725.466514-1-masahiroy@kernel.org> References: <20240917141725.466514-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Since commit b1992c3772e6 ("kbuild: use $(src) instead of $(srctree)/$(src) for source directory"), $(src) consistently points to the source directory whether this is compiled an as external module or not. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- drivers/accessibility/speakup/Makefile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/accessibility/speakup/Makefile b/drivers/accessibility/speakup/Makefile index 6f6a83565c0d..14ba1cca87f4 100644 --- a/drivers/accessibility/speakup/Makefile +++ b/drivers/accessibility/speakup/Makefile @@ -40,9 +40,7 @@ hostprogs += makemapdata makemapdata-objs := makemapdata.o quiet_cmd_mkmap = MKMAP $@ - cmd_mkmap = TOPDIR=$(srctree) \ - SPKDIR=$(if $(KBUILD_EXTMOD),$(KBUILD_EXTMOD),$(srctree)/drivers/accessibility/speakup) \ - $(obj)/makemapdata > $@ + cmd_mkmap = TOPDIR=$(srctree) SPKDIR=$(src) $(obj)/makemapdata > $@ $(obj)/mapdata.h: $(obj)/makemapdata $(call cmd,mkmap) From patchwork Tue Sep 17 14:16:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13806206 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 37D67190486; Tue, 17 Sep 2024 14:17:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582673; cv=none; b=L7yi9M5/3Vft84b6014wYzuKLBrcYvnsSbFdf8yB2Auyfzhv7k//Dx8PYFr9Ydx1SFOiswvfAzdbwcWNXyaKFSlV20ktaMzEGb+NKEcgbvsESm57ARmSZ2xF/pGTJ/r3WMyEVgNJGaWgWk+r/RhK8HWhEM/Yj5lDsGpYlfQkCtI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582673; c=relaxed/simple; bh=WhinTnECYKQ6Ay8RYWYnKkOB1a4zHCeW5QL3zgxwZ7o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JxLu1QAO60KNnjvuij+iUBXY0DAUh9s9HNKC0TlmsFuQ8+T+HXbJR/nmnB8SH5uxb5Ezr8jmkH0UsuhwGGKRhzAVojZbf5UcSdK6aENU7nG4WShan0Ps2l/f1MbpqteFmqN7dvf78M4OwI3YXB/M0TdoaQECRV/0hxRl1s6nldM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FuehOgjg; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FuehOgjg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05521C4CEC5; Tue, 17 Sep 2024 14:17:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726582672; bh=WhinTnECYKQ6Ay8RYWYnKkOB1a4zHCeW5QL3zgxwZ7o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FuehOgjgaEL1OGaw0GMYGiAp1C257VwJJ3DDlRIAKvje33x2KLQ6aQ9off2YHjPoJ qzc2BMF3u+Jm17lrfCn23ZpHJBCm0ytPSJEZXQUYQaGPjlluJ+ekJ2fU6MiYZ3v6JW ggR+XCMn5RARvkuX/Vf17kTgMK7l+II1yH+WndUAh9V76DzVI9kMLPJjOyx3dBiwhb 658ABNr0U0MbgiTa4LBdA2VHzv6R8siZeHDMPee8EsKTAFvnT8BSw5oOBPn1GVnpqc 57aP0YQcEl5cJx4V3ge9vCzBL/lmEsj86ZTA/ZexgbqpoUugEWfpp/cJmt2rIT7HVg tCXdrWqmACbUQ== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Miguel Ojeda , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Nathan Chancellor , Nicolas Schier , Masahiro Yamada Subject: [PATCH 10/23] kbuild: refactor the check for missing config files Date: Tue, 17 Sep 2024 23:16:38 +0900 Message-ID: <20240917141725.466514-11-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240917141725.466514-1-masahiroy@kernel.org> References: <20240917141725.466514-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This commit refactors the check for missing configuration files, making it easier to add more files to the list. The format of the error message has been slightly changed, as follows: [Before] ERROR: Kernel configuration is invalid. include/generated/autoconf.h or include/config/auto.conf are missing. Run 'make oldconfig && make prepare' on kernel src to fix it. [After] *** *** ERROR: Kernel configuration is invalid. The following files are missing: *** - include/generated/autoconf.h *** - include/config/auto.conf *** Run "make oldconfig && make prepare" on kernel source to fix it. *** Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- Makefile | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 4992b2895dd5..3f5c273c2901 100644 --- a/Makefile +++ b/Makefile @@ -778,17 +778,22 @@ $(KCONFIG_CONFIG): else # !may-sync-config # External modules and some install targets need include/generated/autoconf.h # and include/config/auto.conf but do not care if they are up-to-date. -# Use auto.conf to trigger the test +# Use auto.conf to show the error message + +checked-configs := include/generated/autoconf.h include/config/auto.conf +missing-configs := $(filter-out $(wildcard $(checked-configs)), $(checked-configs)) + +ifdef missing-configs PHONY += include/config/auto.conf include/config/auto.conf: - @test -e include/generated/autoconf.h -a -e $@ || ( \ - echo >&2; \ - echo >&2 " ERROR: Kernel configuration is invalid."; \ - echo >&2 " include/generated/autoconf.h or $@ are missing.";\ - echo >&2 " Run 'make oldconfig && make prepare' on kernel src to fix it."; \ - echo >&2 ; \ - /bin/false) + @echo >&2 '***' + @echo >&2 '*** ERROR: Kernel configuration is invalid. The following files are missing:' + @printf >&2 '*** - %s\n' $(missing-configs) + @echo >&2 '*** Run "make oldconfig && make prepare" on kernel source to fix it.' + @echo >&2 '***' + @/bin/false +endif endif # may-sync-config endif # need-config From patchwork Tue Sep 17 14:16:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13806207 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 6B32617BEDB; Tue, 17 Sep 2024 14:17:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582675; cv=none; b=RbI5WCIOxELIDhQZz5PQnJG69s0C8CKFyygMtL0lZvZdrnp2bRjcTToMgBXOpSOWbLbMcidw4VO/riCm2S2j7pzKve/1X+AltkFhNl3eDzAndEIff5UmQP65rWYbpKNV37SPqgp9pfTAzA3lCSdS1JVj1rbaEenjdzGin6SF+jo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582675; c=relaxed/simple; bh=4bq9doD09IGzlJ3vv9HsmysgLeLSxT9Eyw84oRf2g1g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UchGlwTvHAEEwHtJEvD4+lT1+zyvVf45H+CSaYYzFOc7vTClJUYgC1cY2KmzaPEfO0Lj4amNXppa0AhUgsX+Dfi74uAhlC7ovFs3GkAo+541ZjR2qHsTXU3VwTGtK9cyq1xw//aLG+sghg1r5T+nfzjQWMfnbS5fQo3IhTOYtGo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DKX6o4/r; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DKX6o4/r" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42FBCC4CECE; Tue, 17 Sep 2024 14:17:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726582675; bh=4bq9doD09IGzlJ3vv9HsmysgLeLSxT9Eyw84oRf2g1g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DKX6o4/rSSj/+99p6SQAuNKThNXjF+BJA2kw2x9aSClEOtv5zysvRDgXIdXtFwwpk 3kvuQWyTw2vFMucNX5MGNztXZIVXlUYMpWlOhHSgDVNfnYedO4l+hdizb+Yeu2xvTz K4YrjvLrtkBD+dwj7YK4SXhWpNQqW+tgknpFMtdN9cywZO/NbabRrS4iyisKh6PUqz vwp1leq9nFURUP2KOXvHGyvmCZmmokq5wfecgHTTzqbWYSJHiQkuUApUp8oBM9pCYo USu9LBQ2asHTDl/ZJSQfRqa9KHCLzIN9KSXYQ4a+ynOpnBTGu3wEZFFdPeGK06U0U5 KmLsxAvhtVygA== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Miguel Ojeda , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Nathan Chancellor , Nicolas Schier , Masahiro Yamada Subject: [PATCH 11/23] kbuild: check the presence of include/generated/rustc_cfg Date: Tue, 17 Sep 2024 23:16:39 +0900 Message-ID: <20240917141725.466514-12-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240917141725.466514-1-masahiroy@kernel.org> References: <20240917141725.466514-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Since commit 2f7ab1267dc9 ("Kbuild: add Rust support"), Kconfig generates include/generated/rustc_cfg, but its presence is not checked in the top-level Makefile. It should be checked similarly to the C header counterpart, include/generated/autoconf.h. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier Acked-by: Miguel Ojeda Tested-by: Miguel Ojeda --- Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 3f5c273c2901..5700d08c9b57 100644 --- a/Makefile +++ b/Makefile @@ -780,7 +780,7 @@ else # !may-sync-config # and include/config/auto.conf but do not care if they are up-to-date. # Use auto.conf to show the error message -checked-configs := include/generated/autoconf.h include/config/auto.conf +checked-configs := include/generated/autoconf.h include/generated/rustc_cfg include/config/auto.conf missing-configs := $(filter-out $(wildcard $(checked-configs)), $(checked-configs)) ifdef missing-configs @@ -1187,7 +1187,8 @@ PHONY += prepare archprepare archprepare: outputmakefile archheaders archscripts scripts include/config/kernel.release \ asm-generic $(version_h) include/generated/utsrelease.h \ - include/generated/compile.h include/generated/autoconf.h remove-stale-files + include/generated/compile.h include/generated/autoconf.h \ + include/generated/rustc_cfg remove-stale-files prepare0: archprepare $(Q)$(MAKE) $(build)=scripts/mod From patchwork Tue Sep 17 14:16:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13806208 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 AA3A91925B1; Tue, 17 Sep 2024 14:17:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582677; cv=none; b=T205+eUOt70ocOTel9K6FbzcwunRp7RdJUqD6smukABTl8/+0uSNUgtfi87fiKelWXaPoofzdjOjyNv9+t5y4rZCY1g78KiUeEzmnh7z7QrF5pihjP+0GXFqj2jlJSVOlvWo29q8sY3O4YyfHbGdKHBqehkMLJhxDtvWZEVhK/Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582677; c=relaxed/simple; bh=CPGuVVmP9nfnoF+wMfgzB9DaNE/+HVqfHgpUsGHpkck=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ioY400YZboTnuE5kEdBdh05bIrlAuxQ4WLTQ7r8CEGo6Hhdn1HoIon07+EHiFvcYenydkP8DMihnThofVFoZYBcc/zOZS6GMYXfxYxLyrdGYb5IlLh/Y7G8za1k2JTMtq3AtG2HnmhC+cP2EFwhyWIy3j2hoAJH44Y+KDUvyRZ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HxsxDyhz; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HxsxDyhz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94298C4CEC5; Tue, 17 Sep 2024 14:17:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726582677; bh=CPGuVVmP9nfnoF+wMfgzB9DaNE/+HVqfHgpUsGHpkck=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HxsxDyhz/AwuzXACq66np4u4XrLpfHNQqs5Bm6tWzlHQ+885AdHOzSiSN1ztMyrAD 8ZoaJW7oQZwvS4D3qOdA1SKcRue4DSLjJnZfQP9j3kRDcP9Xac9kxgkbeDYIPE6VeB UJOzimE6zu47d+4fAMPldduXCNxV/+Z/9QEQOL2CVsgV+DiZOX6D4kVmtIpwT+8vHB YQSGUQy15KElY6hGYPmxtM6Qb6ghabXxVDXNS52dXQSCuf79b4HJpSeQsERmOu8YMo jjImF+uCPm8IumSRyvo+Pfmmw1JPYIVEppeKTKGExZiwihShQ0V2fld1xU2UnsOBsJ tF1mdozZZts0w== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Miguel Ojeda , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Nathan Chancellor , Nicolas Schier , Masahiro Yamada Subject: [PATCH 12/23] scripts/nsdeps: use VPATH as src_prefix Date: Tue, 17 Sep 2024 23:16:40 +0900 Message-ID: <20240917141725.466514-13-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240917141725.466514-1-masahiroy@kernel.org> References: <20240917141725.466514-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This change allows it to work not only for in-tree modules but also for external modules, even if they are built in a separate build directory. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- scripts/nsdeps | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/nsdeps b/scripts/nsdeps index f1718cc0d700..8b4db63838ce 100644 --- a/scripts/nsdeps +++ b/scripts/nsdeps @@ -19,10 +19,10 @@ if ! { echo "$SPATCH_REQ_VERSION"; echo "$SPATCH_VERSION"; } | sort -CV ; then exit 1 fi -if [ "$KBUILD_EXTMOD" ]; then +if [ "${VPATH+set}" ]; then src_prefix= else - src_prefix=$srctree/ + src_prefix=$VPATH/ fi generate_deps_for_ns() { From patchwork Tue Sep 17 14:16:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13806209 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2275917C99B; Tue, 17 Sep 2024 14:17:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582680; cv=none; b=jrdMsy947iGx17PtAK3yg2qzI/Xk5lnOiGezxICS1aNrjwnsCobzSoKtoL0V0PiDnA2fGvakarQHBwIe/zMH/+gg4QS6ZNly6WEaq0cpYU0e1nlIGCaLZFG6f4SP+5D44+yH7T4gIa5exLMKmCInJY/WGuJ2oLhCC4S1GbDlQTY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582680; c=relaxed/simple; bh=dwKSfpuXEb7k3eYZ4e5Rn0Sa6XU7qYIELYeSbbtc8lc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WkTHrq4HtNc4IpYpuHhsFOtLH2QNWMqRibwt2ua79fKPUHS1aDFdNIZ5ydr/0Uw6tW99kwOY76HsBoubLiIf+I/y8l/7S45Rj/q0f4R04cBSE9elFvqWs9V+AJ2vWKbUufwTV8q61kFmJhSOBH2cRqNkbmStyd+vUwLAwhjtTr8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AIVlRwM2; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AIVlRwM2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DBE01C4CEC5; Tue, 17 Sep 2024 14:17:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726582679; bh=dwKSfpuXEb7k3eYZ4e5Rn0Sa6XU7qYIELYeSbbtc8lc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AIVlRwM2FUewwZKUrJJdl5EsCeHBQBPtX6OhxpHOFEIK9AraokHsrtNY/xSxE5tgl AaAdfZlGy2I7l63r2Kp/Z0qOIujYa/cqQESKw6LrxicB64QqxhRSZRUkpjSgPLFsys g7tWOtUzFpp0KNu0UqbxJzCcH3ySNuiSAbYa7TfkxEA+Y17UlrboAtE74i/DlrM6lt OUhVqIu2xJHr6LZp/X0OKIpEiHK7P0VDI6O+bSI6tg9aVJ8jSWzvu0i+If0JxmKz5g frqA1qk29/VpKAja8loJv7t4rqDDuLlMny6TFTIpUyYLgyvbIMIw3AO+EmiFQF178d Gr1AUE1Pkcr3g== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Miguel Ojeda , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Nathan Chancellor , Nicolas Schier , Masahiro Yamada Subject: [PATCH 13/23] kbuild: replace two $(abs_objtree) with $(CURDIR) in top Makefile Date: Tue, 17 Sep 2024 23:16:41 +0900 Message-ID: <20240917141725.466514-14-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240917141725.466514-1-masahiroy@kernel.org> References: <20240917141725.466514-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Kbuild changes the working directory until it matches $(abs_objtree). When $(need-sub-make) is empty, $(abs_objtree) is the same as $(CURDIR). Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 5700d08c9b57..ee9ad0f0960f 100644 --- a/Makefile +++ b/Makefile @@ -228,12 +228,12 @@ else # need-sub-make # We process the rest of the Makefile if this is the final invocation of make -ifeq ($(abs_srctree),$(abs_objtree)) +ifeq ($(abs_srctree),$(CURDIR)) # building in the source tree srctree := . building_out_of_srctree := else - ifeq ($(abs_srctree)/,$(dir $(abs_objtree))) + ifeq ($(abs_srctree)/,$(dir $(CURDIR))) # building in a subdirectory of the source tree srctree := .. else From patchwork Tue Sep 17 14:16:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13806210 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 40DFB192D8F; Tue, 17 Sep 2024 14:18:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582682; cv=none; b=UTSiHAysM4I4lO2CpcC4lhd3Da6SUs5z/wbXOGkcoTmXWfz2SlEtdX1Bwje2XHVmT7/MwPQES0Cwe4ltZwS8VA6fHEYjXjX2nN7I+qzrGfMPiXFd5VF+SJBkh/ZFstjF9gl4r+wr/qUbu2epo2j9rZc/wmAlET78gBwX6JvBwus= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582682; c=relaxed/simple; bh=sHAeApIqfGlTqapdYcO1A9RoNWPGiHzfamf04FN3TXw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BfhadMkElLGCM7fl0p0tVroUR1xN6TeQjQHtIOQLVWkwSOBnQ5Nt2B+gpKICFKnF/JJta9RBmdaEPLMrwmM4swN4Z25/f7nJrhgcqFkI1FnhKr7v1+R/g3mrHJlqJSYdNjPw2Z7TLKKkr42fhoqVrqG2l1nt2zD/PbYPKTS79AY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=vAWXa3CM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="vAWXa3CM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 56AF5C4CECF; Tue, 17 Sep 2024 14:18:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726582682; bh=sHAeApIqfGlTqapdYcO1A9RoNWPGiHzfamf04FN3TXw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vAWXa3CM6bRnk2tcv0VM8xus1m2aTcJ4Ezr1niZCoBOikv643tfUQo++zFf3nyeRD Clj166vJaIk/hzTqNqD1X4dwK0Zu5S4KycUa47I+rRhW9OYtFCNxTYNCAIcW6v6FXS RZGFoerGLHHvz5r+DylcvjYvHcwZQy+M/vISpIYlycFIvgnmOFdcbzif7dVAmVMZla srCtee5Wx9c6j2X8U7/GKmHbG3yaafF8olPSB801Q67Bm06o1iK9ECDmGOAkyRsIWg nEuoEDLTn7Xi0ZqTybXbkHpVoiSuOwfYa4/v5g0nVgnYRKnb/iJhXZMynO2f6fxlHu DNBOunYiKEgdA== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Miguel Ojeda , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Nathan Chancellor , Nicolas Schier , Masahiro Yamada Subject: [PATCH 14/23] kbuild: add $(objtree)/ prefix to some in-kernel build artifacts Date: Tue, 17 Sep 2024 23:16:42 +0900 Message-ID: <20240917141725.466514-15-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240917141725.466514-1-masahiroy@kernel.org> References: <20240917141725.466514-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 $(objtree) refers to the top of the output directory of kernel builds. This commit adds the explicit (objtree)/ prefix to build artifacts needed for building external modules. This change has no immediate impact, as the top-level Makefile currently defines: objtree := . However, it prepares for supporting the building of external modules in a different directory. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- Makefile | 10 +++++----- scripts/Kbuild.include | 2 +- scripts/Makefile.build | 4 ++-- scripts/Makefile.modfinal | 14 +++++++------- scripts/Makefile.modinst | 2 +- scripts/Makefile.modpost | 12 ++++++------ scripts/depmod.sh | 4 ++-- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index ee9ad0f0960f..c923bea7043b 100644 --- a/Makefile +++ b/Makefile @@ -354,7 +354,7 @@ else # !mixed-build include $(srctree)/scripts/Kbuild.include # Read KERNELRELEASE from include/config/kernel.release (if it exists) -KERNELRELEASE = $(call read-file, include/config/kernel.release) +KERNELRELEASE = $(call read-file, $(objtree)/include/config/kernel.release) KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION) export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION @@ -717,7 +717,7 @@ endif export KBUILD_MODULES KBUILD_BUILTIN ifdef need-config -include include/config/auto.conf +include $(objtree)/include/config/auto.conf endif ifeq ($(KBUILD_EXTMOD),) @@ -780,13 +780,13 @@ else # !may-sync-config # and include/config/auto.conf but do not care if they are up-to-date. # Use auto.conf to show the error message -checked-configs := include/generated/autoconf.h include/generated/rustc_cfg include/config/auto.conf +checked-configs := $(addprefix $(objtree)/, include/generated/autoconf.h include/generated/rustc_cfg include/config/auto.conf) missing-configs := $(filter-out $(wildcard $(checked-configs)), $(checked-configs)) ifdef missing-configs -PHONY += include/config/auto.conf +PHONY += $(objtree)/include/config/auto.conf -include/config/auto.conf: +$(objtree)/include/config/auto.conf: @echo >&2 '***' @echo >&2 '*** ERROR: Kernel configuration is invalid. The following files are missing:' @printf >&2 '*** - %s\n' $(missing-configs) diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index ed8a7493524b..8c311b997e24 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -205,7 +205,7 @@ if_changed_dep = $(if $(if-changed-cond),$(cmd_and_fixdep),@:) cmd_and_fixdep = \ $(cmd); \ - scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).cmd;\ + $(objtree)/scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).cmd;\ rm -f $(depfile) # Usage: $(call if_changed_rule,foo) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 8403eba15457..6e8954cbf53a 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -34,7 +34,7 @@ subdir-asflags-y := subdir-ccflags-y := # Read auto.conf if it exists, otherwise ignore --include include/config/auto.conf +-include $(objtree)/include/config/auto.conf include $(srctree)/scripts/Kbuild.include include $(srctree)/scripts/Makefile.compiler @@ -107,7 +107,7 @@ cmd_cpp_i_c = $(CPP) $(c_flags) -o $@ $< $(obj)/%.i: $(obj)/%.c FORCE $(call if_changed_dep,cpp_i_c) -genksyms = scripts/genksyms/genksyms \ +genksyms = $(objtree)/scripts/genksyms/genksyms \ $(if $(1), -T $(2)) \ $(if $(KBUILD_PRESERVE), -p) \ -r $(or $(wildcard $(2:.symtypes=.symref)), /dev/null) diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal index 1482884ec3ca..6d8aa3059ee2 100644 --- a/scripts/Makefile.modfinal +++ b/scripts/Makefile.modfinal @@ -6,7 +6,7 @@ PHONY := __modfinal __modfinal: -include include/config/auto.conf +include $(objtree)/include/config/auto.conf include $(srctree)/scripts/Kbuild.include # for c_flags @@ -37,15 +37,15 @@ quiet_cmd_ld_ko_o = LD [M] $@ cmd_ld_ko_o = \ $(LD) -r $(KBUILD_LDFLAGS) \ $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \ - -T scripts/module.lds -o $@ $(filter %.o, $^) + -T $(objtree)/scripts/module.lds -o $@ $(filter %.o, $^) quiet_cmd_btf_ko = BTF [M] $@ cmd_btf_ko = \ - if [ ! -f vmlinux ]; then \ + if [ ! -f $(objtree)/vmlinux ]; then \ printf "Skipping BTF generation for %s due to unavailability of vmlinux\n" $@ 1>&2; \ else \ - LLVM_OBJCOPY="$(OBJCOPY)" $(PAHOLE) -J $(PAHOLE_FLAGS) $(MODULE_PAHOLE_FLAGS) --btf_base vmlinux $@; \ - $(RESOLVE_BTFIDS) -b vmlinux $@; \ + LLVM_OBJCOPY="$(OBJCOPY)" $(PAHOLE) -J $(PAHOLE_FLAGS) $(MODULE_PAHOLE_FLAGS) --btf_base $(objtree)/vmlinux $@; \ + $(RESOLVE_BTFIDS) -b $(objtree)/vmlinux $@; \ fi; # Same as newer-prereqs, but allows to exclude specified extra dependencies @@ -57,8 +57,8 @@ if_changed_except = $(if $(call newer_prereqs_except,$(2))$(cmd-check), \ printf '%s\n' 'savedcmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:) # Re-generate module BTFs if either module's .ko or vmlinux changed -%.ko: %.o %.mod.o $(extmod_prefix).module-common.o scripts/module.lds $(and $(CONFIG_DEBUG_INFO_BTF_MODULES),$(KBUILD_BUILTIN),vmlinux) FORCE - +$(call if_changed_except,ld_ko_o,vmlinux) +%.ko: %.o %.mod.o $(extmod_prefix).module-common.o $(objtree)/scripts/module.lds $(and $(CONFIG_DEBUG_INFO_BTF_MODULES),$(KBUILD_BUILTIN),$(objtree)/vmlinux) FORCE + +$(call if_changed_except,ld_ko_o,$(objtree)/vmlinux) ifdef CONFIG_DEBUG_INFO_BTF_MODULES +$(if $(newer-prereqs),$(call cmd,btf_ko)) endif diff --git a/scripts/Makefile.modinst b/scripts/Makefile.modinst index 4d81ed9af294..2d39d452c49e 100644 --- a/scripts/Makefile.modinst +++ b/scripts/Makefile.modinst @@ -6,7 +6,7 @@ PHONY := __modinst __modinst: -include include/config/auto.conf +include $(objtree)/include/config/auto.conf include $(srctree)/scripts/Kbuild.include install-y := diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost index 44936ebad161..12e7c15d099c 100644 --- a/scripts/Makefile.modpost +++ b/scripts/Makefile.modpost @@ -35,10 +35,10 @@ PHONY := __modpost __modpost: -include include/config/auto.conf +include $(objtree)/include/config/auto.conf include $(srctree)/scripts/Kbuild.include -MODPOST = scripts/mod/modpost +MODPOST = $(objtree)/scripts/mod/modpost modpost-args = \ $(if $(CONFIG_MODULES),-M) \ @@ -119,11 +119,11 @@ include $(kbuild-file) output-symdump := $(KBUILD_EXTMOD)/Module.symvers -ifeq ($(wildcard Module.symvers),) -missing-input := Module.symvers +ifeq ($(wildcard $(objtree)/Module.symvers),) +missing-input := $(objtree)/Module.symvers else -modpost-args += -i Module.symvers -modpost-deps += Module.symvers +modpost-args += -i $(objtree)/Module.symvers +modpost-deps += $(objtree)/Module.symvers endif modpost-args += -e $(addprefix -i , $(KBUILD_EXTRA_SYMBOLS)) diff --git a/scripts/depmod.sh b/scripts/depmod.sh index e22da27fe13e..3c34fecacbc8 100755 --- a/scripts/depmod.sh +++ b/scripts/depmod.sh @@ -12,7 +12,7 @@ KERNELRELEASE=$1 : ${DEPMOD:=depmod} -if ! test -r System.map ; then +if ! test -r "${objtree}/System.map" ; then echo "Warning: modules_install: missing 'System.map' file. Skipping depmod." >&2 exit 0 fi @@ -25,7 +25,7 @@ if [ -z $(command -v $DEPMOD) ]; then exit 0 fi -set -- -ae -F System.map +set -- -ae -F "${objtree}/System.map" if test -n "$INSTALL_MOD_PATH"; then set -- "$@" -b "$INSTALL_MOD_PATH" fi From patchwork Tue Sep 17 14:16:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13806211 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 E8BE1181339; Tue, 17 Sep 2024 14:18:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582685; cv=none; b=sXJ5dSX/feEphSRkVbsZs5n6s5j2sb3UJMyVq6osbaw92R2MAKundCYaW23afTL/8EP6SRjOI82D2e3rqQH2TxMtFqYp68IX2kN4kmTkpHqk0kuUuXeXuvAY3O/zZKxWcbZIQMSDR+7VlEUXu7iAj9yGfbSPli+tbpxa/ZCZAcQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582685; c=relaxed/simple; bh=lf/ZusSJTTcvWWbKf+tPGBQ2Lsaj7xnEDyV2byZ55dg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XK1ApRgFMb8lulHGpvXxqSyeaZGQ3ebC2dEAj+5vKmLYAP2Gcv5TOS5iYGQoob6dpGPtIywxw0GvuwAryb+8KQhkBKwMVKkK0QxAbBBDnx14NCH33j2BdNqmtF02U6JxKfzW+0j16/ppOVMPhSOKddlyAxwlfQfU/dWTYX/ZROs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YSht7sGd; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YSht7sGd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A9F9CC4CEC5; Tue, 17 Sep 2024 14:18:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726582684; bh=lf/ZusSJTTcvWWbKf+tPGBQ2Lsaj7xnEDyV2byZ55dg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YSht7sGdptXhO3YCVWjSFjEnvDgmPbBRhnvjHUlHEoa1d8cjTb3mXka24xbS5ZG3V wPAtAQf9mDwYJN5DWv1MUaJb1W99lk/o97D3FjYHIGaHwJmywl+HPtxyydIrH6JMjr 50AABl4Oje1D3AP9DmCQDDe4R+aXYKly2kRc1SIQ6kiMiiLF4pKJbFqNBUPO+SvdGU gm96Nul5sJDu20O8lbxU/25vMh9t+Gg7wwvu3BKg089flfx8slIuD52ekmmBfSvkV/ /ODBNo8Y7aE2qcWl78WDi4JL7wAD1m/udiIF6uA6Ej5Gm2tbLQWati1RNpuXFEXMa8 /ebgLQIirKBcA== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Miguel Ojeda , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Nathan Chancellor , Nicolas Schier , Masahiro Yamada Subject: [PATCH 15/23] kbuild: rename abs_objtree to abs_output Date: Tue, 17 Sep 2024 23:16:43 +0900 Message-ID: <20240917141725.466514-16-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240917141725.466514-1-masahiroy@kernel.org> References: <20240917141725.466514-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 'objtree' refers to the top of the output directory of kernel builds. Rename abs_objtree to a more generic name, to better reflect its use in the context of external module builds. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index c923bea7043b..254f05a1cc0f 100644 --- a/Makefile +++ b/Makefile @@ -40,7 +40,7 @@ __all: this-makefile := $(lastword $(MAKEFILE_LIST)) abs_srctree := $(realpath $(dir $(this-makefile))) -abs_objtree := $(CURDIR) +abs_output := $(CURDIR) ifneq ($(sub_make_done),1) @@ -185,8 +185,8 @@ ifneq ($(KBUILD_OUTPUT),) # $(realpath ...) gets empty if the path does not exist. Run 'mkdir -p' first. $(shell mkdir -p "$(KBUILD_OUTPUT)") # $(realpath ...) resolves symlinks -abs_objtree := $(realpath $(KBUILD_OUTPUT)) -$(if $(abs_objtree),,$(error failed to create output directory "$(KBUILD_OUTPUT)")) +abs_output := $(realpath $(KBUILD_OUTPUT)) +$(if $(abs_output),,$(error failed to create output directory "$(KBUILD_OUTPUT)")) endif # ifneq ($(KBUILD_OUTPUT),) ifneq ($(words $(subst :, ,$(abs_srctree))), 1) @@ -197,7 +197,7 @@ export sub_make_done := 1 endif # sub_make_done -ifeq ($(abs_objtree),$(CURDIR)) +ifeq ($(abs_output),$(CURDIR)) # Suppress "Entering directory ..." if we are at the final work directory. no-print-directory := --no-print-directory else @@ -221,7 +221,7 @@ $(filter-out $(this-makefile), $(MAKECMDGOALS)) __all: __sub-make # Invoke a second make in the output directory, passing relevant variables __sub-make: - $(Q)$(MAKE) $(no-print-directory) -C $(abs_objtree) \ + $(Q)$(MAKE) $(no-print-directory) -C $(abs_output) \ -f $(abs_srctree)/Makefile $(MAKECMDGOALS) else # need-sub-make From patchwork Tue Sep 17 14:16:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13806212 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 22E71193422; Tue, 17 Sep 2024 14:18:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582687; cv=none; b=QPL85Bq8KhYJICp1vbwDR82aopxlwS1FFFkW819W72HDYRLKFVMc2bz8atQN5wCwNPlBpLB5Hz7FBL6U5mxns30DPznLkawKryrGbZcKyFcTmhqmTpfBADzJCGeIPGxE5azh6RDcQ/PvQJvEiHYiet/lUG0OUS5cpTez2whnP0U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582687; c=relaxed/simple; bh=Ujo2ggpWsK2c23dBQVr2WlNq1lt94SVOQJZd+ZZqT5Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mEukZPrAFMAxWCXhc6pexJufZBdMjyp3rClBh6gMGp1JLcn/UHxvIHCZ0G0UnseJ8rb7teQ7OtbgBlBpMGJhfhZR7f9uGoRGqfdiP1Zvb/W0o/hpLBJUHFXGHQQ7SixYB2fUAXV5kGeOhLkKmImJ5VYvsrO2ajk4wFyNtFEaNQk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Xhr2bnFx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Xhr2bnFx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0CBC1C4CECD; Tue, 17 Sep 2024 14:18:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726582686; bh=Ujo2ggpWsK2c23dBQVr2WlNq1lt94SVOQJZd+ZZqT5Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xhr2bnFxx6Qe2WRGAYtU1rvX95LalQzsjFmtepTxfstZfY1gIJz4D6J15Av92AywL CqOfGOSxZ1k0o9rc3LuoquQZB97fiQ/fgfQE/lzOfrsrIqhzjeJHZ2K9+lRMVNJ7/7 fnXvHnDBAnMXxJa4vjm+LfnGEFS6xS4YSHce2NJ7uNKCGzZkhM/c9l9Trd1c4BtqIR BfU9OTtkFiJ33wjEWu8cvRyaTNdprCm8jpCAeDFZdMrkRx4KWOwHf4jCmFolSPYkVr ZUYDxNYoYWK8y/KTJLpzu1DpA8ydwcfqBNu86/Sw1gOdIOtOQGJToJYbvWMxDD7N6C tbhwVq4w+OhfQ== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Miguel Ojeda , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Nathan Chancellor , Nicolas Schier , Masahiro Yamada Subject: [PATCH 16/23] kbuild: use 'output' variable to create the output directory Date: Tue, 17 Sep 2024 23:16:44 +0900 Message-ID: <20240917141725.466514-17-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240917141725.466514-1-masahiroy@kernel.org> References: <20240917141725.466514-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 $(KBUILD_OUTPUT) specifies the output directory of kernel builds. Use a more generic name, 'output', to better reflect this code hunk in the context of external module builds. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- Makefile | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 254f05a1cc0f..7a76452049ea 100644 --- a/Makefile +++ b/Makefile @@ -176,18 +176,20 @@ export KBUILD_EXTRA_WARN # The O= assignment takes precedence over the KBUILD_OUTPUT environment # variable. -# Do we want to change the working directory? ifeq ("$(origin O)", "command line") KBUILD_OUTPUT := $(O) endif -ifneq ($(KBUILD_OUTPUT),) +output := $(KBUILD_OUTPUT) + +# Do we want to change the working directory? +ifneq ($(output),) # $(realpath ...) gets empty if the path does not exist. Run 'mkdir -p' first. -$(shell mkdir -p "$(KBUILD_OUTPUT)") +$(shell mkdir -p "$(output)") # $(realpath ...) resolves symlinks -abs_output := $(realpath $(KBUILD_OUTPUT)) -$(if $(abs_output),,$(error failed to create output directory "$(KBUILD_OUTPUT)")) -endif # ifneq ($(KBUILD_OUTPUT),) +abs_output := $(realpath $(output)) +$(if $(abs_output),,$(error failed to create output directory "$(output)")) +endif ifneq ($(words $(subst :, ,$(abs_srctree))), 1) $(error source directory cannot contain spaces or colons) From patchwork Tue Sep 17 14:16:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13806213 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 0E30F194090; Tue, 17 Sep 2024 14:18:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582689; cv=none; b=B6qp/xjBZx2V/fUsZezKx+0o7BlfjfF5526RAh+Ids1YaKtABZoZbJQaZtP3RRLZC3gfl4N2CAzj1yWxsBLOAXlfrWR4fxczRxGbcK9YpRubNW6gLvjXRIR01gPowORw8DIXwjPyhul/BxepK8KNQPbcfvszjwQdaHS0lge3cHQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582689; c=relaxed/simple; bh=rC19NpWl2LrUP5KgEEq6tX2ykKFGea+wJn+TOwWQ65k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F4V2dOw3ffCyebSz9Vtz30KEYXvmm6CXz8AtBlF1halb20XY2L07TZ1Yy4h75SnRefwvS8jbzhyK7OXMC80xo6KKOcP+T4DltDQldaT+jHRqeIoTnMvQepvUhJKdIG6akyi2Elqnt+Ke+CvZSXXpjrnMfNS+W5VVX9rB1MNgmWg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GbAuieaB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GbAuieaB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31088C4CEC5; Tue, 17 Sep 2024 14:18:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726582688; bh=rC19NpWl2LrUP5KgEEq6tX2ykKFGea+wJn+TOwWQ65k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GbAuieaBOcq4UwSovs/7O1oA27Zl7P2iltGJJDnuucQLOQNdUvauWS1hVjHprHRle JQ3tM/EZHYnvdtRUuxD++OAD3x7sXA8lSQPoy/lQaoEr0cU2kT3KF9/NlebINxnF/z cWnjBSuxO7amFrryjyIt30Tef3/gMdrdXowud6n50pkJwrI5BxhXyh4KFJ4GWZaXsK xhLScUhTFfo1lEuo5OD5nT4jVW59mn1vB+/LgVXbIhDrbMvXaChy5Acc+a8VGYr7It a+931lABvTmqrHNVsLmE6z2sfQjXnA0l7yBBoQeZaX2B/YHgVquHog9LmPHnlgkNtW 2uZKR08uevCWg== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Miguel Ojeda , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Nathan Chancellor , Nicolas Schier , Masahiro Yamada Subject: [PATCH 17/23] kbuild: build external modules in their directory Date: Tue, 17 Sep 2024 23:16:45 +0900 Message-ID: <20240917141725.466514-18-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240917141725.466514-1-masahiroy@kernel.org> References: <20240917141725.466514-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently, Kbuild always operates in the output directory of the kernel, even when building external modules. This increases the risk of external module Makefiles attempting to write to the kernel directory. This commit switches the working directory to the external module directory, allowing the removal of the $(KBUILD_EXTMOD)/ prefix from some build artifacts. The command for building external modules maintains backward compatibility, but Makefiles that rely on working in the kernel directory may break. In such cases, $(objtree) and $(srctree) should be used to refer to the output and source directories of the kernel. The appearance of the build log will change as follows: [Before] $ make -C /path/to/my/linux M=/path/to/my/externel/module make: Entering directory '/path/to/my/linux' CC [M] /path/to/my/externel/module/helloworld.o MODPOST /path/to/my/externel/module/Module.symvers CC [M] /path/to/my/externel/module/helloworld.mod.o CC [M] /path/to/my/externel/module/.module-common.o LD [M] /path/to/my/externel/module/helloworld.ko make: Leaving directory '/path/to/my/linux' [After] $ make -C /path/to/my/linux M=/path/to/my/externel/module make: Entering directory '/path/to/my/linux' make[1]: Entering directory '/path/to/my/externel/module' CC [M] helloworld.o MODPOST Module.symvers CC [M] helloworld.mod.o CC [M] .module-common.o LD [M] helloworld.ko make[1]: Leaving directory '/path/to/my/externel/module' make: Leaving directory '/path/to/my/linux' Printing "Entering directory" twice is cumbersome. This will be addressed later. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- Documentation/dev-tools/coccinelle.rst | 19 +++++------- Makefile | 40 +++++++++++++++++--------- rust/Makefile | 4 +-- scripts/Makefile.compiler | 2 +- scripts/Makefile.modpost | 6 ++-- scripts/coccicheck | 6 ++-- scripts/package/install-extmod-build | 7 +++++ 7 files changed, 49 insertions(+), 35 deletions(-) diff --git a/Documentation/dev-tools/coccinelle.rst b/Documentation/dev-tools/coccinelle.rst index 535ce126fb4f..80c83ce0babc 100644 --- a/Documentation/dev-tools/coccinelle.rst +++ b/Documentation/dev-tools/coccinelle.rst @@ -250,25 +250,20 @@ variables for .cocciconfig is as follows: - Your directory from which spatch is called is processed next - The directory provided with the ``--dir`` option is processed last, if used -Since coccicheck runs through make, it naturally runs from the kernel -proper dir; as such the second rule above would be implied for picking up a -.cocciconfig when using ``make coccicheck``. - ``make coccicheck`` also supports using M= targets. If you do not supply any M= target, it is assumed you want to target the entire kernel. The kernel coccicheck script has:: - if [ "$KBUILD_EXTMOD" = "" ] ; then - OPTIONS="--dir $srctree $COCCIINCLUDE" + if [ "$VPATH" ] ; then + OPTIONS="--dir $VPATH $COCCIINCLUDE" else - OPTIONS="--dir $KBUILD_EXTMOD $COCCIINCLUDE" + OPTIONS="--dir . $COCCIINCLUDE" fi -KBUILD_EXTMOD is set when an explicit target with M= is used. For both cases -the spatch ``--dir`` argument is used, as such third rule applies when whether -M= is used or not, and when M= is used the target directory can have its own -.cocciconfig file. When M= is not passed as an argument to coccicheck the -target directory is the same as the directory from where spatch was called. +When an explicit target is executed with a separate output directory, VPATH is +set to the target source directory. The third rule ensures the spatch reads the +.cocciconfig from the target directory. When M= is used, the external module +directory can have its own.cocciconfig file. If not using the kernel's coccicheck target, keep the above precedence order logic of .cocciconfig reading. If using the kernel's coccicheck target, diff --git a/Makefile b/Makefile index 7a76452049ea..4db22c3a8555 100644 --- a/Makefile +++ b/Makefile @@ -180,7 +180,20 @@ ifeq ("$(origin O)", "command line") KBUILD_OUTPUT := $(O) endif -output := $(KBUILD_OUTPUT) +ifdef KBUILD_EXTMOD + ifdef KBUILD_OUTPUT + objtree := $(realpath $(KBUILD_OUTPUT)) + $(if $(objtree),,$(error specified kernel directory "$(KBUILD_OUTPUT)" does not exist)) + else + objtree := $(CURDIR) + endif + output := $(KBUILD_EXTMOD) +else + objtree := . + output := $(KBUILD_OUTPUT) +endif + +export objtree # Do we want to change the working directory? ifneq ($(output),) @@ -248,8 +261,6 @@ ifneq ($(KBUILD_ABS_SRCTREE),) srctree := $(abs_srctree) endif -objtree := . - VPATH := ifeq ($(KBUILD_EXTMOD),) @@ -258,7 +269,7 @@ VPATH := $(srctree) endif endif -export building_out_of_srctree srctree objtree VPATH +export building_out_of_srctree srctree VPATH # To make sure we do not include .config for any of the *config targets # catch them early, and hand them over to scripts/kconfig/Makefile @@ -708,7 +719,7 @@ endif # in addition to whatever we do anyway. # Just "make" or "make all" shall build modules as well -ifneq ($(filter all modules nsdeps %compile_commands.json clang-%,$(MAKECMDGOALS)),) +ifneq ($(filter all modules nsdeps compile_commands.json clang-%,$(MAKECMDGOALS)),) KBUILD_MODULES := 1 endif @@ -1091,7 +1102,7 @@ export MODLIB PHONY += prepare0 -export extmod_prefix = $(if $(KBUILD_EXTMOD),$(KBUILD_EXTMOD)/) +export extmod_prefix = export MODORDER := $(extmod_prefix)modules.order export MODULES_NSDEPS := $(extmod_prefix)modules.nsdeps @@ -1789,14 +1800,10 @@ filechk_kernel.release = echo $(KERNELRELEASE) KBUILD_BUILTIN := KBUILD_MODULES := 1 -build-dir := $(KBUILD_EXTMOD) +build-dir := . -compile_commands.json: $(extmod_prefix)compile_commands.json -PHONY += compile_commands.json - -clean-dirs := $(KBUILD_EXTMOD) -clean: private rm-files := $(KBUILD_EXTMOD)/Module.symvers $(KBUILD_EXTMOD)/modules.nsdeps \ - $(KBUILD_EXTMOD)/compile_commands.json +clean-dirs := . +clean: private rm-files := Module.symvers modules.nsdeps compile_commands.json PHONY += prepare # now expand this into a simple variable to reduce the cost of shell evaluations @@ -1938,7 +1945,7 @@ $(clean-dirs): clean: $(clean-dirs) $(call cmd,rmfiles) - @find $(or $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \ + @find . $(RCS_FIND_IGNORE) \ \( -name '*.[aios]' -o -name '*.rsi' -o -name '*.ko' -o -name '.*.cmd' \ -o -name '*.ko.*' \ -o -name '*.dtb' -o -name '*.dtbo' \ @@ -1971,7 +1978,12 @@ tags TAGS cscope gtags: FORCE PHONY += rust-analyzer rust-analyzer: +$(Q)$(CONFIG_SHELL) $(srctree)/scripts/rust_is_available.sh +ifdef KBUILD_EXTMOD +# FIXME: external modules must not descend into a sub-directory of the kernel + $(Q)$(MAKE) $(build)=$(objtree)/rust src=$(srctree)/rust $@ +else $(Q)$(MAKE) $(build)=rust $@ +endif # Script to generate missing namespace dependencies # --------------------------------------------------------------------------- diff --git a/rust/Makefile b/rust/Makefile index 8de3ebba9551..8a686ffbd3a2 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -350,8 +350,8 @@ rust-analyzer: $(Q)$(srctree)/scripts/generate_rust_analyzer.py \ --cfgs='core=$(core-cfgs)' --cfgs='alloc=$(alloc-cfgs)' \ $(realpath $(srctree)) $(realpath $(objtree)) \ - $(rustc_sysroot) $(RUST_LIB_SRC) $(KBUILD_EXTMOD) > \ - $(if $(KBUILD_EXTMOD),$(extmod_prefix),$(objtree))/rust-project.json + $(rustc_sysroot) $(RUST_LIB_SRC) $(if $(KBUILD_EXTMOD),$(realpath $(or $(VPATH),.))) \ + > rust-project.json redirect-intrinsics = \ __addsf3 __eqsf2 __extendsfdf2 __gesf2 __lesf2 __ltsf2 __mulsf3 __nesf2 __truncdfsf2 __unordsf2 \ diff --git a/scripts/Makefile.compiler b/scripts/Makefile.compiler index 92be0c9a13ee..4b80b525d386 100644 --- a/scripts/Makefile.compiler +++ b/scripts/Makefile.compiler @@ -13,7 +13,7 @@ cc-cross-prefix = $(firstword $(foreach c, $(1), \ $(if $(shell command -v -- $(c)gcc 2>/dev/null), $(c)))) # output directory for tests below -TMPOUT = $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_$$$$ +TMPOUT = .tmp_$$$$ # try-run # Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise) diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost index 12e7c15d099c..ccca705bc389 100644 --- a/scripts/Makefile.modpost +++ b/scripts/Makefile.modpost @@ -111,13 +111,13 @@ endif else # set src + obj - they may be used in the modules's Makefile -obj := $(KBUILD_EXTMOD) -src := $(if $(VPATH),$(VPATH)/)$(obj) +obj := . +src := $(or $(VPATH),.) # Include the module's Makefile to find KBUILD_EXTRA_SYMBOLS include $(kbuild-file) -output-symdump := $(KBUILD_EXTMOD)/Module.symvers +output-symdump := Module.symvers ifeq ($(wildcard $(objtree)/Module.symvers),) missing-input := $(objtree)/Module.symvers diff --git a/scripts/coccicheck b/scripts/coccicheck index e52cb43fede6..6272fe4814cd 100755 --- a/scripts/coccicheck +++ b/scripts/coccicheck @@ -80,10 +80,10 @@ command results in a shift count error.' NPROC=1 else ONLINE=0 - if [ "$KBUILD_EXTMOD" = "" ] ; then - OPTIONS="--dir $srctree $COCCIINCLUDE" + if [ "${VPATH+set}" ] ; then + OPTIONS="--dir $VPATH $COCCIINCLUDE" else - OPTIONS="--dir $KBUILD_EXTMOD $COCCIINCLUDE" + OPTIONS="--dir . $COCCIINCLUDE" fi # Use only one thread per core by default if hyperthreading is enabled diff --git a/scripts/package/install-extmod-build b/scripts/package/install-extmod-build index d2c9cacecc0c..5d7d79a23bf9 100755 --- a/scripts/package/install-extmod-build +++ b/scripts/package/install-extmod-build @@ -53,6 +53,13 @@ mkdir -p "${destdir}" if [ "${CC}" != "${HOSTCC}" ] && is_enabled CONFIG_CC_CAN_LINK; then echo "Rebuilding host programs with ${CC}..." + # This leverages external module building. + # - Clear sub_make_done to allow the top-level Makefile to redo sub-make. + # - Filter out --no-print-directory to print "Entering directory" logs + # when Make changes the working directory. + unset sub_make_done + MAKEFLAGS=$(echo "${MAKEFLAGS}" | sed s/--no-print-directory//) + cat <<-'EOF' > "${destdir}/Kbuild" subdir-y := scripts EOF From patchwork Tue Sep 17 14:16:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13806214 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 37C6D1940AB; Tue, 17 Sep 2024 14:18:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582691; cv=none; b=c0zCsz8fV8ByVHzsVmISyRHxOfnMXfrijYxLUUA0UBzYkbBLOfazy5ON8kdpp6OUGx07LHgqzLfGsxraybgqXGcpaC4YlgCciZOrKXpEJsJGs8x3PMOER7IdGBE5ChXE9hRqTkhDiWHskEHiBy4ed2xsiHozBOw15VE9ZttBiWI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582691; c=relaxed/simple; bh=v3F59l//1EQnAHqTp5K6zCSernv13ZDiW1k6H5qe7cg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iOltvXPiFHGUY42sCf2+icpJY8EsfvzR5inQ9GFG1StBDNVqTQZDIOD6rGTLOlGCLaXNj2Tb3cmUMu0A3AtIdxU1CLpc9t31q72+nuQ2BlfJXsjskwRUKbP9W8ZgUTPUoarfsH+nX/A+ysVutVdpIoaNMuIKuOEf6LqkGwT17qU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Sg+Cbsfg; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Sg+Cbsfg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 240A4C4CECF; Tue, 17 Sep 2024 14:18:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726582690; bh=v3F59l//1EQnAHqTp5K6zCSernv13ZDiW1k6H5qe7cg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Sg+CbsfggQ1DwMg5dmajZbso8K5l8nvl3ZItaOU6Z/GnNbKX3B1OGxrhm2zG5P+Rv LdbUYnWXbqCgz4yCJ9D5cChgx6Eml8/vTG4FDf2Ls5cCzWGL9WlJ1GdqODA1cfrdWl X9WtC97VOAsg0qfZaV+ypgo2nzHcLZ1qmOIyow7gSjUkHuo7hGEuzF0wJKxtE3iyvw YoNiE9+mOqDhtatkb3OP5ar8TbcsGvnpSYHMMqTtBWzQqIvA7xUTwskROG6KynkZbe m1bm4eZN/hvPTMEInvxhx3jYdbluKV39HnRIHMMWBTsjG8XtYMiqRbGgUjuiZbl4rp yypdw+vYWigMQ== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Miguel Ojeda , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Nathan Chancellor , Nicolas Schier , Masahiro Yamada Subject: [PATCH 18/23] kbuild: remove extmod_prefix, MODORDER, MODULES_NSDEPS variables Date: Tue, 17 Sep 2024 23:16:46 +0900 Message-ID: <20240917141725.466514-19-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240917141725.466514-1-masahiroy@kernel.org> References: <20240917141725.466514-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 With the previous changes, $(extmod_prefix), $(MODORDER), and $(MODULES_NSDEPS) are constant. (empty, modules.order, and modules.nsdeps, respectively). Remove these variables and hard-code their values. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- Makefile | 22 +++++++++------------- scripts/Makefile.modfinal | 2 +- scripts/Makefile.modinst | 2 +- scripts/Makefile.modpost | 6 +++--- scripts/nsdeps | 2 +- 5 files changed, 15 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 4db22c3a8555..9fbf7ef6e394 100644 --- a/Makefile +++ b/Makefile @@ -1102,10 +1102,6 @@ export MODLIB PHONY += prepare0 -export extmod_prefix = -export MODORDER := $(extmod_prefix)modules.order -export MODULES_NSDEPS := $(extmod_prefix)modules.nsdeps - ifeq ($(KBUILD_EXTMOD),) build-dir := . @@ -1862,7 +1858,7 @@ endif ifdef CONFIG_MODULES -$(MODORDER): $(build-dir) +modules.order: $(build-dir) @: # KBUILD_MODPOST_NOFINAL can be set to skip the final link of modules. @@ -1873,7 +1869,7 @@ ifneq ($(KBUILD_MODPOST_NOFINAL),1) endif PHONY += modules_check -modules_check: $(MODORDER) +modules_check: modules.order $(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh $< else # CONFIG_MODULES @@ -1914,15 +1910,15 @@ $(single-ko): single_modules $(single-no-ko): $(build-dir) @: -# Remove MODORDER when done because it is not the real one. +# Remove modules.order when done because it is not the real one. PHONY += single_modules single_modules: $(single-no-ko) modules_prepare - $(Q){ $(foreach m, $(single-ko), echo $(extmod_prefix)$(m:%.ko=%.o);) } > $(MODORDER) + $(Q){ $(foreach m, $(single-ko), echo $(extmod_prefix)$(m:%.ko=%.o);) } > modules.order $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost ifneq ($(KBUILD_MODPOST_NOFINAL),1) $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinal endif - $(Q)rm -f $(MODORDER) + $(Q)rm -f modules.order single-goals := $(addprefix $(build-dir)/, $(single-no-ko)) @@ -1999,12 +1995,12 @@ nsdeps: modules quiet_cmd_gen_compile_commands = GEN $@ cmd_gen_compile_commands = $(PYTHON3) $< -a $(AR) -o $@ $(filter-out $<, $(real-prereqs)) -$(extmod_prefix)compile_commands.json: $(srctree)/scripts/clang-tools/gen_compile_commands.py \ +compile_commands.json: $(srctree)/scripts/clang-tools/gen_compile_commands.py \ $(if $(KBUILD_EXTMOD),, vmlinux.a $(KBUILD_VMLINUX_LIBS)) \ - $(if $(CONFIG_MODULES), $(MODORDER)) FORCE + $(if $(CONFIG_MODULES), modules.order) FORCE $(call if_changed,gen_compile_commands) -targets += $(extmod_prefix)compile_commands.json +targets += compile_commands.json PHONY += clang-tidy clang-analyzer @@ -2012,7 +2008,7 @@ ifdef CONFIG_CC_IS_CLANG quiet_cmd_clang_tools = CHECK $< cmd_clang_tools = $(PYTHON3) $(srctree)/scripts/clang-tools/run-clang-tools.py $@ $< -clang-tidy clang-analyzer: $(extmod_prefix)compile_commands.json +clang-tidy clang-analyzer: compile_commands.json $(call cmd,clang_tools) else clang-tidy clang-analyzer: diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal index 6d8aa3059ee2..1d787b867c6d 100644 --- a/scripts/Makefile.modfinal +++ b/scripts/Makefile.modfinal @@ -13,7 +13,7 @@ include $(srctree)/scripts/Kbuild.include include $(srctree)/scripts/Makefile.lib # find all modules listed in modules.order -modules := $(call read-file, $(MODORDER)) +modules := $(call read-file, modules.order) __modfinal: $(modules:%.o=%.ko) @: diff --git a/scripts/Makefile.modinst b/scripts/Makefile.modinst index 2d39d452c49e..1ec739d138b3 100644 --- a/scripts/Makefile.modinst +++ b/scripts/Makefile.modinst @@ -40,7 +40,7 @@ $(addprefix $(MODLIB)/, modules.builtin modules.builtin.modinfo modules.builtin. endif -modules := $(call read-file, $(MODORDER)) +modules := $(call read-file, modules.order) ifeq ($(KBUILD_EXTMOD),) dst := $(MODLIB)/kernel diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost index ccca705bc389..586456c72e6d 100644 --- a/scripts/Makefile.modpost +++ b/scripts/Makefile.modpost @@ -46,7 +46,7 @@ modpost-args = \ $(if $(CONFIG_MODULE_SRCVERSION_ALL),-a) \ $(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E) \ $(if $(KBUILD_MODPOST_WARN),-w) \ - $(if $(KBUILD_NSDEPS),-d $(MODULES_NSDEPS)) \ + $(if $(KBUILD_NSDEPS),-d modules.nsdeps) \ $(if $(CONFIG_MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS)$(KBUILD_NSDEPS),-N) \ $(if $(findstring 1, $(KBUILD_EXTRA_WARN)),-W) \ -o $@ @@ -61,8 +61,8 @@ endif # Read out modules.order to pass in modpost. # Otherwise, allmodconfig would fail with "Argument list too long". ifdef KBUILD_MODULES -modpost-args += -T $(MODORDER) -modpost-deps += $(MODORDER) +modpost-args += -T modules.order +modpost-deps += modules.order endif ifeq ($(KBUILD_EXTMOD),) diff --git a/scripts/nsdeps b/scripts/nsdeps index 8b4db63838ce..3192a3945871 100644 --- a/scripts/nsdeps +++ b/scripts/nsdeps @@ -57,4 +57,4 @@ generate_deps() { while read line do generate_deps $line -done < $MODULES_NSDEPS +done < modules.nsdeps From patchwork Tue Sep 17 14:16:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13806215 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 308B9194A4B; Tue, 17 Sep 2024 14:18:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582693; cv=none; b=gXzTizwG+7W1iB07M3jennmgt0Q9Ns1DBi/Ohdk2khCqsj2IBLVQQTkRcxJ323c2b5ZGgydGfmlfV9UMkZaNnFt5miwAE6nE4bwi97EI/ZRQEcIAccuSbnE1EMq/m4BSoUI6XOorhCGlBvyHlA633a6nJbwYty8HsRYIszsNMo8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582693; c=relaxed/simple; bh=FI3kBAdkWmeCKCnshcw4HjVMuzXsQc84gzzbOu4ug78=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NF507QhGFtfLEw+9xoSmtE476SYIteTEvu1xk6NgPCjX1Wr9cBDcV8zo7Vc5JP0L68x/ZZDP0Vth6G4DjEPzb5nVpEC3wv3pMlEIDf+C+YTmY5iMRNfnjSJ7FEl+KuP2SGdw2w0s8P7IguG6EtiTlMbxuoLqqx8X+JKfYbFoEaU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KJdjwRDY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KJdjwRDY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 61A21C4CECD; Tue, 17 Sep 2024 14:18:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726582693; bh=FI3kBAdkWmeCKCnshcw4HjVMuzXsQc84gzzbOu4ug78=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KJdjwRDYVqIaBYqJlmBD1QiMZBvwzt8Y03mjrrThgG1wa4NmXiSaI1c6ZazZ9AOcN bKKUWRAID9yfu2nltrNlxbFBoLLU35FGEXOUMhmlkykUXWvBYWmR/C3BiAIKnSRJGh Z35xx6zpvPycfYktWKWHDGVRBLQEifxRAd/xZd0HyOnMx1Sz69T3iRdH9KmYDGJ6ck +nX6Dvck8jhQEN/k8MMEouFICumxRFMlc2zLOTLxQ0oOWu5mWaMAFyhQ3N8eLBiwwg k5+heFtOIy6Y63S1bjDPpr1KsTW0E04AOepjB2t+ZntAQr/Z2vsx4RKv8ZSKrxc3TU Wa12r9NLkNXDA== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Miguel Ojeda , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Nathan Chancellor , Nicolas Schier , Masahiro Yamada Subject: [PATCH 19/23] kbuild: support building external modules in a separate build directory Date: Tue, 17 Sep 2024 23:16:47 +0900 Message-ID: <20240917141725.466514-20-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240917141725.466514-1-masahiroy@kernel.org> References: <20240917141725.466514-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 There has been a long-standing request to support building external modules in a separate build directory. This commit introduces a new environment variable, KBUILD_EXTMOD_OUTPUT, and its shorthand Make variable, MO. A simple usage: $ make -C M= MO= Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- Documentation/kbuild/kbuild.rst | 8 +++++- Documentation/kbuild/modules.rst | 5 +++- Makefile | 44 +++++++++++++++++++++++--------- 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/Documentation/kbuild/kbuild.rst b/Documentation/kbuild/kbuild.rst index 716f6fb70829..66a9dc44ea28 100644 --- a/Documentation/kbuild/kbuild.rst +++ b/Documentation/kbuild/kbuild.rst @@ -132,12 +132,18 @@ Specify the output directory when building the kernel. This variable can also be used to point to the kernel output directory when building external modules using kernel build artifacts in a separate build directory. Please note that this does NOT specify the output directory for the -external modules themselves. +external modules themselves. (Use KBUILD_EXTMOD_OUTPUT for that purpose.) The output directory can also be specified using "O=...". Setting "O=..." takes precedence over KBUILD_OUTPUT. +KBUILD_EXTMOD_OUTPUT +-------------------- +Specify the output directory for external modules. + +Setting "MO=..." takes precedence over KBUILD_EXTMOD_OUTPUT. + KBUILD_EXTRA_WARN ----------------- Specify the extra build checks. The same value can be assigned by passing diff --git a/Documentation/kbuild/modules.rst b/Documentation/kbuild/modules.rst index 3a6e7bdc0889..03347e13eeb5 100644 --- a/Documentation/kbuild/modules.rst +++ b/Documentation/kbuild/modules.rst @@ -95,7 +95,7 @@ executed to make module versioning work. of the kernel output directory if the kernel was built in a separate build directory.) - make -C $KDIR M=$PWD + make -C $KDIR M=$PWD [MO=$BUILD_DIR] -C $KDIR The directory that contains the kernel and relevant build @@ -109,6 +109,9 @@ executed to make module versioning work. directory where the external module (kbuild file) is located. + MO=$BUILD_DIR + Speficies a separate output directory for the external module. + 2.3 Targets =========== diff --git a/Makefile b/Makefile index 9fbf7ef6e394..b654baa0763a 100644 --- a/Makefile +++ b/Makefile @@ -134,6 +134,10 @@ ifeq ("$(origin M)", "command line") KBUILD_EXTMOD := $(M) endif +ifeq ("$(origin MO)", "command line") + KBUILD_EXTMOD_OUTPUT := $(MO) +endif + $(if $(word 2, $(KBUILD_EXTMOD)), \ $(error building multiple external modules is not supported)) @@ -187,7 +191,11 @@ ifdef KBUILD_EXTMOD else objtree := $(CURDIR) endif - output := $(KBUILD_EXTMOD) + output := $(or $(KBUILD_EXTMOD_OUTPUT),$(KBUILD_EXTMOD)) + # KBUILD_EXTMOD might be a relative path. Remember its absolute path before + # Make changes the working directory. + export abs_extmodtree := $(realpath $(KBUILD_EXTMOD)) + $(if $(abs_extmodtree),,$(error specified external module directory "$(KBUILD_EXTMOD)" does not exist)) else objtree := . output := $(KBUILD_OUTPUT) @@ -246,7 +254,6 @@ else # need-sub-make ifeq ($(abs_srctree),$(CURDIR)) # building in the source tree srctree := . - building_out_of_srctree := else ifeq ($(abs_srctree)/,$(dir $(CURDIR))) # building in a subdirectory of the source tree @@ -254,22 +261,23 @@ else else srctree := $(abs_srctree) endif - building_out_of_srctree := 1 endif ifneq ($(KBUILD_ABS_SRCTREE),) srctree := $(abs_srctree) endif -VPATH := +export srctree -ifeq ($(KBUILD_EXTMOD),) -ifdef building_out_of_srctree -VPATH := $(srctree) -endif -endif +_vpath = $(or $(abs_extmodtree),$(srctree)) -export building_out_of_srctree srctree VPATH +ifeq ($(realpath $(_vpath)),$(CURDIR)) +building_out_of_srctree := +VPATH := +else +export building_out_of_srctree := 1 +export VPATH := $(_vpath) +endif # To make sure we do not include .config for any of the *config targets # catch them early, and hand them over to scripts/kconfig/Makefile @@ -550,7 +558,7 @@ USERINCLUDE := \ LINUXINCLUDE := \ -I$(srctree)/arch/$(SRCARCH)/include \ -I$(objtree)/arch/$(SRCARCH)/include/generated \ - $(if $(building_out_of_srctree),-I$(srctree)/include) \ + -I$(srctree)/include \ -I$(objtree)/include \ $(USERINCLUDE) @@ -640,6 +648,7 @@ quiet_cmd_makefile = GEN Makefile } > Makefile outputmakefile: +ifeq ($(KBUILD_EXTMOD),) @if [ -f $(srctree)/.config -o \ -d $(srctree)/include/config -o \ -d $(srctree)/arch/$(SRCARCH)/include/generated ]; then \ @@ -649,7 +658,16 @@ outputmakefile: echo >&2 "***"; \ false; \ fi - $(Q)ln -fsn $(srctree) source +else + @if [ -f $(KBUILD_EXTMOD)/modules.order ]; then \ + echo >&2 "***"; \ + echo >&2 "*** The external module source tree is not clean."; \ + echo >&2 "*** Please run 'make -C $(abs_srctree) M=$(realpath $(KBUILD_EXTMOD)) clean'"; \ + echo >&2 "***"; \ + false; \ + fi +endif + $(Q)ln -fsn $(_vpath) source $(call cmd,makefile) $(Q)test -e .gitignore || \ { echo "# this is build directory, ignore it"; echo "*"; } > .gitignore @@ -1926,6 +1944,8 @@ KBUILD_MODULES := 1 endif +prepare: outputmakefile + # Preset locale variables to speed up the build process. Limit locale # tweaks to this spot to avoid wrong language settings when running # make menuconfig etc. From patchwork Tue Sep 17 14:16:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13806216 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 B7491194AD6; Tue, 17 Sep 2024 14:18:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582695; cv=none; b=fvft7fx5OwayeKcJGWbfV/McVAWET/tkaggh1v9iHvfozZCgx8vKliJwj/2F1w1GqY7SQLJ1IjvPg/EmsLs2dsR0DfRd2IG+eKYym7mwt8TPJfxCzjo6tiUKk3K+/ftBxno6WW/gdkzEqpPQ02M9/kT89hHPAbe/6Fc2i3zYSUs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582695; c=relaxed/simple; bh=6ovtfxPLSr9bMGDxuc9bLq1SSFe119PmyqlLKy/y1gI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h8oGr0EXo2xHT4xrr33qmQyggN+tRtF3eWaVr1SC/aGugUUiPDzRxAJEcYLlC7J6ALXbn5AOsSWfG3YHB7IoZAQAZtYX2/Tl7yPH86kfOLWI1YjTsYhDeLEcqM2NnHR2i+hjmaw2YyZvGJmj0kLkj1WemBHz59BTy2rIdbHDgWk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SxcRo7Hx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SxcRo7Hx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F5C8C4CECD; Tue, 17 Sep 2024 14:18:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726582695; bh=6ovtfxPLSr9bMGDxuc9bLq1SSFe119PmyqlLKy/y1gI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SxcRo7Hxr/XE+diRmR2zFq37e+ot4nD4aE1owbXAC0SQ+F2TWekZarZQ/uUuauT9C u0Jwa7AXmYwSGtP4c/RCPj4rTsDK47ns+fEEpYSJWDcxS/i0Vyc+IeVJ4izadvDoAV M0u0DZ5xBnR1WdhUuTLm0zDLJ8R+TSU37uzV4SIeiO0gBmMPupMbGvTf5oSOHRQF57 0iNR/bU/5lfz0GO25Qy4uJDeZPhq4TicVVqWAmwk3pinfopcGeKCfdi/l/GN3yWTQG 1f2a7U+Yf7lVcx0Ja4AjJTDfpJ0Ta2lzoLYyWngviZF2Zx8VSdCB+w+OYzV2j86pSt daeCHkYTSE9WQ== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Miguel Ojeda , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Nathan Chancellor , Nicolas Schier , Masahiro Yamada Subject: [PATCH 20/23] kbuild: support -fmacro-prefix-map for external modules Date: Tue, 17 Sep 2024 23:16:48 +0900 Message-ID: <20240917141725.466514-21-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240917141725.466514-1-masahiroy@kernel.org> References: <20240917141725.466514-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This commit makes -fmacro-prefix-map work for external modules built in a separate output directory. It improves the reproducibility of external modules and provides the benefits described in commit a73619a845d5 ("kbuild: use -fmacro-prefix-map to make __FILE__ a relative path"). When VPATH is not defined (e.g., when the kernel or external module is built in the source directory), this option is unnecessary. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index b654baa0763a..ce646a6994a6 100644 --- a/Makefile +++ b/Makefile @@ -1027,8 +1027,10 @@ ifdef CONFIG_CC_IS_GCC KBUILD_CFLAGS += -fconserve-stack endif -# change __FILE__ to the relative path from the srctree -KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=) +# change __FILE__ to the relative path to the source directory +ifdef VPATH +KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(VPATH)/=) +endif # include additional Makefiles when needed include-y := scripts/Makefile.extrawarn From patchwork Tue Sep 17 14:16:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13806217 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 E8D41194C8F; Tue, 17 Sep 2024 14:18:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582698; cv=none; b=D43DPf7pEMYt4XstW53dcTB21/QogvXLMWVR+2fsv9j1gIpTBZCUjZ5a7VqxmSY1It9FFj4lKm7xQ+rOUC/hBOD7y85nvTig8M3QnDSREPXj7QMdVuIle2YF3WyvzEL0jwI7johOKxv1kwW25UiMaTnIrBvCKkHqaZZJMHzKl0E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582698; c=relaxed/simple; bh=/5fq3didrGVAcPh4C5/Q4yo410TOLiRILJJC0tUs9Go=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JFwan9NsTcltTkiaVcWVS2unPBJ/ibOUnycr7v9VWVEBnPd/eRTaBldE+EdD/XiVUBWC3xq6V3LfcI5vqHm9UUIkAUw4ah4K7FVeI8IYc1672tR+3Ia1iW6P628Fpo5OKHwlfmsrVClmxq39g41OzhjBfz31D66ThyjdrbMjiTI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=T19nYlja; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="T19nYlja" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DD112C4CECD; Tue, 17 Sep 2024 14:18:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726582697; bh=/5fq3didrGVAcPh4C5/Q4yo410TOLiRILJJC0tUs9Go=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T19nYlja1p0xgVKeZLU/WtpTcajsT9vIRdu+VTu6ffeetHV3TGr7u2PJTInnpQ81h xF6CCxARdatLfOpHWY7dD6BuacR33KEG9QrU+VRR+li7Pc1q1rDW1T3q/4lpbR0ZQn rukdp5z4ZvMhuAwlW6NsSCpte9bV8lLvyE/jEeWaXkzmb70n0ocyYsUejL9hdIV59o HqMpXEx98OZFDDvWbPt4tSdLWbYuuvaRclBeRj6HZe+Ud3KPXMBS5UIKSO8mxl30mu vFtO0GDDBkNjAEgNm6uMVYeYGGmoSlCn9S1ax+JTjUPo7noquQOLlPoLtRw0dIXtn9 o2qMBlcGa27Jw== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Miguel Ojeda , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Nathan Chancellor , Nicolas Schier , Masahiro Yamada Subject: [PATCH 21/23] kbuild: use absolute path in the generated wrapper Makefile Date: Tue, 17 Sep 2024 23:16:49 +0900 Message-ID: <20240917141725.466514-22-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240917141725.466514-1-masahiroy@kernel.org> References: <20240917141725.466514-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Keep the consistent behavior when this Makefile is invoked from another directory. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index ce646a6994a6..9f0ba07e8f25 100644 --- a/Makefile +++ b/Makefile @@ -643,8 +643,9 @@ ifdef building_out_of_srctree quiet_cmd_makefile = GEN Makefile cmd_makefile = { \ - echo "\# Automatically generated by $(srctree)/Makefile: don't edit"; \ - echo "include $(srctree)/Makefile"; \ + echo "\# Automatically generated by $(abs_srctree)/Makefile: don't edit"; \ + echo "export KBUILD_OUTPUT = $(CURDIR)"; \ + echo "include $(abs_srctree)/Makefile"; \ } > Makefile outputmakefile: From patchwork Tue Sep 17 14:16:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13806218 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 B3F43185E6A; Tue, 17 Sep 2024 14:18:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582699; cv=none; b=CDNDtlma+90n3GYW+xss4MjsYgduoqGtYrFYTFfnW93Sz8WWvvl+G4kAzdXp+rB40D6JhuFFhh0JMd+Z/fhHDDAHAp6oQI9FfVIqKViWwTYgLCsa4I0cpvQoU+GkdeeM9mNHV9QxfrKh4ryiModMON7v8FmNrzm6WAugwejY/zo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582699; c=relaxed/simple; bh=Ra2sKRWgqwv0KIZWzt1FwqFPZ+ccaJpIfL/OUlJKdGk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jIHYCiAFO3fTOqAg75Z1Nnjn2Hp4ZUduODcjLb06IdLk9nm3Vd6ECKU/2DeSdxZ6wgMi9obiWILmjUqxidebriwKZ0hjs1GgVb01AvGsAr7sxM7LgbhYX7nwyVtppdhV/kvNrvvFmf1tR80R8GiNBYxn7fEnLKmIT6jcPFF1h8Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gMyHmEtB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gMyHmEtB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F184DC4CEC5; Tue, 17 Sep 2024 14:18:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726582699; bh=Ra2sKRWgqwv0KIZWzt1FwqFPZ+ccaJpIfL/OUlJKdGk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gMyHmEtBAND0LFpuaHHdvm0IL6/fXRl36eFKyQbZChRo2vlMflHk4XQ3s8gwIs8Ox G27dtJKz1R+zGfW9Y7vcs6rALMqJ3rGtHrZDkOoB3Js89lsHKyUaTlZNLEe3u9gDL+ QY/q84LuowH3vg7iunMQo/iAWsbjsXly2MgNK3O30VdX98lqlrSeAuseLjudBUlKlr FR2EQJsH/fiLABxt6Xni3qSQRQWjwCzyuDlesg18H4l+9169Gop4dT9xl07m5PSfLr l8rluzKhKEeaAfwDmtLIiglXraNgKkA5eEWoRLLf2lXQWPnnMbgrSfiwd6ebgZC6ku ZeWgf4Uqhk0bQ== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Miguel Ojeda , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Nathan Chancellor , Nicolas Schier , Masahiro Yamada Subject: [PATCH 22/23] kbuild: make wrapper Makefile more convenient for external modules Date: Tue, 17 Sep 2024 23:16:50 +0900 Message-ID: <20240917141725.466514-23-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240917141725.466514-1-masahiroy@kernel.org> References: <20240917141725.466514-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When Kbuild starts building in a separate output directory, it generates a wrapper Makefile, allowing you to invoke 'make' from the output directory. This commit makes it more convenient, so you can invoke 'make' without M= or MO=. First, you need to build external modules in a separate directory: $ make M=/path/to/module/source/dir MO=/path/to/module/build/dir Once the wrapper Makefile is generated in /path/to/module/build/dir, you can proceed as follows: $ cd /path/to/module/build/dir $ make Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- Makefile | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9f0ba07e8f25..81603a50c757 100644 --- a/Makefile +++ b/Makefile @@ -641,10 +641,20 @@ ifdef building_out_of_srctree # At the same time when output Makefile generated, generate .gitignore to # ignore whole output directory +ifdef KBUILD_EXTMOD +print_env_for_makefile = \ + echo "export KBUILD_OUTPUT = $(objtree)"; \ + echo "export KBUILD_EXTMOD = $(_vpath)" ; \ + echo "export KBUILD_EXTMOD_OUTPUT = $(CURDIR)" +else +print_env_for_makefile = \ + echo "export KBUILD_OUTPUT = $(CURDIR)" +endif + quiet_cmd_makefile = GEN Makefile cmd_makefile = { \ echo "\# Automatically generated by $(abs_srctree)/Makefile: don't edit"; \ - echo "export KBUILD_OUTPUT = $(CURDIR)"; \ + $(print_env_for_makefile); \ echo "include $(abs_srctree)/Makefile"; \ } > Makefile From patchwork Tue Sep 17 14:16:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13806219 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 628DE1974FE; Tue, 17 Sep 2024 14:18:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582702; cv=none; b=rhe6V0Yp69d5cWeBcd4NlJ1QuW0vERgN3H3XSjciFnsbfyctVM7dtaVNxRgpxyl98VCg/BSPJ4CzfzQfldqnGKu/tnQNk4Ud3gZTwm6TzkN5rvSAV5Yt0nNDfyVgFBPzBfetqWPSBatKc97V2b+eYSuYcOAELjbpYM/Yo/3myxU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726582702; c=relaxed/simple; bh=pVqPlXHwRAmKMtMxmsQTphSqu9eVJ5zq5Yus+QdHq+Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OFrJwUrqpPD6fKVonu1Kn2t2M1FXbI4bFHyjAWC4t2UlhYmn7b7P1xiRk28C02mxxNRLSFVYCBZg0WLuEBFn0GKwGTSF59xeqP8pesfp0F4ZMKfL7tBnBHivDTJqiceGcHfN5tNUGgpdhfutXNKnwaszgZRRzTaOP7K3AqshpeY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qFZRWt3b; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qFZRWt3b" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 32AF8C4CEC5; Tue, 17 Sep 2024 14:18:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726582702; bh=pVqPlXHwRAmKMtMxmsQTphSqu9eVJ5zq5Yus+QdHq+Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qFZRWt3bLzlLXEazL48GBC+oGSAyKzF5TRwsK3RJi9kuKr7Wm+eTzqSILwkzH4l7t e7GF3zChXVOv/eL2+dq17FaFYgpGuKlqnTSgI3C77zxkQR6k6IC58Q6b199ewt+4iS 9xeqRkcEDLFM3aAt0l4AQhmXiAYQ2zGipdr3A2ovuX3yoIikkyf/mmTbttthFL9trF QxYX00wpSikIluRDyIqNdXjqKfXsLnn3FKCGw8vNIJwTbUhN3Xv0bv5c5Vfi1kcLjc cHDjtsj1NBLne3wa4+AI/4pXbIqjg4cGKByuzP3ssqKQil2NW8qSc79WJoWbv1qVz8 Zsvvwl0Jyw0Kw== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Miguel Ojeda , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Nathan Chancellor , Nicolas Schier , Masahiro Yamada Subject: [PATCH 23/23] kbuild: allow to start building external module in any directory Date: Tue, 17 Sep 2024 23:16:51 +0900 Message-ID: <20240917141725.466514-24-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240917141725.466514-1-masahiroy@kernel.org> References: <20240917141725.466514-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Unless an explicit O= option is provided, external module builds must start from the kernel directory. This can be achieved by using the -C option: $ make -C /path/to/kernel M=/path/to/external/module This commit allows starting external module builds from any directory, so you can also do the following: $ make -f /path/to/kernel/Makefile M=/path/to/external/module The key difference is that the -C option changes the working directory and parses the Makefile located there, while the -f option only specifies the Makefile to use. As shown in the examples in Documentation/kbuild/modules.rst, external modules usually have a wrapper Makefile that allows you to build them without specifying any make arguments. The Makefile typically contains a rule as follows: KDIR ?= /path/to/kernel default: $(MAKE) -C $(KDIR) M=$(CURDIR) $(MAKECMDGOALS) The log will appear as follows: $ make make -C /path/to/kernel M=/path/to/external/module make[1]: Entering directory '/path/to/kernel' make[2]: Entering directory '/path/to/exernal/module' CC [M] helloworld.o MODPOST Module.symvers CC [M] helloworld.mod.o CC [M] .module-common.o LD [M] helloworld.ko make[2]: Leaving directory '/path/to/exernal/module' make[1]: Leaving directory '/path/to/kernel' This changes the working directory twice because the -C option first switches to the kernel directory, and then Kbuild internally recurses back to the external module directory. With this commit, the wrapper Makefile can directly include the kernel Makefile: KDIR ?= /path/to/kernel export KBUILD_EXTMOD = $(CURDIR) include $(KDIR)/Makefile This avoids unnecessary sub-make invocations: $ make CC [M] helloworld.o MODPOST Module.symvers CC [M] helloworld.mod.o CC [M] .module-common.o LD [M] helloworld.ko Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- Documentation/kbuild/modules.rst | 21 +++++++++++++++++++++ Makefile | 8 ++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Documentation/kbuild/modules.rst b/Documentation/kbuild/modules.rst index 03347e13eeb5..5610cfa426bb 100644 --- a/Documentation/kbuild/modules.rst +++ b/Documentation/kbuild/modules.rst @@ -88,6 +88,12 @@ executed to make module versioning work. $ make -C /lib/modules/`uname -r`/build M=$PWD modules_install + Starting from Linux 6.13, you can use the -f option instead of -C. This + will avoid unnecessary change of the working directory. The external + module will be output to the directory where you invoke make. + + $ make -f /lib/modules/`uname -r`/build/Makefile M=$PWD + 2.2 Options =========== @@ -246,6 +252,21 @@ module 8123.ko, which is built from the following files:: consisting of several hundred lines, and here it really pays off to separate the kbuild part from the rest. + Linux 6.13 and later support another way. The external module Makefile + can include the kernel Makefile directly, rather than invoking sub Make. + + Example 3:: + + --> filename: Kbuild + obj-m := 8123.o + 8123-y := 8123_if.o 8123_pci.o + + --> filename: Makefile + KDIR ?= /lib/modules/`uname -r`/build + export KBUILD_EXTMOD = $(CURDIR) + include $(KDIR)/Makefile + + 3.4 Building Multiple Modules ============================= diff --git a/Makefile b/Makefile index 81603a50c757..88c160ac7b3c 100644 --- a/Makefile +++ b/Makefile @@ -189,9 +189,13 @@ ifdef KBUILD_EXTMOD objtree := $(realpath $(KBUILD_OUTPUT)) $(if $(objtree),,$(error specified kernel directory "$(KBUILD_OUTPUT)" does not exist)) else - objtree := $(CURDIR) + objtree := $(abs_srctree) endif - output := $(or $(KBUILD_EXTMOD_OUTPUT),$(KBUILD_EXTMOD)) + # If Make is invoked from the kernel directory (either kernel + # source directory or kernel build directory), external modules + # are built in $(KBUILD_EXTMOD) for backward compatibility, + # otherwise, built in the current directory. + output := $(or $(KBUILD_EXTMOD_OUTPUT),$(if $(filter $(CURDIR),$(objtree) $(abs_srctree)),$(KBUILD_EXTMOD))) # KBUILD_EXTMOD might be a relative path. Remember its absolute path before # Make changes the working directory. export abs_extmodtree := $(realpath $(KBUILD_EXTMOD))