Skip to content

Commit 8f81d85

Browse files
committed
kbuild: move kbuild syntax processing to scripts/Makefile.build
scripts/Makefile.lib is included by the following Makefiles: scripts/Makefile.build scripts/Makefile.modfinal scripts/Makefile.package scripts/Makefile.vmlinux scripts/Makefile.vmlinux_o However, the last four do not need to process Kbuild syntax such as obj-*, lib-*, subdir-*, etc. Move the relevant code to scripts/Makefile.build. Signed-off-by: Masahiro Yamada <[email protected]> Reviewed-by: Nicolas Schier <[email protected]>
1 parent 2adde2e commit 8f81d85

File tree

2 files changed

+84
-84
lines changed

2 files changed

+84
-84
lines changed

scripts/Makefile.build

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,90 @@ include $(srctree)/scripts/Makefile.compiler
3737
include $(kbuild-file)
3838
include $(srctree)/scripts/Makefile.lib
3939

40+
# flags that take effect in current and sub directories
41+
KBUILD_AFLAGS += $(subdir-asflags-y)
42+
KBUILD_CFLAGS += $(subdir-ccflags-y)
43+
KBUILD_RUSTFLAGS += $(subdir-rustflags-y)
44+
45+
# Figure out what we need to build from the various variables
46+
# ===========================================================================
47+
48+
# When an object is listed to be built compiled-in and modular,
49+
# only build the compiled-in version
50+
obj-m := $(filter-out $(obj-y),$(obj-m))
51+
52+
# Libraries are always collected in one lib file.
53+
# Filter out objects already built-in
54+
lib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m)))
55+
56+
# Subdirectories we need to descend into
57+
subdir-ym := $(sort $(subdir-y) $(subdir-m) \
58+
$(patsubst %/,%, $(filter %/, $(obj-y) $(obj-m))))
59+
60+
# Handle objects in subdirs:
61+
# - If we encounter foo/ in $(obj-y), replace it by foo/built-in.a and
62+
# foo/modules.order
63+
# - If we encounter foo/ in $(obj-m), replace it by foo/modules.order
64+
#
65+
# Generate modules.order to determine modorder. Unfortunately, we don't have
66+
# information about ordering between -y and -m subdirs. Just put -y's first.
67+
68+
ifdef need-modorder
69+
obj-m := $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-m))
70+
else
71+
obj-m := $(filter-out %/, $(obj-m))
72+
endif
73+
74+
ifdef need-builtin
75+
obj-y := $(patsubst %/, %/built-in.a, $(obj-y))
76+
else
77+
obj-y := $(filter-out %/, $(obj-y))
78+
endif
79+
80+
# Expand $(foo-objs) $(foo-y) etc. by replacing their individuals
81+
suffix-search = $(strip $(foreach s, $3, $($(1:%$(strip $2)=%$s))))
82+
# List composite targets that are constructed by combining other targets
83+
multi-search = $(sort $(foreach m, $1, $(if $(call suffix-search, $m, $2, $3 -), $m)))
84+
# List primitive targets that are compiled from source files
85+
real-search = $(foreach m, $1, $(if $(call suffix-search, $m, $2, $3 -), $(call suffix-search, $m, $2, $3), $m))
86+
87+
# If $(foo-objs), $(foo-y), $(foo-m), or $(foo-) exists, foo.o is a composite object
88+
multi-obj-y := $(call multi-search, $(obj-y), .o, -objs -y)
89+
multi-obj-m := $(call multi-search, $(obj-m), .o, -objs -y -m)
90+
multi-obj-ym := $(multi-obj-y) $(multi-obj-m)
91+
92+
# Replace multi-part objects by their individual parts,
93+
# including built-in.a from subdirectories
94+
real-obj-y := $(call real-search, $(obj-y), .o, -objs -y)
95+
real-obj-m := $(call real-search, $(obj-m), .o, -objs -y -m)
96+
97+
always-y += $(always-m)
98+
99+
# hostprogs-always-y += foo
100+
# ... is a shorthand for
101+
# hostprogs += foo
102+
# always-y += foo
103+
hostprogs += $(hostprogs-always-y) $(hostprogs-always-m)
104+
always-y += $(hostprogs-always-y) $(hostprogs-always-m)
105+
106+
# userprogs-always-y is likewise.
107+
userprogs += $(userprogs-always-y) $(userprogs-always-m)
108+
always-y += $(userprogs-always-y) $(userprogs-always-m)
109+
110+
# Add subdir path
111+
112+
ifneq ($(obj),.)
113+
extra-y := $(addprefix $(obj)/, $(extra-y))
114+
always-y := $(addprefix $(obj)/, $(always-y))
115+
targets := $(addprefix $(obj)/, $(targets))
116+
obj-m := $(addprefix $(obj)/, $(obj-m))
117+
lib-y := $(addprefix $(obj)/, $(lib-y))
118+
real-obj-y := $(addprefix $(obj)/, $(real-obj-y))
119+
real-obj-m := $(addprefix $(obj)/, $(real-obj-m))
120+
multi-obj-m := $(addprefix $(obj)/, $(multi-obj-m))
121+
subdir-ym := $(addprefix $(obj)/, $(subdir-ym))
122+
endif
123+
40124
ifndef obj
41125
$(warning kbuild: Makefile.build is included improperly)
42126
endif

