and added files
[bcm963xx.git] / kernel / linux / scripts / Makefile.build
1 # ==========================================================================
2 # Building
3 # ==========================================================================
4
5 src := $(obj)
6
7 .PHONY: __build
8 __build:
9
10 # Read .config if it exist, otherwise ignore
11 -include .config
12
13 include $(obj)/Makefile
14
15 include scripts/Makefile.lib
16
17 ifneq ($(KBUILD_SRC),)
18 # Create output directory if not already present
19 _dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj))
20
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)))
24 endif
25
26
27 ifdef EXTRA_TARGETS
28 $(warning kbuild: $(obj)/Makefile - Usage of EXTRA_TARGETS is obsolete in 2.6. Please fix!)
29 endif
30
31 ifdef build-targets
32 $(warning kbuild: $(obj)/Makefile - Usage of build-targets is obsolete in 2.6. Please fix!)
33 endif
34
35 ifdef export-objs
36 $(warning kbuild: $(obj)/Makefile - Usage of export-objs is obsolete in 2.6. Please fix!)
37 endif
38
39 ifdef O_TARGET
40 $(warning kbuild: $(obj)/Makefile - Usage of O_TARGET := $(O_TARGET) is obsolete in 2.6. Please fix!)
41 endif
42
43 ifdef L_TARGET
44 $(error kbuild: $(obj)/Makefile - Use of L_TARGET is replaced by lib-y in 2.6. Please fix!)
45 endif
46
47 ifdef list-multi
48 $(warning kbuild: $(obj)/Makefile - list-multi := $(list-multi) is obsolete in 2.6. Please fix!)
49 endif
50
51 ifndef obj
52 $(warning kbuild: Makefile.build is included improperly)
53 endif
54
55 # ===========================================================================
56
57 ifneq ($(strip $(lib-y) $(lib-m) $(lib-n) $(lib-)),)
58 lib-target := $(obj)/lib.a
59 endif
60
61 ifneq ($(strip $(obj-y) $(obj-m) $(obj-n) $(obj-) $(lib-target)),)
62 builtin-target := $(obj)/built-in.o
63 endif
64
65 # We keep a list of all modules in $(MODVERDIR)
66
67 __build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \
68          $(if $(KBUILD_MODULES),$(obj-m)) \
69          $(subdir-ym) $(always)
70         @:
71
72 # Linus' kernel sanity checking tool
73 ifneq ($(KBUILD_CHECKSRC),0)
74 quiet_cmd_checksrc = CHECK   $<
75       cmd_checksrc = $(CHECK) $(c_flags) $< ;
76 endif
77
78
79 # Compile C sources (.c)
80 # ---------------------------------------------------------------------------
81
82 # Default is built-in, unless we know otherwise
83 modkern_cflags := $(CFLAGS_KERNEL)
84 quiet_modtag := $(empty)   $(empty)
85
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)
90
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]
95
96 $(obj-m)              : quiet_modtag := [M]
97
98 # Default for not multi-part modules
99 modname = $(*F)
100
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)
109
110 quiet_cmd_cc_s_c = CC $(quiet_modtag)  $@
111 cmd_cc_s_c       = $(CC) $(c_flags) -S -o $@ $< 
112
113 %.s: %.c FORCE
114         $(call if_changed_dep,cc_s_c)
115
116 quiet_cmd_cc_i_c = CPP $(quiet_modtag) $@
117 cmd_cc_i_c       = $(CPP) $(c_flags)   -o $@ $<
118
119 %.i: %.c FORCE
120         $(call if_changed_dep,cc_i_c)
121
122 # C (.c) files
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)
125
126 quiet_cmd_cc_o_c = CC $(quiet_modtag)  $@
127
128 ifndef CONFIG_MODVERSIONS
129 cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
130
131 else
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
136 #   are done.
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
143
144 cmd_cc_o_c = $(CC) $(c_flags) -c -o $(@D)/.tmp_$(@F) $<
145 cmd_modversions =                                                       \
146         if ! $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then   \
147                 mv $(@D)/.tmp_$(@F) $@;                                 \
148         else                                                            \
149                 $(CPP) -D__GENKSYMS__ $(c_flags) $<                     \
150                 | $(GENKSYMS)                                           \
151                 > $(@D)/.tmp_$(@F:.o=.ver);                             \
152                                                                         \
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);        \
156         fi;
157 endif
158
159 define rule_cc_o_c
160         $(if $($(quiet)cmd_checksrc),echo '  $($(quiet)cmd_checksrc)';)   \
161         $(cmd_checksrc)                                                   \
162         $(if $($(quiet)cmd_cc_o_c),echo '  $($(quiet)cmd_cc_o_c)';)       \
163         $(cmd_cc_o_c);                                                    \
164         $(cmd_modversions)                                                \
165         scripts/basic/fixdep $(depfile) $@ '$(cmd_cc_o_c)' > $(@D)/.$(@F).tmp;  \
166         rm -f $(depfile);                                                 \
167         mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd
168 endef
169
170 # Built-in and composite module parts
171
172 %.o: %.c FORCE
173         $(call if_changed_rule,cc_o_c)
174
175 # CONFIG_MIPS_BRCM Begin Broadcom changed code.
176 # C++ support
177 cmd_cc_o_cpp = $(CXX) $(c_flags) -c -o $@ $<
178 quiet_cmd_cc_o_cpp = C++ $(quiet_modtag) $@
179
180 define rule_cc_o_cpp
181         $(if $($(quiet)cmd_checksrc),echo '  $($(quiet)cmd_checksrc)';) \
182         $(cmd_checksrc)                                                 \
183         $(if $($(quiet)cmd_cc_o_cpp),echo '  $($(quiet)cmd_cc_o_cpp)';) \
184         $(cmd_cc_o_cpp);                                                \
185         $(cmd_modversions)                                              \
186         scripts/basic/fixdep $(depfile) $@ '$(cmd_cc_o_cpp)' > $(@D)/.$(@F).tmp; \
187         rm -f $(depfile);                                               \
188         mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd
189 endef
190
191 %.o: %.cpp FORCE
192         $(call if_changed_rule,cc_o_cpp)
193 # CONFIG_MIPS_BRCM End Broadcom changed code.
194
195
196 # Single-part modules are special since we need to mark them in $(MODVERDIR)
197
198 $(single-used-m): %.o: %.c FORCE
199         $(call if_changed_rule,cc_o_c)
200         @{ echo $(@:.o=.ko); echo $@; } > $(MODVERDIR)/$(@F:.o=.mod)
201
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) > $@
206
207 %.lst: %.c FORCE
208         $(call if_changed_dep,cc_lst_c)
209
210 # Compile assembler sources (.S)
211 # ---------------------------------------------------------------------------
212
213 modkern_aflags := $(AFLAGS_KERNEL)
214
215 $(real-objs-m)      : modkern_aflags := $(AFLAGS_MODULE)
216 $(real-objs-m:.o=.s): modkern_aflags := $(AFLAGS_MODULE)
217
218 quiet_cmd_as_s_S = CPP $(quiet_modtag) $@
219 cmd_as_s_S       = $(CPP) $(a_flags)   -o $@ $< 
220
221 %.s: %.S FORCE
222         $(call if_changed_dep,as_s_S)
223
224 quiet_cmd_as_o_S = AS $(quiet_modtag)  $@
225 cmd_as_o_S       = $(CC) $(a_flags) -c -o $@ $<
226
227 %.o: %.S FORCE
228         $(call if_changed_dep,as_o_S)
229
230 targets += $(real-objs-y) $(real-objs-m) $(lib-y)
231 targets += $(extra-y) $(MAKECMDGOALS) $(always)
232
233 # Build the compiled-in targets
234 # ---------------------------------------------------------------------------
235
236 # To build objects in subdirs, we need to descend into the directories
237 $(sort $(subdir-obj-y)): $(subdir-ym) ;
238
239 #
240 # Rule to compile a set of .o files into one .o file
241 #
242 ifdef builtin-target
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 $@)
248
249 $(builtin-target): $(obj-y) FORCE
250         $(call if_changed,link_o_target)
251
252 targets += $(builtin-target)
253 endif # builtin-target
254
255 #
256 # Rule to compile a set of .o files into one .a file
257 #
258 ifdef lib-target
259 quiet_cmd_link_l_target = AR      $@
260 cmd_link_l_target = rm -f $@; $(AR) $(EXTRA_ARFLAGS) rcs $@ $(lib-y)
261
262 $(lib-target): $(lib-y) FORCE
263         $(call if_changed,link_l_target)
264
265 targets += $(lib-target)
266 endif
267
268 #
269 # Rule to link composite objects
270 #
271 #  Composite objects are specified in kbuild makefile as follows:
272 #    <composite-object>-objs := <list of .o files>
273 #  or
274 #    <composite-object>-y    := <list of .o files>
275 link_multi_deps =                     \
276 $(filter $(addprefix $(obj)/,         \
277 $($(subst $(obj)/,,$(@:.o=-objs)))    \
278 $($(subst $(obj)/,,$(@:.o=-y)))), $^)
279  
280 quiet_cmd_link_multi-y = LD      $@
281 cmd_link_multi-y = $(LD) $(ld_flags) -r -o $@ $(link_multi_deps)
282
283 quiet_cmd_link_multi-m = LD [M]  $@
284 cmd_link_multi-m = $(LD) $(ld_flags) $(LDFLAGS_MODULE) -o $@ $(link_multi_deps)
285
286 # We would rather have a list of rules like
287 #       foo.o: $(foo-objs)
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)
292
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)
296
297 targets += $(multi-used-y) $(multi-used-m)
298
299 # Compile programs on the host
300 # ===========================================================================
301 # host-progs := bin2hex
302 # Will compile bin2hex.c and create an executable named bin2hex
303 #
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
308 #
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
314
315 # host-progs := conf
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  
324 #
325
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)
332
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)
341
342 # Create .o file from a single .c file
343 # host-cobjs -> .o
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)
348
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)
358
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)
364
365 # Compile .c file, create position independent .o file
366 # host-cshobjs -> .o
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)
371
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)
380
381 targets += $(host-csingle)  $(host-cmulti) $(host-cobjs)\
382            $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) 
383
384 # Descending
385 # ---------------------------------------------------------------------------
386
387 .PHONY: $(subdir-ym)
388 $(subdir-ym):
389         $(Q)$(MAKE) $(build)=$@
390
391 # Add FORCE to the prequisites of a target to force it to be always rebuilt.
392 # ---------------------------------------------------------------------------
393
394 .PHONY: FORCE
395
396 FORCE:
397
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.
402
403 targets := $(wildcard $(sort $(targets)))
404 cmd_files := $(wildcard $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
405
406 ifneq ($(cmd_files),)
407   include $(cmd_files)
408 endif