kbuild: doc: remove documentation about copying Module.symvers around
[linux-2.6-block.git] / scripts / Makefile.build
CommitLineData
b2441318 1# SPDX-License-Identifier: GPL-2.0
1da177e4
LT
2# ==========================================================================
3# Building
4# ==========================================================================
5
6src := $(obj)
7
4f193362 8PHONY := __build
1da177e4
LT
9__build:
10
d72e5edb
SR
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 :=
5f2fb52f
MY
19always-y :=
20always-m :=
d72e5edb
SR
21targets :=
22subdir-y :=
23subdir-m :=
24EXTRA_AFLAGS :=
25EXTRA_CFLAGS :=
26EXTRA_CPPFLAGS :=
27EXTRA_LDFLAGS :=
f77bf014
SR
28asflags-y :=
29ccflags-y :=
30cppflags-y :=
31ldflags-y :=
d72e5edb 32
720097d8
SR
33subdir-asflags-y :=
34subdir-ccflags-y :=
35
3156fd05 36# Read auto.conf if it exists, otherwise ignore
c955ccaf 37-include include/config/auto.conf
1da177e4 38
20a468b5
SR
39include scripts/Kbuild.include
40
2a691470 41# The filename Kbuild has precedence over Makefile
db8c1a7b 42kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
0c53c8e6
SR
43kbuild-file := $(if $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Kbuild,$(kbuild-dir)/Makefile)
44include $(kbuild-file)
45
1da177e4
LT
46include scripts/Makefile.lib
47
3156fd05 48# Do not include host rules unless needed
77342a02 49ifneq ($(hostprogs)$(hostcxxlibs-y)$(hostcxxlibs-m),)
1da177e4
LT
50include scripts/Makefile.host
51endif
52
7f3a59db
MY
53# Do not include userprogs rules unless needed.
54userprogs := $(sort $(userprogs))
55ifneq ($(userprogs),)
56include scripts/Makefile.userprogs
57endif
58
1da177e4
LT
59ifndef obj
60$(warning kbuild: Makefile.build is included improperly)
61endif
62
394053f4 63ifeq ($(need-modorder),)
c07d8d47
MY
64ifneq ($(obj-m),)
65$(warning $(patsubst %.o,'%.ko',$(obj-m)) will not be built even though obj-m is specified.)
66$(warning You cannot use subdir-y/m to visit a module Makefile. Use obj-y/m instead.)
67endif
68endif
69
1da177e4
LT
70# ===========================================================================
71
a4954fd7 72ifneq ($(strip $(lib-y) $(lib-m) $(lib-)),)
1da177e4
LT
73lib-target := $(obj)/lib.a
74endif
75
56d58936 76ifdef need-builtin
f49821ee 77builtin-target := $(obj)/built-in.a
1da177e4
LT
78endif
79
7e131918 80ifeq ($(CONFIG_MODULES)$(need-modorder),y1)
551559e1 81modorder-target := $(obj)/modules.order
1d8001ef 82endif
551559e1 83
9f69a496
MY
84mod-targets := $(patsubst %.o, %.mod, $(obj-m))
85
1da177e4 86# Linus' kernel sanity checking tool
7d0ea252
MY
87ifeq ($(KBUILD_CHECKSRC),1)
88 quiet_cmd_checksrc = CHECK $<
e5d28910 89 cmd_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $<
7d0ea252
MY
90else ifeq ($(KBUILD_CHECKSRC),2)
91 quiet_cmd_force_checksrc = CHECK $<
e5d28910 92 cmd_force_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $<
1da177e4
LT
93endif
94
e27128db 95ifneq ($(KBUILD_EXTRA_WARN),)
e5d28910 96 cmd_checkdoc = $(srctree)/scripts/kernel-doc -none $<
3a025e1d
MW
97endif
98
1da177e4
LT
99# Compile C sources (.c)
100# ---------------------------------------------------------------------------
101
1da177e4 102quiet_cmd_cc_s_c = CC $(quiet_modtag) $@
1e88e415 103 cmd_cc_s_c = $(CC) $(filter-out $(DEBUG_CFLAGS), $(c_flags)) $(DISABLE_LTO) -fverbose-asm -S -o $@ $<
1da177e4 104
767e581d 105$(obj)/%.s: $(src)/%.c FORCE
1da177e4
LT
106 $(call if_changed_dep,cc_s_c)
107
23d43848
MY
108quiet_cmd_cpp_i_c = CPP $(quiet_modtag) $@
109cmd_cpp_i_c = $(CPP) $(c_flags) -o $@ $<
1da177e4 110
767e581d 111$(obj)/%.i: $(src)/%.c FORCE
23d43848 112 $(call if_changed_dep,cpp_i_c)
1da177e4 113
4efca4ed
NP
114# These mirror gensymtypes_S and co below, keep them in synch.
115cmd_gensymtypes_c = \
37a8d9f6 116 $(CPP) -D__GENKSYMS__ $(c_flags) $< | \
88110713 117 scripts/genksyms/genksyms $(if $(1), -T $(2)) \
56067812 118 $(patsubst y,-R,$(CONFIG_MODULE_REL_CRCS)) \
37a8d9f6 119 $(if $(KBUILD_PRESERVE),-p) \
e26d6b83 120 -r $(firstword $(wildcard $(2:.symtypes=.symref) /dev/null))
37a8d9f6 121
15fde675 122quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@
37a8d9f6 123cmd_cc_symtypes_c = \
4efca4ed 124 $(call cmd_gensymtypes_c,true,$@) >/dev/null; \
37a8d9f6 125 test -s $@ || rm -f $@
15fde675 126
767e581d 127$(obj)/%.symtypes : $(src)/%.c FORCE
64e6c1e1 128 $(call cmd,cc_symtypes_c)
15fde675 129
433db3e2
VT
130# LLVM assembly
131# Generate .ll files from .c
132quiet_cmd_cc_ll_c = CC $(quiet_modtag) $@
133 cmd_cc_ll_c = $(CC) $(c_flags) -emit-llvm -S -o $@ $<
134
135$(obj)/%.ll: $(src)/%.c FORCE
136 $(call if_changed_dep,cc_ll_c)
137
1da177e4
LT
138# C (.c) files
139# The C file is compiled and updated dependency information is generated.
140# (See cmd_cc_o_c + relevant part of rule_cc_o_c)
141
142quiet_cmd_cc_o_c = CC $(quiet_modtag) $@
ee3e46b7 143 cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
1da177e4 144
ee3e46b7 145ifdef CONFIG_MODVERSIONS
1da177e4 146# When module versioning is enabled the following steps are executed:
ee3e46b7
MY
147# o compile a <file>.o from <file>.c
148# o if <file>.o doesn't contain a __ksymtab version, i.e. does
149# not export symbols, it's done.
1da177e4
LT
150# o otherwise, we calculate symbol versions using the good old
151# genksyms on the preprocessed source and postprocess them in a way
2ea03891 152# that they are usable as a linker script
ee3e46b7 153# o generate .tmp_<file>.o from <file>.o using the linker to
2ea03891
SR
154# replace the unresolved symbols __crc_exported_symbol with
155# the actual value of the checksum generated by genksyms
ee3e46b7 156# o remove .tmp_<file>.o to <file>.o
4efca4ed
NP
157
158cmd_modversions_c = \
ee3e46b7 159 if $(OBJDUMP) -h $@ | grep -q __ksymtab; then \
4efca4ed 160 $(call cmd_gensymtypes_c,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \
e26d6b83
DZ
161 > $(@D)/.tmp_$(@F:.o=.ver); \
162 \
ee3e46b7 163 $(LD) $(KBUILD_LDFLAGS) -r -o $(@D)/.tmp_$(@F) $@ \
e26d6b83 164 -T $(@D)/.tmp_$(@F:.o=.ver); \
e26d6b83 165 mv -f $(@D)/.tmp_$(@F) $@; \
ee3e46b7 166 rm -f $(@D)/.tmp_$(@F:.o=.ver); \
e5d28910 167 fi
1da177e4
LT
168endif
169
8da3821b 170ifdef CONFIG_FTRACE_MCOUNT_RECORD
07d04081
VG
171ifndef CC_USING_RECORD_MCOUNT
172# compiler will not generate __mcount_loc use recordmcount or recordmcount.pl
72441cb1 173ifdef BUILD_C_RECORDMCOUNT
85356f80
SR
174ifeq ("$(origin RECORDMCOUNT_WARN)", "command line")
175 RECORDMCOUNT_FLAGS = -w
176endif
d7b4d6de
SR
177# Due to recursion, we must skip empty.o.
178# The empty.o file is created in the make process in order to determine
312a3d09
C
179# the target endianness and word size. It is made before all other C
180# files, including recordmcount.
45677454
WZ
181sub_cmd_record_mcount = \
182 if [ $(@) != "scripts/mod/empty.o" ]; then \
85356f80 183 $(objtree)/scripts/recordmcount $(RECORDMCOUNT_FLAGS) "$(@)"; \
45677454 184 fi;
d6971822
MM
185recordmcount_source := $(srctree)/scripts/recordmcount.c \
186 $(srctree)/scripts/recordmcount.h
72441cb1 187else
4317ee3b 188sub_cmd_record_mcount = perl $(srctree)/scripts/recordmcount.pl "$(ARCH)" \
e6299d26 189 "$(if $(CONFIG_CPU_BIG_ENDIAN),big,little)" \
b3acf29a 190 "$(if $(CONFIG_64BIT),64,32)" \
5a4630aa 191 "$(OBJDUMP)" "$(OBJCOPY)" "$(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS)" \
d503ac53 192 "$(LD) $(KBUILD_LDFLAGS)" "$(NM)" "$(RM)" "$(MV)" \
18c167fd 193 "$(if $(part-of-module),1,0)" "$(@)";
d6971822 194recordmcount_source := $(srctree)/scripts/recordmcount.pl
312a3d09 195endif # BUILD_C_RECORDMCOUNT
1a49b2fd
JL
196cmd_record_mcount = $(if $(findstring $(strip $(CC_FLAGS_FTRACE)),$(_c_flags)), \
197 $(sub_cmd_record_mcount))
07d04081 198endif # CC_USING_RECORD_MCOUNT
312a3d09 199endif # CONFIG_FTRACE_MCOUNT_RECORD
8da3821b 200
b9ab5ebb 201ifdef CONFIG_STACK_VALIDATION
3b27a0c8 202ifneq ($(SKIP_STACK_VALIDATION),1)
b9ab5ebb
JP
203
204__objtool_obj := $(objtree)/tools/objtool/objtool
205
11af8474 206objtool_args = $(if $(CONFIG_UNWINDER_ORC),orc generate,check)
ee9f8fce 207
ca41b97e
PZ
208objtool_args += $(if $(part-of-module), --module,)
209
b9ab5ebb
JP
210ifndef CONFIG_FRAME_POINTER
211objtool_args += --no-fp
212endif
867ac9d7
JP
213ifdef CONFIG_GCOV_KERNEL
214objtool_args += --no-unreachable
215endif
b5bc2231
PZ
216ifdef CONFIG_RETPOLINE
217 objtool_args += --retpoline
218endif
ea24213d
PZ
219ifdef CONFIG_X86_SMAP
220 objtool_args += --uaccess
221endif
b5bc2231 222
b9ab5ebb
JP
223# 'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory
224# 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file
225# 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file
226cmd_objtool = $(if $(patsubst y%,, \
227 $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \
e5d28910 228 $(__objtool_obj) $(objtool_args) $@)
b9ab5ebb
JP
229objtool_obj = $(if $(patsubst y%,, \
230 $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \
231 $(__objtool_obj))
232
3b27a0c8 233endif # SKIP_STACK_VALIDATION
b9ab5ebb
JP
234endif # CONFIG_STACK_VALIDATION
235
ee9f8fce
JP
236# Rebuild all objects when objtool changes, or is enabled/disabled.
237objtool_dep = $(objtool_obj) \
238 $(wildcard include/config/orc/unwinder.h \
239 include/config/stack/validation.h)
240
bbda5ec6
MY
241ifdef CONFIG_TRIM_UNUSED_KSYMS
242cmd_gen_ksymdeps = \
e5d28910 243 $(CONFIG_SHELL) $(srctree)/scripts/gen_ksymdeps.sh $@ >> $(dot-target).cmd
bbda5ec6
MY
244endif
245
1da177e4 246define rule_cc_o_c
3a2429e1
MY
247 $(call cmd,checksrc)
248 $(call cmd_and_fixdep,cc_o_c)
249 $(call cmd,gen_ksymdeps)
250 $(call cmd,checkdoc)
251 $(call cmd,objtool)
252 $(call cmd,modversions_c)
253 $(call cmd,record_mcount)
1da177e4
LT
254endef
255
b9ab5ebb 256define rule_as_o_S
3a2429e1
MY
257 $(call cmd_and_fixdep,as_o_S)
258 $(call cmd,gen_ksymdeps)
259 $(call cmd,objtool)
260 $(call cmd,modversions_S)
b9ab5ebb
JP
261endef
262
9895c03d
NP
263# List module undefined symbols (or empty line if not enabled)
264ifdef CONFIG_TRIM_UNUSED_KSYMS
9f69a496 265cmd_undef_syms = $(NM) $< | sed -n 's/^ *U //p' | xargs echo
9895c03d
NP
266else
267cmd_undef_syms = echo
268endif
269
1da177e4 270# Built-in and composite module parts
ee9f8fce 271$(obj)/%.o: $(src)/%.c $(recordmcount_source) $(objtool_dep) FORCE
1da177e4
LT
272 $(call cmd,force_checksrc)
273 $(call if_changed_rule,cc_o_c)
274
9f69a496
MY
275cmd_mod = { \
276 echo $(if $($*-objs)$($*-y)$($*-m), $(addprefix $(obj)/, $($*-objs) $($*-y) $($*-m)), $(@:.mod=.o)); \
277 $(cmd_undef_syms); \
278 } > $@
279
280$(obj)/%.mod: $(obj)/%.o FORCE
281 $(call if_changed,mod)
282
283targets += $(mod-targets)
1da177e4
LT
284
285quiet_cmd_cc_lst_c = MKLST $@
286 cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \
287 $(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \
288 System.map $(OBJDUMP) > $@
289
767e581d 290$(obj)/%.lst: $(src)/%.c FORCE
1da177e4
LT
291 $(call if_changed_dep,cc_lst_c)
292
293# Compile assembler sources (.S)
294# ---------------------------------------------------------------------------
295
4efca4ed
NP
296# .S file exports must have their C prototypes defined in asm/asm-prototypes.h
297# or a file that it includes, in order to get versioned symbols. We build a
298# dummy C file that includes asm-prototypes and the EXPORT_SYMBOL lines from
299# the .S file (with trailing ';'), and run genksyms on that, to extract vers.
300#
301# This is convoluted. The .S file must first be preprocessed to run guards and
302# expand names, then the resulting exports must be constructed into plain
303# EXPORT_SYMBOL(symbol); to build our dummy C file, and that gets preprocessed
304# to make the genksyms input.
305#
306# These mirror gensymtypes_c and co above, keep them in synch.
307cmd_gensymtypes_S = \
b79c6aa6 308 { echo "\#include <linux/kernel.h>" ; \
4efca4ed
NP
309 echo "\#include <asm/asm-prototypes.h>" ; \
310 $(CPP) $(a_flags) $< | \
cc6acc11 311 grep "\<___EXPORT_SYMBOL\>" | \
b79c6aa6 312 sed 's/.*___EXPORT_SYMBOL[[:space:]]*\([a-zA-Z0-9_]*\)[[:space:]]*,.*/EXPORT_SYMBOL(\1);/' ; } | \
4efca4ed 313 $(CPP) -D__GENKSYMS__ $(c_flags) -xc - | \
88110713 314 scripts/genksyms/genksyms $(if $(1), -T $(2)) \
56067812 315 $(patsubst y,-R,$(CONFIG_MODULE_REL_CRCS)) \
4efca4ed
NP
316 $(if $(KBUILD_PRESERVE),-p) \
317 -r $(firstword $(wildcard $(2:.symtypes=.symref) /dev/null))
318
319quiet_cmd_cc_symtypes_S = SYM $(quiet_modtag) $@
320cmd_cc_symtypes_S = \
4efca4ed
NP
321 $(call cmd_gensymtypes_S,true,$@) >/dev/null; \
322 test -s $@ || rm -f $@
323
324$(obj)/%.symtypes : $(src)/%.S FORCE
325 $(call cmd,cc_symtypes_S)
326
327
e0f41e52
MY
328quiet_cmd_cpp_s_S = CPP $(quiet_modtag) $@
329cmd_cpp_s_S = $(CPP) $(a_flags) -o $@ $<
1da177e4 330
767e581d 331$(obj)/%.s: $(src)/%.S FORCE
e0f41e52 332 $(call if_changed_dep,cpp_s_S)
1da177e4
LT
333
334quiet_cmd_as_o_S = AS $(quiet_modtag) $@
ee3e46b7 335 cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
4efca4ed 336
2ff2b7ec 337ifdef CONFIG_ASM_MODVERSIONS
4efca4ed
NP
338
339# versioning matches the C process described above, with difference that
340# we parse asm-prototypes.h C header to get function definitions.
341
4efca4ed 342cmd_modversions_S = \
ee3e46b7 343 if $(OBJDUMP) -h $@ | grep -q __ksymtab; then \
4efca4ed
NP
344 $(call cmd_gensymtypes_S,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \
345 > $(@D)/.tmp_$(@F:.o=.ver); \
346 \
ee3e46b7 347 $(LD) $(KBUILD_LDFLAGS) -r -o $(@D)/.tmp_$(@F) $@ \
4efca4ed 348 -T $(@D)/.tmp_$(@F:.o=.ver); \
4efca4ed 349 mv -f $(@D)/.tmp_$(@F) $@; \
ee3e46b7 350 rm -f $(@D)/.tmp_$(@F:.o=.ver); \
e5d28910 351 fi
4efca4ed 352endif
1da177e4 353
ee9f8fce 354$(obj)/%.o: $(src)/%.S $(objtool_dep) FORCE
b9ab5ebb 355 $(call if_changed_rule,as_o_S)
1da177e4 356
f98fe47c 357targets += $(filter-out $(subdir-obj-y), $(real-obj-y)) $(real-obj-m) $(lib-y)
5f2fb52f 358targets += $(extra-y) $(always-y) $(MAKECMDGOALS)
1da177e4
LT
359
360# Linker scripts preprocessor (.lds.S -> .lds)
361# ---------------------------------------------------------------------------
362quiet_cmd_cpp_lds_S = LDS $@
5cb0512c 363 cmd_cpp_lds_S = $(CPP) $(cpp_flags) -P -U$(ARCH) \
42f29a25 364 -D__ASSEMBLY__ -DLINKER_SCRIPT -o $@ $<
1da177e4 365
767e581d 366$(obj)/%.lds: $(src)/%.lds.S FORCE
1da177e4
LT
367 $(call if_changed_dep,cpp_lds_S)
368
4520c6a4
DH
369# ASN.1 grammar
370# ---------------------------------------------------------------------------
49d5089d 371quiet_cmd_asn1_compiler = ASN.1 $(basename $@).[ch]
4520c6a4 372 cmd_asn1_compiler = $(objtree)/scripts/asn1_compiler $< \
49d5089d 373 $(basename $@).c $(basename $@).h
4520c6a4 374
4fa8bc94 375$(obj)/%.asn1.c $(obj)/%.asn1.h: $(src)/%.asn1 $(objtree)/scripts/asn1_compiler
4520c6a4
DH
376 $(call cmd,asn1_compiler)
377
1da177e4
LT
378# Build the compiled-in targets
379# ---------------------------------------------------------------------------
380
381# To build objects in subdirs, we need to descend into the directories
a7499267 382$(obj)/%/built-in.a: $(obj)/% ;
1da177e4
LT
383
384#
dee94953 385# Rule to compile a set of .o files into one .a file (without symbol table)
1da177e4
LT
386#
387ifdef builtin-target
a5967db9 388
5e18f029 389quiet_cmd_ar_builtin = AR $@
13dc8c02 390 cmd_ar_builtin = rm -f $@; $(AR) cDPrST $@ $(real-prereqs)
1da177e4 391
f98fe47c 392$(builtin-target): $(real-obj-y) FORCE
5e18f029 393 $(call if_changed,ar_builtin)
1da177e4
LT
394
395targets += $(builtin-target)
396endif # builtin-target
397
551559e1
TH
398#
399# Rule to create modules.order file
400#
401# Create commands to either record .ko file or cat modules.order from
402# a subdirectory
551559e1 403$(modorder-target): $(subdir-ym) FORCE
e0e1b1ec
MY
404 $(Q){ $(foreach m, $(modorder), \
405 $(if $(filter %/modules.order, $m), cat $m, echo $m);) :; } \
406 | $(AWK) '!x[$$0]++' - > $@
551559e1 407
1da177e4 408#
dee94953 409# Rule to compile a set of .o files into one .a file (with symbol table)
1da177e4
LT
410#
411ifdef lib-target
1da177e4
LT
412
413$(lib-target): $(lib-y) FORCE
898f5a00 414 $(call if_changed,ar)
1da177e4
LT
415
416targets += $(lib-target)
7f2084fa 417
1da177e4
LT
418endif
419
afa974b7
MY
420# NOTE:
421# Do not replace $(filter %.o,^) with $(real-prereqs). When a single object
422# module is turned into a multi object module, $^ will contain header file
423# dependencies recorded in the .*.cmd file.
1da177e4 424quiet_cmd_link_multi-m = LD [M] $@
b7dca6dd 425 cmd_link_multi-m = $(LD) $(ld_flags) -r -o $@ $(filter %.o,$^)
1da177e4 426
c8589d1e 427$(multi-used-m): FORCE
1da177e4 428 $(call if_changed,link_multi-m)
cf4f2193 429$(call multi_depend, $(multi-used-m), .o, -objs -y -m)
1da177e4 430
f98fe47c 431targets += $(multi-used-m)
591f6689 432targets := $(filter-out $(PHONY), $(targets))
1da177e4 433
b23d1a24
MY
434# Add intermediate targets:
435# When building objects with specific suffix patterns, add intermediate
436# targets that the final targets are derived from.
437intermediate_targets = $(foreach sfx, $(2), \
438 $(patsubst %$(strip $(1)),%$(sfx), \
439 $(filter %$(strip $(1)), $(targets))))
54a702f7 440# %.asn1.o <- %.asn1.[ch] <- %.asn1
a7f92419 441# %.dtb.o <- %.dtb.S <- %.dtb <- %.dts
b23d1a24
MY
442# %.lex.o <- %.lex.c <- %.l
443# %.tab.o <- %.tab.[ch] <- %.y
54a702f7
MY
444targets += $(call intermediate_targets, .asn1.o, .asn1.c .asn1.h) \
445 $(call intermediate_targets, .dtb.o, .dtb.S .dtb) \
a7f92419 446 $(call intermediate_targets, .lex.o, .lex.c) \
b23d1a24
MY
447 $(call intermediate_targets, .tab.o, .tab.c .tab.h)
448
394053f4
MY
449# Build
450# ---------------------------------------------------------------------------
451
452ifdef single-build
453
20312629
MY
454KBUILD_SINGLE_TARGETS := $(filter $(obj)/%, $(KBUILD_SINGLE_TARGETS))
455
394053f4
MY
456curdir-single := $(sort $(foreach x, $(KBUILD_SINGLE_TARGETS), \
457 $(if $(filter $(x) $(basename $(x)).o, $(targets)), $(x))))
458
459# Handle single targets without any rule: show "Nothing to be done for ..." or
460# "No rule to make target ..." depending on whether the target exists.
461unknown-single := $(filter-out $(addsuffix /%, $(subdir-ym)), \
20312629 462 $(filter-out $(curdir-single), $(KBUILD_SINGLE_TARGETS)))
394053f4 463
2dffd23f
MY
464single-subdirs := $(foreach d, $(subdir-ym), \
465 $(if $(filter $(d)/%, $(KBUILD_SINGLE_TARGETS)), $(d)))
466
467__build: $(curdir-single) $(single-subdirs)
394053f4
MY
468ifneq ($(unknown-single),)
469 $(Q)$(MAKE) -f /dev/null $(unknown-single)
470endif
471 @:
472
473ifeq ($(curdir-single),)
474# Nothing to do in this directory. Do not include any .*.cmd file for speed-up
475targets :=
476else
477targets += $(curdir-single)
478endif
479
480else
481
482__build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \
483 $(if $(KBUILD_MODULES),$(obj-m) $(mod-targets) $(modorder-target)) \
5f2fb52f 484 $(subdir-ym) $(always-y)
394053f4
MY
485 @:
486
487endif
488
1da177e4
LT
489# Descending
490# ---------------------------------------------------------------------------
491
4f193362 492PHONY += $(subdir-ym)
1da177e4 493$(subdir-ym):
d9f78edf 494 $(Q)$(MAKE) $(build)=$@ \
394053f4 495 $(if $(filter $@/, $(KBUILD_SINGLE_TARGETS)),single-build=) \
4f2c8f30
MY
496 need-builtin=$(if $(filter $@/built-in.a, $(subdir-obj-y)),1) \
497 need-modorder=$(if $(need-modorder),$(if $(filter $@/modules.order, $(modorder)),1))
1da177e4
LT
498
499# Add FORCE to the prequisites of a target to force it to be always rebuilt.
500# ---------------------------------------------------------------------------
501
4f193362 502PHONY += FORCE
1da177e4
LT
503
504FORCE:
505
506# Read all saved command lines and dependencies for the $(targets) we
507# may be building above, using $(if_changed{,_dep}). As an
508# optimization, we don't need to read them if the target does not
509# exist, we will rebuild anyway in that case.
510
392885ee 511existing-targets := $(wildcard $(sort $(targets)))
1da177e4 512
392885ee 513-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
4f193362 514
051f278e 515ifdef building_out_of_srctree
8a78756e
MY
516# Create directories for object files if they do not exist
517obj-dirs := $(sort $(obj) $(patsubst %/,%, $(dir $(targets))))
392885ee
MY
518# If targets exist, their directories apparently exist. Skip mkdir.
519existing-dirs := $(sort $(patsubst %/,%, $(dir $(existing-targets))))
520obj-dirs := $(strip $(filter-out $(existing-dirs), $(obj-dirs)))
c4da7ed0 521ifneq ($(obj-dirs),)
8a78756e
MY
522$(shell mkdir -p $(obj-dirs))
523endif
c4da7ed0 524endif
8a78756e 525
4f193362 526.PHONY: $(PHONY)