scripts/Makefile.lib

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,5 @@
11
# SPDX-License-Identifier: GPL-2.0
22

3-
# flags that take effect in current and sub directories
4-
KBUILD_AFLAGS += $(subdir-asflags-y)
5-
KBUILD_CFLAGS += $(subdir-ccflags-y)
6-
KBUILD_RUSTFLAGS += $(subdir-rustflags-y)
7-
8-
# Figure out what we need to build from the various variables
9-
# ===========================================================================
10-
11-
# When an object is listed to be built compiled-in and modular,
12-
# only build the compiled-in version
13-
obj-m := $(filter-out $(obj-y),$(obj-m))
14-
15-
# Libraries are always collected in one lib file.
16-
# Filter out objects already built-in
17-
lib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m)))
18-
19-
# Subdirectories we need to descend into
20-
subdir-ym := $(sort $(subdir-y) $(subdir-m) \
21-
$(patsubst %/,%, $(filter %/, $(obj-y) $(obj-m))))
22-
23-
# Handle objects in subdirs:
24-
# - If we encounter foo/ in $(obj-y), replace it by foo/built-in.a and
25-
# foo/modules.order
26-
# - If we encounter foo/ in $(obj-m), replace it by foo/modules.order
27-
#
28-
# Generate modules.order to determine modorder. Unfortunately, we don't have
29-
# information about ordering between -y and -m subdirs. Just put -y's first.
30-
31-
ifdef need-modorder
32-
obj-m := $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-m))
33-
else
34-
obj-m := $(filter-out %/, $(obj-m))
35-
endif
36-
37-
ifdef need-builtin
38-
obj-y := $(patsubst %/, %/built-in.a, $(obj-y))
39-
else
40-
obj-y := $(filter-out %/, $(obj-y))
41-
endif
42-
43-
# Expand $(foo-objs) $(foo-y) etc. by replacing their individuals
44-
suffix-search = $(strip $(foreach s, $3, $($(1:%$(strip $2)=%$s))))
45-
# List composite targets that are constructed by combining other targets
46-
multi-search = $(sort $(foreach m, $1, $(if $(call suffix-search, $m, $2, $3 -), $m)))
47-
# List primitive targets that are compiled from source files
48-
real-search = $(foreach m, $1, $(if $(call suffix-search, $m, $2, $3 -), $(call suffix-search, $m, $2, $3), $m))
49-
50-
# If $(foo-objs), $(foo-y), $(foo-m), or $(foo-) exists, foo.o is a composite object
51-
multi-obj-y := $(call multi-search, $(obj-y), .o, -objs -y)
52-
multi-obj-m := $(call multi-search, $(obj-m), .o, -objs -y -m)
53-
multi-obj-ym := $(multi-obj-y) $(multi-obj-m)
54-
55-
# Replace multi-part objects by their individual parts,
56-
# including built-in.a from subdirectories
57-
real-obj-y := $(call real-search, $(obj-y), .o, -objs -y)
58-
real-obj-m := $(call real-search, $(obj-m), .o, -objs -y -m)
59-
60-
always-y += $(always-m)
61-
62-
# hostprogs-always-y += foo
63-
# ... is a shorthand for
64-
# hostprogs += foo
65-
# always-y += foo
66-
hostprogs += $(hostprogs-always-y) $(hostprogs-always-m)
67-
always-y += $(hostprogs-always-y) $(hostprogs-always-m)
68-
69-
# userprogs-always-y is likewise.
70-
userprogs += $(userprogs-always-y) $(userprogs-always-m)
71-
always-y += $(userprogs-always-y) $(userprogs-always-m)
72-
73-
# Add subdir path
74-
75-
ifneq ($(obj),.)
76-
extra-y := $(addprefix $(obj)/,$(extra-y))
77-
always-y := $(addprefix $(obj)/,$(always-y))
78-
targets := $(addprefix $(obj)/,$(targets))
79-
obj-m := $(addprefix $(obj)/,$(obj-m))
80-
lib-y := $(addprefix $(obj)/,$(lib-y))
81-
real-obj-y := $(addprefix $(obj)/,$(real-obj-y))
82-
real-obj-m := $(addprefix $(obj)/,$(real-obj-m))
83-
multi-obj-m := $(addprefix $(obj)/, $(multi-obj-m))
84-
subdir-ym := $(addprefix $(obj)/,$(subdir-ym))
85-
endif
86-
873
# Finds the multi-part object the current object will be linked into.
884
# If the object belongs to two or more multi-part objects, list them all.
895
modname-multi = $(sort $(foreach m,$(multi-obj-ym),\

0 commit comments

Comments
 (0)