|
1 | 1 | # SPDX-License-Identifier: GPL-2.0 |
2 | 2 |
|
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 | | - |
87 | 3 | # Finds the multi-part object the current object will be linked into. |
88 | 4 | # If the object belongs to two or more multi-part objects, list them all. |
89 | 5 | modname-multi = $(sort $(foreach m,$(multi-obj-ym),\ |
|
0 commit comments