Skip to content

Commit a1b9805

Browse files
author
Herton R. Krzesinski
committed
kbuild: use $(src) instead of $(srctree)/$(src) for source directory
JIRA: https://issues.redhat.com/browse/RHEL-107194 commit b1992c3 Author: Masahiro Yamada <masahiroy@kernel.org> Date: Sat Apr 27 23:55:02 2024 +0900 kbuild: use $(src) instead of $(srctree)/$(src) for source directory Kbuild conventionally uses $(obj)/ for generated files, and $(src)/ for checked-in source files. It is merely a convention without any functional difference. In fact, $(obj) and $(src) are exactly the same, as defined in scripts/Makefile.build: src := $(obj) When the kernel is built in a separate output directory, $(src) does not accurately reflect the source directory location. While Kbuild resolves this discrepancy by specifying VPATH=$(srctree) to search for source files, it does not cover all cases. For example, when adding a header search path for local headers, -I$(srctree)/$(src) is typically passed to the compiler. This introduces inconsistency between upstream and downstream Makefiles because $(src) is used instead of $(srctree)/$(src) for the latter. To address this inconsistency, this commit changes the semantics of $(src) so that it always points to the directory in the source tree. Going forward, the variables used in Makefiles will have the following meanings: $(obj) - directory in the object tree $(src) - directory in the source tree (changed by this commit) $(objtree) - the top of the kernel object tree $(srctree) - the top of the kernel source tree Consequently, $(srctree)/$(src) in upstream Makefiles need to be replaced with $(src). Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Nicolas Schier <nicolas@fjasle.eu> Conflicts: There is a extensive list of fixes/conflicts due the amount of files originally changed by this commit, plus the difference of rhel-9 code against upstream. All conflicts/differences are listed below: - Context difference at Documentation/Makefile since RHEL 9 does not have the change "docs: allow to pass extra DOCS_CSS themes via make" and later changes. - Conflict at Documentation/devicetree/bindings/Makefile, patch find_cmd instead of find_all_cmd since RHEL-9 doesn't have "dt-bindings: Consider DT_SCHEMA_FILES when finding all json-schema", "dt-bindings: kbuild: Split targets out to separate rules" and later changes. - Conflict at Documentation/kbuild/makefiles.rst due different identation since RHEL-9 doesn't have the change "docs/kbuild/makefiles: clean up indentation and whitespace" - Patched additional $(srctree)/$(src) references at: * arch/arm/mach-davinci/Makefile * arch/arm/mach-omap2/Makefile * arch/arm/mach-spear/Makefile * arch/arm/plat-pxa/Makefile * arch/arm/plat-versatile/Makefile * arch/ia64/kernel/Makefile * arch/nds32/boot/Makefile * arch/nds32/kernel/vdso/Makefile * drivers/net/ethernet/hisilicon/hns3/hns3pf/Makefile * drivers/net/ethernet/hisilicon/hns3/hns3vf/Makefile * drivers/staging/rtl8188eu/Makefile * drivers/staging/unisys/visorhba/Makefile * drivers/staging/unisys/visornic/Makefile * scripts/gcc-plugins/Makefile Since RHEL-9 does not have later upstream changes that dropped/made those references uneeded. - Conflict at arch/arm/mach-s3c/Makefile since RHEL-9 doesn't have "ARM: s3c: remove s3c24xx specific hacks" and related changes. Also, extra locations needed patching because of not having the changes "ARM: s3c: remove all s3c24xx support" and "ARM: s3c: fix include path". Due lacking the last change also arch/arm/mach-s3c/Makefile.s3c64xx needs additional two places patched as well. - Conflict at arch/arm/plat-orion/Makefile since RHEL-9 doesn't have the commit "ARM: orion: fix include path" and its previous related changes. - Dropped changes for arch/loongarch since it doesn't exist on rhel-9 - Dropped changes to arch/parisc/kernel/{vdso32,vdso64}/Makefile since RHEL 9 does not have the change "parisc: Add vDSO support" and later updates to it. - Dropped change to arch/riscv/kernel/compat_vdso/Makefile since RHEL 9 does not have the change "riscv: compat: vdso: Add COMPAT_VDSO base code implementation" - Dropped change to arch/riscv/kvm/Makefile since there is no KVM support/commits in RHEL 9 for riscv. - Apply change for arch/riscv/kernel/vdso/Makefile in a different place since RHEL-9 does not have the change "riscv: explicitly use symbol offsets for VDSO" which changed the location of the $(srctree)/$(src) reference - Dropped change to certs/Makefile related to check-blacklist-hashes.awk since that script was only added with commit "certs: Check that builtin blacklist hashes are valid" which is not backported/available in RHEL 9 code right now. - Dropped change to drivers/md/dm-vdo/Makefile since dm-vdo was never backported to RHEL-9 main. - Dropped change to drivers/net/ethernet/fungible/funeth/Makefile since fungible ethernet driver/devices code is not available/backported to RHEL-9. - Fixed conflict at drivers/net/ethernet/hisilicon/hns3/Makefile since RHEL-9 does not have the change "net: hns3: refactor hns3 makefile to support hns3_common module" - Fixed conflict at drivers/net/wireless/intel/iwlwifi/mvm/Makefile due already backported commit "wifi: iwlwifi: mvm: implement link grading" - Dropped change to init/Makefile since we are not backporting "kbuild: build init/built-in.a just once" that introduced the section patched. - Dropped change to rust/Makefile since there is no rust support backported to RHEL-9. - Fixed conflict at scripts/dtc/Makefile since RHEL-9 does not have the change "dt-bindings: kbuild: Use DTB files for validation" - Dropped change to security/tomoyo/Makefile since it's not needed, it's just reverting the change "tomoyo: fix broken dependency on *.conf.default" which was never applied to RHEL-9. However, we also bring a different change/patch location since RHEL-9 does not have the change "tomoyo: Omit use of bin2c". - Dropped change to usr/include/Makefile since "kbuild: move headers_check.pl to usr/include/" is not being backported to RHEL-9. - Misc/minor context differences at other places. Signed-off-by: Herton R. Krzesinski <herton@redhat.com>
1 parent 5332bc5 commit a1b9805

