Makefile.build 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  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. targets :=
  17. subdir-y :=
  18. subdir-m :=
  19. EXTRA_AFLAGS :=
  20. EXTRA_CFLAGS :=
  21. EXTRA_CPPFLAGS :=
  22. EXTRA_LDFLAGS :=
  23. asflags-y :=
  24. ccflags-y :=
  25. cppflags-y :=
  26. ldflags-y :=
  27. subdir-asflags-y :=
  28. subdir-ccflags-y :=
  29. # Read auto.conf if it exists, otherwise ignore
  30. -include include/config/auto.conf
  31. include scripts/Kbuild.include
  32. # For backward compatibility check that these variables do not change
  33. save-cflags := $(CFLAGS)
  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. # If the save-* variables changed error out
  39. ifeq ($(KBUILD_NOPEDANTIC),)
  40. ifneq ("$(save-cflags)","$(CFLAGS)")
  41. $(error CFLAGS was changed in "$(kbuild-file)". Fix it to use ccflags-y)
  42. endif
  43. endif
  44. include scripts/Makefile.lib
  45. # Do not include host rules unless needed
  46. ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
  47. include scripts/Makefile.host
  48. endif
  49. ifndef obj
  50. $(warning kbuild: Makefile.build is included improperly)
  51. endif
  52. # ===========================================================================
  53. ifneq ($(strip $(lib-y) $(lib-m) $(lib-)),)
  54. lib-target := $(obj)/lib.a
  55. real-obj-y += $(obj)/lib-ksyms.o
  56. endif
  57. ifneq ($(strip $(real-obj-y) $(need-builtin)),)
  58. builtin-target := $(obj)/built-in.a
  59. endif
  60. modorder-target := $(obj)/modules.order
  61. # We keep a list of all modules in $(MODVERDIR)
  62. __build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \
  63. $(if $(KBUILD_MODULES),$(obj-m) $(modorder-target)) \
  64. $(subdir-ym) $(always)
  65. @:
  66. # Linus' kernel sanity checking tool
  67. ifneq ($(KBUILD_CHECKSRC),0)
  68. ifeq ($(KBUILD_CHECKSRC),2)
  69. quiet_cmd_force_checksrc = CHECK $<
  70. cmd_force_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $< ;
  71. else
  72. quiet_cmd_checksrc = CHECK $<
  73. cmd_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $< ;
  74. endif
  75. endif
  76. ifneq ($(KBUILD_ENABLE_EXTRA_GCC_CHECKS),)
  77. cmd_checkdoc = $(srctree)/scripts/kernel-doc -none $< ;
  78. endif
  79. # Do section mismatch analysis for each module/built-in.a
  80. ifdef CONFIG_DEBUG_SECTION_MISMATCH
  81. cmd_secanalysis = ; scripts/mod/modpost $@
  82. endif
  83. # Compile C sources (.c)
  84. # ---------------------------------------------------------------------------
  85. # Default is built-in, unless we know otherwise
  86. modkern_cflags = \
  87. $(if $(part-of-module), \
  88. $(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE), \
  89. $(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL))
  90. quiet_modtag := $(empty) $(empty)
  91. $(real-obj-m) : part-of-module := y
  92. $(real-obj-m:.o=.i) : part-of-module := y
  93. $(real-obj-m:.o=.s) : part-of-module := y
  94. $(real-obj-m:.o=.lst): part-of-module := y
  95. $(real-obj-m) : quiet_modtag := [M]
  96. $(real-obj-m:.o=.i) : quiet_modtag := [M]
  97. $(real-obj-m:.o=.s) : quiet_modtag := [M]
  98. $(real-obj-m:.o=.lst): quiet_modtag := [M]
  99. $(obj-m) : quiet_modtag := [M]
  100. quiet_cmd_cc_s_c = CC $(quiet_modtag) $@
  101. cmd_cc_s_c = $(CC) $(c_flags) $(DISABLE_LTO) -fverbose-asm -S -o $@ $<
  102. $(obj)/%.s: $(src)/%.c FORCE
  103. $(call if_changed_dep,cc_s_c)
  104. quiet_cmd_cpp_i_c = CPP $(quiet_modtag) $@
  105. cmd_cpp_i_c = $(CPP) $(c_flags) -o $@ $<
  106. $(obj)/%.i: $(src)/%.c FORCE
  107. $(call if_changed_dep,cpp_i_c)
  108. # These mirror gensymtypes_S and co below, keep them in synch.
  109. cmd_gensymtypes_c = \
  110. $(CPP) -D__GENKSYMS__ $(c_flags) $< | \
  111. $(GENKSYMS) $(if $(1), -T $(2)) \
  112. $(patsubst y,-R,$(CONFIG_MODULE_REL_CRCS)) \
  113. $(if $(KBUILD_PRESERVE),-p) \
  114. -r $(firstword $(wildcard $(2:.symtypes=.symref) /dev/null))
  115. quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@
  116. cmd_cc_symtypes_c = \
  117. set -e; \
  118. $(call cmd_gensymtypes_c,true,$@) >/dev/null; \
  119. test -s $@ || rm -f $@
  120. $(obj)/%.symtypes : $(src)/%.c FORCE
  121. $(call cmd,cc_symtypes_c)
  122. # LLVM assembly
  123. # Generate .ll files from .c
  124. quiet_cmd_cc_ll_c = CC $(quiet_modtag) $@
  125. cmd_cc_ll_c = $(CC) $(c_flags) -emit-llvm -S -o $@ $<
  126. $(obj)/%.ll: $(src)/%.c FORCE
  127. $(call if_changed_dep,cc_ll_c)
  128. # C (.c) files
  129. # The C file is compiled and updated dependency information is generated.
  130. # (See cmd_cc_o_c + relevant part of rule_cc_o_c)
  131. quiet_cmd_cc_o_c = CC $(quiet_modtag) $@
  132. ifndef CONFIG_MODVERSIONS
  133. cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
  134. else
  135. # When module versioning is enabled the following steps are executed:
  136. # o compile a .tmp_<file>.o from <file>.c
  137. # o if .tmp_<file>.o doesn't contain a __ksymtab version, i.e. does
  138. # not export symbols, we just rename .tmp_<file>.o to <file>.o and
  139. # are done.
  140. # o otherwise, we calculate symbol versions using the good old
  141. # genksyms on the preprocessed source and postprocess them in a way
  142. # that they are usable as a linker script
  143. # o generate <file>.o from .tmp_<file>.o using the linker to
  144. # replace the unresolved symbols __crc_exported_symbol with
  145. # the actual value of the checksum generated by genksyms
  146. cmd_cc_o_c = $(CC) $(c_flags) -c -o $(@D)/.tmp_$(@F) $<
  147. cmd_modversions_c = \
  148. if $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then \
  149. $(call cmd_gensymtypes_c,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \
  150. > $(@D)/.tmp_$(@F:.o=.ver); \
  151. \
  152. $(LD) $(KBUILD_LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \
  153. -T $(@D)/.tmp_$(@F:.o=.ver); \
  154. rm -f $(@D)/.tmp_$(@F) $(@D)/.tmp_$(@F:.o=.ver); \
  155. else \
  156. mv -f $(@D)/.tmp_$(@F) $@; \
  157. fi;
  158. endif
  159. ifdef CONFIG_FTRACE_MCOUNT_RECORD
  160. ifndef CC_USING_RECORD_MCOUNT
  161. # compiler will not generate __mcount_loc use recordmcount or recordmcount.pl
  162. ifdef BUILD_C_RECORDMCOUNT
  163. ifeq ("$(origin RECORDMCOUNT_WARN)", "command line")
  164. RECORDMCOUNT_FLAGS = -w
  165. endif
  166. # Due to recursion, we must skip empty.o.
  167. # The empty.o file is created in the make process in order to determine
  168. # the target endianness and word size. It is made before all other C
  169. # files, including recordmcount.
  170. sub_cmd_record_mcount = \
  171. if [ $(@) != "scripts/mod/empty.o" ]; then \
  172. $(objtree)/scripts/recordmcount $(RECORDMCOUNT_FLAGS) "$(@)"; \
  173. fi;
  174. recordmcount_source := $(srctree)/scripts/recordmcount.c \
  175. $(srctree)/scripts/recordmcount.h
  176. else
  177. sub_cmd_record_mcount = set -e ; perl $(srctree)/scripts/recordmcount.pl "$(ARCH)" \
  178. "$(if $(CONFIG_CPU_BIG_ENDIAN),big,little)" \
  179. "$(if $(CONFIG_64BIT),64,32)" \
  180. "$(OBJDUMP)" "$(OBJCOPY)" "$(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS)" \
  181. "$(LD) $(KBUILD_LDFLAGS)" "$(NM)" "$(RM)" "$(MV)" \
  182. "$(if $(part-of-module),1,0)" "$(@)";
  183. recordmcount_source := $(srctree)/scripts/recordmcount.pl
  184. endif # BUILD_C_RECORDMCOUNT
  185. cmd_record_mcount = \
  186. if [ "$(findstring $(CC_FLAGS_FTRACE),$(_c_flags))" = \
  187. "$(CC_FLAGS_FTRACE)" ]; then \
  188. $(sub_cmd_record_mcount) \
  189. fi;
  190. endif # CC_USING_RECORD_MCOUNT
  191. endif # CONFIG_FTRACE_MCOUNT_RECORD
  192. ifdef CONFIG_STACK_VALIDATION
  193. ifneq ($(SKIP_STACK_VALIDATION),1)
  194. __objtool_obj := $(objtree)/tools/objtool/objtool
  195. objtool_args = $(if $(CONFIG_UNWINDER_ORC),orc generate,check)
  196. objtool_args += $(if $(part-of-module), --module,)
  197. ifndef CONFIG_FRAME_POINTER
  198. objtool_args += --no-fp
  199. endif
  200. ifdef CONFIG_GCOV_KERNEL
  201. objtool_args += --no-unreachable
  202. endif
  203. ifdef CONFIG_RETPOLINE
  204. objtool_args += --retpoline
  205. endif
  206. ifdef CONFIG_MODVERSIONS
  207. objtool_o = $(@D)/.tmp_$(@F)
  208. else
  209. objtool_o = $(@)
  210. endif
  211. # 'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory
  212. # 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file
  213. # 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file
  214. cmd_objtool = $(if $(patsubst y%,, \
  215. $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \
  216. $(__objtool_obj) $(objtool_args) "$(objtool_o)";)
  217. objtool_obj = $(if $(patsubst y%,, \
  218. $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \
  219. $(__objtool_obj))
  220. endif # SKIP_STACK_VALIDATION
  221. endif # CONFIG_STACK_VALIDATION
  222. # Rebuild all objects when objtool changes, or is enabled/disabled.
  223. objtool_dep = $(objtool_obj) \
  224. $(wildcard include/config/orc/unwinder.h \
  225. include/config/stack/validation.h)
  226. define rule_cc_o_c
  227. $(call echo-cmd,checksrc) $(cmd_checksrc) \
  228. $(call cmd_and_fixdep,cc_o_c) \
  229. $(cmd_checkdoc) \
  230. $(call echo-cmd,objtool) $(cmd_objtool) \
  231. $(cmd_modversions_c) \
  232. $(call echo-cmd,record_mcount) $(cmd_record_mcount)
  233. endef
  234. define rule_as_o_S
  235. $(call cmd_and_fixdep,as_o_S) \
  236. $(call echo-cmd,objtool) $(cmd_objtool) \
  237. $(cmd_modversions_S)
  238. endef
  239. # List module undefined symbols (or empty line if not enabled)
  240. ifdef CONFIG_TRIM_UNUSED_KSYMS
  241. cmd_undef_syms = $(NM) $@ | sed -n 's/^ *U //p' | xargs echo
  242. else
  243. cmd_undef_syms = echo
  244. endif
  245. # Built-in and composite module parts
  246. $(obj)/%.o: $(src)/%.c $(recordmcount_source) $(objtool_dep) FORCE
  247. $(call cmd,force_checksrc)
  248. $(call if_changed_rule,cc_o_c)
  249. # Single-part modules are special since we need to mark them in $(MODVERDIR)
  250. $(single-used-m): $(obj)/%.o: $(src)/%.c $(recordmcount_source) $(objtool_dep) FORCE
  251. $(call cmd,force_checksrc)
  252. $(call if_changed_rule,cc_o_c)
  253. @{ echo $(@:.o=.ko); echo $@; \
  254. $(cmd_undef_syms); } > $(MODVERDIR)/$(@F:.o=.mod)
  255. quiet_cmd_cc_lst_c = MKLST $@
  256. cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \
  257. $(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \
  258. System.map $(OBJDUMP) > $@
  259. $(obj)/%.lst: $(src)/%.c FORCE
  260. $(call if_changed_dep,cc_lst_c)
  261. # Compile assembler sources (.S)
  262. # ---------------------------------------------------------------------------
  263. modkern_aflags := $(KBUILD_AFLAGS_KERNEL) $(AFLAGS_KERNEL)
  264. $(real-obj-m) : modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE)
  265. $(real-obj-m:.o=.s): modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE)
  266. # .S file exports must have their C prototypes defined in asm/asm-prototypes.h
  267. # or a file that it includes, in order to get versioned symbols. We build a
  268. # dummy C file that includes asm-prototypes and the EXPORT_SYMBOL lines from
  269. # the .S file (with trailing ';'), and run genksyms on that, to extract vers.
  270. #
  271. # This is convoluted. The .S file must first be preprocessed to run guards and
  272. # expand names, then the resulting exports must be constructed into plain
  273. # EXPORT_SYMBOL(symbol); to build our dummy C file, and that gets preprocessed
  274. # to make the genksyms input.
  275. #
  276. # These mirror gensymtypes_c and co above, keep them in synch.
  277. cmd_gensymtypes_S = \
  278. (echo "\#include <linux/kernel.h>" ; \
  279. echo "\#include <asm/asm-prototypes.h>" ; \
  280. $(CPP) $(a_flags) $< | \
  281. grep "\<___EXPORT_SYMBOL\>" | \
  282. sed 's/.*___EXPORT_SYMBOL[[:space:]]*\([a-zA-Z0-9_]*\)[[:space:]]*,.*/EXPORT_SYMBOL(\1);/' ) | \
  283. $(CPP) -D__GENKSYMS__ $(c_flags) -xc - | \
  284. $(GENKSYMS) $(if $(1), -T $(2)) \
  285. $(patsubst y,-R,$(CONFIG_MODULE_REL_CRCS)) \
  286. $(if $(KBUILD_PRESERVE),-p) \
  287. -r $(firstword $(wildcard $(2:.symtypes=.symref) /dev/null))
  288. quiet_cmd_cc_symtypes_S = SYM $(quiet_modtag) $@
  289. cmd_cc_symtypes_S = \
  290. set -e; \
  291. $(call cmd_gensymtypes_S,true,$@) >/dev/null; \
  292. test -s $@ || rm -f $@
  293. $(obj)/%.symtypes : $(src)/%.S FORCE
  294. $(call cmd,cc_symtypes_S)
  295. quiet_cmd_cpp_s_S = CPP $(quiet_modtag) $@
  296. cmd_cpp_s_S = $(CPP) $(a_flags) -o $@ $<
  297. $(obj)/%.s: $(src)/%.S FORCE
  298. $(call if_changed_dep,cpp_s_S)
  299. quiet_cmd_as_o_S = AS $(quiet_modtag) $@
  300. ifndef CONFIG_MODVERSIONS
  301. cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
  302. else
  303. ASM_PROTOTYPES := $(wildcard $(srctree)/arch/$(SRCARCH)/include/asm/asm-prototypes.h)
  304. ifeq ($(ASM_PROTOTYPES),)
  305. cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
  306. else
  307. # versioning matches the C process described above, with difference that
  308. # we parse asm-prototypes.h C header to get function definitions.
  309. cmd_as_o_S = $(CC) $(a_flags) -c -o $(@D)/.tmp_$(@F) $<
  310. cmd_modversions_S = \
  311. if $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then \
  312. $(call cmd_gensymtypes_S,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \
  313. > $(@D)/.tmp_$(@F:.o=.ver); \
  314. \
  315. $(LD) $(KBUILD_LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \
  316. -T $(@D)/.tmp_$(@F:.o=.ver); \
  317. rm -f $(@D)/.tmp_$(@F) $(@D)/.tmp_$(@F:.o=.ver); \
  318. else \
  319. mv -f $(@D)/.tmp_$(@F) $@; \
  320. fi;
  321. endif
  322. endif
  323. $(obj)/%.o: $(src)/%.S $(objtool_dep) FORCE
  324. $(call if_changed_rule,as_o_S)
  325. targets += $(filter-out $(subdir-obj-y), $(real-obj-y)) $(real-obj-m) $(lib-y)
  326. targets += $(extra-y) $(MAKECMDGOALS) $(always)
  327. # Linker scripts preprocessor (.lds.S -> .lds)
  328. # ---------------------------------------------------------------------------
  329. quiet_cmd_cpp_lds_S = LDS $@
  330. cmd_cpp_lds_S = $(CPP) $(cpp_flags) -P -U$(ARCH) \
  331. -D__ASSEMBLY__ -DLINKER_SCRIPT -o $@ $<
  332. $(obj)/%.lds: $(src)/%.lds.S FORCE
  333. $(call if_changed_dep,cpp_lds_S)
  334. # ASN.1 grammar
  335. # ---------------------------------------------------------------------------
  336. quiet_cmd_asn1_compiler = ASN.1 $@
  337. cmd_asn1_compiler = $(objtree)/scripts/asn1_compiler $< \
  338. $(subst .h,.c,$@) $(subst .c,.h,$@)
  339. $(obj)/%.asn1.c $(obj)/%.asn1.h: $(src)/%.asn1 $(objtree)/scripts/asn1_compiler
  340. $(call cmd,asn1_compiler)
  341. # Build the compiled-in targets
  342. # ---------------------------------------------------------------------------
  343. # To build objects in subdirs, we need to descend into the directories
  344. $(sort $(subdir-obj-y)): $(subdir-ym) ;
  345. #
  346. # Rule to compile a set of .o files into one .o file
  347. #
  348. ifdef builtin-target
  349. # built-in.a archives are made with no symbol table or index which
  350. # makes them small and fast, but unable to be used by the linker.
  351. # scripts/link-vmlinux.sh builds an aggregate built-in.a with a symbol
  352. # table and index.
  353. quiet_cmd_ar_builtin = AR $@
  354. cmd_ar_builtin = rm -f $@; \
  355. $(AR) rcSTP$(KBUILD_ARFLAGS) $@ $(filter $(real-obj-y), $^)
  356. $(builtin-target): $(real-obj-y) FORCE
  357. $(call if_changed,ar_builtin)
  358. targets += $(builtin-target)
  359. endif # builtin-target
  360. #
  361. # Rule to create modules.order file
  362. #
  363. # Create commands to either record .ko file or cat modules.order from
  364. # a subdirectory
  365. modorder-cmds = \
  366. $(foreach m, $(modorder), \
  367. $(if $(filter %/modules.order, $m), \
  368. cat $m;, echo kernel/$m;))
  369. $(modorder-target): $(subdir-ym) FORCE
  370. $(Q)(cat /dev/null; $(modorder-cmds)) > $@
  371. #
  372. # Rule to compile a set of .o files into one .a file
  373. #
  374. ifdef lib-target
  375. quiet_cmd_link_l_target = AR $@
  376. # lib target archives do get a symbol table and index
  377. cmd_link_l_target = rm -f $@; $(AR) rcsTP$(KBUILD_ARFLAGS) $@ $(lib-y)
  378. $(lib-target): $(lib-y) FORCE
  379. $(call if_changed,link_l_target)
  380. targets += $(lib-target)
  381. dummy-object = $(obj)/.lib_exports.o
  382. ksyms-lds = $(dot-target).lds
  383. quiet_cmd_export_list = EXPORTS $@
  384. cmd_export_list = $(OBJDUMP) -h $< | \
  385. sed -ne '/___ksymtab/s/.*+\([^ ]*\).*/EXTERN(\1)/p' >$(ksyms-lds);\
  386. rm -f $(dummy-object);\
  387. echo | $(CC) $(a_flags) -c -o $(dummy-object) -x assembler -;\
  388. $(LD) $(ld_flags) -r -o $@ -T $(ksyms-lds) $(dummy-object);\
  389. rm $(dummy-object) $(ksyms-lds)
  390. $(obj)/lib-ksyms.o: $(lib-target) FORCE
  391. $(call if_changed,export_list)
  392. targets += $(obj)/lib-ksyms.o
  393. endif
  394. #
  395. # Rule to link composite objects
  396. #
  397. # Composite objects are specified in kbuild makefile as follows:
  398. # <composite-object>-objs := <list of .o files>
  399. # or
  400. # <composite-object>-y := <list of .o files>
  401. # or
  402. # <composite-object>-m := <list of .o files>
  403. # The -m syntax only works if <composite object> is a module
  404. link_multi_deps = \
  405. $(filter $(addprefix $(obj)/, \
  406. $($(subst $(obj)/,,$(@:.o=-objs))) \
  407. $($(subst $(obj)/,,$(@:.o=-y))) \
  408. $($(subst $(obj)/,,$(@:.o=-m)))), $^)
  409. quiet_cmd_link_multi-m = LD [M] $@
  410. cmd_link_multi-m = $(LD) $(ld_flags) -r -o $@ $(link_multi_deps) $(cmd_secanalysis)
  411. $(multi-used-m): FORCE
  412. $(call if_changed,link_multi-m)
  413. @{ echo $(@:.o=.ko); echo $(link_multi_deps); \
  414. $(cmd_undef_syms); } > $(MODVERDIR)/$(@F:.o=.mod)
  415. $(call multi_depend, $(multi-used-m), .o, -objs -y -m)
  416. targets += $(multi-used-m)
  417. targets := $(filter-out $(PHONY), $(targets))
  418. # Add intermediate targets:
  419. # When building objects with specific suffix patterns, add intermediate
  420. # targets that the final targets are derived from.
  421. intermediate_targets = $(foreach sfx, $(2), \
  422. $(patsubst %$(strip $(1)),%$(sfx), \
  423. $(filter %$(strip $(1)), $(targets))))
  424. # %.asn1.o <- %.asn1.[ch] <- %.asn1
  425. # %.dtb.o <- %.dtb.S <- %.dtb <- %.dts
  426. # %.lex.o <- %.lex.c <- %.l
  427. # %.tab.o <- %.tab.[ch] <- %.y
  428. targets += $(call intermediate_targets, .asn1.o, .asn1.c .asn1.h) \
  429. $(call intermediate_targets, .dtb.o, .dtb.S .dtb) \
  430. $(call intermediate_targets, .lex.o, .lex.c) \
  431. $(call intermediate_targets, .tab.o, .tab.c .tab.h)
  432. # Descending
  433. # ---------------------------------------------------------------------------
  434. PHONY += $(subdir-ym)
  435. $(subdir-ym):
  436. $(Q)$(MAKE) $(build)=$@ need-builtin=$(if $(findstring $@,$(subdir-obj-y)),1)
  437. # Add FORCE to the prequisites of a target to force it to be always rebuilt.
  438. # ---------------------------------------------------------------------------
  439. PHONY += FORCE
  440. FORCE:
  441. # Read all saved command lines and dependencies for the $(targets) we
  442. # may be building above, using $(if_changed{,_dep}). As an
  443. # optimization, we don't need to read them if the target does not
  444. # exist, we will rebuild anyway in that case.
  445. cmd_files := $(wildcard $(foreach f,$(sort $(targets)),$(dir $(f)).$(notdir $(f)).cmd))
  446. ifneq ($(cmd_files),)
  447. include $(cmd_files)
  448. endif
  449. ifneq ($(KBUILD_SRC),)
  450. # Create directories for object files if they do not exist
  451. obj-dirs := $(sort $(obj) $(patsubst %/,%, $(dir $(targets))))
  452. # If cmd_files exist, their directories apparently exist. Skip mkdir.
  453. exist-dirs := $(sort $(patsubst %/,%, $(dir $(cmd_files))))
  454. obj-dirs := $(strip $(filter-out $(exist-dirs), $(obj-dirs)))
  455. ifneq ($(obj-dirs),)
  456. $(shell mkdir -p $(obj-dirs))
  457. endif
  458. endif
  459. # Some files contained in $(targets) are intermediate artifacts.
  460. # We never want them to be removed automatically.
  461. .SECONDARY: $(targets)
  462. .PHONY: $(PHONY)