1 # ==========================================================================
3 # ==========================================================================
10 # Read .config if it exist, otherwise ignore
13 include $(obj)/Makefile
15 include scripts/Makefile.lib
17 ifneq ($(KBUILD_SRC),)
18 # Create output directory if not already present
19 _dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj))
21 # Create directories for object files if directory does not exist
22 # Needed when obj-y := dir/file.o syntax is used
23 _dummy := $(foreach d,$(obj-dirs), $(shell [ -d $(d) ] || mkdir -p $(d)))
28 $(warning kbuild: $(obj)/Makefile - Usage of EXTRA_TARGETS is obsolete in 2.6. Please fix!)
32 $(warning kbuild: $(obj)/Makefile - Usage of build-targets is obsolete in 2.6. Please fix!)
36 $(warning kbuild: $(obj)/Makefile - Usage of export-objs is obsolete in 2.6. Please fix!)
40 $(warning kbuild: $(obj)/Makefile - Usage of O_TARGET := $(O_TARGET) is obsolete in 2.6. Please fix!)
44 $(error kbuild: $(obj)/Makefile - Use of L_TARGET is replaced by lib-y in 2.6. Please fix!)
48 $(warning kbuild: $(obj)/Makefile - list-multi := $(list-multi) is obsolete in 2.6. Please fix!)
52 $(warning kbuild: Makefile.build is included improperly)
55 # ===========================================================================
57 ifneq ($(strip $(lib-y) $(lib-m) $(lib-n) $(lib-)),)
58 lib-target := $(obj)/lib.a
61 ifneq ($(strip $(obj-y) $(obj-m) $(obj-n) $(obj-) $(lib-target)),)
62 builtin-target := $(obj)/built-in.o
65 # We keep a list of all modules in $(MODVERDIR)
67 __build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \
68 $(if $(KBUILD_MODULES),$(obj-m)) \
69 $(subdir-ym) $(always)
72 # Linus' kernel sanity checking tool
73 ifneq ($(KBUILD_CHECKSRC),0)
74 quiet_cmd_checksrc = CHECK $<
75 cmd_checksrc = $(CHECK) $(c_flags) $< ;
79 # Compile C sources (.c)
80 # ---------------------------------------------------------------------------
82 # Default is built-in, unless we know otherwise
83 modkern_cflags := $(CFLAGS_KERNEL)
84 quiet_modtag := $(empty) $(empty)
86 $(real-objs-m) : modkern_cflags := $(CFLAGS_MODULE)
87 $(real-objs-m:.o=.i) : modkern_cflags := $(CFLAGS_MODULE)
88 $(real-objs-m:.o=.s) : modkern_cflags := $(CFLAGS_MODULE)
89 $(real-objs-m:.o=.lst): modkern_cflags := $(CFLAGS_MODULE)
91 $(real-objs-m) : quiet_modtag := [M]
92 $(real-objs-m:.o=.i) : quiet_modtag := [M]
93 $(real-objs-m:.o=.s) : quiet_modtag := [M]
94 $(real-objs-m:.o=.lst): quiet_modtag := [M]
96 $(obj-m) : quiet_modtag := [M]
98 # Default for not multi-part modules
101 $(multi-objs-m) : modname = $(modname-multi)
102 $(multi-objs-m:.o=.i) : modname = $(modname-multi)
103 $(multi-objs-m:.o=.s) : modname = $(modname-multi)
104 $(multi-objs-m:.o=.lst) : modname = $(modname-multi)
105 $(multi-objs-y) : modname = $(modname-multi)
106 $(multi-objs-y:.o=.i) : modname = $(modname-multi)
107 $(multi-objs-y:.o=.s) : modname = $(modname-multi)
108 $(multi-objs-y:.o=.lst) : modname = $(modname-multi)
110 quiet_cmd_cc_s_c = CC $(quiet_modtag) $@
111 cmd_cc_s_c = $(CC) $(c_flags) -S -o $@ $<
114 $(call if_changed_dep,cc_s_c)
116 quiet_cmd_cc_i_c = CPP $(quiet_modtag) $@
117 cmd_cc_i_c = $(CPP) $(c_flags) -o $@ $<
120 $(call if_changed_dep,cc_i_c)
123 # The C file is compiled and updated dependency information is generated.
124 # (See cmd_cc_o_c + relevant part of rule_cc_o_c)
126 quiet_cmd_cc_o_c = CC $(quiet_modtag) $@
128 ifndef CONFIG_MODVERSIONS
129 cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
132 # When module versioning is enabled the following steps are executed:
133 # o compile a .tmp_<file>.o from <file>.c
134 # o if .tmp_<file>.o doesn't contain a __ksymtab version, i.e. does
135 # not export symbols, we just rename .tmp_<file>.o to <file>.o and
137 # o otherwise, we calculate symbol versions using the good old
138 # genksyms on the preprocessed source and postprocess them in a way
139 # that they are usable as a linker script
140 # o generate <file>.o from .tmp_<file>.o using the linker to
141 # replace the unresolved symbols __crc_exported_symbol with
142 # the actual value of the checksum generated by genksyms
144 cmd_cc_o_c = $(CC) $(c_flags) -c -o $(@D)/.tmp_$(@F) $<
146 if ! $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then \
147 mv $(@D)/.tmp_$(@F) $@; \
149 $(CPP) -D__GENKSYMS__ $(c_flags) $< \
151 > $(@D)/.tmp_$(@F:.o=.ver); \
153 $(LD) $(LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \
154 -T $(@D)/.tmp_$(@F:.o=.ver); \
155 rm -f $(@D)/.tmp_$(@F) $(@D)/.tmp_$(@F:.o=.ver); \
160 $(if $($(quiet)cmd_checksrc),echo ' $($(quiet)cmd_checksrc)';) \
162 $(if $($(quiet)cmd_cc_o_c),echo ' $($(quiet)cmd_cc_o_c)';) \
165 scripts/basic/fixdep $(depfile) $@ '$(cmd_cc_o_c)' > $(@D)/.$(@F).tmp; \
167 mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd
170 # Built-in and composite module parts
173 $(call if_changed_rule,cc_o_c)
175 # CONFIG_MIPS_BRCM Begin Broadcom changed code.
177 cmd_cc_o_cpp = $(CXX) $(c_flags) -c -o $@ $<
178 quiet_cmd_cc_o_cpp = C++ $(quiet_modtag) $@
181 $(if $($(quiet)cmd_checksrc),echo ' $($(quiet)cmd_checksrc)';) \
183 $(if $($(quiet)cmd_cc_o_cpp),echo ' $($(quiet)cmd_cc_o_cpp)';) \
186 scripts/basic/fixdep $(depfile) $@ '$(cmd_cc_o_cpp)' > $(@D)/.$(@F).tmp; \
188 mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd
192 $(call if_changed_rule,cc_o_cpp)
193 # CONFIG_MIPS_BRCM End Broadcom changed code.
196 # Single-part modules are special since we need to mark them in $(MODVERDIR)
198 $(single-used-m): %.o: %.c FORCE
199 $(call if_changed_rule,cc_o_c)
200 @{ echo $(@:.o=.ko); echo $@; } > $(MODVERDIR)/$(@F:.o=.mod)
202 quiet_cmd_cc_lst_c = MKLST $@
203 cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \
204 $(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \
205 System.map $(OBJDUMP) > $@
208 $(call if_changed_dep,cc_lst_c)
210 # Compile assembler sources (.S)
211 # ---------------------------------------------------------------------------
213 modkern_aflags := $(AFLAGS_KERNEL)
215 $(real-objs-m) : modkern_aflags := $(AFLAGS_MODULE)
216 $(real-objs-m:.o=.s): modkern_aflags := $(AFLAGS_MODULE)
218 quiet_cmd_as_s_S = CPP $(quiet_modtag) $@
219 cmd_as_s_S = $(CPP) $(a_flags) -o $@ $<
222 $(call if_changed_dep,as_s_S)
224 quiet_cmd_as_o_S = AS $(quiet_modtag) $@
225 cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
228 $(call if_changed_dep,as_o_S)
230 targets += $(real-objs-y) $(real-objs-m) $(lib-y)
231 targets += $(extra-y) $(MAKECMDGOALS) $(always)
233 # Build the compiled-in targets
234 # ---------------------------------------------------------------------------
236 # To build objects in subdirs, we need to descend into the directories
237 $(sort $(subdir-obj-y)): $(subdir-ym) ;
240 # Rule to compile a set of .o files into one .o file
243 quiet_cmd_link_o_target = LD $@
244 # If the list of objects to link is empty, just create an empty built-in.o
245 cmd_link_o_target = $(if $(strip $(obj-y)),\
246 $(LD) $(ld_flags) -r -o $@ $(filter $(obj-y), $^),\
247 rm -f $@; $(AR) rcs $@)
249 $(builtin-target): $(obj-y) FORCE
250 $(call if_changed,link_o_target)
252 targets += $(builtin-target)
253 endif # builtin-target
256 # Rule to compile a set of .o files into one .a file
259 quiet_cmd_link_l_target = AR $@
260 cmd_link_l_target = rm -f $@; $(AR) $(EXTRA_ARFLAGS) rcs $@ $(lib-y)
262 $(lib-target): $(lib-y) FORCE
263 $(call if_changed,link_l_target)
265 targets += $(lib-target)
269 # Rule to link composite objects
271 # Composite objects are specified in kbuild makefile as follows:
272 # <composite-object>-objs := <list of .o files>
274 # <composite-object>-y := <list of .o files>
276 $(filter $(addprefix $(obj)/, \
277 $($(subst $(obj)/,,$(@:.o=-objs))) \
278 $($(subst $(obj)/,,$(@:.o=-y)))), $^)
280 quiet_cmd_link_multi-y = LD $@
281 cmd_link_multi-y = $(LD) $(ld_flags) -r -o $@ $(link_multi_deps)
283 quiet_cmd_link_multi-m = LD [M] $@
284 cmd_link_multi-m = $(LD) $(ld_flags) $(LDFLAGS_MODULE) -o $@ $(link_multi_deps)
286 # We would rather have a list of rules like
288 # but that's not so easy, so we rather make all composite objects depend
289 # on the set of all their parts
290 $(multi-used-y) : %.o: $(multi-objs-y) FORCE
291 $(call if_changed,link_multi-y)
293 $(multi-used-m) : %.o: $(multi-objs-m) FORCE
294 $(call if_changed,link_multi-m)
295 @{ echo $(@:.o=.ko); echo $(link_multi_deps); } > $(MODVERDIR)/$(@F:.o=.mod)
297 targets += $(multi-used-y) $(multi-used-m)
299 # Compile programs on the host
300 # ===========================================================================
301 # host-progs := bin2hex
302 # Will compile bin2hex.c and create an executable named bin2hex
304 # host-progs := lxdialog
305 # lxdialog-objs := checklist.o lxdialog.o
306 # Will compile lxdialog.c and checklist.c, and then link the executable
307 # lxdialog, based on checklist.o and lxdialog.o
309 # host-progs := qconf
310 # qconf-cxxobjs := qconf.o
311 # qconf-objs := menu.o
312 # Will compile qconf as a C++ program, and menu as a C program.
313 # They are linked as C++ code to the executable qconf
316 # conf-objs := conf.o libkconfig.so
317 # libkconfig-objs := expr.o type.o
318 # Will create a shared library named libkconfig.so that consist of
319 # expr.o and type.o (they are both compiled as C code and the object file
320 # are made as position independent code).
321 # conf.c is compiled as a c program, and conf.o is linked together with
322 # libkconfig.so as the executable conf.
323 # Note: Shared libraries consisting of C++ files are not supported
326 # Create executable from a single .c file
327 # host-csingle -> Executable
328 quiet_cmd_host-csingle = HOSTCC $@
329 cmd_host-csingle = $(HOSTCC) $(hostc_flags) $(HOST_LOADLIBES) -o $@ $<
330 $(host-csingle): %: %.c FORCE
331 $(call if_changed_dep,host-csingle)
333 # Link an executable based on list of .o files, all plain c
334 # host-cmulti -> executable
335 quiet_cmd_host-cmulti = HOSTLD $@
336 cmd_host-cmulti = $(HOSTCC) $(HOSTLDFLAGS) -o $@ \
337 $(addprefix $(obj)/,$($(@F)-objs)) \
338 $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
339 $(host-cmulti): %: $(host-cobjs) $(host-cshlib) FORCE
340 $(call if_changed,host-cmulti)
342 # Create .o file from a single .c file
344 quiet_cmd_host-cobjs = HOSTCC $@
345 cmd_host-cobjs = $(HOSTCC) $(hostc_flags) -c -o $@ $<
346 $(host-cobjs): %.o: %.c FORCE
347 $(call if_changed_dep,host-cobjs)
349 # Link an executable based on list of .o files, a mixture of .c and .cc
350 # host-cxxmulti -> executable
351 quiet_cmd_host-cxxmulti = HOSTLD $@
352 cmd_host-cxxmulti = $(HOSTCXX) $(HOSTLDFLAGS) -o $@ \
353 $(foreach o,objs cxxobjs,\
354 $(addprefix $(obj)/,$($(@F)-$(o)))) \
355 $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
356 $(host-cxxmulti): %: $(host-cobjs) $(host-cxxobjs) $(host-cshlib) FORCE
357 $(call if_changed,host-cxxmulti)
359 # Create .o file from a single .cc (C++) file
360 quiet_cmd_host-cxxobjs = HOSTCXX $@
361 cmd_host-cxxobjs = $(HOSTCXX) $(hostcxx_flags) -c -o $@ $<
362 $(host-cxxobjs): %.o: %.cc FORCE
363 $(call if_changed_dep,host-cxxobjs)
365 # Compile .c file, create position independent .o file
367 quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
368 cmd_host-cshobjs = $(HOSTCC) $(hostc_flags) -fPIC -c -o $@ $<
369 $(host-cshobjs): %.o: %.c FORCE
370 $(call if_changed_dep,host-cshobjs)
372 # Link a shared library, based on position independent .o files
373 # *.o -> .so shared library (host-cshlib)
374 quiet_cmd_host-cshlib = HOSTLLD -shared $@
375 cmd_host-cshlib = $(HOSTCC) $(HOSTLDFLAGS) -shared -o $@ \
376 $(addprefix $(obj)/,$($(@F:.so=-objs))) \
377 $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
378 $(host-cshlib): %: $(host-cshobjs) FORCE
379 $(call if_changed,host-cshlib)
381 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
382 $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
385 # ---------------------------------------------------------------------------
389 $(Q)$(MAKE) $(build)=$@
391 # Add FORCE to the prequisites of a target to force it to be always rebuilt.
392 # ---------------------------------------------------------------------------
398 # Read all saved command lines and dependencies for the $(targets) we
399 # may be building above, using $(if_changed{,_dep}). As an
400 # optimization, we don't need to read them if the target does not
401 # exist, we will rebuild anyway in that case.
403 targets := $(wildcard $(sort $(targets)))
404 cmd_files := $(wildcard $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
406 ifneq ($(cmd_files),)