rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Masahiro Yamada <masahiroy@kernel.org>
To: linux-kbuild@vger.kernel.org
Cc: Miguel Ojeda <ojeda@kernel.org>,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
	Nathan Chancellor <nathan@kernel.org>,
	Nicolas Schier <nicolas@fjasle.eu>,
	Masahiro Yamada <masahiroy@kernel.org>
Subject: [PATCH 14/23] kbuild: add $(objtree)/ prefix to some in-kernel build artifacts
Date: Tue, 17 Sep 2024 23:16:42 +0900	[thread overview]
Message-ID: <20240917141725.466514-15-masahiroy@kernel.org> (raw)
In-Reply-To: <20240917141725.466514-1-masahiroy@kernel.org>

$(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 <masahiroy@kernel.org>
---

 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
-- 
2.43.0


  parent reply	other threads:[~2024-09-17 14:18 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-17 14:16 [PATCH 00/23] kbuild: support building external modules in a separate build directory Masahiro Yamada
2024-09-17 14:16 ` [PATCH 01/23] kbuild: doc: update the description about Kbuild/Makefile split Masahiro Yamada
2024-09-18 15:35   ` Nicolas Schier
2024-09-17 14:16 ` [PATCH 02/23] kbuild: doc: remove description about grepping CONFIG options Masahiro Yamada
2024-09-18 15:35   ` Nicolas Schier
2024-09-17 14:16 ` [PATCH 03/23] kbuild: doc: remove outdated description of the limitation on -I usage Masahiro Yamada
2024-09-18 15:38   ` Nicolas Schier
2024-09-17 14:16 ` [PATCH 04/23] kbuild: doc: remove the description about shipped files Masahiro Yamada
2024-09-18 16:24   ` Nicolas Schier
2024-09-19 16:53     ` Masahiro Yamada
2024-09-17 14:16 ` [PATCH 05/23] kbuild: doc: describe the -C option precisely for external module builds Masahiro Yamada
2024-09-18 16:44   ` Nicolas Schier
2024-09-18 16:47   ` Nicolas Schier
2024-09-17 14:16 ` [PATCH 06/23] kbuild: doc: replace "gcc" in external module description Masahiro Yamada
2024-09-19 11:22   ` Nicolas Schier
2024-09-17 14:16 ` [PATCH 07/23] kbuild: remove unnecessary prune of rust/alloc for rustfmt Masahiro Yamada
2024-09-19 11:23   ` Nicolas Schier
2024-09-19 13:46     ` Nicolas Schier
2024-09-30 14:29       ` Miguel Ojeda
2024-09-17 14:16 ` [PATCH 08/23] kbuild: simplify find command " Masahiro Yamada
2024-09-19 13:54   ` Nicolas Schier
2024-09-19 13:59     ` Masahiro Yamada
2024-09-30 18:37   ` Miguel Ojeda
2024-10-01  2:18     ` Masahiro Yamada
2024-10-01  5:45       ` Miguel Ojeda
2024-09-17 14:16 ` [PATCH 09/23] speakup: use SPKDIR=$(src) to specify the source directory Masahiro Yamada
2024-10-03 18:25   ` Nicolas Schier
2024-09-17 14:16 ` [PATCH 10/23] kbuild: refactor the check for missing config files Masahiro Yamada
2024-09-25 14:04   ` Nicolas Schier
2024-09-17 14:16 ` [PATCH 11/23] kbuild: check the presence of include/generated/rustc_cfg Masahiro Yamada
2024-09-25 14:10   ` Nicolas Schier
2024-09-30 14:37   ` Miguel Ojeda
2024-09-17 14:16 ` [PATCH 12/23] scripts/nsdeps: use VPATH as src_prefix Masahiro Yamada
2024-09-25 14:18   ` Nicolas Schier
2024-09-26  7:30     ` Nicolas Schier
2024-09-17 14:16 ` [PATCH 13/23] kbuild: replace two $(abs_objtree) with $(CURDIR) in top Makefile Masahiro Yamada
2024-09-25 14:27   ` Nicolas Schier
2024-09-17 14:16 ` Masahiro Yamada [this message]
2024-09-26  7:50   ` [PATCH 14/23] kbuild: add $(objtree)/ prefix to some in-kernel build artifacts Nicolas Schier
2024-09-17 14:16 ` [PATCH 15/23] kbuild: rename abs_objtree to abs_output Masahiro Yamada
2024-09-26  7:51   ` Nicolas Schier
2024-09-17 14:16 ` [PATCH 16/23] kbuild: use 'output' variable to create the output directory Masahiro Yamada
2024-09-26  7:54   ` Nicolas Schier
2024-09-17 14:16 ` [PATCH 17/23] kbuild: build external modules in their directory Masahiro Yamada
2024-10-03 18:41   ` Nicolas Schier
2024-09-17 14:16 ` [PATCH 18/23] kbuild: remove extmod_prefix, MODORDER, MODULES_NSDEPS variables Masahiro Yamada
2024-10-03 18:47   ` Nicolas Schier
2024-11-10  1:36     ` Masahiro Yamada
2024-09-17 14:16 ` [PATCH 19/23] kbuild: support building external modules in a separate build directory Masahiro Yamada
2024-10-03 19:47   ` Nicolas Schier
2024-10-04 19:45     ` Nicolas Schier
2024-11-10  1:36       ` Masahiro Yamada
2024-11-10  1:36     ` Masahiro Yamada
2024-09-17 14:16 ` [PATCH 20/23] kbuild: support -fmacro-prefix-map for external modules Masahiro Yamada
2024-10-04 18:51   ` Nicolas Schier
2024-09-17 14:16 ` [PATCH 21/23] kbuild: use absolute path in the generated wrapper Makefile Masahiro Yamada
2024-10-04 19:02   ` Nicolas Schier
2024-11-29 23:31   ` Caleb Connolly
2024-11-30  9:19     ` Masahiro Yamada
2024-09-17 14:16 ` [PATCH 22/23] kbuild: make wrapper Makefile more convenient for external modules Masahiro Yamada
2024-10-04 19:46   ` Nicolas Schier
2024-09-17 14:16 ` [PATCH 23/23] kbuild: allow to start building external module in any directory Masahiro Yamada
2024-10-04 20:05   ` Nicolas Schier
2024-09-20 10:39 ` [PATCH 00/23] kbuild: support building external modules in a separate build directory Nicolas Schier
2024-09-20 12:58   ` Masahiro Yamada
2024-09-20 13:41     ` Nicolas Schier
2024-09-28  6:50 ` Masahiro Yamada
2024-09-30 14:28   ` Miguel Ojeda
2024-10-04 20:16 ` Nicolas Schier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240917141725.466514-15-masahiroy@kernel.org \
    --to=masahiroy@kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nathan@kernel.org \
    --cc=nicolas@fjasle.eu \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).