xref: /linux/scripts/Makefile.build (revision 4ab22c543f18cfbcc2f8ae691dc5ec5cc0ac35fb)
1# SPDX-License-Identifier: GPL-2.0
2# ==========================================================================
3# Building
4# ==========================================================================
5
6src := $(srcroot)/$(obj)
7
8PHONY := $(obj)/
9$(obj)/:
10
11# Init all relevant variables used in kbuild files so
12# 1) they have correct type
13# 2) they do not inherit any value from the environment
14obj-y :=
15obj-m :=
16lib-y :=
17lib-m :=
18always-y :=
19always-m :=
20targets :=
21subdir-y :=
22subdir-m :=
23asflags-y  :=
24ccflags-y  :=
25rustflags-y :=
26cppflags-y :=
27ldflags-y  :=
28
29subdir-asflags-y :=
30subdir-ccflags-y :=
31
32# Read auto.conf if it exists, otherwise ignore
33-include $(objtree)/include/config/auto.conf
34
35include $(srctree)/scripts/Kbuild.include
36include $(srctree)/scripts/Makefile.compiler
37include $(kbuild-file)
38include $(srctree)/scripts/Makefile.lib
39
40# flags that take effect in current and sub directories
41KBUILD_AFLAGS += $(subdir-asflags-y)
42KBUILD_CFLAGS += $(subdir-ccflags-y)
43KBUILD_RUSTFLAGS += $(subdir-rustflags-y)
44
45# Figure out what we need to build from the various variables
46# ===========================================================================
47
48# When an object is listed to be built compiled-in and modular,
49# only build the compiled-in version
50obj-m := $(filter-out $(obj-y),$(obj-m))
51
52# Libraries are always collected in one lib file.
53# Filter out objects already built-in
54lib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m)))
55
56# Subdirectories we need to descend into
57subdir-ym := $(sort $(subdir-y) $(subdir-m) \
58			$(patsubst %/,%, $(filter %/, $(obj-y) $(obj-m))))
59
60# Handle objects in subdirs:
61# - If we encounter foo/ in $(obj-y), replace it by foo/built-in.a and
62#   foo/modules.order
63# - If we encounter foo/ in $(obj-m), replace it by foo/modules.order
64#
65# Generate modules.order to determine modorder. Unfortunately, we don't have
66# information about ordering between -y and -m subdirs. Just put -y's first.
67
68ifdef need-modorder
69obj-m := $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-m))
70else
71obj-m := $(filter-out %/, $(obj-m))
72endif
73
74ifdef need-builtin
75obj-y		:= $(patsubst %/, %/built-in.a, $(obj-y))
76else
77obj-y		:= $(filter-out %/, $(obj-y))
78endif
79
80# Expand $(foo-objs) $(foo-y) etc. by replacing their individuals
81suffix-search = $(strip $(foreach s, $3, $($(1:%$(strip $2)=%$s))))
82# List composite targets that are constructed by combining other targets
83multi-search = $(sort $(foreach m, $1, $(if $(call suffix-search, $m, $2, $3 -), $m)))
84# List primitive targets that are compiled from source files
85real-search = $(foreach m, $1, $(if $(call suffix-search, $m, $2, $3 -), $(call suffix-search, $m, $2, $3), $m))
86
87# If $(foo-objs), $(foo-y), $(foo-m), or $(foo-) exists, foo.o is a composite object
88multi-obj-y := $(call multi-search, $(obj-y), .o, -objs -y)
89multi-obj-m := $(call multi-search, $(obj-m), .o, -objs -y -m)
90multi-obj-ym := $(multi-obj-y) $(multi-obj-m)
91
92# Replace multi-part objects by their individual parts,
93# including built-in.a from subdirectories
94real-obj-y := $(call real-search, $(obj-y), .o, -objs -y)
95real-obj-m := $(call real-search, $(obj-m), .o, -objs -y -m)
96
97always-y += $(always-m)
98
99# hostprogs-always-y += foo
100# ... is a shorthand for
101# hostprogs += foo
102# always-y  += foo
103hostprogs += $(hostprogs-always-y) $(hostprogs-always-m)
104always-y += $(hostprogs-always-y) $(hostprogs-always-m)
105
106# userprogs-always-y is likewise.
107userprogs += $(userprogs-always-y) $(userprogs-always-m)
108always-y += $(userprogs-always-y) $(userprogs-always-m)
109
110# Add subdir path
111
112ifneq ($(obj),.)
113extra-y		:= $(addprefix $(obj)/, $(extra-y))
114always-y	:= $(addprefix $(obj)/, $(always-y))
115targets		:= $(addprefix $(obj)/, $(targets))
116obj-m		:= $(addprefix $(obj)/, $(obj-m))
117lib-y		:= $(addprefix $(obj)/, $(lib-y))
118real-obj-y	:= $(addprefix $(obj)/, $(real-obj-y))
119real-obj-m	:= $(addprefix $(obj)/, $(real-obj-m))
120multi-obj-m	:= $(addprefix $(obj)/, $(multi-obj-m))
121subdir-ym	:= $(addprefix $(obj)/, $(subdir-ym))
122endif
123
124ifndef obj
125$(warning kbuild: Makefile.build is included improperly)
126endif
127
128ifeq ($(need-modorder),)
129ifneq ($(obj-m),)
130$(warning $(patsubst %.o,'%.ko',$(obj-m)) will not be built even though obj-m is specified.)
131$(warning You cannot use subdir-y/m to visit a module Makefile. Use obj-y/m instead.)
132endif
133endif
134
135# ===========================================================================
136
137# subdir-builtin and subdir-modorder may contain duplications. Use $(sort ...)
138subdir-builtin := $(sort $(filter %/built-in.a, $(real-obj-y)))
139subdir-modorder := $(sort $(filter %/modules.order, $(obj-m)))
140
141targets-for-builtin := $(extra-y)
142
143ifneq ($(strip $(lib-y) $(lib-m) $(lib-)),)
144targets-for-builtin += $(obj)/lib.a
145endif
146
147ifdef need-builtin
148targets-for-builtin += $(obj)/built-in.a
149endif
150
151targets-for-modules := $(foreach x, o mod, \
152				$(patsubst %.o, %.$x, $(filter %.o, $(obj-m))))
153
154ifdef need-modorder
155targets-for-modules += $(obj)/modules.order
156endif
157
158targets += $(targets-for-builtin) $(targets-for-modules)
159
160# Linus' kernel sanity checking tool
161ifeq ($(KBUILD_CHECKSRC),1)
162  quiet_cmd_checksrc       = CHECK   $<
163        cmd_checksrc       = $(CHECK) $(CHECKFLAGS) $(c_flags) $<
164else ifeq ($(KBUILD_CHECKSRC),2)
165  quiet_cmd_force_checksrc = CHECK   $<
166        cmd_force_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $<
167endif
168
169ifeq ($(KBUILD_EXTMOD),)
170ifneq ($(KBUILD_EXTRA_WARN),)
171  cmd_checkdoc = PYTHONDONTWRITEBYTECODE=1 $(PYTHON3) $(KERNELDOC) -none $(KDOCFLAGS) \
172        $(if $(findstring 2, $(KBUILD_EXTRA_WARN)), -Wall) \
173        $<
174endif
175endif
176
177# Compile C sources (.c)
178# ---------------------------------------------------------------------------
179
180quiet_cmd_cc_s_c = CC $(quiet_modtag)  $@
181      cmd_cc_s_c = $(CC) $(filter-out $(DEBUG_CFLAGS) $(CC_FLAGS_LTO), $(c_flags)) -fverbose-asm -S -o $@ $<
182
183$(obj)/%.s: $(obj)/%.c FORCE
184	$(call if_changed_dep,cc_s_c)
185
186quiet_cmd_cpp_i_c = CPP $(quiet_modtag) $@
187cmd_cpp_i_c       = $(CPP) $(c_flags) -o $@ $<
188
189$(obj)/%.i: $(obj)/%.c FORCE
190	$(call if_changed_dep,cpp_i_c)
191
192getexportsymbols = $(NM) $@ | sed -n 's/.* __export_symbol_\(.*\)/$(1)/p'
193
194gendwarfksyms = $(objtree)/scripts/gendwarfksyms/gendwarfksyms	\
195	$(if $(KBUILD_SYMTYPES), --symtypes $(@:.o=.symtypes))	\
196	$(if $(KBUILD_GENDWARFKSYMS_STABLE), --stable)
197
198genksyms = $(objtree)/scripts/genksyms/genksyms		\
199	$(if $(KBUILD_SYMTYPES), -T $(@:.o=.symtypes))	\
200	$(if $(KBUILD_PRESERVE), -p)			\
201	$(addprefix -r , $(wildcard $(@:.o=.symref)))
202
203# These mirror gensymtypes_S and co below, keep them in synch.
204ifdef CONFIG_GENDWARFKSYMS
205cmd_gensymtypes_c = $(if $(skip_gendwarfksyms),,	\
206	$(call getexportsymbols,\1) | $(gendwarfksyms) $@)
207else
208cmd_gensymtypes_c = $(CPP) -D__GENKSYMS__ $(c_flags) $< | $(genksyms)
209endif # CONFIG_GENDWARFKSYMS
210
211# LLVM assembly
212# Generate .ll files from .c
213quiet_cmd_cc_ll_c = CC $(quiet_modtag)  $@
214      cmd_cc_ll_c = $(CC) $(c_flags) -emit-llvm -S -fno-discard-value-names -o $@ $<
215
216$(obj)/%.ll: $(obj)/%.c FORCE
217	$(call if_changed_dep,cc_ll_c)
218
219# C (.c) files
220# The C file is compiled and updated dependency information is generated.
221# (See cmd_cc_o_c + relevant part of rule_cc_o_c)
222
223is-single-obj-m = $(and $(part-of-module),$(filter $@, $(obj-m)),y)
224
225ifdef CONFIG_MODVERSIONS
226# When module versioning is enabled the following steps are executed:
227# o compile a <file>.o from <file>.c
228# o if <file>.o doesn't contain a __export_symbol_*, i.e. does
229#   not export symbols, it's done.
230# o otherwise, we calculate symbol versions using the good old
231#   genksyms on the preprocessed source and dump them into the .cmd file.
232# o modpost will extract versions from that file and create *.c files that will
233#   be compiled and linked to the kernel and/or modules.
234
235gen_symversions =								\
236	if $(NM) $@ 2>/dev/null | grep -q ' __export_symbol_'; then		\
237		$(cmd_gensymtypes_$1) >> $(dot-target).cmd;			\
238	fi
239
240cmd_gen_symversions_c =	$(call gen_symversions,c)
241
242endif
243
244ifdef CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT
245# compiler will not generate __mcount_loc use recordmcount or recordmcount.pl
246ifdef BUILD_C_RECORDMCOUNT
247ifeq ("$(origin RECORDMCOUNT_WARN)", "command line")
248  RECORDMCOUNT_FLAGS = -w
249endif
250# Due to recursion, we must skip empty.o.
251# The empty.o file is created in the make process in order to determine
252# the target endianness and word size. It is made before all other C
253# files, including recordmcount.
254sub_cmd_record_mcount =					\
255	if [ $(@) != "scripts/mod/empty.o" ]; then	\
256		$(objtree)/scripts/recordmcount $(RECORDMCOUNT_FLAGS) "$(@)";	\
257	fi;
258recordmcount_source := $(srctree)/scripts/recordmcount.c \
259		    $(srctree)/scripts/recordmcount.h
260else
261sub_cmd_record_mcount = perl $(srctree)/scripts/recordmcount.pl "$(ARCH)" \
262	"$(if $(CONFIG_CPU_BIG_ENDIAN),big,little)" \
263	"$(if $(CONFIG_64BIT),64,32)" \
264	"$(OBJDUMP)" "$(OBJCOPY)" "$(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS)" \
265	"$(LD) $(KBUILD_LDFLAGS)" "$(NM)" "$(RM)" "$(MV)" \
266	"$(if $(part-of-module),1,0)" "$(@)";
267recordmcount_source := $(srctree)/scripts/recordmcount.pl
268endif # BUILD_C_RECORDMCOUNT
269cmd_record_mcount = $(if $(findstring $(strip $(CC_FLAGS_FTRACE)),$(_c_flags)),	\
270	$(sub_cmd_record_mcount))
271endif # CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT
272
273# 'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory
274# 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file
275# 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file
276
277is-standard-object = $(if $(filter-out y%, $(OBJECT_FILES_NON_STANDARD_$(target-stem).o)$(OBJECT_FILES_NON_STANDARD)n),$(is-kernel-object))
278
279ifdef CONFIG_OBJTOOL
280$(obj)/%.o: private objtool-enabled = $(if $(is-standard-object),$(if $(delay-objtool),$(is-single-obj-m),y))
281endif
282
283ifneq ($(findstring 1, $(KBUILD_EXTRA_WARN)),)
284cmd_warn_shared_object = $(if $(word 2, $(modname-multi)),$(warning $(kbuild-file): $*.o is added to multiple modules: $(modname-multi)))
285endif
286
287# Built-in and composite module parts
288$(obj)/%.o: $(obj)/%.c $(recordmcount_source) FORCE
289	$(call if_changed_rule,cc_o_c)
290	$(call cmd,force_checksrc)
291
292# To make this rule robust against "Argument list too long" error,
293# ensure to add $(obj)/ prefix by a shell command.
294cmd_mod = printf '%s\n' $(call real-search, $*.o, .o, -objs -y -m) | \
295	$(AWK) '!x[$$0]++ { print("$(obj)/"$$0) }' > $@
296
297$(obj)/%.mod: FORCE
298	$(call if_changed,mod)
299
300quiet_cmd_cc_lst_c = MKLST   $@
301      cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \
302		     $(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \
303				     System.map $(OBJDUMP) > $@
304
305$(obj)/%.lst: $(obj)/%.c FORCE
306	$(call if_changed_dep,cc_lst_c)
307
308# Compile Rust sources (.rs)
309# ---------------------------------------------------------------------------
310
311# The features in this list are the ones allowed for non-`rust/` code.
312#
313#   - Stable since Rust 1.79.0: `feature(inline_const)`.
314#   - Stable since Rust 1.81.0: `feature(lint_reasons)`.
315#   - Stable since Rust 1.82.0: `feature(asm_const)`,
316#     `feature(offset_of_nested)`, `feature(raw_ref_op)`.
317#   - Stable since Rust 1.87.0: `feature(asm_goto)`.
318#   - Expected to become stable: `feature(arbitrary_self_types)`.
319#   - To be determined: `feature(used_with_arg)`.
320#
321# Please see https://github.com/Rust-for-Linux/linux/issues/2 for details on
322# the unstable features in use.
323rust_allowed_features := asm_const,asm_goto,arbitrary_self_types,inline_const,lint_reasons,offset_of_nested,raw_ref_op,used_with_arg
324
325# `--out-dir` is required to avoid temporaries being created by `rustc` in the
326# current working directory, which may be not accessible in the out-of-tree
327# modules case.
328rust_common_cmd = \
329	OBJTREE=$(abspath $(objtree)) \
330	RUST_MODFILE=$(modfile) $(RUSTC_OR_CLIPPY) $(rust_flags) \
331	-Zallow-features=$(rust_allowed_features) \
332	-Zcrate-attr=no_std \
333	-Zcrate-attr='feature($(rust_allowed_features))' \
334	-Zunstable-options --extern pin_init --extern kernel \
335	--crate-type rlib -L $(objtree)/rust/ \
336	--sysroot=/dev/null \
337	--out-dir $(dir $@) --emit=dep-info=$(depfile)
338
339# `--emit=obj`, `--emit=asm` and `--emit=llvm-ir` imply a single codegen unit
340# will be used. We explicitly request `-Ccodegen-units=1` in any case, and
341# the compiler shows a warning if it is not 1. However, if we ever stop
342# requesting it explicitly and we start using some other `--emit` that does not
343# imply it (and for which codegen is performed), then we would be out of sync,
344# i.e. the outputs we would get for the different single targets (e.g. `.ll`)
345# would not match each other.
346
347quiet_cmd_rustc_o_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
348      cmd_rustc_o_rs = $(rust_common_cmd) --emit=$(if $(CONFIG_RUST_INLINE_HELPERS),llvm-bc=$(patsubst %.o,%.bc,$@),obj=$@) $< \
349	$(if $(CONFIG_RUST_INLINE_HELPERS),;$(LLVM_LINK) --internalize --suppress-warnings $(patsubst %.o,%.bc,$@) \
350		$(objtree)/rust/helpers/helpers$(if $(part-of-module),_module).bc -o $(patsubst %.o,%.m.bc,$@); \
351		$(CC) $(CLANG_FLAGS) $(KBUILD_CFLAGS) -Wno-override-module -c $(patsubst %.o,%.m.bc,$@) -o $@ \
352		$(cmd_ld_single)) \
353	$(cmd_objtool)
354
355define rule_rustc_o_rs
356	$(call cmd_and_fixdep,rustc_o_rs)
357	$(call cmd,gen_objtooldep)
358endef
359
360$(obj)/%.o: $(obj)/%.rs FORCE
361	+$(call if_changed_rule,rustc_o_rs)
362
363quiet_cmd_rustc_rsi_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
364      cmd_rustc_rsi_rs = \
365	$(rust_common_cmd) -Zunpretty=expanded $< >$@; \
366	command -v $(RUSTFMT) >/dev/null && $(RUSTFMT) --config-path $(srctree)/.rustfmt.toml $@
367
368$(obj)/%.rsi: $(obj)/%.rs FORCE
369	+$(call if_changed_dep,rustc_rsi_rs)
370
371quiet_cmd_rustc_s_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
372      cmd_rustc_s_rs = $(rust_common_cmd) --emit=asm=$@ $<
373
374$(obj)/%.s: $(obj)/%.rs FORCE
375	+$(call if_changed_dep,rustc_s_rs)
376
377quiet_cmd_rustc_ll_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
378      cmd_rustc_ll_rs = $(rust_common_cmd) --emit=llvm-ir=$@ $<
379
380$(obj)/%.ll: $(obj)/%.rs FORCE
381	+$(call if_changed_dep,rustc_ll_rs)
382
383quiet_cmd_rustc_rs_rs_S = RSCPP $(quiet_modtag) $@
384      cmd_rustc_rs_rs_S = $(CPP) $(c_flags) -xc -C -P $< | sed '1,/^\/\/ Cut here.$$/d' >$@
385
386$(obj)/%.rs: $(obj)/%.rs.S FORCE
387	+$(call if_changed_dep,rustc_rs_rs_S)
388
389# Compile assembler sources (.S)
390# ---------------------------------------------------------------------------
391
392# .S file exports must have their C prototypes defined in asm/asm-prototypes.h
393# or a file that it includes, in order to get versioned symbols. We build a
394# dummy C file that includes asm-prototypes and the EXPORT_SYMBOL lines from
395# the .S file (with trailing ';'), and run genksyms on that, to extract vers.
396#
397# This is convoluted. The .S file must first be preprocessed to run guards and
398# expand names, then the resulting exports must be constructed into plain
399# EXPORT_SYMBOL(symbol); to build our dummy C file, and that gets preprocessed
400# to make the genksyms input or compiled into an object for gendwarfksyms.
401#
402# These mirror gensymtypes_c and co above, keep them in synch.
403getasmexports =								\
404   { echo "\#include <linux/kernel.h>" ;				\
405     echo "\#include <linux/string.h>" ;				\
406     echo "\#include <asm/asm-prototypes.h>" ;				\
407     $(call getexportsymbols,EXPORT_SYMBOL(\1);) ; }
408
409ifdef CONFIG_GENDWARFKSYMS
410cmd_gensymtypes_S =							\
411	$(getasmexports) |						\
412	$(CC) $(c_flags) -c -o $(@:.o=.gendwarfksyms.o) -xc -;		\
413	$(call getexportsymbols,\1) |					\
414	$(gendwarfksyms) $(@:.o=.gendwarfksyms.o)
415else
416cmd_gensymtypes_S =							\
417	$(getasmexports) |						\
418	$(CPP) -D__GENKSYMS__ $(c_flags) -xc - | $(genksyms)
419endif # CONFIG_GENDWARFKSYMS
420
421quiet_cmd_cpp_s_S = CPP $(quiet_modtag) $@
422cmd_cpp_s_S       = $(CPP) $(a_flags) -o $@ $<
423
424$(obj)/%.s: $(obj)/%.S FORCE
425	$(call if_changed_dep,cpp_s_S)
426
427ifdef CONFIG_ASM_MODVERSIONS
428
429# versioning matches the C process described above, with difference that
430# we parse asm-prototypes.h C header to get function definitions.
431
432cmd_gen_symversions_S = $(call gen_symversions,S)
433
434endif
435
436$(obj)/%.o: $(obj)/%.S FORCE
437	$(call if_changed_rule,as_o_S)
438
439targets += $(filter-out $(subdir-builtin), $(real-obj-y))
440targets += $(filter-out $(subdir-modorder), $(real-obj-m))
441targets += $(lib-y) $(always-y)
442
443# Linker scripts preprocessor (.lds.S -> .lds)
444# ---------------------------------------------------------------------------
445quiet_cmd_cpp_lds_S = LDS     $@
446      cmd_cpp_lds_S = $(CPP) $(cpp_flags) -P -U$(ARCH) \
447	                     -D__ASSEMBLY__ -DLINKER_SCRIPT -o $@ $<
448
449$(obj)/%.lds: $(src)/%.lds.S FORCE
450	$(call if_changed_dep,cpp_lds_S)
451
452# ASN.1 grammar
453# ---------------------------------------------------------------------------
454quiet_cmd_asn1_compiler = ASN.1   $(basename $@).[ch]
455      cmd_asn1_compiler = $(objtree)/scripts/asn1_compiler $< \
456				$(basename $@).c $(basename $@).h
457
458$(obj)/%.asn1.c $(obj)/%.asn1.h: $(src)/%.asn1 $(objtree)/scripts/asn1_compiler
459	$(call cmd,asn1_compiler)
460
461# Build the compiled-in targets
462# ---------------------------------------------------------------------------
463
464# To build objects in subdirs, we need to descend into the directories
465$(subdir-builtin): $(obj)/%/built-in.a: $(obj)/% ;
466$(subdir-modorder): $(obj)/%/modules.order: $(obj)/% ;
467
468#
469# Rule to compile a set of .o files into one .a file (without symbol table)
470#
471# To make this rule robust against "Argument list too long" error,
472# remove $(obj)/ prefix, and restore it by a shell command.
473
474quiet_cmd_ar_builtin = AR      $@
475      cmd_ar_builtin = rm -f $@; \
476	$(if $(real-prereqs), printf "$(obj)/%s " $(patsubst $(obj)/%,%,$(real-prereqs)) | xargs) \
477	$(AR) cDPrST $@
478
479$(obj)/built-in.a: $(real-obj-y) FORCE
480	$(call if_changed,ar_builtin)
481
482# This is a list of build artifacts from the current Makefile and its
483# sub-directories. The timestamp should be updated when any of the member files.
484
485cmd_gen_order = { $(foreach m, $(real-prereqs), \
486	$(if $(filter %/$(notdir $@), $m), cat $m, echo $m);) :; } \
487	> $@
488
489$(obj)/modules.order: $(obj-m) FORCE
490	$(call if_changed,gen_order)
491
492#
493# Rule to compile a set of .o files into one .a file (with symbol table)
494#
495
496$(obj)/lib.a: $(lib-y) FORCE
497	$(call if_changed,ar)
498
499quiet_cmd_ld_multi_m = LD [M]  $@
500      cmd_ld_multi_m = $(LD) $(ld_flags) -r -o $@ @$< $(cmd_objtool)
501
502define rule_ld_multi_m
503	$(call cmd_and_savecmd,ld_multi_m)
504	$(call cmd,gen_objtooldep)
505endef
506
507$(multi-obj-m): private objtool-enabled := $(delay-objtool)
508$(multi-obj-m): private part-of-module := y
509$(multi-obj-m): %.o: %.mod FORCE
510	$(call if_changed_rule,ld_multi_m)
511$(call multi_depend, $(multi-obj-m), .o, -objs -y -m)
512
513# Add intermediate targets:
514# When building objects with specific suffix patterns, add intermediate
515# targets that the final targets are derived from.
516intermediate_targets = $(foreach sfx, $(2), \
517				$(patsubst %$(strip $(1)),%$(sfx), \
518					$(filter %$(strip $(1)), $(targets))))
519# %.asn1.o <- %.asn1.[ch] <- %.asn1
520targets += $(call intermediate_targets, .asn1.o, .asn1.c .asn1.h)
521
522# Include additional build rules when necessary
523# ---------------------------------------------------------------------------
524
525# $(sort ...) is used here to remove duplicated words and excessive spaces.
526hostprogs := $(sort $(hostprogs))
527ifneq ($(hostprogs),)
528include $(srctree)/scripts/Makefile.host
529endif
530
531# $(sort ...) is used here to remove duplicated words and excessive spaces.
532userprogs := $(sort $(userprogs))
533ifneq ($(userprogs),)
534include $(srctree)/scripts/Makefile.userprogs
535endif
536
537# Single targets
538# ---------------------------------------------------------------------------
539
540single-subdirs := $(foreach d, $(subdir-ym), $(if $(filter $d/%, $(MAKECMDGOALS)), $d))
541single-subdir-goals := $(filter $(addsuffix /%, $(single-subdirs)), $(MAKECMDGOALS))
542
543$(single-subdir-goals): $(single-subdirs)
544	@:
545
546# Descending
547# ---------------------------------------------------------------------------
548
549PHONY += $(subdir-ym)
550$(subdir-ym):
551	$(Q)$(MAKE) $(build)=$@ \
552	need-builtin=$(if $(filter $@/built-in.a, $(subdir-builtin)),1) \
553	need-modorder=$(if $(filter $@/modules.order, $(subdir-modorder)),1) \
554	$(filter $@/%, $(single-subdir-goals))
555
556# Add FORCE to the prerequisites of a target to force it to be always rebuilt.
557# ---------------------------------------------------------------------------
558
559PHONY += FORCE
560
561FORCE:
562
563targets += $(filter-out $(single-subdir-goals), $(MAKECMDGOALS))
564targets := $(filter-out $(PHONY), $(targets))
565
566# Now that targets is fully known, include dtb rules if needed
567ifneq ($(need-dtbslist)$(dtb-y)$(dtb-)$(filter %.dtb %.dtb.o %.dtbo.o,$(targets)),)
568include $(srctree)/scripts/Makefile.dtbs
569endif
570
571# Build
572# Needs to be after the include of Makefile.dtbs, which updates always-y
573# ---------------------------------------------------------------------------
574
575$(obj)/: $(if $(KBUILD_BUILTIN), $(targets-for-builtin)) \
576	 $(if $(KBUILD_MODULES), $(targets-for-modules)) \
577	 $(subdir-ym) $(always-y)
578	@:
579
580# Read all saved command lines and dependencies for the $(targets) we
581# may be building above, using $(if_changed{,_dep}). As an
582# optimization, we don't need to read them if the target does not
583# exist, we will rebuild anyway in that case.
584
585existing-targets := $(wildcard $(sort $(targets)))
586
587-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
588
589# Create directories for object files if they do not exist
590obj-dirs := $(sort $(patsubst %/,%, $(dir $(targets))))
591# If targets exist, their directories apparently exist. Skip mkdir.
592existing-dirs := $(sort $(patsubst %/,%, $(dir $(existing-targets))))
593obj-dirs := $(strip $(filter-out $(existing-dirs), $(obj-dirs)))
594ifneq ($(obj-dirs),)
595$(shell mkdir -p $(obj-dirs))
596endif
597
598.PHONY: $(PHONY)
599