History

kbuild: add $(objtree)/ prefix to some in-kernel build artifacts

$(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.

Masahiro Yamada committed 2 years ago

Commit 214c0ee1 parent 0afd73c11 files · +30 −30Browse files

Unified · Split

11 files
  1. Makefile +5 −5
  2. arch/arm/Makefile +2 −2
  3. arch/arm64/Makefile +1 −1
  4. arch/powerpc/Makefile +2 −2
  5. arch/riscv/Makefile +1 −1
  6. scripts/Kbuild.include +1 −1
  7. scripts/Makefile.build +2 −2
  8. scripts/Makefile.modfinal +7 −7
  9. scripts/Makefile.modinst +1 −1
  10. scripts/Makefile.modpost +6 −6
  11. scripts/depmod.sh +2 −2
Makefile+5−5
@@ -354,7 +354,7 @@ else # !mixed-build · 353 unmodified lines
354include $(srctree)/scripts/Kbuild.include354include $(srctree)/scripts/Kbuild.include
355 355
356# Read KERNELRELEASE from include/config/kernel.release (if it exists)356# Read KERNELRELEASE from include/config/kernel.release (if it exists)
357KERNELRELEASE = $(call read-file, include/config/kernel.release)357KERNELRELEASE = $(call read-file, $(objtree)/include/config/kernel.release)
358KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)358KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
359export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION359export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION
360 360
@@ -720,7 +720,7 @@ endif · 359 unmodified lines
720export KBUILD_MODULES KBUILD_BUILTIN720export KBUILD_MODULES KBUILD_BUILTIN
721 721
722ifdef need-config722ifdef need-config
723include include/config/auto.conf723include $(objtree)/include/config/auto.conf
724endif724endif
725 725
726ifeq ($(KBUILD_EXTMOD),)726ifeq ($(KBUILD_EXTMOD),)
@@ -783,13 +783,13 @@ else # !may-sync-config · 56 unmodified lines
783# and include/config/auto.conf but do not care if they are up-to-date.783# and include/config/auto.conf but do not care if they are up-to-date.
784# Use auto.conf to show the error message784# Use auto.conf to show the error message
785 785
786checked-configs := include/generated/autoconf.h include/generated/rustc_cfg include/config/auto.conf786checked-configs := $(addprefix $(objtree)/, include/generated/autoconf.h include/generated/rustc_cfg include/config/auto.conf)
787missing-configs := $(filter-out $(wildcard $(checked-configs)), $(checked-configs))787missing-configs := $(filter-out $(wildcard $(checked-configs)), $(checked-configs))
788 788
789ifdef missing-configs789ifdef missing-configs
790PHONY += include/config/auto.conf790PHONY += $(objtree)/include/config/auto.conf
791 791
792include/config/auto.conf:792$(objtree)/include/config/auto.conf:
793 @echo >&2 '***'793 @echo >&2 '***'
794 @echo >&2 '*** ERROR: Kernel configuration is invalid. The following files are missing:'794 @echo >&2 '*** ERROR: Kernel configuration is invalid. The following files are missing:'
795 @printf >&2 '*** - %s\n' $(missing-configs)795 @printf >&2 '*** - %s\n' $(missing-configs)
arch/arm/Makefile+2−2
@@ -264,13 +264,13 @@ stack_protector_prepare: prepare0 · 263 unmodified lines
264 -mstack-protector-guard=tls \264 -mstack-protector-guard=tls \
265 -mstack-protector-guard-offset=$(shell \265 -mstack-protector-guard-offset=$(shell \
266 awk '{if ($$2 == "TSK_STACK_CANARY") print $$3;}'\266 awk '{if ($$2 == "TSK_STACK_CANARY") print $$3;}'\
267 include/generated/asm-offsets.h))267 $(objtree)/include/generated/asm-offsets.h))
268else268else
269stack_protector_prepare: prepare0269stack_protector_prepare: prepare0
270 $(eval SSP_PLUGIN_CFLAGS := \270 $(eval SSP_PLUGIN_CFLAGS := \
271 -fplugin-arg-arm_ssp_per_task_plugin-offset=$(shell \271 -fplugin-arg-arm_ssp_per_task_plugin-offset=$(shell \
272 awk '{if ($$2 == "TSK_STACK_CANARY") print $$3;}'\272 awk '{if ($$2 == "TSK_STACK_CANARY") print $$3;}'\
273 include/generated/asm-offsets.h))273 $(objtree)/include/generated/asm-offsets.h))
274 $(eval KBUILD_CFLAGS += $(SSP_PLUGIN_CFLAGS))274 $(eval KBUILD_CFLAGS += $(SSP_PLUGIN_CFLAGS))
275 $(eval GCC_PLUGINS_CFLAGS += $(SSP_PLUGIN_CFLAGS))275 $(eval GCC_PLUGINS_CFLAGS += $(SSP_PLUGIN_CFLAGS))
276endif276endif
arch/arm64/Makefile+1−1
@@ -71,7 +71,7 @@ stack_protector_prepare: prepare0 · 70 unmodified lines
71 -mstack-protector-guard-reg=sp_el0 \71 -mstack-protector-guard-reg=sp_el0 \
72 -mstack-protector-guard-offset=$(shell \72 -mstack-protector-guard-offset=$(shell \
73 awk '{if ($$2 == "TSK_STACK_CANARY") print $$3;}' \73 awk '{if ($$2 == "TSK_STACK_CANARY") print $$3;}' \
74 include/generated/asm-offsets.h))74 $(objtree)/include/generated/asm-offsets.h))
75endif75endif
76 76
77ifeq ($(CONFIG_ARM64_BTI_KERNEL),y)77ifeq ($(CONFIG_ARM64_BTI_KERNEL),y)
arch/powerpc/Makefile+2−2
@@ -402,9 +402,9 @@ prepare: stack_protector_prepare · 401 unmodified lines
402PHONY += stack_protector_prepare402PHONY += stack_protector_prepare
403stack_protector_prepare: prepare0403stack_protector_prepare: prepare0
404ifdef CONFIG_PPC64404ifdef CONFIG_PPC64
405 $(eval KBUILD_CFLAGS += -mstack-protector-guard-offset=$(shell awk '{if ($$2 == "PACA_CANARY") print $$3;}' include/generated/asm-offsets.h))405 $(eval KBUILD_CFLAGS += -mstack-protector-guard-offset=$(shell awk '{if ($$2 == "PACA_CANARY") print $$3;}' $(objtree)/include/generated/asm-offsets.h))
406else406else
407 $(eval KBUILD_CFLAGS += -mstack-protector-guard-offset=$(shell awk '{if ($$2 == "TASK_CANARY") print $$3;}' include/generated/asm-offsets.h))407 $(eval KBUILD_CFLAGS += -mstack-protector-guard-offset=$(shell awk '{if ($$2 == "TASK_CANARY") print $$3;}' $(objtree)/include/generated/asm-offsets.h))
408endif408endif
409endif409endif
410 410
arch/riscv/Makefile+1−1
@@ -129,7 +129,7 @@ stack_protector_prepare: prepare0 · 128 unmodified lines
129 -mstack-protector-guard-reg=tp \129 -mstack-protector-guard-reg=tp \
130 -mstack-protector-guard-offset=$(shell \130 -mstack-protector-guard-offset=$(shell \
131 awk '{if ($$2 == "TSK_STACK_CANARY") print $$3;}' \131 awk '{if ($$2 == "TSK_STACK_CANARY") print $$3;}' \
132 include/generated/asm-offsets.h))132 $(objtree)/include/generated/asm-offsets.h))
133endif133endif
134 134
135# arch specific predefines for sparse135# arch specific predefines for sparse
scripts/Kbuild.include+1−1
@@ -205,7 +205,7 @@ if_changed_dep = $(if $(if-changed-cond),$(cmd_and_fixdep),@:) · 204 unmodified lines
205 205
206cmd_and_fixdep = \206cmd_and_fixdep = \
207 $(cmd); \207 $(cmd); \
208 scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).cmd;\208 $(objtree)/scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).cmd;\
209 rm -f $(depfile)209 rm -f $(depfile)
210 210
211# Usage: $(call if_changed_rule,foo)211# Usage: $(call if_changed_rule,foo)
scripts/Makefile.build+2−2
@@ -34,7 +34,7 @@ subdir-asflags-y := · 33 unmodified lines
34subdir-ccflags-y :=34subdir-ccflags-y :=
35 35
36# Read auto.conf if it exists, otherwise ignore36# Read auto.conf if it exists, otherwise ignore
37-include include/config/auto.conf37-include $(objtree)/include/config/auto.conf
38 38
39include $(srctree)/scripts/Kbuild.include39include $(srctree)/scripts/Kbuild.include
40include $(srctree)/scripts/Makefile.compiler40include $(srctree)/scripts/Makefile.compiler
@@ -107,7 +107,7 @@ cmd_cpp_i_c = $(CPP) $(c_flags) -o $@ $< · 66 unmodified lines
107$(obj)/%.i: $(obj)/%.c FORCE107$(obj)/%.i: $(obj)/%.c FORCE
108 $(call if_changed_dep,cpp_i_c)108 $(call if_changed_dep,cpp_i_c)
109 109
110genksyms = scripts/genksyms/genksyms \110genksyms = $(objtree)/scripts/genksyms/genksyms \
111 $(if $(1), -T $(2)) \111 $(if $(1), -T $(2)) \
112 $(if $(KBUILD_PRESERVE), -p) \112 $(if $(KBUILD_PRESERVE), -p) \
113 -r $(or $(wildcard $(2:.symtypes=.symref)), /dev/null)113 -r $(or $(wildcard $(2:.symtypes=.symref)), /dev/null)
scripts/Makefile.modfinal+7−7
@@ -6,7 +6,7 @@ · 5 unmodified lines
6PHONY := __modfinal6PHONY := __modfinal
7__modfinal:7__modfinal:
8 8
9include include/config/auto.conf9include $(objtree)/include/config/auto.conf
10include $(srctree)/scripts/Kbuild.include10include $(srctree)/scripts/Kbuild.include
11 11
12# for c_flags12# for c_flags
@@ -37,15 +37,15 @@ quiet_cmd_ld_ko_o = LD [M] $@ · 24 unmodified lines
37 cmd_ld_ko_o = \37 cmd_ld_ko_o = \
38 $(LD) -r $(KBUILD_LDFLAGS) \38 $(LD) -r $(KBUILD_LDFLAGS) \
39 $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \39 $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \
40 -T scripts/module.lds -o $@ $(filter %.o, $^)40 -T $(objtree)/scripts/module.lds -o $@ $(filter %.o, $^)
41 41
42quiet_cmd_btf_ko = BTF [M] $@42quiet_cmd_btf_ko = BTF [M] $@
43 cmd_btf_ko = \43 cmd_btf_ko = \
44 if [ ! -f vmlinux ]; then \44 if [ ! -f $(objtree)/vmlinux ]; then \
45 printf "Skipping BTF generation for %s due to unavailability of vmlinux\n" $@ 1>&2; \45 printf "Skipping BTF generation for %s due to unavailability of vmlinux\n" $@ 1>&2; \
46 else \46 else \
47 LLVM_OBJCOPY="$(OBJCOPY)" $(PAHOLE) -J $(PAHOLE_FLAGS) $(MODULE_PAHOLE_FLAGS) --btf_base vmlinux $@; \47 LLVM_OBJCOPY="$(OBJCOPY)" $(PAHOLE) -J $(PAHOLE_FLAGS) $(MODULE_PAHOLE_FLAGS) --btf_base $(objtree)/vmlinux $@; \
48 $(RESOLVE_BTFIDS) -b vmlinux $@; \48 $(RESOLVE_BTFIDS) -b $(objtree)/vmlinux $@; \
49 fi;49 fi;
50 50
51# Same as newer-prereqs, but allows to exclude specified extra dependencies51# 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), \ · 5 unmodified lines
57 printf '%s\n' 'savedcmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:)57 printf '%s\n' 'savedcmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:)
58 58
59# Re-generate module BTFs if either module's .ko or vmlinux changed59# Re-generate module BTFs if either module's .ko or vmlinux changed
60%.ko: %.o %.mod.o $(extmod_prefix).module-common.o scripts/module.lds $(and $(CONFIG_DEBUG_INFO_BTF_MODULES),$(KBUILD_BUILTIN),vmlinux) FORCE60%.ko: %.o %.mod.o $(extmod_prefix).module-common.o $(objtree)/scripts/module.lds $(and $(CONFIG_DEBUG_INFO_BTF_MODULES),$(KBUILD_BUILTIN),$(objtree)/vmlinux) FORCE
61 +$(call if_changed_except,ld_ko_o,vmlinux)61 +$(call if_changed_except,ld_ko_o,$(objtree)/vmlinux)
62ifdef CONFIG_DEBUG_INFO_BTF_MODULES62ifdef CONFIG_DEBUG_INFO_BTF_MODULES
63 +$(if $(newer-prereqs),$(call cmd,btf_ko))63 +$(if $(newer-prereqs),$(call cmd,btf_ko))
64endif64endif
scripts/Makefile.modinst+1−1
@@ -6,7 +6,7 @@ · 5 unmodified lines
6PHONY := __modinst6PHONY := __modinst
7__modinst:7__modinst:
8 8
9include include/config/auto.conf9include $(objtree)/include/config/auto.conf
10include $(srctree)/scripts/Kbuild.include10include $(srctree)/scripts/Kbuild.include
11 11
12install-y :=12install-y :=
scripts/Makefile.modpost+6−6
@@ -35,10 +35,10 @@ · 34 unmodified lines
35PHONY := __modpost35PHONY := __modpost
36__modpost:36__modpost:
37 37
38include include/config/auto.conf38include $(objtree)/include/config/auto.conf
39include $(srctree)/scripts/Kbuild.include39include $(srctree)/scripts/Kbuild.include
40 40
41MODPOST = scripts/mod/modpost41MODPOST = $(objtree)/scripts/mod/modpost
42 42
43modpost-args = \43modpost-args = \
44 $(if $(CONFIG_MODULES),-M) \44 $(if $(CONFIG_MODULES),-M) \
@@ -119,11 +119,11 @@ include $(kbuild-file) · 74 unmodified lines
119 119
120output-symdump := $(KBUILD_EXTMOD)/Module.symvers120output-symdump := $(KBUILD_EXTMOD)/Module.symvers
121 121
122ifeq ($(wildcard Module.symvers),)122ifeq ($(wildcard $(objtree)/Module.symvers),)
123missing-input := Module.symvers123missing-input := $(objtree)/Module.symvers
124else124else
125modpost-args += -i Module.symvers125modpost-args += -i $(objtree)/Module.symvers
126modpost-deps += Module.symvers126modpost-deps += $(objtree)/Module.symvers
127endif127endif
128 128
129modpost-args += -e $(addprefix -i , $(KBUILD_EXTRA_SYMBOLS))129modpost-args += -e $(addprefix -i , $(KBUILD_EXTRA_SYMBOLS))
scripts/depmod.sh+2−2
@@ -12,7 +12,7 @@ KERNELRELEASE=$1 · 11 unmodified lines
12 12
13: ${DEPMOD:=depmod}13: ${DEPMOD:=depmod}
14 14
15if ! test -r System.map ; then15if ! test -r "${objtree}/System.map" ; then
16 echo "Warning: modules_install: missing 'System.map' file. Skipping depmod." >&216 echo "Warning: modules_install: missing 'System.map' file. Skipping depmod." >&2
17 exit 017 exit 0
18fi18fi
@@ -25,7 +25,7 @@ if [ -z $(command -v $DEPMOD) ]; then · 6 unmodified lines
25 exit 025 exit 0
26fi26fi
27 27
28set -- -ae -F System.map28set -- -ae -F "${objtree}/System.map"
29if test -n "$INSTALL_MOD_PATH"; then29if test -n "$INSTALL_MOD_PATH"; then
30 set -- "$@" -b "$INSTALL_MOD_PATH"30 set -- "$@" -b "$INSTALL_MOD_PATH"
31fi31fi