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