Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | # Figure out what we need to build from the various variables |
2 | # =========================================================================== | |
3 | ||
4 | # When an object is listed to be built compiled-in and modular, | |
5 | # only build the compiled-in version | |
6 | ||
7 | obj-m := $(filter-out $(obj-y),$(obj-m)) | |
8 | ||
9 | # Libraries are always collected in one lib file. | |
10 | # Filter out objects already built-in | |
11 | ||
12 | lib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m))) | |
13 | ||
14 | ||
15 | # Handle objects in subdirs | |
16 | # --------------------------------------------------------------------------- | |
17 | # o if we encounter foo/ in $(obj-y), replace it by foo/built-in.o | |
18 | # and add the directory to the list of dirs to descend into: $(subdir-y) | |
19 | # o if we encounter foo/ in $(obj-m), remove it from $(obj-m) | |
20 | # and add the directory to the list of dirs to descend into: $(subdir-m) | |
21 | ||
22 | __subdir-y := $(patsubst %/,%,$(filter %/, $(obj-y))) | |
23 | subdir-y += $(__subdir-y) | |
24 | __subdir-m := $(patsubst %/,%,$(filter %/, $(obj-m))) | |
25 | subdir-m += $(__subdir-m) | |
26 | obj-y := $(patsubst %/, %/built-in.o, $(obj-y)) | |
27 | obj-m := $(filter-out %/, $(obj-m)) | |
28 | ||
29 | # Subdirectories we need to descend into | |
30 | ||
31 | subdir-ym := $(sort $(subdir-y) $(subdir-m)) | |
32 | ||
33 | # if $(foo-objs) exists, foo.o is a composite object | |
34 | multi-used-y := $(sort $(foreach m,$(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m)))) | |
35 | multi-used-m := $(sort $(foreach m,$(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m)))) | |
36 | multi-used := $(multi-used-y) $(multi-used-m) | |
37 | single-used-m := $(sort $(filter-out $(multi-used-m),$(obj-m))) | |
38 | ||
39 | # Build list of the parts of our composite objects, our composite | |
40 | # objects depend on those (obviously) | |
41 | multi-objs-y := $(foreach m, $(multi-used-y), $($(m:.o=-objs)) $($(m:.o=-y))) | |
42 | multi-objs-m := $(foreach m, $(multi-used-m), $($(m:.o=-objs)) $($(m:.o=-y))) | |
43 | multi-objs := $(multi-objs-y) $(multi-objs-m) | |
44 | ||
f5fb9765 SR |
45 | # $(subdir-obj-y) is the list of objects in $(obj-y) which uses dir/ to |
46 | # tell kbuild to descend | |
47 | subdir-obj-y := $(filter %/built-in.o, $(obj-y)) | |
1da177e4 LT |
48 | |
49 | # $(obj-dirs) is a list of directories that contain object files | |
50 | obj-dirs := $(dir $(multi-objs) $(subdir-obj-y)) | |
51 | ||
52 | # Replace multi-part objects by their individual parts, look at local dir only | |
53 | real-objs-y := $(foreach m, $(filter-out $(subdir-obj-y), $(obj-y)), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m))) $(extra-y) | |
54 | real-objs-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m))) | |
55 | ||
56 | # Add subdir path | |
57 | ||
58 | extra-y := $(addprefix $(obj)/,$(extra-y)) | |
59 | always := $(addprefix $(obj)/,$(always)) | |
60 | targets := $(addprefix $(obj)/,$(targets)) | |
61 | obj-y := $(addprefix $(obj)/,$(obj-y)) | |
62 | obj-m := $(addprefix $(obj)/,$(obj-m)) | |
63 | lib-y := $(addprefix $(obj)/,$(lib-y)) | |
64 | subdir-obj-y := $(addprefix $(obj)/,$(subdir-obj-y)) | |
65 | real-objs-y := $(addprefix $(obj)/,$(real-objs-y)) | |
66 | real-objs-m := $(addprefix $(obj)/,$(real-objs-m)) | |
67 | single-used-m := $(addprefix $(obj)/,$(single-used-m)) | |
68 | multi-used-y := $(addprefix $(obj)/,$(multi-used-y)) | |
69 | multi-used-m := $(addprefix $(obj)/,$(multi-used-m)) | |
70 | multi-objs-y := $(addprefix $(obj)/,$(multi-objs-y)) | |
71 | multi-objs-m := $(addprefix $(obj)/,$(multi-objs-m)) | |
72 | subdir-ym := $(addprefix $(obj)/,$(subdir-ym)) | |
73 | obj-dirs := $(addprefix $(obj)/,$(obj-dirs)) | |
74 | ||
1da177e4 LT |
75 | # These flags are needed for modversions and compiling, so we define them here |
76 | # already | |
77 | # $(modname_flags) #defines KBUILD_MODNAME as the name of the module it will | |
78 | # end up in (or would, if it gets compiled in) | |
79 | # Note: It's possible that one object gets potentially linked into more | |
80 | # than one module. In that case KBUILD_MODNAME will be set to foo_bar, | |
81 | # where foo and bar are the name of the modules. | |
f83b5e32 | 82 | name-fix = $(subst $(comma),_,$(subst -,_,$1)) |
5e8d780d | 83 | basename_flags = -D"KBUILD_BASENAME=KBUILD_STR($(call name-fix,$(basetarget)))" |
f83b5e32 UR |
84 | modname_flags = $(if $(filter 1,$(words $(modname))),\ |
85 | -D"KBUILD_MODNAME=KBUILD_STR($(call name-fix,$(modname)))") | |
1da177e4 | 86 | |
a0f97e06 | 87 | _c_flags = $(KBUILD_CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$(basetarget).o) |
222d394d | 88 | _a_flags = $(KBUILD_AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$(basetarget).o) |
1da177e4 LT |
89 | _cpp_flags = $(CPPFLAGS) $(EXTRA_CPPFLAGS) $(CPPFLAGS_$(@F)) |
90 | ||
91 | # If building the kernel in a separate objtree expand all occurrences | |
92 | # of -Idir to -I$(srctree)/dir except for absolute paths (starting with '/'). | |
93 | ||
94 | ifeq ($(KBUILD_SRC),) | |
95 | __c_flags = $(_c_flags) | |
96 | __a_flags = $(_a_flags) | |
97 | __cpp_flags = $(_cpp_flags) | |
98 | else | |
99 | ||
1da177e4 LT |
100 | # -I$(obj) locates generated .h files |
101 | # $(call addtree,-I$(obj)) locates .h files in srctree, from generated .c files | |
102 | # and locates generated .h files | |
103 | # FIXME: Replace both with specific CFLAGS* statements in the makefiles | |
104 | __c_flags = $(call addtree,-I$(obj)) $(call flags,_c_flags) | |
105 | __a_flags = $(call flags,_a_flags) | |
106 | __cpp_flags = $(call flags,_cpp_flags) | |
107 | endif | |
108 | ||
109 | c_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(CPPFLAGS) \ | |
110 | $(__c_flags) $(modkern_cflags) \ | |
f83b5e32 | 111 | -D"KBUILD_STR(s)=\#s" $(basename_flags) $(modname_flags) |
1da177e4 LT |
112 | |
113 | a_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(CPPFLAGS) \ | |
114 | $(__a_flags) $(modkern_aflags) | |
115 | ||
116 | cpp_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(__cpp_flags) | |
117 | ||
118 | ld_flags = $(LDFLAGS) $(EXTRA_LDFLAGS) | |
119 | ||
120 | # Finds the multi-part object the current object will be linked into | |
121 | modname-multi = $(sort $(foreach m,$(multi-used),\ | |
122 | $(if $(filter $(subst $(obj)/,,$*.o), $($(m:.o=-objs)) $($(m:.o=-y))),$(m:.o=)))) | |
123 | ||
124 | # Shipped files | |
125 | # =========================================================================== | |
126 | ||
127 | quiet_cmd_shipped = SHIPPED $@ | |
128 | cmd_shipped = cat $< > $@ | |
129 | ||
130 | $(obj)/%:: $(src)/%_shipped | |
131 | $(call cmd,shipped) | |
132 | ||
133 | # Commands useful for building a boot image | |
134 | # =========================================================================== | |
135 | # | |
136 | # Use as following: | |
137 | # | |
138 | # target: source(s) FORCE | |
139 | # $(if_changed,ld/objcopy/gzip) | |
140 | # | |
836caba7 | 141 | # and add target to extra-y so that we know we have to |
1da177e4 LT |
142 | # read in the saved command line |
143 | ||
144 | # Linking | |
145 | # --------------------------------------------------------------------------- | |
146 | ||
147 | quiet_cmd_ld = LD $@ | |
148 | cmd_ld = $(LD) $(LDFLAGS) $(EXTRA_LDFLAGS) $(LDFLAGS_$(@F)) \ | |
149 | $(filter-out FORCE,$^) -o $@ | |
150 | ||
151 | # Objcopy | |
152 | # --------------------------------------------------------------------------- | |
153 | ||
154 | quiet_cmd_objcopy = OBJCOPY $@ | |
155 | cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@ | |
156 | ||
157 | # Gzip | |
158 | # --------------------------------------------------------------------------- | |
159 | ||
160 | quiet_cmd_gzip = GZIP $@ | |
161 | cmd_gzip = gzip -f -9 < $< > $@ | |
162 | ||
1da177e4 | 163 |