source: MondoRescue/branches/2.2.9/mindi-busybox/scripts/Makefile.build@ 2725

Last change on this file since 2725 was 2725, checked in by Bruno Cornec, 13 years ago
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File size: 10.2 KB
Line 
1# ==========================================================================
2# Building
3# ==========================================================================
4
5src := $(obj)
6
7PHONY := __build
8__build:
9
10# Read .config if it exist, otherwise ignore
11-include .config
12
13include scripts/Kbuild.include
14
15# The filename Kbuild has precedence over Makefile
16# bbox: we also try to include Kbuild file in obj tree first
17kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
18include $(if $(wildcard $(src)/Kbuild), $(src)/Kbuild, \
19 $(if $(wildcard $(kbuild-dir)/Kbuild), $(kbuild-dir)/Kbuild, \
20 $(kbuild-dir)/Makefile \
21 ) \
22 )
23
24include scripts/Makefile.lib
25
26ifdef host-progs
27ifneq ($(hostprogs-y),$(host-progs))
28$(warning kbuild: $(obj)/Makefile - Usage of host-progs is deprecated. Please replace with hostprogs-y!)
29hostprogs-y += $(host-progs)
30endif
31endif
32
33# Do not include host rules unles needed
34ifneq ($(hostprogs-y)$(hostprogs-m),)
35include scripts/Makefile.host
36endif
37
38ifneq ($(KBUILD_SRC),)
39# Create output directory if not already present
40_dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj))
41
42# Create directories for object files if directory does not exist
43# Needed when obj-y := dir/file.o syntax is used
44_dummy := $(foreach d,$(obj-dirs), $(shell [ -d $(d) ] || mkdir -p $(d)))
45endif
46
47
48ifdef EXTRA_TARGETS
49$(warning kbuild: $(obj)/Makefile - Usage of EXTRA_TARGETS is obsolete in 2.6. Please fix!)
50endif
51
52ifdef build-targets
53$(warning kbuild: $(obj)/Makefile - Usage of build-targets is obsolete in 2.6. Please fix!)
54endif
55
56ifdef export-objs
57$(warning kbuild: $(obj)/Makefile - Usage of export-objs is obsolete in 2.6. Please fix!)
58endif
59
60ifdef O_TARGET
61$(warning kbuild: $(obj)/Makefile - Usage of O_TARGET := $(O_TARGET) is obsolete in 2.6. Please fix!)
62endif
63
64ifdef L_TARGET
65$(error kbuild: $(obj)/Makefile - Use of L_TARGET is replaced by lib-y in 2.6. Please fix!)
66endif
67
68ifdef list-multi
69$(warning kbuild: $(obj)/Makefile - list-multi := $(list-multi) is obsolete in 2.6. Please fix!)
70endif
71
72ifndef obj
73$(warning kbuild: Makefile.build is included improperly)
74endif
75
76# ===========================================================================
77
78ifneq ($(strip $(lib-y) $(lib-m) $(lib-n) $(lib-)),)
79lib-target := $(obj)/lib.a
80endif
81
82ifneq ($(strip $(obj-y) $(obj-m) $(obj-n) $(obj-) $(lib-target)),)
83builtin-target := $(obj)/built-in.o
84endif
85
86# We keep a list of all modules in $(MODVERDIR)
87
88__build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \
89 $(if $(KBUILD_MODULES),$(obj-m)) \
90 $(subdir-ym) $(always)
91 @:
92
93# Linus' kernel sanity checking tool
94ifneq ($(KBUILD_CHECKSRC),0)
95 ifeq ($(KBUILD_CHECKSRC),2)
96 quiet_cmd_force_checksrc = CHECK $<
97 cmd_force_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $< ;
98 else
99 quiet_cmd_checksrc = CHECK $<
100 cmd_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $< ;
101 endif
102endif
103
104
105# Compile C sources (.c)
106# ---------------------------------------------------------------------------
107
108# Default is built-in, unless we know otherwise
109modkern_cflags := $(CFLAGS_KERNEL)
110quiet_modtag := $(empty) $(empty)
111
112$(real-objs-m) : modkern_cflags := $(CFLAGS_MODULE)
113$(real-objs-m:.o=.i) : modkern_cflags := $(CFLAGS_MODULE)
114$(real-objs-m:.o=.s) : modkern_cflags := $(CFLAGS_MODULE)
115$(real-objs-m:.o=.lst): modkern_cflags := $(CFLAGS_MODULE)
116
117$(real-objs-m) : quiet_modtag := [M]
118$(real-objs-m:.o=.i) : quiet_modtag := [M]
119$(real-objs-m:.o=.s) : quiet_modtag := [M]
120$(real-objs-m:.o=.lst): quiet_modtag := [M]
121
122$(obj-m) : quiet_modtag := [M]
123
124# Default for not multi-part modules
125modname = $(*F)
126
127$(multi-objs-m) : modname = $(modname-multi)
128$(multi-objs-m:.o=.i) : modname = $(modname-multi)
129$(multi-objs-m:.o=.s) : modname = $(modname-multi)
130$(multi-objs-m:.o=.lst) : modname = $(modname-multi)
131$(multi-objs-y) : modname = $(modname-multi)
132$(multi-objs-y:.o=.i) : modname = $(modname-multi)
133$(multi-objs-y:.o=.s) : modname = $(modname-multi)
134$(multi-objs-y:.o=.lst) : modname = $(modname-multi)
135
136quiet_cmd_cc_s_c = CC $(quiet_modtag) $@
137cmd_cc_s_c = $(CC) $(c_flags) -fverbose-asm -S -o $@ $<
138
139%.s: %.c FORCE
140 $(call if_changed_dep,cc_s_c)
141
142quiet_cmd_cc_i_c = CPP $(quiet_modtag) $@
143cmd_cc_i_c = $(CPP) $(c_flags) -o $@ $<
144
145%.i: %.c FORCE
146 $(call if_changed_dep,cc_i_c)
147
148# C (.c) files
149# The C file is compiled and updated dependency information is generated.
150# (See cmd_cc_o_c + relevant part of rule_cc_o_c)
151
152quiet_cmd_cc_o_c = CC $(quiet_modtag) $@
153
154ifndef CONFIG_MODVERSIONS
155cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
156
157else
158# When module versioning is enabled the following steps are executed:
159# o compile a .tmp_<file>.o from <file>.c
160# o if .tmp_<file>.o doesn't contain a __ksymtab version, i.e. does
161# not export symbols, we just rename .tmp_<file>.o to <file>.o and
162# are done.
163# o otherwise, we calculate symbol versions using the good old
164# genksyms on the preprocessed source and postprocess them in a way
165# that they are usable as a linker script
166# o generate <file>.o from .tmp_<file>.o using the linker to
167# replace the unresolved symbols __crc_exported_symbol with
168# the actual value of the checksum generated by genksyms
169
170cmd_cc_o_c = $(CC) $(c_flags) -c -o $(@D)/.tmp_$(@F) $<
171cmd_modversions = \
172 if $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then \
173 $(CPP) -D__GENKSYMS__ $(c_flags) $< \
174 | $(GENKSYMS) -a $(ARCH) \
175 > $(@D)/.tmp_$(@F:.o=.ver); \
176 \
177 $(LD) $(LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \
178 -T $(@D)/.tmp_$(@F:.o=.ver); \
179 rm -f $(@D)/.tmp_$(@F) $(@D)/.tmp_$(@F:.o=.ver); \
180 else \
181 mv -f $(@D)/.tmp_$(@F) $@; \
182 fi;
183endif
184
185define rule_cc_o_c
186 $(call echo-cmd,checksrc) $(cmd_checksrc) \
187 $(call echo-cmd,cc_o_c) $(cmd_cc_o_c); \
188 $(cmd_modversions) \
189 scripts/basic/fixdep $(depfile) $@ '$(call make-cmd,cc_o_c)' > $(@D)/.$(@F).tmp; \
190 rm -f $(depfile); \
191 mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd
192endef
193
194# Built-in and composite module parts
195
196%.o: %.c FORCE
197 $(call cmd,force_checksrc)
198 $(call if_changed_rule,cc_o_c)
199
200# Single-part modules are special since we need to mark them in $(MODVERDIR)
201
202$(single-used-m): %.o: %.c FORCE
203 $(call cmd,force_checksrc)
204 $(call if_changed_rule,cc_o_c)
205 @{ echo $(@:.o=.ko); echo $@; } > $(MODVERDIR)/$(@F:.o=.mod)
206
207quiet_cmd_cc_lst_c = MKLST $@
208 cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \
209 $(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \
210 System.map $(OBJDUMP) > $@
211
212%.lst: %.c FORCE
213 $(call if_changed_dep,cc_lst_c)
214
215# Compile assembler sources (.S)
216# ---------------------------------------------------------------------------
217
218modkern_aflags := $(AFLAGS_KERNEL)
219
220$(real-objs-m) : modkern_aflags := $(AFLAGS_MODULE)
221$(real-objs-m:.o=.s): modkern_aflags := $(AFLAGS_MODULE)
222
223quiet_cmd_as_s_S = CPP $(quiet_modtag) $@
224cmd_as_s_S = $(CPP) $(a_flags) -o $@ $<
225
226%.s: %.S FORCE
227 $(call if_changed_dep,as_s_S)
228
229quiet_cmd_as_o_S = AS $(quiet_modtag) $@
230cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
231
232%.o: %.S FORCE
233 $(call if_changed_dep,as_o_S)
234
235targets += $(real-objs-y) $(real-objs-m) $(lib-y)
236targets += $(extra-y) $(MAKECMDGOALS) $(always)
237
238# Linker scripts preprocessor (.lds.S -> .lds)
239# ---------------------------------------------------------------------------
240quiet_cmd_cpp_lds_S = LDS $@
241 cmd_cpp_lds_S = $(CPP) $(cpp_flags) -D__ASSEMBLY__ -o $@ $<
242
243%.lds: %.lds.S FORCE
244 $(call if_changed_dep,cpp_lds_S)
245
246# Build the compiled-in targets
247# ---------------------------------------------------------------------------
248
249# To build objects in subdirs, we need to descend into the directories
250$(sort $(subdir-obj-y)): $(subdir-ym) ;
251
252#
253# Rule to compile a set of .o files into one .o file
254#
255ifdef builtin-target
256quiet_cmd_link_o_target = LD $@
257# If the list of objects to link is empty, just create an empty built-in.o
258cmd_link_o_target = $(if $(strip $(obj-y)),\
259 $(LD) $(ld_flags) -r -o $@ $(filter $(obj-y), $^),\
260 rm -f $@; $(AR) rcs $@)
261
262$(builtin-target): $(obj-y) FORCE
263 $(call if_changed,link_o_target)
264
265targets += $(builtin-target)
266endif # builtin-target
267
268#
269# Rule to compile a set of .o files into one .a file
270#
271ifdef lib-target
272quiet_cmd_link_l_target = AR $@
273cmd_link_l_target = rm -f $@; $(AR) $(EXTRA_ARFLAGS) rcs $@ $(lib-y)
274
275$(lib-target): $(lib-y) FORCE
276 $(call if_changed,link_l_target)
277
278targets += $(lib-target)
279endif
280
281#
282# Rule to link composite objects
283#
284# Composite objects are specified in kbuild makefile as follows:
285# <composite-object>-objs := <list of .o files>
286# or
287# <composite-object>-y := <list of .o files>
288link_multi_deps = \
289$(filter $(addprefix $(obj)/, \
290$($(subst $(obj)/,,$(@:.o=-objs))) \
291$($(subst $(obj)/,,$(@:.o=-y)))), $^)
292
293quiet_cmd_link_multi-y = LD $@
294cmd_link_multi-y = $(LD) $(ld_flags) -r -o $@ $(link_multi_deps)
295
296quiet_cmd_link_multi-m = LD [M] $@
297cmd_link_multi-m = $(LD) $(ld_flags) $(LDFLAGS_MODULE) -o $@ $(link_multi_deps)
298
299# We would rather have a list of rules like
300# foo.o: $(foo-objs)
301# but that's not so easy, so we rather make all composite objects depend
302# on the set of all their parts
303$(multi-used-y) : %.o: $(multi-objs-y) FORCE
304 $(call if_changed,link_multi-y)
305
306$(multi-used-m) : %.o: $(multi-objs-m) FORCE
307 $(call if_changed,link_multi-m)
308 @{ echo $(@:.o=.ko); echo $(link_multi_deps); } > $(MODVERDIR)/$(@F:.o=.mod)
309
310targets += $(multi-used-y) $(multi-used-m)
311
312
313# Descending
314# ---------------------------------------------------------------------------
315
316PHONY += $(subdir-ym)
317$(subdir-ym):
318 $(Q)$(MAKE) $(build)=$@
319
320# Add FORCE to the prequisites of a target to force it to be always rebuilt.
321# ---------------------------------------------------------------------------
322
323PHONY += FORCE
324
325FORCE:
326
327# Read all saved command lines and dependencies for the $(targets) we
328# may be building above, using $(if_changed{,_dep}). As an
329# optimization, we don't need to read them if the target does not
330# exist, we will rebuild anyway in that case.
331
332targets := $(wildcard $(sort $(targets)))
333cmd_files := $(wildcard $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
334
335ifneq ($(cmd_files),)
336 include $(cmd_files)
337endif
338
339
340# Declare the contents of the .PHONY variable as phony. We keep that
341# information in a variable se we can use it in if_changed and friends.
342
343.PHONY: $(PHONY)
Note: See TracBrowser for help on using the repository browser.