Skip to content

Commit b1992c3

Browse files
committed
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 <[email protected]> Reviewed-by: Nicolas Schier <[email protected]>
1 parent 9a0ebe5 commit b1992c3

File tree

102 files changed

+173
-182
lines changed

Some content is hidden

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

102 files changed

+173
-182
lines changed

Documentation/Makefile

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

8282
quiet_cmd_sphinx = SPHINX $@ --> file://$(abspath $(BUILDDIR)/$3/$4)
8383
cmd_sphinx = $(MAKE) BUILDDIR=$(abspath $(BUILDDIR)) $(build)=Documentation/userspace-api/media $2 && \
8484
PYTHONDONTWRITEBYTECODE=1 \
85-
BUILDDIR=$(abspath $(BUILDDIR)) SPHINX_CONF=$(abspath $(srctree)/$(src)/$5/$(SPHINX_CONF)) \
85+
BUILDDIR=$(abspath $(BUILDDIR)) SPHINX_CONF=$(abspath $(src)/$5/$(SPHINX_CONF)) \
8686
$(PYTHON3) $(srctree)/scripts/jobserver-exec \
8787
$(CONFIG_SHELL) $(srctree)/Documentation/sphinx/parallel-wrapper.sh \
8888
$(SPHINXBUILD) \
8989
-b $2 \
90-
-c $(abspath $(srctree)/$(src)) \
90+
-c $(abspath $(src)) \
9191
-d $(abspath $(BUILDDIR)/.doctrees/$3) \
9292
-D version=$(KERNELVERSION) -D release=$(KERNELRELEASE) \
9393
$(ALLSPHINXOPTS) \
94-
$(abspath $(srctree)/$(src)/$5) \
94+
$(abspath $(src)/$5) \
9595
$(abspath $(BUILDDIR)/$3/$4) && \
9696
if [ "x$(DOCS_CSS)" != "x" ]; then \
9797
cp $(if $(patsubst /%,,$(DOCS_CSS)),$(abspath $(srctree)/$(DOCS_CSS)),$(DOCS_CSS)) $(BUILDDIR)/$3/_static/; \

Documentation/devicetree/bindings/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ quiet_cmd_extract_ex = DTEX $@
2525
$(obj)/%.example.dts: $(src)/%.yaml check_dtschema_version FORCE
2626
$(call if_changed,extract_ex)
2727

28-
find_all_cmd = find $(srctree)/$(src) \( -name '*.yaml' ! \
28+
find_all_cmd = find $(src) \( -name '*.yaml' ! \
2929
-name 'processed-schema*' \)
3030

3131
find_cmd = $(find_all_cmd) | \
@@ -37,12 +37,12 @@ CHK_DT_EXAMPLES := $(patsubst $(srctree)/%.yaml,%.example.dtb, $(shell $(find_cm
3737
quiet_cmd_yamllint = LINT $(src)
3838
cmd_yamllint = ($(find_cmd) | \
3939
xargs -n200 -P$$(nproc) \
40-
$(DT_SCHEMA_LINT) -f parsable -c $(srctree)/$(src)/.yamllint >&2) \
40+
$(DT_SCHEMA_LINT) -f parsable -c $(src)/.yamllint >&2) \
4141
&& touch $@ || true
4242

4343
quiet_cmd_chk_bindings = CHKDT $(src)
4444
cmd_chk_bindings = ($(find_cmd) | \
45-
xargs -n200 -P$$(nproc) $(DT_DOC_CHECKER) -u $(srctree)/$(src)) \
45+
xargs -n200 -P$$(nproc) $(DT_DOC_CHECKER) -u $(src)) \
4646
&& touch $@ || true
4747

4848
quiet_cmd_mk_schema = SCHEMA $@

Documentation/kbuild/makefiles.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ ccflags-y, asflags-y and ldflags-y
346346
Example::
347347

348348
#arch/cris/boot/compressed/Makefile
349-
ldflags-y += -T $(srctree)/$(src)/decompress_$(arch-y).lds
349+
ldflags-y += -T $(src)/decompress_$(arch-y).lds
350350

351351
subdir-ccflags-y, subdir-asflags-y
352352
The two flags listed above are similar to ccflags-y and asflags-y.
@@ -426,14 +426,14 @@ path to prerequisite files and target files.
426426
Two variables are used when defining custom rules:
427427

428428
$(src)
429-
$(src) is a relative path which points to the directory
430-
where the Makefile is located. Always use $(src) when
429+
$(src) is the directory where the Makefile is located. Always use $(src) when
431430
referring to files located in the src tree.
432431

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

438438
Example::
439439

Makefile

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

265265
objtree := .
266+
267+
VPATH :=
268+
269+
ifeq ($(KBUILD_EXTMOD),)
270+
ifdef building_out_of_srctree
266271
VPATH := $(srctree)
272+
endif
273+
endif
267274

268275
export building_out_of_srctree srctree objtree VPATH
269276

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
@@ -25,8 +25,7 @@ targets := Image zImage xipImage bootpImage uImage
2525

2626
ifeq ($(CONFIG_XIP_KERNEL),y)
2727

28-
cmd_deflate_xip_data = $(CONFIG_SHELL) -c \
29-
'$(srctree)/$(src)/deflate_xip_data.sh $< $@'
28+
cmd_deflate_xip_data = $(CONFIG_SHELL) -c '$(src)/deflate_xip_data.sh $< $@'
3029

3130
ifeq ($(CONFIG_XIP_DEFLATED_DATA),y)
3231
quiet_cmd_mkxip = XIPZ $@

arch/arm/mach-s3c/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# Copyright 2009 Simtec Electronics
44

5-
include $(srctree)/$(src)/Makefile.s3c64xx
5+
include $(src)/Makefile.s3c64xx
66

77
# Objects we always build independent of SoC choice
88

arch/arm/plat-orion/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# Makefile for the linux kernel.
44
#
5-
ccflags-y := -I$(srctree)/$(src)/include
5+
ccflags-y := -I$(src)/include
66

77
orion-gpio-$(CONFIG_GPIOLIB) += gpio.o
88
obj-$(CONFIG_PLAT_ORION_LEGACY) += irq.o pcie.o time.o common.o mpp.o

arch/arm/tools/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ gen := arch/$(ARCH)/include/generated
99
kapi := $(gen)/asm
1010
uapi := $(gen)/uapi/asm
1111
syshdr := $(srctree)/scripts/syscallhdr.sh
12-
sysnr := $(srctree)/$(src)/syscallnr.sh
12+
sysnr := $(src)/syscallnr.sh
1313
systbl := $(srctree)/scripts/syscalltbl.sh
1414
syscall := $(src)/syscall.tbl
1515

0 commit comments

Comments
 (0)