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