File tree

106 files changed

+178
-187
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+178
-187
lines changed

Documentation/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,22 @@ loop_cmd = $(echo-cmd) $(cmd_$(1)) || exit;
6868
# * dest folder relative to $(BUILDDIR) and
6969
# * cache folder relative to $(BUILDDIR)/.doctrees
7070
# $4 dest subfolder e.g. "man" for man pages at userspace-api/media/man
71-
# $5 reST source folder relative to $(srctree)/$(src),
71+
# $5 reST source folder relative to $(src),
7272
# e.g. "userspace-api/media" for the linux-tv book-set at ./Documentation/userspace-api/media
7373

7474
quiet_cmd_sphinx = SPHINX $@ --> file://$(abspath $(BUILDDIR)/$3/$4)
7575
cmd_sphinx = $(MAKE) BUILDDIR=$(abspath $(BUILDDIR)) $(build)=Documentation/userspace-api/media $2 && \
7676
PYTHONDONTWRITEBYTECODE=1 \
77-
BUILDDIR=$(abspath $(BUILDDIR)) SPHINX_CONF=$(abspath $(srctree)/$(src)/$5/$(SPHINX_CONF)) \
77+
BUILDDIR=$(abspath $(BUILDDIR)) SPHINX_CONF=$(abspath $(src)/$5/$(SPHINX_CONF)) \
7878
$(PYTHON3) $(srctree)/scripts/jobserver-exec \
7979
$(CONFIG_SHELL) $(srctree)/Documentation/sphinx/parallel-wrapper.sh \
8080
$(SPHINXBUILD) \
8181
-b $2 \
82-
-c $(abspath $(srctree)/$(src)) \
82+
-c $(abspath $(src)) \
8383
-d $(abspath $(BUILDDIR)/.doctrees/$3) \
8484
-D version=$(KERNELVERSION) -D release=$(KERNELRELEASE) \
8585
$(ALLSPHINXOPTS) \
86-
$(abspath $(srctree)/$(src)/$5) \
86+
$(abspath $(src)/$5) \
8787
$(abspath $(BUILDDIR)/$3/$4)
8888

8989
YNL_INDEX:=$(srctree)/Documentation/networking/netlink_spec/index.rst

Documentation/devicetree/bindings/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ $(obj)/%.example.dts: $(src)/%.yaml check_dtschema_version FORCE
2222
# Use full schemas when checking %.example.dts
2323
DT_TMP_SCHEMA := $(obj)/processed-schema-examples.json
2424

25-
find_cmd = find $(srctree)/$(src) \( -name '*.yaml' ! \
25+
find_cmd = find $(src) \( -name '*.yaml' ! \
2626
-name 'processed-schema*' ! \
2727
-name '*.example.dt.yaml' \)
2828

2929
quiet_cmd_yamllint = LINT $(src)
3030
cmd_yamllint = ($(find_cmd) | \
31-
xargs $(DT_SCHEMA_LINT) -f parsable -c $(srctree)/$(src)/.yamllint) || true
31+
xargs $(DT_SCHEMA_LINT) -f parsable -c $(src)/.yamllint) || true
3232

3333
quiet_cmd_chk_bindings = CHKDT $@
3434
cmd_chk_bindings = ($(find_cmd) | \
35-
xargs -n200 -P$$(nproc) $(DT_DOC_CHECKER) -u $(srctree)/$(src)) || true
35+
xargs -n200 -P$$(nproc) $(DT_DOC_CHECKER) -u $(src)) || true
3636

3737
quiet_cmd_mk_schema = SCHEMA $@
3838
cmd_mk_schema = f=$$(mktemp) ; \

Documentation/kbuild/makefiles.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ more details, with real examples.
421421
Example::
422422

