Skip to content

Commit 5750121

Browse files
committed
kbuild: list sub-directories in ./Kbuild
Use the ordinary obj-y syntax to list subdirectories. Note1: Previously, the link order of lib-y depended on CONFIG_MODULES; lib-y was linked before drivers-y when CONFIG_MODULES=y, otherwise after drivers-y. This was a bug of commit 7273ad2 ("kbuild: link lib-y objects to vmlinux forcibly when CONFIG_MODULES=y"), but it was not a big deal after all. Now, all objects listed in lib-y are linked last, irrespective of CONFIG_MODULES. Note2: Finally, the single target build in arch/*/lib/ works correctly. There was a bug report about this. [1] $ make ARCH=arm arch/arm/lib/findbit.o CALL scripts/checksyscalls.sh AS arch/arm/lib/findbit.o [1]: https://lore.kernel.org/linux-kbuild/YvUQOwL6lD4%2F5%[email protected]/ Signed-off-by: Masahiro Yamada <[email protected]> Tested-by: Nick Desaulniers <[email protected]> Reviewed-by: Nicolas Schier <[email protected]>
1 parent 88b61e3 commit 5750121

File tree

3 files changed

+46
-43
lines changed

3 files changed

+46
-43
lines changed

Kbuild

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,27 @@ $(atomic-checks): $(obj)/.checked-%: include/linux/atomic/% FORCE
7272
PHONY += prepare
7373
prepare: $(offsets-file) missing-syscalls $(atomic-checks)
7474
@:
75+
76+
# Ordinary directory descending
77+
# ---------------------------------------------------------------------------
78+
79+
obj-y += init/
80+
obj-y += usr/
81+
obj-y += arch/$(SRCARCH)/
82+
obj-y += $(ARCH_CORE)
83+
obj-y += kernel/
84+
obj-y += certs/
85+
obj-y += mm/
86+
obj-y += fs/
87+
obj-y += ipc/
88+
obj-y += security/
89+
obj-y += crypto/
90+
obj-$(CONFIG_BLOCK) += block/
91+
obj-$(CONFIG_IO_URING) += io_uring/
92+
obj-y += $(ARCH_LIB)
93+
obj-y += drivers/
94+
obj-y += sound/
95+
obj-$(CONFIG_SAMPLES) += samples/
96+
obj-$(CONFIG_NET) += net/
97+
obj-y += virt/
98+
obj-y += $(ARCH_DRIVERS)

Makefile

Lines changed: 20 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -676,11 +676,8 @@ endif
676676

677677
ifeq ($(KBUILD_EXTMOD),)
678678
# Objects we will link into vmlinux / subdirs we need to visit
679-
core-y := init/ usr/ arch/$(SRCARCH)/
680-
drivers-y := drivers/ sound/
681-
drivers-$(CONFIG_SAMPLES) += samples/
682-
drivers-$(CONFIG_NET) += net/
683-
drivers-y += virt/
679+
core-y :=
680+
drivers-y :=
684681
libs-y := lib/
685682
endif # KBUILD_EXTMOD
686683

@@ -1099,31 +1096,24 @@ export MODORDER := $(extmod_prefix)modules.order
10991096
export MODULES_NSDEPS := $(extmod_prefix)modules.nsdeps
11001097

11011098
ifeq ($(KBUILD_EXTMOD),)
1102-
core-y += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/
1103-
core-$(CONFIG_BLOCK) += block/
1104-
core-$(CONFIG_IO_URING) += io_uring/
11051099

1106-
vmlinux-dirs := $(patsubst %/,%,$(filter %/, \
1107-
$(core-y) $(core-m) $(drivers-y) $(drivers-m) \
1108-
$(libs-y) $(libs-m)))
1109-
1110-
build-dirs := $(vmlinux-dirs)
1111-
clean-dirs := $(sort $(vmlinux-dirs) Documentation . \
1100+
build-dir := .
1101+
clean-dirs := $(sort . Documentation \
11121102
$(patsubst %/,%,$(filter %/, $(core-) \
11131103
$(drivers-) $(libs-))))
11141104

1115-
subdir-modorder := $(addsuffix /modules.order, $(build-dirs))
1116-
1105+
export ARCH_CORE := $(core-y)
1106+
export ARCH_LIB := $(filter %/, $(libs-y))
1107+
export ARCH_DRIVERS := $(drivers-y) $(drivers-m)
11171108
# Externally visible symbols (used by link-vmlinux.sh)
1118-
KBUILD_VMLINUX_OBJS := $(head-y) $(patsubst %/,%/built-in.a, $(core-y))
1119-
KBUILD_VMLINUX_OBJS += $(addsuffix built-in.a, $(filter %/, $(libs-y)))
1109+
1110+
KBUILD_VMLINUX_OBJS := $(head-y) ./built-in.a
11201111
ifdef CONFIG_MODULES
11211112
KBUILD_VMLINUX_OBJS += $(patsubst %/, %/lib.a, $(filter %/, $(libs-y)))
11221113
KBUILD_VMLINUX_LIBS := $(filter-out %/, $(libs-y))
11231114
else
11241115
KBUILD_VMLINUX_LIBS := $(patsubst %/,%/lib.a, $(libs-y))
11251116
endif
1126-
KBUILD_VMLINUX_OBJS += $(patsubst %/,%/built-in.a, $(drivers-y))
11271117

11281118
export KBUILD_VMLINUX_OBJS KBUILD_VMLINUX_LIBS
11291119
export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds
@@ -1138,7 +1128,7 @@ ifdef CONFIG_TRIM_UNUSED_KSYMS
11381128
# (this can be evaluated only once include/config/auto.conf has been included)
11391129
KBUILD_MODULES := 1
11401130

1141-
autoksyms_recursive: descend modules.order
1131+
autoksyms_recursive: $(build-dir) modules.order
11421132
$(Q)$(CONFIG_SHELL) $(srctree)/scripts/adjust_autoksyms.sh \
11431133
"$(MAKE) -f $(srctree)/Makefile autoksyms_recursive"
11441134
endif
@@ -1166,7 +1156,7 @@ targets := vmlinux
11661156

11671157
# The actual objects are generated when descending,
11681158
# make sure no implicit rule kicks in
1169-
$(sort $(vmlinux-deps) $(subdir-modorder)): descend ;
1159+
$(sort $(vmlinux-deps)): . ;
11701160

11711161
filechk_kernel.release = \
11721162
echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree))"
@@ -1437,13 +1427,6 @@ endif
14371427

14381428
modules: $(if $(KBUILD_BUILTIN),vmlinux) modules_prepare
14391429

1440-
cmd_modules_order = cat $(real-prereqs) > $@
1441-
1442-
modules.order: $(subdir-modorder) FORCE
1443-
$(call if_changed,modules_order)
1444-
1445-
targets += modules.order
1446-
14471430
# Target to prepare building external modules
14481431
modules_prepare: prepare
14491432
$(Q)$(MAKE) $(build)=scripts scripts/module.lds
@@ -1714,9 +1697,7 @@ else # KBUILD_EXTMOD
17141697
KBUILD_BUILTIN :=
17151698
KBUILD_MODULES := 1
17161699

1717-
build-dirs := $(KBUILD_EXTMOD)
1718-
$(MODORDER): descend
1719-
@:
1700+
build-dir := $(KBUILD_EXTMOD)
17201701

17211702
compile_commands.json: $(extmod_prefix)compile_commands.json
17221703
PHONY += compile_commands.json
@@ -1754,6 +1735,9 @@ PHONY += modules modules_install modules_prepare
17541735

17551736
ifdef CONFIG_MODULES
17561737

1738+
$(MODORDER): $(build-dir)
1739+
@:
1740+
17571741
modules: modules_check
17581742
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
17591743

@@ -1807,7 +1791,7 @@ single-no-ko := $(filter-out $(single-ko), $(MAKECMDGOALS)) \
18071791

18081792
$(single-ko): single_modpost
18091793
@:
1810-
$(single-no-ko): descend
1794+
$(single-no-ko): $(build-dir)
18111795
@:
18121796

18131797
# Remove MODORDER when done because it is not the real one.
@@ -1817,24 +1801,17 @@ single_modpost: $(single-no-ko) modules_prepare
18171801
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
18181802
$(Q)rm -f $(MODORDER)
18191803

1820-
single-goals := $(addprefix $(extmod_prefix), $(single-no-ko))
1821-
1822-
# trim unrelated directories
1823-
build-dirs := $(foreach d, $(build-dirs), \
1824-
$(if $(filter $d/%, $(single-goals)), $d))
1804+
single-goals := $(addprefix $(build-dir)/, $(single-no-ko))
18251805

18261806
endif
18271807

1828-
# Handle descending into subdirectories listed in $(build-dirs)
18291808
# Preset locale variables to speed up the build process. Limit locale
18301809
# tweaks to this spot to avoid wrong language settings when running
18311810
# make menuconfig etc.
18321811
# Error messages still appears in the original language
1833-
PHONY += descend $(build-dirs)
1834-
descend: $(build-dirs)
1835-
$(build-dirs): prepare
1836-
$(Q)$(MAKE) $(build)=$@ need-builtin=1 need-modorder=1 \
1837-
$(filter $@/%, $(single-goals))
1812+
PHONY += $(build-dir)
1813+
$(build-dir): prepare
1814+
$(Q)$(MAKE) $(build)=$@ need-builtin=1 need-modorder=1 $(single-goals)
18381815

18391816
clean-dirs := $(addprefix _clean_, $(clean-dirs))
18401817
PHONY += $(clean-dirs) clean

scripts/Makefile.lib

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ always-y += $(dtb-y)
8989

9090
# Add subdir path
9191

92+
ifneq ($(obj),.)
9293
extra-y := $(addprefix $(obj)/,$(extra-y))
9394
always-y := $(addprefix $(obj)/,$(always-y))
9495
targets := $(addprefix $(obj)/,$(targets))
@@ -100,6 +101,7 @@ multi-obj-m := $(addprefix $(obj)/, $(multi-obj-m))
100101
multi-dtb-y := $(addprefix $(obj)/, $(multi-dtb-y))
101102
real-dtb-y := $(addprefix $(obj)/, $(real-dtb-y))
102103
subdir-ym := $(addprefix $(obj)/,$(subdir-ym))
104+
endif
103105

104106
# Finds the multi-part object the current object will be linked into.
105107
# If the object belongs to two or more multi-part objects, list them all.

0 commit comments

Comments
 (0)