]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
kbuild: add $(objtree)/ prefix to some in-kernel build artifacts
authorMasahiro Yamada <masahiroy@kernel.org>
Sun, 10 Nov 2024 01:34:30 +0000 (10:34 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Wed, 27 Nov 2024 00:38:27 +0000 (09:38 +0900)
$(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         := .

This commit prepares for supporting the building of external modules
in a different directory.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
Makefile
arch/arm/Makefile
arch/arm64/Makefile
arch/powerpc/Makefile
arch/riscv/Makefile
scripts/Kbuild.include
scripts/Makefile.build
scripts/Makefile.modfinal
scripts/Makefile.modinst
scripts/Makefile.modpost
scripts/depmod.sh

index 891d28e54791b2da9c73fa85c8cdc4c899b062d8..9b8f4f4cb01bb739ec56e17fd218dc47ce72c2a2 100644 (file)
--- 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
 
@@ -720,7 +720,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),)
@@ -783,13 +783,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)
index aafebf145738ab1a443c116a1bf648953f7afed4..00ca7886b18efe2d01f33bc079eda2483ec807a7 100644 (file)
@@ -264,13 +264,13 @@ stack_protector_prepare: prepare0
                -mstack-protector-guard=tls \
                -mstack-protector-guard-offset=$(shell  \
                        awk '{if ($$2 == "TSK_STACK_CANARY") print $$3;}'\
-                               include/generated/asm-offsets.h))
+                               $(objtree)/include/generated/asm-offsets.h))
 else
 stack_protector_prepare: prepare0
        $(eval SSP_PLUGIN_CFLAGS := \
                -fplugin-arg-arm_ssp_per_task_plugin-offset=$(shell     \
                        awk '{if ($$2 == "TSK_STACK_CANARY") print $$3;}'\
-                               include/generated/asm-offsets.h))
+                               $(objtree)/include/generated/asm-offsets.h))
        $(eval KBUILD_CFLAGS += $(SSP_PLUGIN_CFLAGS))
        $(eval GCC_PLUGINS_CFLAGS += $(SSP_PLUGIN_CFLAGS))
 endif
index 9efd3f37c2fd9de155019f69cee1a0bb09e9a6dd..358c68565bfd0633d8565187016e1003445208fc 100644 (file)
@@ -71,7 +71,7 @@ stack_protector_prepare: prepare0
                                -mstack-protector-guard-reg=sp_el0        \
                                -mstack-protector-guard-offset=$(shell    \
                        awk '{if ($$2 == "TSK_STACK_CANARY") print $$3;}' \
-                                       include/generated/asm-offsets.h))
+                               $(objtree)/include/generated/asm-offsets.h))
 endif
 
 ifeq ($(CONFIG_ARM64_BTI_KERNEL),y)
index bbfe4a1f06ef9db9b2f2e48e02096b1e0500a14b..321b596d25501c72290aaeb93cb2759705f7f675 100644 (file)
@@ -402,9 +402,9 @@ prepare: stack_protector_prepare
 PHONY += stack_protector_prepare
 stack_protector_prepare: prepare0
 ifdef CONFIG_PPC64
-       $(eval KBUILD_CFLAGS += -mstack-protector-guard-offset=$(shell awk '{if ($$2 == "PACA_CANARY") print $$3;}' include/generated/asm-offsets.h))
+       $(eval KBUILD_CFLAGS += -mstack-protector-guard-offset=$(shell awk '{if ($$2 == "PACA_CANARY") print $$3;}' $(objtree)/include/generated/asm-offsets.h))
 else
-       $(eval KBUILD_CFLAGS += -mstack-protector-guard-offset=$(shell awk '{if ($$2 == "TASK_CANARY") print $$3;}' include/generated/asm-offsets.h))
+       $(eval KBUILD_CFLAGS += -mstack-protector-guard-offset=$(shell awk '{if ($$2 == "TASK_CANARY") print $$3;}' $(objtree)/include/generated/asm-offsets.h))
 endif
 endif
 
index d469db9f46f426122a1d6a41861622171402763c..a08cfeb6cbf98d2fe4069b4c67afe98b62d0435e 100644 (file)
@@ -129,7 +129,7 @@ stack_protector_prepare: prepare0
                                -mstack-protector-guard-reg=tp            \
                                -mstack-protector-guard-offset=$(shell    \
                        awk '{if ($$2 == "TSK_STACK_CANARY") print $$3;}' \
-                                       include/generated/asm-offsets.h))
+                               $(objtree)/include/generated/asm-offsets.h))
 endif
 
 # arch specific predefines for sparse
index ed8a7493524b299321d66a3fe61797f83c751e05..8c311b997e246319d8118de2796de96c8d1ab68d 100644 (file)
@@ -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)
index 8f423a1faf507738fb62217e7c79c6d24ccbe690..dd7a80ebca62e5bd53f1eaf55fd3cda2f2b5cdf8 100644 (file)
@@ -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)
index 1482884ec3ca820c0a1dbd4d25c5463985561a49..6d8aa3059ee219e6745822ccf751ae867575c1ef 100644 (file)
@@ -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
index d977209431898befac99a4a4ec937b036c33f3f2..6fa9af4a25b4296f904a729b6cb5c28d7c5ddd1d 100644 (file)
@@ -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 :=
index 44936ebad161e914cbcc40ac74a2d651596d7b07..12e7c15d099c2c53815419d29a804f6bdc33630b 100644 (file)
 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))
index e22da27fe13eb35fccb3a34cfc90b558e3adc31f..3c34fecacbc82e297fd4919e98ab70f0283c6b10 100755 (executable)
@@ -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