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 # Single-part modules are special since we need to mark them in $(MODVERDIR)
177 $(single-used-m): %.o: %.c FORCE
178 $(call if_changed_rule,cc_o_c)
179 @{ echo $(@:.o=.ko); echo $@; } > $(MODVERDIR)/$(@F:.o=.mod)
181 quiet_cmd_cc_lst_c = MKLST $@
182 cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \
183 $(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \
184 System.map $(OBJDUMP) > $@
187 $(call if_changed_dep,cc_lst_c)
189 # Compile assembler sources (.S)
190 # ---------------------------------------------------------------------------
192 modkern_aflags := $(AFLAGS_KERNEL)
194 $(real-objs-m) : modkern_aflags := $(AFLAGS_MODULE)
195 $(real-objs-m:.o=.s): modkern_aflags := $(AFLAGS_MODULE)
197 quiet_cmd_as_s_S = CPP $(quiet_modtag) $@
198 cmd_as_s_S = $(CPP) $(a_flags) -o $@ $<
201 $(call if_changed_dep,as_s_S)
203 quiet_cmd_as_o_S = AS $(quiet_modtag) $@
204 cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
207 $(call if_changed_dep,as_o_S)
209 targets += $(real-objs-y) $(real-objs-m) $(lib-y)
210 targets += $(extra-y) $(MAKECMDGOALS) $(always)
212 # Build the compiled-in targets
213 # ---------------------------------------------------------------------------
215 # To build objects in subdirs, we need to descend into the directories
216 $(sort $(subdir-obj-y)): $(subdir-ym) ;
219 # Rule to compile a set of .o files into one .o file
222 quiet_cmd_link_o_target = LD $@
223 # If the list of objects to link is empty, just create an empty built-in.o
224 cmd_link_o_target = $(if $(strip $(obj-y)),\
225 $(LD) $(ld_flags) -r -o $@ $(filter $(obj-y), $^),\
226 rm -f $@; $(AR) rcs $@)
228 $(builtin-target): $(obj-y) FORCE
229 $(call if_changed,link_o_target)
231 targets += $(builtin-target)
232 endif # builtin-target
235 # Rule to compile a set of .o files into one .a file
238 quiet_cmd_link_l_target = AR $@
239 cmd_link_l_target = rm -f $@; $(AR) $(EXTRA_ARFLAGS) rcs $@ $(lib-y)
241 $(lib-target): $(lib-y) FORCE
242 $(call if_changed,link_l_target)
244 targets += $(lib-target)
248 # Rule to link composite objects
250 # Composite objects are specified in kbuild makefile as follows:
251 # <composite-object>-objs := <list of .o files>
253 # <composite-object>-y := <list of .o files>
255 $(filter $(addprefix $(obj)/, \
256 $($(subst $(obj)/,,$(@:.o=-objs))) \
257 $($(subst $(obj)/,,$(@:.o=-y)))), $^)
259 quiet_cmd_link_multi-y = LD $@
260 cmd_link_multi-y = $(LD) $(ld_flags) -r -o $@ $(link_multi_deps)
262 quiet_cmd_link_multi-m = LD [M] $@
263 cmd_link_multi-m = $(LD) $(ld_flags) $(LDFLAGS_MODULE) -o $@ $(link_multi_deps)
265 # We would rather have a list of rules like
267 # but that's not so easy, so we rather make all composite objects depend
268 # on the set of all their parts
269 $(multi-used-y) : %.o: $(multi-objs-y) FORCE
270 $(call if_changed,link_multi-y)
272 $(multi-used-m) : %.o: $(multi-objs-m) FORCE
273 $(call if_changed,link_multi-m)
274 @{ echo $(@:.o=.ko); echo $(link_multi_deps); } > $(MODVERDIR)/$(@F:.o=.mod)
276 targets += $(multi-used-y) $(multi-used-m)
278 # Compile programs on the host
279 # ===========================================================================
280 # host-progs := bin2hex
281 # Will compile bin2hex.c and create an executable named bin2hex
283 # host-progs := lxdialog
284 # lxdialog-objs := checklist.o lxdialog.o
285 # Will compile lxdialog.c and checklist.c, and then link the executable
286 # lxdialog, based on checklist.o and lxdialog.o
288 # host-progs := qconf
289 # qconf-cxxobjs := qconf.o
290 # qconf-objs := menu.o
291 # Will compile qconf as a C++ program, and menu as a C program.
292 # They are linked as C++ code to the executable qconf
295 # conf-objs := conf.o libkconfig.so
296 # libkconfig-objs := expr.o type.o
297 # Will create a shared library named libkconfig.so that consist of
298 # expr.o and type.o (they are both compiled as C code and the object file
299 # are made as position independent code).
300 # conf.c is compiled as a c program, and conf.o is linked together with
301 # libkconfig.so as the executable conf.
302 # Note: Shared libraries consisting of C++ files are not supported
305 # Create executable from a single .c file
306 # host-csingle -> Executable
307 quiet_cmd_host-csingle = HOSTCC $@
308 cmd_host-csingle = $(HOSTCC) $(hostc_flags) $(HOST_LOADLIBES) -o $@ $<
309 $(host-csingle): %: %.c FORCE
310 $(call if_changed_dep,host-csingle)
312 # Link an executable based on list of .o files, all plain c
313 # host-cmulti -> executable
314 quiet_cmd_host-cmulti = HOSTLD $@
315 cmd_host-cmulti = $(HOSTCC) $(HOSTLDFLAGS) -o $@ \
316 $(addprefix $(obj)/,$($(@F)-objs)) \
317 $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
318 $(host-cmulti): %: $(host-cobjs) $(host-cshlib) FORCE
319 $(call if_changed,host-cmulti)
321 # Create .o file from a single .c file
323 quiet_cmd_host-cobjs = HOSTCC $@
324 cmd_host-cobjs = $(HOSTCC) $(hostc_flags) -c -o $@ $<
325 $(host-cobjs): %.o: %.c FORCE
326 $(call if_changed_dep,host-cobjs)
328 # Link an executable based on list of .o files, a mixture of .c and .cc
329 # host-cxxmulti -> executable
330 quiet_cmd_host-cxxmulti = HOSTLD $@
331 cmd_host-cxxmulti = $(HOSTCXX) $(HOSTLDFLAGS) -o $@ \
332 $(foreach o,objs cxxobjs,\
333 $(addprefix $(obj)/,$($(@F)-$(o)))) \
334 $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
335 $(host-cxxmulti): %: $(host-cobjs) $(host-cxxobjs) $(host-cshlib) FORCE
336 $(call if_changed,host-cxxmulti)
338 # Create .o file from a single .cc (C++) file
339 quiet_cmd_host-cxxobjs = HOSTCXX $@
340 cmd_host-cxxobjs = $(HOSTCXX) $(hostcxx_flags) -c -o $@ $<
341 $(host-cxxobjs): %.o: %.cc FORCE
342 $(call if_changed_dep,host-cxxobjs)
344 # Compile .c file, create position independent .o file
346 quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
347 cmd_host-cshobjs = $(HOSTCC) $(hostc_flags) -fPIC -c -o $@ $<
348 $(host-cshobjs): %.o: %.c FORCE
349 $(call if_changed_dep,host-cshobjs)
351 # Link a shared library, based on position independent .o files
352 # *.o -> .so shared library (host-cshlib)
353 quiet_cmd_host-cshlib = HOSTLLD -shared $@
354 cmd_host-cshlib = $(HOSTCC) $(HOSTLDFLAGS) -shared -o $@ \
355 $(addprefix $(obj)/,$($(@F:.so=-objs))) \
356 $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
357 $(host-cshlib): %: $(host-cshobjs) FORCE
358 $(call if_changed,host-cshlib)
360 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
361 $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
364 # ---------------------------------------------------------------------------
368 $(Q)$(MAKE) $(build)=$@
370 # Add FORCE to the prequisites of a target to force it to be always rebuilt.
371 # ---------------------------------------------------------------------------
377 # Read all saved command lines and dependencies for the $(targets) we
378 # may be building above, using $(if_changed{,_dep}). As an
379 # optimization, we don't need to read them if the target does not
380 # exist, we will rebuild anyway in that case.
382 targets := $(wildcard $(sort $(targets)))
383 cmd_files := $(wildcard $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
385 ifneq ($(cmd_files),)