423423
#arch/cris/boot/compressed/Makefile
424-
ldflags-y += -T $(srctree)/$(src)/decompress_$(arch-y).lds
424+
ldflags-y += -T $(src)/decompress_$(arch-y).lds
425425

426426
subdir-ccflags-y, subdir-asflags-y
427427
The two flags listed above are similar to ccflags-y and asflags-y.
@@ -502,14 +502,14 @@ more details, with real examples.
502502
Two variables are used when defining custom rules:
503503

504504
$(src)
505-
$(src) is a relative path which points to the directory
506-
where the Makefile is located. Always use $(src) when
505+
$(src) is the directory where the Makefile is located. Always use $(src) when
507506
referring to files located in the src tree.
508507

509508
$(obj)
510-
$(obj) is a relative path which points to the directory
511-
where the target is saved. Always use $(obj) when
512-
referring to generated files.
509+
$(obj) is the directory where the target is saved. Always use $(obj) when
510+
referring to generated files. Use $(obj) for pattern rules that need to work
511+
for both generated files and real sources (VPATH will help to find the
512+
prerequisites not only in the object tree but also in the source tree).
513513

514514
Example::
515515

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,14 @@ srctree := $(abs_srctree)
264264
endif
265265

266266
objtree := .
267+
268+
VPATH :=
269+
270+
ifeq ($(KBUILD_EXTMOD),)
271+
ifdef building_out_of_srctree
267272
VPATH := $(srctree)
273+
endif
274+
endif
268275

269276
export building_out_of_srctree srctree objtree VPATH
270277

arch/arc/boot/dts/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ obj-y += $(builtindtb-y).dtb.o
1010
dtb-y := $(builtindtb-y).dtb
1111

1212
# for CONFIG_OF_ALL_DTBS test
13-
dtstree := $(srctree)/$(src)
14-
dtb- := $(patsubst $(dtstree)/%.dts,%.dtb, $(wildcard $(dtstree)/*.dts))
13+
dtb- := $(patsubst $(src)/%.dts,%.dtb, $(wildcard $(src)/*.dts))
1514

1615
# board-specific dtc flags
1716
DTC_FLAGS_hsdk += --pad 20

arch/arm/Kbuild

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-License-Identifier: GPL-2.0-only
22
obj-$(CONFIG_FPE_NWFPE) += nwfpe/
33
# Put arch/arm/fastfpe/ to use this.
4-
obj-$(CONFIG_FPE_FASTFPE) += $(patsubst $(srctree)/$(src)/%,%,$(wildcard $(srctree)/$(src)/fastfpe/))
4+
obj-$(CONFIG_FPE_FASTFPE) += $(patsubst $(src)/%,%,$(wildcard $(src)/fastfpe/))
55
obj-$(CONFIG_VFP) += vfp/
66
obj-$(CONFIG_XEN) += xen/
77
obj-$(CONFIG_VDSO) += vdso/

arch/arm/boot/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ targets := Image zImage xipImage bootpImage uImage
3131

3232
ifeq ($(CONFIG_XIP_KERNEL),y)
3333

34-
cmd_deflate_xip_data = $(CONFIG_SHELL) -c \
35-
'$(srctree)/$(src)/deflate_xip_data.sh $< $@'
34+
cmd_deflate_xip_data = $(CONFIG_SHELL) -c '$(src)/deflate_xip_data.sh $< $@'
3635

3736
ifeq ($(CONFIG_XIP_DEFLATED_DATA),y)
3837
quiet_cmd_mkxip = XIPZ $@

arch/arm/mach-davinci/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
#
66

7-
ccflags-$(CONFIG_ARCH_MULTIPLATFORM) := -I$(srctree)/$(src)/include
7+
ccflags-$(CONFIG_ARCH_MULTIPLATFORM) := -I$(src)/include
88

99
# Common objects
1010
obj-y := serial.o usb.o common.o sram.o

arch/arm/mach-omap2/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Makefile for the linux kernel.
44
#
55

6-
ccflags-y := -I$(srctree)/$(src)/include \
6+
ccflags-y := -I$(src)/include \
77
-I$(srctree)/arch/arm/plat-omap/include
88

99
# Common support

arch/arm/mach-s3c/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
#
33
# Copyright 2009 Simtec Electronics
44

5-
ccflags-$(CONFIG_ARCH_MULTIPLATFORM) += -I$(srctree)/$(src)/include
5+
ccflags-$(CONFIG_ARCH_MULTIPLATFORM) += -I$(src)/include
66

77
ifdef CONFIG_ARCH_S3C24XX
8-
include $(srctree)/$(src)/Makefile.s3c24xx
8+
include $(src)/Makefile.s3c24xx
99
endif
1010

1111
ifdef CONFIG_ARCH_S3C64XX
12-
include $(srctree)/$(src)/Makefile.s3c64xx
12+
include $(src)/Makefile.s3c64xx
1313
endif
1414

1515
# Objects we always build independent of SoC choice

0 commit comments

Comments
 (0)