Makefile.build 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. # SPDX-License-Identifier: GPL-2.0
  2. # ==========================================================================
  3. # Building
  4. # ==========================================================================
  5. src := $(obj)
  6. PHONY := __build
  7. __build:
  8. # Init all relevant variables used in kbuild files so
  9. # 1) they have correct type
  10. # 2) they do not inherit any value from the environment
  11. obj-y :=
  12. obj-m :=
  13. lib-y :=
  14. lib-m :=
  15. always :=
  16. always-y :=
  17. always-m :=
  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. subdir-asflags-y :=
  30. subdir-ccflags-y :=
  31. # Read auto.conf if it exists, otherwise ignore
  32. -include include/config/auto.conf
  33. include scripts/Kbuild.include
  34. # The filename Kbuild has precedence over Makefile
  35. kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
  36. kbuild-file := $(if $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Kbuild,$(kbuild-dir)/Makefile)
  37. include $(kbuild-file)
  38. include scripts/Makefile.lib
  39. # Do not include hostprogs rules unless needed.
  40. # $(sort ...) is used here to remove duplicated words and excessive spaces.
  41. hostprogs := $(sort $(hostprogs))
  42. ifneq ($(hostprogs),)
  43. include scripts/Makefile.host
  44. endif
  45. # Do not include userprogs rules unless needed.
  46. # $(sort ...) is used here to remove duplicated words and excessive spaces.
  47. userprogs := $(sort $(userprogs))
  48. ifneq ($(userprogs),)
  49. include scripts/Makefile.userprogs
  50. endif
  51. ifndef obj
  52. $(warning kbuild: Makefile.build is included improperly)
  53. endif
  54. ifeq ($(need-modorder),)
  55. ifneq ($(obj-m),)
  56. $(warning $(patsubst %.o,'%.ko',$(obj-m)) will not be built even though obj-m is specified.)
  57. $(warning You cannot use subdir-y/m to visit a module Makefile. Use obj-y/m instead.)
  58. endif
  59. endif
  60. # ===========================================================================
  61. # subdir-builtin and subdir-modorder may contain duplications. Use $(sort ...)
  62. subdir-builtin := $(sort $(filter %/built-in.a, $(real-obj-y)))
  63. subdir-modorder := $(sort $(filter %/modules.order, $(obj-m)))
  64. targets-for-builtin := $(extra-y)
  65. ifneq ($(strip $(lib-y) $(lib-m) $(lib-)),)
  66. targets-for-builtin += $(obj)/lib.a
  67. endif
  68. ifdef need-builtin
  69. targets-for-builtin += $(obj)/built-in.a
  70. endif
  71. targets-for-modules := $(patsubst %.o, %.mod, $(filter %.o, $(obj-m)))
  72. ifdef need-modorder
  73. targets-for-modules += $(obj)/modules.order
  74. endif
  75. targets += $(targets-for-builtin) $(targets-for-modules)
  76. # Linus' kernel sanity checking tool
  77. ifeq ($(KBUILD_CHECKSRC),1)
  78. quiet_cmd_checksrc = CHECK $<
  79. cmd_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $<
  80. else ifeq ($(KBUILD_CHECKSRC),2)
  81. quiet_cmd_force_checksrc = CHECK $<
  82. cmd_force_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $<
  83. endif
  84. ifneq ($(KBUILD_EXTRA_WARN),)
  85. cmd_checkdoc = $(srctree)/scripts/kernel-doc -none $<
  86. endif
  87. # Compile C sources (.c)
  88. # ---------------------------------------------------------------------------
  89. quiet_cmd_cc_s_c = CC $(quiet_modtag) $@
  90. cmd_cc_s_c = $(CC) $(filter-out $(DEBUG_CFLAGS) $(CC_FLAGS_LTO), $(c_flags)) -fverbose-asm -S -o $@ $<
  91. $(obj)/%.s: $(src)/%.c FORCE
  92. $(call if_changed_dep,cc_s_c)
  93. quiet_cmd_cpp_i_c = CPP $(quiet_modtag) $@
  94. cmd_cpp_i_c = $(CPP) $(c_flags) -o $@ $<
  95. $(obj)/%.i: $(src)/%.c FORCE
  96. $(call if_changed_dep,cpp_i_c)
  97. # These mirror gensymtypes_S and co below, keep them in synch.
  98. cmd_gensymtypes_c = \
  99. $(CPP) -D__GENKSYMS__ $(c_flags) $< | \
  100. scripts/genksyms/genksyms $(if $(1), -T $(2)) \
  101. $(patsubst y,-R,$(CONFIG_MODULE_REL_CRCS)) \
  102. $(if $(KBUILD_PRESERVE),-p) \
  103. -r $(firstword $(wildcard $(2:.symtypes=.symref) /dev/null))
  104. quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@
  105. cmd_cc_symtypes_c = \
  106. $(call cmd_gensymtypes_c,true,$@) >/dev/null; \
  107. test -s $@ || rm -f $@
  108. $(obj)/%.symtypes : $(src)/%.c FORCE
  109. $(call cmd,cc_symtypes_c)
  110. # LLVM assembly
  111. # Generate .ll files from .c
  112. quiet_cmd_cc_ll_c = CC $(quiet_modtag) $@
  113. cmd_cc_ll_c = $(CC) $(c_flags) -emit-llvm -S -o $@ $<
  114. $(obj)/%.ll: $(src)/%.c FORCE
  115. $(call if_changed_dep,cc_ll_c)
  116. # C (.c) files
  117. # The C file is compiled and updated dependency information is generated.
  118. # (See cmd_cc_o_c + relevant part of rule_cc_o_c)
  119. quiet_cmd_cc_o_c = CC $(quiet_modtag) $@
  120. cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
  121. ifdef CONFIG_MODVERSIONS
  122. # When module versioning is enabled the following steps are executed:
  123. # o compile a <file>.o from <file>.c
  124. # o if <file>.o doesn't contain a __ksymtab version, i.e. does
  125. # not export symbols, it's done.
  126. # o otherwise, we calculate symbol versions using the good old
  127. # genksyms on the preprocessed source and postprocess them in a way
  128. # that they are usable as a linker script
  129. # o generate .tmp_<file>.o from <file>.o using the linker to
  130. # replace the unresolved symbols __crc_exported_symbol with
  131. # the actual value of the checksum generated by genksyms
  132. # o remove .tmp_<file>.o to <file>.o
  133. ifdef CONFIG_LTO_CLANG
  134. # Generate .o.symversions files for each .o with exported symbols, and link these
  135. # to the kernel and/or modules at the end.
  136. cmd_modversions_c = \
  137. if $(NM) $@ 2>/dev/null | grep -q __ksymtab; then \
  138. $(call cmd_gensymtypes_c,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \
  139. > $@.symversions; \
  140. fi;
  141. else
  142. cmd_modversions_c = \
  143. if $(OBJDUMP) -h $@ | grep -q __ksymtab; then \
  144. $(call cmd_gensymtypes_c,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \
  145. > $(@D)/.tmp_$(@F:.o=.ver); \
  146. \
  147. $(LD) $(KBUILD_LDFLAGS) -r -o $(@D)/.tmp_$(@F) $@ \
  148. -T $(@D)/.tmp_$(@F:.o=.ver); \
  149. mv -f $(@D)/.tmp_$(@F) $@; \
  150. rm -f $(@D)/.tmp_$(@F:.o=.ver); \
  151. fi
  152. endif
  153. endif
  154. ifdef CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT
  155. # compiler will not generate __mcount_loc use recordmcount or recordmcount.pl
  156. ifdef BUILD_C_RECORDMCOUNT
  157. ifeq ("$(origin RECORDMCOUNT_WARN)", "command line")
  158. RECORDMCOUNT_FLAGS = -w
  159. endif
  160. # Due to recursion, we must skip empty.o.
  161. # The empty.o file is created in the make process in order to determine
  162. # the target endianness and word size. It is made before all other C
  163. # files, including recordmcount.
  164. sub_cmd_record_mcount = \
  165. if [ $(@) != "scripts/mod/empty.o" ]; then \
  166. $(objtree)/scripts/recordmcount $(RECORDMCOUNT_FLAGS) "$(@)"; \
  167. fi;
  168. recordmcount_source := $(srctree)/scripts/recordmcount.c \
  169. $(srctree)/scripts/recordmcount.h
  170. else
  171. sub_cmd_record_mcount = perl $(srctree)/scripts/recordmcount.pl "$(ARCH)" \
  172. "$(if $(CONFIG_CPU_BIG_ENDIAN),big,little)" \
  173. "$(if $(CONFIG_64BIT),64,32)" \
  174. "$(OBJDUMP)" "$(OBJCOPY)" "$(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS)" \
  175. "$(LD) $(KBUILD_LDFLAGS)" "$(NM)" "$(RM)" "$(MV)" \
  176. "$(if $(part-of-module),1,0)" "$(@)";
  177. recordmcount_source := $(srctree)/scripts/recordmcount.pl
  178. endif # BUILD_C_RECORDMCOUNT
  179. cmd_record_mcount = $(if $(findstring $(strip $(CC_FLAGS_FTRACE)),$(_c_flags)), \
  180. $(sub_cmd_record_mcount))
  181. endif # CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT
  182. ifdef CONFIG_STACK_VALIDATION
  183. ifndef CONFIG_LTO_CLANG
  184. ifneq ($(SKIP_STACK_VALIDATION),1)
  185. __objtool_obj := $(objtree)/tools/objtool/objtool
  186. # 'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory
  187. # 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file
  188. # 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file
  189. cmd_objtool = $(if $(patsubst y%,, \
  190. $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \
  191. $(__objtool_obj) $(objtool_args) $@)
  192. objtool_obj = $(if $(patsubst y%,, \
  193. $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \
  194. $(__objtool_obj))
  195. endif # SKIP_STACK_VALIDATION
  196. endif # CONFIG_LTO_CLANG
  197. endif # CONFIG_STACK_VALIDATION
  198. # Rebuild all objects when objtool changes, or is enabled/disabled.
  199. objtool_dep = $(objtool_obj) \
  200. $(wildcard include/config/orc/unwinder.h \
  201. include/config/stack/validation.h)
  202. ifdef CONFIG_TRIM_UNUSED_KSYMS
  203. cmd_gen_ksymdeps = \
  204. $(CONFIG_SHELL) $(srctree)/scripts/gen_ksymdeps.sh $@ >> $(dot-target).cmd
  205. # List module undefined symbols
  206. undefined_syms = $(NM) $< | $(AWK) '$$1 == "U" { printf("%s%s", x++ ? " " : "", $$2) }';
  207. endif
  208. define rule_cc_o_c
  209. $(call cmd_and_fixdep,cc_o_c)
  210. $(call cmd,gen_ksymdeps)
  211. $(call cmd,checksrc)
  212. $(call cmd,checkdoc)
  213. $(call cmd,objtool)
  214. $(call cmd,modversions_c)
  215. $(call cmd,record_mcount)
  216. endef
  217. define rule_as_o_S
  218. $(call cmd_and_fixdep,as_o_S)
  219. $(call cmd,gen_ksymdeps)
  220. $(call cmd,objtool)
  221. $(call cmd,modversions_S)
  222. endef
  223. # Built-in and composite module parts
  224. .SECONDEXPANSION:
  225. $(obj)/%.o: $(src)/%.c $(recordmcount_source) $$(objtool_dep) FORCE
  226. $(call if_changed_rule,cc_o_c)
  227. $(call cmd,force_checksrc)
  228. cmd_mod = { \
  229. echo $(if $($*-objs)$($*-y)$($*-m), $(addprefix $(obj)/, $($*-objs) $($*-y) $($*-m)), $(@:.mod=.o)); \
  230. $(undefined_syms) echo; \
  231. } > $@
  232. $(obj)/%.mod: $(obj)/%.o FORCE
  233. $(call if_changed,mod)
  234. quiet_cmd_cc_lst_c = MKLST $@
  235. cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \
  236. $(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \
  237. System.map $(OBJDUMP) > $@
  238. $(obj)/%.lst: $(src)/%.c FORCE
  239. $(call if_changed_dep,cc_lst_c)
  240. # Compile assembler sources (.S)
  241. # ---------------------------------------------------------------------------
  242. # .S file exports must have their C prototypes defined in asm/asm-prototypes.h
  243. # or a file that it includes, in order to get versioned symbols. We build a
  244. # dummy C file that includes asm-prototypes and the EXPORT_SYMBOL lines from
  245. # the .S file (with trailing ';'), and run genksyms on that, to extract vers.
  246. #
  247. # This is convoluted. The .S file must first be preprocessed to run guards and
  248. # expand names, then the resulting exports must be constructed into plain
  249. # EXPORT_SYMBOL(symbol); to build our dummy C file, and that gets preprocessed
  250. # to make the genksyms input.
  251. #
  252. # These mirror gensymtypes_c and co above, keep them in synch.
  253. cmd_gensymtypes_S = \
  254. { echo "\#include <linux/kernel.h>" ; \
  255. echo "\#include <asm/asm-prototypes.h>" ; \
  256. $(CPP) $(a_flags) $< | \
  257. grep "\<___EXPORT_SYMBOL\>" | \
  258. sed 's/.*___EXPORT_SYMBOL[[:space:]]*\([a-zA-Z0-9_]*\)[[:space:]]*,.*/EXPORT_SYMBOL(\1);/' ; } | \
  259. $(CPP) -D__GENKSYMS__ $(c_flags) -xc - | \
  260. scripts/genksyms/genksyms $(if $(1), -T $(2)) \
  261. $(patsubst y,-R,$(CONFIG_MODULE_REL_CRCS)) \
  262. $(if $(KBUILD_PRESERVE),-p) \
  263. -r $(firstword $(wildcard $(2:.symtypes=.symref) /dev/null))
  264. quiet_cmd_cc_symtypes_S = SYM $(quiet_modtag) $@
  265. cmd_cc_symtypes_S = \
  266. $(call cmd_gensymtypes_S,true,$@) >/dev/null; \
  267. test -s $@ || rm -f $@
  268. $(obj)/%.symtypes : $(src)/%.S FORCE
  269. $(call cmd,cc_symtypes_S)
  270. quiet_cmd_cpp_s_S = CPP $(quiet_modtag) $@
  271. cmd_cpp_s_S = $(CPP) $(a_flags) -o $@ $<
  272. $(obj)/%.s: $(src)/%.S FORCE
  273. $(call if_changed_dep,cpp_s_S)
  274. quiet_cmd_as_o_S = AS $(quiet_modtag) $@
  275. cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
  276. ifdef CONFIG_ASM_MODVERSIONS
  277. # versioning matches the C process described above, with difference that
  278. # we parse asm-prototypes.h C header to get function definitions.
  279. cmd_modversions_S = \
  280. if $(OBJDUMP) -h $@ | grep -q __ksymtab; then \
  281. $(call cmd_gensymtypes_S,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \
  282. > $(@D)/.tmp_$(@F:.o=.ver); \
  283. \
  284. $(LD) $(KBUILD_LDFLAGS) -r -o $(@D)/.tmp_$(@F) $@ \
  285. -T $(@D)/.tmp_$(@F:.o=.ver); \
  286. mv -f $(@D)/.tmp_$(@F) $@; \
  287. rm -f $(@D)/.tmp_$(@F:.o=.ver); \
  288. fi
  289. endif
  290. $(obj)/%.o: $(src)/%.S $$(objtool_dep) FORCE
  291. $(call if_changed_rule,as_o_S)
  292. targets += $(filter-out $(subdir-builtin), $(real-obj-y))
  293. targets += $(filter-out $(subdir-modorder), $(real-obj-m))
  294. targets += $(lib-y) $(always-y) $(MAKECMDGOALS)
  295. # Linker scripts preprocessor (.lds.S -> .lds)
  296. # ---------------------------------------------------------------------------
  297. quiet_cmd_cpp_lds_S = LDS $@
  298. cmd_cpp_lds_S = $(CPP) $(cpp_flags) -P -U$(ARCH) \
  299. -D__ASSEMBLY__ -DLINKER_SCRIPT -o $@ $<
  300. $(obj)/%.lds: $(src)/%.lds.S FORCE
  301. $(call if_changed_dep,cpp_lds_S)
  302. # ASN.1 grammar
  303. # ---------------------------------------------------------------------------
  304. quiet_cmd_asn1_compiler = ASN.1 $(basename $@).[ch]
  305. cmd_asn1_compiler = $(objtree)/scripts/asn1_compiler $< \
  306. $(basename $@).c $(basename $@).h
  307. $(obj)/%.asn1.c $(obj)/%.asn1.h: $(src)/%.asn1 $(objtree)/scripts/asn1_compiler
  308. $(call cmd,asn1_compiler)
  309. # Build the compiled-in targets
  310. # ---------------------------------------------------------------------------
  311. # To build objects in subdirs, we need to descend into the directories
  312. $(subdir-builtin): $(obj)/%/built-in.a: $(obj)/% ;
  313. $(subdir-modorder): $(obj)/%/modules.order: $(obj)/% ;
  314. # combine symversions for later processing
  315. quiet_cmd_update_lto_symversions = SYMVER $@
  316. ifeq ($(CONFIG_LTO_CLANG) $(CONFIG_MODVERSIONS),y y)
  317. cmd_update_lto_symversions = \
  318. rm -f $@.symversions \
  319. $(foreach n, $(filter-out FORCE,$^), \
  320. $(if $(wildcard $(n).symversions), \
  321. ; cat $(n).symversions >> $@.symversions))
  322. else
  323. cmd_update_lto_symversions = echo >/dev/null
  324. endif
  325. #
  326. # Rule to compile a set of .o files into one .a file (without symbol table)
  327. #
  328. quiet_cmd_ar_builtin = AR $@
  329. cmd_ar_builtin = rm -f $@; $(AR) cDPrST $@ $(real-prereqs)
  330. quiet_cmd_ar_and_symver = AR $@
  331. cmd_ar_and_symver = $(cmd_update_lto_symversions); $(cmd_ar_builtin)
  332. $(obj)/built-in.a: $(real-obj-y) FORCE
  333. $(call if_changed,ar_and_symver)
  334. #
  335. # Rule to create modules.order file
  336. #
  337. # Create commands to either record .ko file or cat modules.order from
  338. # a subdirectory
  339. # Add $(obj-m) as the prerequisite to avoid updating the timestamp of
  340. # modules.order unless contained modules are updated.
  341. cmd_modules_order = { $(foreach m, $(real-prereqs), \
  342. $(if $(filter %/modules.order, $m), cat $m, echo $(patsubst %.o,%.ko,$m));) :; } \
  343. | $(AWK) '!x[$$0]++' - > $@
  344. $(obj)/modules.order: $(obj-m) FORCE
  345. $(call if_changed,modules_order)
  346. #
  347. # Rule to compile a set of .o files into one .a file (with symbol table)
  348. #
  349. quiet_cmd_ar_lib = AR $@
  350. cmd_ar_lib = $(cmd_update_lto_symversions); $(cmd_ar)
  351. $(obj)/lib.a: $(lib-y) FORCE
  352. $(call if_changed,ar_lib)
  353. # NOTE:
  354. # Do not replace $(filter %.o,^) with $(real-prereqs). When a single object
  355. # module is turned into a multi object module, $^ will contain header file
  356. # dependencies recorded in the .*.cmd file.
  357. ifdef CONFIG_LTO_CLANG
  358. quiet_cmd_link_multi-m = AR [M] $@
  359. cmd_link_multi-m = \
  360. $(cmd_update_lto_symversions); \
  361. rm -f $@; \
  362. $(AR) cDPrsT $@ $(filter %.o %.a,$^)
  363. else
  364. quiet_cmd_link_multi-m = LD [M] $@
  365. cmd_link_multi-m = $(LD) $(ld_flags) -r -o $@ $(filter %.o,$^)
  366. endif
  367. $(multi-used-m): FORCE
  368. $(call if_changed,link_multi-m)
  369. $(call multi_depend, $(multi-used-m), .o, -objs -y -m)
  370. targets += $(multi-used-m)
  371. targets := $(filter-out $(PHONY), $(targets))
  372. # Add intermediate targets:
  373. # When building objects with specific suffix patterns, add intermediate
  374. # targets that the final targets are derived from.
  375. intermediate_targets = $(foreach sfx, $(2), \
  376. $(patsubst %$(strip $(1)),%$(sfx), \
  377. $(filter %$(strip $(1)), $(targets))))
  378. # %.asn1.o <- %.asn1.[ch] <- %.asn1
  379. # %.dtb.o <- %.dtb.S <- %.dtb <- %.dts
  380. # %.lex.o <- %.lex.c <- %.l
  381. # %.tab.o <- %.tab.[ch] <- %.y
  382. targets += $(call intermediate_targets, .asn1.o, .asn1.c .asn1.h) \
  383. $(call intermediate_targets, .dtb.o, .dtb.S .dtb) \
  384. $(call intermediate_targets, .lex.o, .lex.c) \
  385. $(call intermediate_targets, .tab.o, .tab.c .tab.h)
  386. # Build
  387. # ---------------------------------------------------------------------------
  388. ifdef single-build
  389. KBUILD_SINGLE_TARGETS := $(filter $(obj)/%, $(KBUILD_SINGLE_TARGETS))
  390. curdir-single := $(sort $(foreach x, $(KBUILD_SINGLE_TARGETS), \
  391. $(if $(filter $(x) $(basename $(x)).o, $(targets)), $(x))))
  392. # Handle single targets without any rule: show "Nothing to be done for ..." or
  393. # "No rule to make target ..." depending on whether the target exists.
  394. unknown-single := $(filter-out $(addsuffix /%, $(subdir-ym)), \
  395. $(filter-out $(curdir-single), $(KBUILD_SINGLE_TARGETS)))
  396. single-subdirs := $(foreach d, $(subdir-ym), \
  397. $(if $(filter $(d)/%, $(KBUILD_SINGLE_TARGETS)), $(d)))
  398. __build: $(curdir-single) $(single-subdirs)
  399. ifneq ($(unknown-single),)
  400. $(Q)$(MAKE) -f /dev/null $(unknown-single)
  401. endif
  402. @:
  403. ifeq ($(curdir-single),)
  404. # Nothing to do in this directory. Do not include any .*.cmd file for speed-up
  405. targets :=
  406. else
  407. targets += $(curdir-single)
  408. endif
  409. else
  410. __build: $(if $(KBUILD_BUILTIN), $(targets-for-builtin)) \
  411. $(if $(KBUILD_MODULES), $(targets-for-modules)) \
  412. $(subdir-ym) $(always-y)
  413. @:
  414. endif
  415. # Descending
  416. # ---------------------------------------------------------------------------
  417. PHONY += $(subdir-ym)
  418. $(subdir-ym):
  419. $(Q)$(MAKE) $(build)=$@ \
  420. $(if $(filter $@/, $(KBUILD_SINGLE_TARGETS)),single-build=) \
  421. need-builtin=$(if $(filter $@/built-in.a, $(subdir-builtin)),1) \
  422. need-modorder=$(if $(filter $@/modules.order, $(subdir-modorder)),1)
  423. # Add FORCE to the prequisites of a target to force it to be always rebuilt.
  424. # ---------------------------------------------------------------------------
  425. PHONY += FORCE
  426. FORCE:
  427. # Read all saved command lines and dependencies for the $(targets) we
  428. # may be building above, using $(if_changed{,_dep}). As an
  429. # optimization, we don't need to read them if the target does not
  430. # exist, we will rebuild anyway in that case.
  431. existing-targets := $(wildcard $(sort $(targets)))
  432. -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
  433. # Create directories for object files if they do not exist
  434. obj-dirs := $(sort $(patsubst %/,%, $(dir $(targets))))
  435. # If targets exist, their directories apparently exist. Skip mkdir.
  436. existing-dirs := $(sort $(patsubst %/,%, $(dir $(existing-targets))))
  437. obj-dirs := $(strip $(filter-out $(existing-dirs), $(obj-dirs)))
  438. ifneq ($(obj-dirs),)
  439. $(shell mkdir -p $(obj-dirs))
  440. endif
  441. .PHONY: $(PHONY)