]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - scripts/Makefile.build
kbuild: improve Kbuild speed
[karo-tx-uboot.git] / scripts / Makefile.build
1 # ==========================================================================
2 # Building
3 # ==========================================================================
4
5 # Modified for U-Boot
6 ifeq ($(CONFIG_TPL_BUILD),y)
7   src := $(patsubst tpl/%,%,$(obj))
8 else
9   ifeq ($(CONFIG_SPL_BUILD),y)
10     src := $(patsubst spl/%,%,$(obj))
11   else
12     src := $(obj)
13   endif
14 endif
15
16 PHONY := __build
17 __build:
18
19 # Init all relevant variables used in kbuild files so
20 # 1) they have correct type
21 # 2) they do not inherit any value from the environment
22 obj-y :=
23 obj-m :=
24 lib-y :=
25 lib-m :=
26 always :=
27 targets :=
28 subdir-y :=
29 subdir-m :=
30 EXTRA_AFLAGS   :=
31 EXTRA_CFLAGS   :=
32 EXTRA_CPPFLAGS :=
33 EXTRA_LDFLAGS  :=
34 asflags-y  :=
35 ccflags-y  :=
36 cppflags-y :=
37 ldflags-y  :=
38
39 subdir-asflags-y :=
40 subdir-ccflags-y :=
41
42 # Read auto.conf if it exists, otherwise ignore
43 -include include/config/auto.conf
44
45 # Added for U-Boot: Load U-Boot configuration
46 ifeq ($(CONFIG_TPL_BUILD),y)
47   -include include/tpl-autoconf.mk
48 else
49   ifeq ($(CONFIG_SPL_BUILD),y)
50     -include include/spl-autoconf.mk
51   else
52     -include include/autoconf.mk
53   endif
54 endif
55
56 include scripts/Kbuild.include
57
58 # For backward compatibility check that these variables do not change
59 save-cflags := $(CFLAGS)
60
61 # The filename Kbuild has precedence over Makefile
62 kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
63 kbuild-file := $(if $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Kbuild,$(kbuild-dir)/Makefile)
64 include $(kbuild-file)
65
66 # Added for U-Boot
67 asflags-y  += $(PLATFORM_CPPFLAGS)
68 ccflags-y  += $(PLATFORM_CPPFLAGS)
69 cppflags-y += $(PLATFORM_CPPFLAGS)
70
71 # If the save-* variables changed error out
72 ifeq ($(KBUILD_NOPEDANTIC),)
73         ifneq ("$(save-cflags)","$(CFLAGS)")
74                 $(error CFLAGS was changed in "$(kbuild-file)". Fix it to use ccflags-y)
75         endif
76 endif
77
78 #
79 # make W=... settings
80 #
81 # W=1 - warnings that may be relevant and does not occur too often
82 # W=2 - warnings that occur quite often but may still be relevant
83 # W=3 - the more obscure warnings, can most likely be ignored
84 #
85 # $(call cc-option, -W...) handles gcc -W.. options which
86 # are not supported by all versions of the compiler
87 ifdef KBUILD_ENABLE_EXTRA_GCC_CHECKS
88 warning-  := $(empty)
89
90 warning-1 := -Wextra -Wunused -Wno-unused-parameter
91 warning-1 += -Wmissing-declarations
92 warning-1 += -Wmissing-format-attribute
93 warning-1 += -Wmissing-prototypes
94 warning-1 += -Wold-style-definition
95 warning-1 += $(call cc-option, -Wmissing-include-dirs)
96 warning-1 += $(call cc-option, -Wunused-but-set-variable)
97 warning-1 += $(call cc-disable-warning, missing-field-initializers)
98
99 warning-2 := -Waggregate-return
100 warning-2 += -Wcast-align
101 warning-2 += -Wdisabled-optimization
102 warning-2 += -Wnested-externs
103 warning-2 += -Wshadow
104 warning-2 += $(call cc-option, -Wlogical-op)
105 warning-2 += $(call cc-option, -Wmissing-field-initializers)
106
107 warning-3 := -Wbad-function-cast
108 warning-3 += -Wcast-qual
109 warning-3 += -Wconversion
110 warning-3 += -Wpacked
111 warning-3 += -Wpadded
112 warning-3 += -Wpointer-arith
113 warning-3 += -Wredundant-decls
114 warning-3 += -Wswitch-default
115 warning-3 += $(call cc-option, -Wpacked-bitfield-compat)
116 warning-3 += $(call cc-option, -Wvla)
117
118 warning := $(warning-$(findstring 1, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)))
119 warning += $(warning-$(findstring 2, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)))
120 warning += $(warning-$(findstring 3, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)))
121
122 ifeq ("$(strip $(warning))","")
123         $(error W=$(KBUILD_ENABLE_EXTRA_GCC_CHECKS) is unknown)
124 endif
125
126 KBUILD_CFLAGS += $(warning)
127 endif
128
129 include scripts/Makefile.lib
130
131 ifdef host-progs
132 ifneq ($(hostprogs-y),$(host-progs))
133 $(warning kbuild: $(obj)/Makefile - Usage of host-progs is deprecated. Please replace with hostprogs-y!)
134 hostprogs-y += $(host-progs)
135 endif
136 endif
137
138 # Do not include host rules unless needed
139 ifneq ($(hostprogs-y)$(hostprogs-m),)
140 include scripts/Makefile.host
141 endif
142
143 # Uncommented for U-Boot
144 #  We need to create output dicrectory for SPL and TPL even for in-tree build
145 #ifneq ($(KBUILD_SRC),)
146 # Create output directory if not already present
147 _dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj))
148
149 # Create directories for object files if directory does not exist
150 # Needed when obj-y := dir/file.o syntax is used
151 _dummy := $(foreach d,$(obj-dirs), $(shell [ -d $(d) ] || mkdir -p $(d)))
152 #endif
153
154 ifndef obj
155 $(warning kbuild: Makefile.build is included improperly)
156 endif
157
158 # ===========================================================================
159
160 ifneq ($(strip $(lib-y) $(lib-m) $(lib-n) $(lib-)),)
161 lib-target := $(obj)/lib.a
162 endif
163
164 ifneq ($(strip $(obj-y) $(obj-m) $(obj-n) $(obj-) $(subdir-m) $(lib-target)),)
165 builtin-target := $(obj)/built-in.o
166 endif
167
168 modorder-target := $(obj)/modules.order
169
170 # We keep a list of all modules in $(MODVERDIR)
171
172 __build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \
173          $(if $(KBUILD_MODULES),$(obj-m) $(modorder-target)) \
174          $(subdir-ym) $(always)
175         @:
176
177 # Linus' kernel sanity checking tool
178 ifneq ($(KBUILD_CHECKSRC),0)
179   ifeq ($(KBUILD_CHECKSRC),2)
180     quiet_cmd_force_checksrc = CHECK   $<
181           cmd_force_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $< ;
182   else
183       quiet_cmd_checksrc     = CHECK   $<
184             cmd_checksrc     = $(CHECK) $(CHECKFLAGS) $(c_flags) $< ;
185   endif
186 endif
187
188 # Do section mismatch analysis for each module/built-in.o
189 ifdef CONFIG_DEBUG_SECTION_MISMATCH
190   cmd_secanalysis = ; scripts/mod/modpost $@
191 endif
192
193 # Compile C sources (.c)
194 # ---------------------------------------------------------------------------
195
196 # Default is built-in, unless we know otherwise
197 modkern_cflags =                                          \
198         $(if $(part-of-module),                           \
199                 $(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE), \
200                 $(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL))
201 quiet_modtag := $(empty)   $(empty)
202
203 $(real-objs-m)        : part-of-module := y
204 $(real-objs-m:.o=.i)  : part-of-module := y
205 $(real-objs-m:.o=.s)  : part-of-module := y
206 $(real-objs-m:.o=.lst): part-of-module := y
207
208 $(real-objs-m)        : quiet_modtag := [M]
209 $(real-objs-m:.o=.i)  : quiet_modtag := [M]
210 $(real-objs-m:.o=.s)  : quiet_modtag := [M]
211 $(real-objs-m:.o=.lst): quiet_modtag := [M]
212
213 $(obj-m)              : quiet_modtag := [M]
214
215 # Default for not multi-part modules
216 modname = $(basetarget)
217
218 $(multi-objs-m)         : modname = $(modname-multi)
219 $(multi-objs-m:.o=.i)   : modname = $(modname-multi)
220 $(multi-objs-m:.o=.s)   : modname = $(modname-multi)
221 $(multi-objs-m:.o=.lst) : modname = $(modname-multi)
222 $(multi-objs-y)         : modname = $(modname-multi)
223 $(multi-objs-y:.o=.i)   : modname = $(modname-multi)
224 $(multi-objs-y:.o=.s)   : modname = $(modname-multi)
225 $(multi-objs-y:.o=.lst) : modname = $(modname-multi)
226
227 quiet_cmd_cc_s_c = CC $(quiet_modtag)  $@
228 cmd_cc_s_c       = $(CC) $(c_flags) -fverbose-asm -S -o $@ $<
229
230 $(obj)/%.s: $(src)/%.c FORCE
231         $(call if_changed_dep,cc_s_c)
232
233 quiet_cmd_cc_i_c = CPP $(quiet_modtag) $@
234 cmd_cc_i_c       = $(CPP) $(c_flags)   -o $@ $<
235
236 $(obj)/%.i: $(src)/%.c FORCE
237         $(call if_changed_dep,cc_i_c)
238
239 cmd_gensymtypes =                                                           \
240     $(CPP) -D__GENKSYMS__ $(c_flags) $< |                                   \
241     $(GENKSYMS) $(if $(1), -T $(2))                                         \
242      $(patsubst y,-s _,$(CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX))             \
243      $(if $(KBUILD_PRESERVE),-p)                                            \
244      -r $(firstword $(wildcard $(2:.symtypes=.symref) /dev/null))
245
246 quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@
247 cmd_cc_symtypes_c =                                                         \
248     set -e;                                                                 \
249     $(call cmd_gensymtypes,true,$@) >/dev/null;                             \
250     test -s $@ || rm -f $@
251
252 $(obj)/%.symtypes : $(src)/%.c FORCE
253         $(call cmd,cc_symtypes_c)
254
255 # C (.c) files
256 # The C file is compiled and updated dependency information is generated.
257 # (See cmd_cc_o_c + relevant part of rule_cc_o_c)
258
259 quiet_cmd_cc_o_c = CC $(quiet_modtag)  $@
260
261 ifndef CONFIG_MODVERSIONS
262 cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
263
264 else
265 # When module versioning is enabled the following steps are executed:
266 # o compile a .tmp_<file>.o from <file>.c
267 # o if .tmp_<file>.o doesn't contain a __ksymtab version, i.e. does
268 #   not export symbols, we just rename .tmp_<file>.o to <file>.o and
269 #   are done.
270 # o otherwise, we calculate symbol versions using the good old
271 #   genksyms on the preprocessed source and postprocess them in a way
272 #   that they are usable as a linker script
273 # o generate <file>.o from .tmp_<file>.o using the linker to
274 #   replace the unresolved symbols __crc_exported_symbol with
275 #   the actual value of the checksum generated by genksyms
276
277 cmd_cc_o_c = $(CC) $(c_flags) -c -o $(@D)/.tmp_$(@F) $<
278 cmd_modversions =                                                               \
279         if $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then             \
280                 $(call cmd_gensymtypes,$(KBUILD_SYMTYPES),$(@:.o=.symtypes))    \
281                     > $(@D)/.tmp_$(@F:.o=.ver);                                 \
282                                                                                 \
283                 $(LD) $(LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F)                      \
284                         -T $(@D)/.tmp_$(@F:.o=.ver);                            \
285                 rm -f $(@D)/.tmp_$(@F) $(@D)/.tmp_$(@F:.o=.ver);                \
286         else                                                                    \
287                 mv -f $(@D)/.tmp_$(@F) $@;                                      \
288         fi;
289 endif
290
291 ifdef CONFIG_FTRACE_MCOUNT_RECORD
292 ifdef BUILD_C_RECORDMCOUNT
293 ifeq ("$(origin RECORDMCOUNT_WARN)", "command line")
294   RECORDMCOUNT_FLAGS = -w
295 endif
296 # Due to recursion, we must skip empty.o.
297 # The empty.o file is created in the make process in order to determine
298 #  the target endianness and word size. It is made before all other C
299 #  files, including recordmcount.
300 sub_cmd_record_mcount =                                 \
301         if [ $(@) != "scripts/mod/empty.o" ]; then      \
302                 $(objtree)/scripts/recordmcount $(RECORDMCOUNT_FLAGS) "$(@)";   \
303         fi;
304 recordmcount_source := $(srctree)/scripts/recordmcount.c \
305                     $(srctree)/scripts/recordmcount.h
306 else
307 sub_cmd_record_mcount = set -e ; perl $(srctree)/scripts/recordmcount.pl "$(ARCH)" \
308         "$(if $(CONFIG_CPU_BIG_ENDIAN),big,little)" \
309         "$(if $(CONFIG_64BIT),64,32)" \
310         "$(OBJDUMP)" "$(OBJCOPY)" "$(CC) $(KBUILD_CFLAGS)" \
311         "$(LD)" "$(NM)" "$(RM)" "$(MV)" \
312         "$(if $(part-of-module),1,0)" "$(@)";
313 recordmcount_source := $(srctree)/scripts/recordmcount.pl
314 endif
315 cmd_record_mcount =                                             \
316         if [ "$(findstring -pg,$(_c_flags))" = "-pg" ]; then    \
317                 $(sub_cmd_record_mcount)                        \
318         fi;
319 endif
320
321 define rule_cc_o_c
322         $(call echo-cmd,checksrc) $(cmd_checksrc)                         \
323         $(call echo-cmd,cc_o_c) $(cmd_cc_o_c);                            \
324         $(cmd_modversions)                                                \
325         $(call echo-cmd,record_mcount)                                    \
326         $(cmd_record_mcount)                                              \
327         scripts/basic/fixdep $(depfile) $@ '$(call make-cmd,cc_o_c)' >    \
328                                                       $(dot-target).tmp;  \
329         rm -f $(depfile);                                                 \
330         mv -f $(dot-target).tmp $(dot-target).cmd
331 endef
332
333 # Built-in and composite module parts
334 $(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE
335         $(call cmd,force_checksrc)
336         $(call if_changed_rule,cc_o_c)
337
338 # Single-part modules are special since we need to mark them in $(MODVERDIR)
339
340 $(single-used-m): $(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE
341         $(call cmd,force_checksrc)
342         $(call if_changed_rule,cc_o_c)
343         @{ echo $(@:.o=.ko); echo $@; } > $(MODVERDIR)/$(@F:.o=.mod)
344
345 quiet_cmd_cc_lst_c = MKLST   $@
346       cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \
347                      $(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \
348                                      System.map $(OBJDUMP) > $@
349
350 $(obj)/%.lst: $(src)/%.c FORCE
351         $(call if_changed_dep,cc_lst_c)
352
353 # Compile assembler sources (.S)
354 # ---------------------------------------------------------------------------
355
356 modkern_aflags := $(KBUILD_AFLAGS_KERNEL) $(AFLAGS_KERNEL)
357
358 $(real-objs-m)      : modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE)
359 $(real-objs-m:.o=.s): modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE)
360
361 quiet_cmd_as_s_S = CPP $(quiet_modtag) $@
362 cmd_as_s_S       = $(CPP) $(a_flags)   -o $@ $< 
363
364 $(obj)/%.s: $(src)/%.S FORCE
365         $(call if_changed_dep,as_s_S)
366
367 quiet_cmd_as_o_S = AS $(quiet_modtag)  $@
368 cmd_as_o_S       = $(CC) $(a_flags) -c -o $@ $<
369
370 $(obj)/%.o: $(src)/%.S FORCE
371         $(call if_changed_dep,as_o_S)
372
373 targets += $(real-objs-y) $(real-objs-m) $(lib-y)
374 targets += $(extra-y) $(MAKECMDGOALS) $(always)
375
376 # Linker scripts preprocessor (.lds.S -> .lds)
377 # ---------------------------------------------------------------------------
378 quiet_cmd_cpp_lds_S = LDS     $@
379       cmd_cpp_lds_S = $(CPP) $(cpp_flags) -P -C -U$(ARCH) \
380                              -D__ASSEMBLY__ -DLINKER_SCRIPT -o $@ $<
381
382 $(obj)/%.lds: $(src)/%.lds.S FORCE
383         $(call if_changed_dep,cpp_lds_S)
384
385 # ASN.1 grammar
386 # ---------------------------------------------------------------------------
387 quiet_cmd_asn1_compiler = ASN.1   $@
388       cmd_asn1_compiler = $(objtree)/scripts/asn1_compiler $< \
389                                 $(subst .h,.c,$@) $(subst .c,.h,$@)
390
391 .PRECIOUS: $(objtree)/$(obj)/%-asn1.c $(objtree)/$(obj)/%-asn1.h
392
393 $(obj)/%-asn1.c $(obj)/%-asn1.h: $(src)/%.asn1 $(objtree)/scripts/asn1_compiler
394         $(call cmd,asn1_compiler)
395
396 # Build the compiled-in targets
397 # ---------------------------------------------------------------------------
398
399 # To build objects in subdirs, we need to descend into the directories
400 $(sort $(subdir-obj-y)): $(subdir-ym) ;
401
402 #
403 # Rule to compile a set of .o files into one .o file
404 #
405 ifdef builtin-target
406 quiet_cmd_link_o_target = LD      $@
407 # If the list of objects to link is empty, just create an empty built-in.o
408 cmd_link_o_target = $(if $(strip $(obj-y)),\
409                       $(LD) $(ld_flags) -r -o $@ $(filter $(obj-y), $^) \
410                       $(cmd_secanalysis),\
411                       rm -f $@; $(AR) rcs$(KBUILD_ARFLAGS) $@)
412
413 $(builtin-target): $(obj-y) FORCE
414         $(call if_changed,link_o_target)
415
416 targets += $(builtin-target)
417 endif # builtin-target
418
419 #
420 # Rule to create modules.order file
421 #
422 # Create commands to either record .ko file or cat modules.order from
423 # a subdirectory
424 modorder-cmds =                                         \
425         $(foreach m, $(modorder),                       \
426                 $(if $(filter %/modules.order, $m),     \
427                         cat $m;, echo kernel/$m;))
428
429 $(modorder-target): $(subdir-ym) FORCE
430         $(Q)(cat /dev/null; $(modorder-cmds)) > $@
431
432 #
433 # Rule to compile a set of .o files into one .a file
434 #
435 ifdef lib-target
436 quiet_cmd_link_l_target = AR      $@
437 cmd_link_l_target = rm -f $@; $(AR) rcs$(KBUILD_ARFLAGS) $@ $(lib-y)
438
439 $(lib-target): $(lib-y) FORCE
440         $(call if_changed,link_l_target)
441
442 targets += $(lib-target)
443 endif
444
445 #
446 # Rule to link composite objects
447 #
448 #  Composite objects are specified in kbuild makefile as follows:
449 #    <composite-object>-objs := <list of .o files>
450 #  or
451 #    <composite-object>-y    := <list of .o files>
452 link_multi_deps =                     \
453 $(filter $(addprefix $(obj)/,         \
454 $($(subst $(obj)/,,$(@:.o=-objs)))    \
455 $($(subst $(obj)/,,$(@:.o=-y)))), $^)
456  
457 quiet_cmd_link_multi-y = LD      $@
458 cmd_link_multi-y = $(LD) $(ld_flags) -r -o $@ $(link_multi_deps) $(cmd_secanalysis)
459
460 quiet_cmd_link_multi-m = LD [M]  $@
461 cmd_link_multi-m = $(cmd_link_multi-y)
462
463 # We would rather have a list of rules like
464 #       foo.o: $(foo-objs)
465 # but that's not so easy, so we rather make all composite objects depend
466 # on the set of all their parts
467 $(multi-used-y) : %.o: $(multi-objs-y) FORCE
468         $(call if_changed,link_multi-y)
469
470 $(multi-used-m) : %.o: $(multi-objs-m) FORCE
471         $(call if_changed,link_multi-m)
472         @{ echo $(@:.o=.ko); echo $(link_multi_deps); } > $(MODVERDIR)/$(@F:.o=.mod)
473
474 targets += $(multi-used-y) $(multi-used-m)
475
476
477 # Descending
478 # ---------------------------------------------------------------------------
479
480 PHONY += $(subdir-ym)
481 $(subdir-ym):
482         $(Q)$(MAKE) $(build)=$@
483
484 # Add FORCE to the prequisites of a target to force it to be always rebuilt.
485 # ---------------------------------------------------------------------------
486
487 PHONY += FORCE
488
489 FORCE:
490
491 # Read all saved command lines and dependencies for the $(targets) we
492 # may be building above, using $(if_changed{,_dep}). As an
493 # optimization, we don't need to read them if the target does not
494 # exist, we will rebuild anyway in that case.
495
496 targets := $(wildcard $(sort $(targets)))
497 cmd_files := $(wildcard $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
498
499 ifneq ($(cmd_files),)
500   include $(cmd_files)
501 endif
502
503 # Declare the contents of the .PHONY variable as phony.  We keep that
504 # information in a variable se we can use it in if_changed and friends.
505
506 .PHONY: $(PHONY)