1 # ==========================================================================
3 # ==========================================================================
14 include $(obj)/Makefile
16 include scripts/Makefile.lib
19 $(warning kbuild: $(obj)/Makefile - Usage of EXTRA_TARGETS is obsolete in 2.5. Please fix!)
23 $(warning kbuild: $(obj)/Makefile - Usage of build-targets is obsolete in 2.5. Please fix!)
27 $(warning kbuild: $(obj)/Makefile - Usage of export-objs is obsolete in 2.5. Please fix!)
31 $(warning kbuild: $(obj)/Makefile - Usage of O_TARGET := $(O_TARGET) is obsolete in 2.5. Please fix!)
35 $(error kbuild: $(obj)/Makefile - Use of L_TARGET is replaced by lib-y in 2.5. Please fix!)
39 $(warning kbuild: $(obj)/Makefile - list-multi := $(list-multi) is obsolete in 2.5. Please fix!)
43 $(warning kbuild: Makefile.build is included improperly)
46 # ===========================================================================
48 ifneq ($(strip $(lib-y) $(lib-m) $(lib-n) $(lib-)),)
49 lib-target := $(obj)/lib.a
52 ifneq ($(strip $(obj-y) $(obj-m) $(obj-n) $(obj-) $(lib-target)),)
53 builtin-target := $(obj)/built-in.o
56 # We keep a list of all modules in $(MODVERDIR)
58 touch-module = @echo $(@:.o=.ko) > $(MODVERDIR)/$(@F:.o=.mod)
60 __build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \
61 $(if $(KBUILD_MODULES),$(obj-m)) \
62 $(subdir-ym) $(always)
65 # Linus' kernel sanity checking tool
66 ifneq ($(KBUILD_CHECKSRC),0)
67 quiet_cmd_checksrc = CHECK $<
68 cmd_checksrc = $(CHECK) $(c_flags) $< ;
72 # Compile C sources (.c)
73 # ---------------------------------------------------------------------------
75 # Default is built-in, unless we know otherwise
76 modkern_cflags := $(CFLAGS_KERNEL)
77 quiet_modtag := $(empty) $(empty)
79 $(real-objs-m) : modkern_cflags := $(CFLAGS_MODULE)
80 $(real-objs-m:.o=.i) : modkern_cflags := $(CFLAGS_MODULE)
81 $(real-objs-m:.o=.s) : modkern_cflags := $(CFLAGS_MODULE)
82 $(real-objs-m:.o=.lst): modkern_cflags := $(CFLAGS_MODULE)
84 $(real-objs-m) : quiet_modtag := [M]
85 $(real-objs-m:.o=.i) : quiet_modtag := [M]
86 $(real-objs-m:.o=.s) : quiet_modtag := [M]
87 $(real-objs-m:.o=.lst): quiet_modtag := [M]
89 $(obj-m) : quiet_modtag := [M]
91 # Default for not multi-part modules
94 $(multi-objs-m) : modname = $(modname-multi)
95 $(multi-objs-m:.o=.i) : modname = $(modname-multi)
96 $(multi-objs-m:.o=.s) : modname = $(modname-multi)
97 $(multi-objs-m:.o=.lst) : modname = $(modname-multi)
98 $(multi-objs-y) : modname = $(modname-multi)
99 $(multi-objs-y:.o=.i) : modname = $(modname-multi)
100 $(multi-objs-y:.o=.s) : modname = $(modname-multi)
101 $(multi-objs-y:.o=.lst) : modname = $(modname-multi)
103 quiet_cmd_cc_s_c = CC $(quiet_modtag) $@
104 cmd_cc_s_c = $(CC) $(c_flags) -S -o $@ $<
107 $(call if_changed_dep,cc_s_c)
109 quiet_cmd_cc_i_c = CPP $(quiet_modtag) $@
110 cmd_cc_i_c = $(CPP) $(c_flags) -o $@ $<
113 $(call if_changed_dep,cc_i_c)
116 # The C file is compiled and updated dependency information is generated.
117 # (See cmd_cc_o_c + relevant part of rule_cc_o_c)
119 quiet_cmd_cc_o_c = CC $(quiet_modtag) $@
121 ifndef CONFIG_MODVERSIONS
122 cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
125 # When module versioning is enabled the following steps are executed:
126 # o compile a .tmp_<file>.o from <file>.c
127 # o if .tmp_<file>.o doesn't contain a __ksymtab version, i.e. does
128 # not export symbols, we just rename .tmp_<file>.o to <file>.o and
130 # o otherwise, we calculate symbol versions using the good old
131 # genksyms on the preprocessed source and postprocess them in a way
132 # that they are usable as a linker script
133 # o generate <file>.o from .tmp_<file>.o using the linker to
134 # replace the unresolved symbols __crc_exported_symbol with
135 # the actual value of the checksum generated by genksyms
137 cmd_cc_o_c = $(CC) $(c_flags) -c -o $(@D)/.tmp_$(@F) $<
139 if ! $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then \
140 mv $(@D)/.tmp_$(@F) $@; \
142 $(CPP) -D__GENKSYMS__ $(c_flags) $< \
144 > $(@D)/.tmp_$(@F:.o=.ver); \
146 $(LD) $(LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \
147 -T $(@D)/.tmp_$(@F:.o=.ver); \
148 rm -f $(@D)/.tmp_$(@F) $(@D)/.tmp_$(@F:.o=.ver); \
153 $(if $($(quiet)cmd_checksrc),echo ' $($(quiet)cmd_checksrc)';) \
155 $(if $($(quiet)cmd_cc_o_c),echo ' $($(quiet)cmd_cc_o_c)';) \
158 scripts/fixdep $(depfile) $@ '$(cmd_cc_o_c)' > $(@D)/.$(@F).tmp; \
160 mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd
163 # Built-in and composite module parts
166 $(call if_changed_rule,cc_o_c)
168 # Single-part modules are special since we need to mark them in $(MODVERDIR)
170 $(single-used-m): %.o: %.c FORCE
171 $(call if_changed_rule,cc_o_c)
174 quiet_cmd_cc_lst_c = MKLST $@
175 cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \
176 $(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \
177 System.map $(OBJDUMP) > $@
180 $(call if_changed_dep,cc_lst_c)
182 # Compile assembler sources (.S)
183 # ---------------------------------------------------------------------------
185 modkern_aflags := $(AFLAGS_KERNEL)
187 $(real-objs-m) : modkern_aflags := $(AFLAGS_MODULE)
188 $(real-objs-m:.o=.s): modkern_aflags := $(AFLAGS_MODULE)
190 quiet_cmd_as_s_S = CPP $(quiet_modtag) $@
191 cmd_as_s_S = $(CPP) $(a_flags) -o $@ $<
194 $(call if_changed_dep,as_s_S)
196 quiet_cmd_as_o_S = AS $(quiet_modtag) $@
197 cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
200 $(call if_changed_dep,as_o_S)
202 targets += $(real-objs-y) $(real-objs-m) $(lib-y)
203 targets += $(extra-y) $(MAKECMDGOALS) $(always)
205 # Build the compiled-in targets
206 # ---------------------------------------------------------------------------
208 # To build objects in subdirs, we need to descend into the directories
209 $(sort $(subdir-obj-y)): $(subdir-ym) ;
212 # Rule to compile a set of .o files into one .o file
215 quiet_cmd_link_o_target = LD $@
216 # If the list of objects to link is empty, just create an empty built-in.o
217 cmd_link_o_target = $(if $(strip $(obj-y)),\
218 $(LD) $(ld_flags) -r -o $@ $(filter $(obj-y), $^),\
219 rm -f $@; $(AR) rcs $@)
221 $(builtin-target): $(obj-y) FORCE
222 $(call if_changed,link_o_target)
224 targets += $(builtin-target)
225 endif # builtin-target
228 # Rule to compile a set of .o files into one .a file
231 quiet_cmd_link_l_target = AR $@
232 cmd_link_l_target = rm -f $@; $(AR) $(EXTRA_ARFLAGS) rcs $@ $(lib-y)
234 $(lib-target): $(lib-y) FORCE
235 $(call if_changed,link_l_target)
237 targets += $(lib-target)
241 # Rule to link composite objects
243 # Composite objects are specified in kbuild makefile as follows:
244 # <composite-object>-objs := <list of .o files>
246 # <composite-object>-y := <list of .o files>
248 $(filter $(addprefix $(obj)/, \
249 $($(subst $(obj)/,,$(@:.o=-objs))) \
250 $($(subst $(obj)/,,$(@:.o=-y)))), $^)
252 quiet_cmd_link_multi-y = LD $@
253 cmd_link_multi-y = $(LD) $(ld_flags) -r -o $@ $(link_multi_deps)
255 quiet_cmd_link_multi-m = LD [M] $@
256 cmd_link_multi-m = $(LD) $(ld_flags) $(LDFLAGS_MODULE) -o $@ $(link_multi_deps)
258 # We would rather have a list of rules like
260 # but that's not so easy, so we rather make all composite objects depend
261 # on the set of all their parts
262 $(multi-used-y) : %.o: $(multi-objs-y) FORCE
263 $(call if_changed,link_multi-y)
265 $(multi-used-m) : %.o: $(multi-objs-m) FORCE
266 $(call if_changed,link_multi-m)
269 targets += $(multi-used-y) $(multi-used-m)
271 # Compile programs on the host
272 # ===========================================================================
273 # host-progs := bin2hex
274 # Will compile bin2hex.c and create an executable named bin2hex
276 # host-progs := lxdialog
277 # lxdialog-objs := checklist.o lxdialog.o
278 # Will compile lxdialog.c and checklist.c, and then link the executable
279 # lxdialog, based on checklist.o and lxdialog.o
281 # host-progs := qconf
282 # qconf-cxxobjs := qconf.o
283 # qconf-objs := menu.o
284 # Will compile qconf as a C++ program, and menu as a C program.
285 # They are linked as C++ code to the executable qconf
288 # conf-objs := conf.o libkconfig.so
289 # libkconfig-objs := expr.o type.o
290 # Will create a shared library named libkconfig.so that consist of
291 # expr.o and type.o (they are both compiled as C code and the object file
292 # are made as position independent code).
293 # conf.c is compiled as a c program, and conf.o is linked together with
294 # libkconfig.so as the executable conf.
295 # Note: Shared libraries consisting of C++ files are not supported
298 # Create executable from a single .c file
299 # host-csingle -> Executable
300 quiet_cmd_host-csingle = HOSTCC $@
301 cmd_host-csingle = $(HOSTCC) $(hostc_flags) $(HOST_LOADLIBES) -o $@ $<
302 $(host-csingle): %: %.c FORCE
303 $(call if_changed_dep,host-csingle)
305 # Link an executable based on list of .o files, all plain c
306 # host-cmulti -> executable
307 quiet_cmd_host-cmulti = HOSTLD $@
308 cmd_host-cmulti = $(HOSTCC) $(HOSTLDFLAGS) -o $@ \
309 $(addprefix $(obj)/,$($(@F)-objs)) \
310 $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
311 $(host-cmulti): %: $(host-cobjs) $(host-cshlib) FORCE
312 $(call if_changed,host-cmulti)
314 # Create .o file from a single .c file
316 quiet_cmd_host-cobjs = HOSTCC $@
317 cmd_host-cobjs = $(HOSTCC) $(hostc_flags) -c -o $@ $<
318 $(host-cobjs): %.o: %.c FORCE
319 $(call if_changed_dep,host-cobjs)
321 # Link an executable based on list of .o files, a mixture of .c and .cc
322 # host-cxxmulti -> executable
323 quiet_cmd_host-cxxmulti = HOSTLD $@
324 cmd_host-cxxmulti = $(HOSTCXX) $(HOSTLDFLAGS) -o $@ \
325 $(foreach o,objs cxxobjs,\
326 $(addprefix $(obj)/,$($(@F)-$(o)))) \
327 $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
328 $(host-cxxmulti): %: $(host-cobjs) $(host-cxxobjs) $(host-cshlib) FORCE
329 $(call if_changed,host-cxxmulti)
331 # Create .o file from a single .cc (C++) file
332 quiet_cmd_host-cxxobjs = HOSTCXX $@
333 cmd_host-cxxobjs = $(HOSTCXX) $(hostcxx_flags) -c -o $@ $<
334 $(host-cxxobjs): %.o: %.cc FORCE
335 $(call if_changed_dep,host-cxxobjs)
337 # Compile .c file, create position independent .o file
339 quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
340 cmd_host-cshobjs = $(HOSTCC) $(hostc_flags) -fPIC -c -o $@ $<
341 $(host-cshobjs): %.o: %.c FORCE
342 $(call if_changed_dep,host-cshobjs)
344 # Link a shared library, based on position independent .o files
345 # *.o -> .so shared library (host-cshlib)
346 quiet_cmd_host-cshlib = HOSTLLD -shared $@
347 cmd_host-cshlib = $(HOSTCC) $(HOSTLDFLAGS) -shared -o $@ \
348 $(addprefix $(obj)/,$($(@F:.so=-objs))) \
349 $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
350 $(host-cshlib): %: $(host-cshobjs) FORCE
351 $(call if_changed,host-cshlib)
353 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
354 $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
357 # ---------------------------------------------------------------------------
361 $(Q)$(MAKE) $(build)=$@
363 # Add FORCE to the prequisites of a target to force it to be always rebuilt.
364 # ---------------------------------------------------------------------------
370 # Read all saved command lines and dependencies for the $(targets) we
371 # may be building above, using $(if_changed{,_dep}). As an
372 # optimization, we don't need to read them if the target does not
373 # exist, we will rebuild anyway in that case.
375 targets := $(wildcard $(sort $(targets)))
376 cmd_files := $(wildcard $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
378 ifneq ($(cmd_files),)