Makefile.build 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  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. # Don't require recordmcount source for an OOT build.
  193. ifdef KBUILD_EXTMOD
  194. recordmcount_source :=
  195. endif
  196. ifdef CONFIG_STACK_VALIDATION
  197. ifneq ($(SKIP_STACK_VALIDATION),1)
  198. __objtool_obj := $(objtree)/tools/objtool/objtool
  199. objtool_args = $(if $(CONFIG_UNWINDER_ORC),orc generate,check)
  200. objtool_args += $(if $(part-of-module), --module,)
  201. ifndef CONFIG_FRAME_POINTER
  202. objtool_args += --no-fp
  203. endif
  204. ifdef CONFIG_GCOV_KERNEL
  205. objtool_args += --no-unreachable
  206. endif
  207. ifdef CONFIG_RETPOLINE
  208. objtool_args += --retpoline
  209. endif
  210. ifdef CONFIG_MODVERSIONS
  211. objtool_o = $(@D)/.tmp_$(@F)
  212. else
  213. objtool_o = $(@)
  214. endif
  215. # 'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory
  216. # 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file
  217. # 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file
  218. cmd_objtool = $(if $(patsubst y%,, \
  219. $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \
  220. $(__objtool_obj) $(objtool_args) "$(objtool_o)";)
  221. objtool_obj = $(if $(patsubst y%,, \
  222. $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \
  223. $(__objtool_obj))
  224. endif # SKIP_STACK_VALIDATION
  225. endif # CONFIG_STACK_VALIDATION
  226. # Rebuild all objects when objtool changes, or is enabled/disabled.
  227. objtool_dep = $(objtool_obj) \
  228. $(wildcard include/config/orc/unwinder.h \
  229. include/config/stack/validation.h)
  230. define rule_cc_o_c
  231. $(call echo-cmd,checksrc) $(cmd_checksrc) \
  232. $(call cmd_and_fixdep,cc_o_c) \
  233. $(cmd_checkdoc) \
  234. $(call echo-cmd,objtool) $(cmd_objtool) \
  235. $(cmd_modversions_c) \
  236. $(call echo-cmd,record_mcount) $(cmd_record_mcount)
  237. endef
  238. define rule_as_o_S
  239. $(call cmd_and_fixdep,as_o_S) \
  240. $(call echo-cmd,objtool) $(cmd_objtool) \
  241. $(cmd_modversions_S)
  242. endef
  243. # List module undefined symbols (or empty line if not enabled)
  244. ifdef CONFIG_TRIM_UNUSED_KSYMS
  245. cmd_undef_syms = $(NM) $@ | sed -n 's/^ *U //p' | xargs echo
  246. else
  247. cmd_undef_syms = echo
  248. endif
  249. # Built-in and composite module parts
  250. $(obj)/%.o: $(src)/%.c $(recordmcount_source) $(objtool_dep) FORCE
  251. $(call cmd,force_checksrc)
  252. $(call if_changed_rule,cc_o_c)
  253. # Single-part modules are special since we need to mark them in $(MODVERDIR)
  254. $(single-used-m): $(obj)/%.o: $(src)/%.c $(recordmcount_source) $(objtool_dep) FORCE
  255. $(call cmd,force_checksrc)
  256. $(call if_changed_rule,cc_o_c)
  257. @{ echo $(@:.o=.ko); echo $@; \
  258. $(cmd_undef_syms); } > $(MODVERDIR)/$(@F:.o=.mod)
  259. quiet_cmd_cc_lst_c = MKLST $@
  260. cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \
  261. $(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \
  262. System.map $(OBJDUMP) > $@
  263. $(obj)/%.lst: $(src)/%.c FORCE
  264. $(call if_changed_dep,cc_lst_c)
  265. # Compile assembler sources (.S)
  266. # ---------------------------------------------------------------------------
  267. modkern_aflags := $(KBUILD_AFLAGS_KERNEL) $(AFLAGS_KERNEL)
  268. $(real-obj-m) : modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE)
  269. $(real-obj-m:.o=.s): modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE)
  270. # .S file exports must have their C prototypes defined in asm/asm-prototypes.h
  271. # or a file that it includes, in order to get versioned symbols. We build a
  272. # dummy C file that includes asm-prototypes and the EXPORT_SYMBOL lines from
  273. # the .S file (with trailing ';'), and run genksyms on that, to extract vers.
  274. #
  275. # This is convoluted. The .S file must first be preprocessed to run guards and
  276. # expand names, then the resulting exports must be constructed into plain
  277. # EXPORT_SYMBOL(symbol); to build our dummy C file, and that gets preprocessed
  278. # to make the genksyms input.
  279. #
  280. # These mirror gensymtypes_c and co above, keep them in synch.
  281. cmd_gensymtypes_S = \
  282. (echo "\#include <linux/kernel.h>" ; \
  283. echo "\#include <asm/asm-prototypes.h>" ; \
  284. $(CPP) $(a_flags) $< | \
  285. grep "\<___EXPORT_SYMBOL\>" | \
  286. sed 's/.*___EXPORT_SYMBOL[[:space:]]*\([a-zA-Z0-9_]*\)[[:space:]]*,.*/EXPORT_SYMBOL(\1);/' ) | \
  287. $(CPP) -D__GENKSYMS__ $(c_flags) -xc - | \
  288. $(GENKSYMS) $(if $(1), -T $(2)) \
  289. $(patsubst y,-R,$(CONFIG_MODULE_REL_CRCS)) \
  290. $(if $(KBUILD_PRESERVE),-p) \
  291. -r $(firstword $(wildcard $(2:.symtypes=.symref) /dev/null))
  292. quiet_cmd_cc_symtypes_S = SYM $(quiet_modtag) $@
  293. cmd_cc_symtypes_S = \
  294. set -e; \
  295. $(call cmd_gensymtypes_S,true,$@) >/dev/null; \
  296. test -s $@ || rm -f $@
  297. $(obj)/%.symtypes : $(src)/%.S FORCE
  298. $(call cmd,cc_symtypes_S)
  299. quiet_cmd_cpp_s_S = CPP $(quiet_modtag) $@
  300. cmd_cpp_s_S = $(CPP) $(a_flags) -o $@ $<
  301. $(obj)/%.s: $(src)/%.S FORCE
  302. $(call if_changed_dep,cpp_s_S)
  303. quiet_cmd_as_o_S = AS $(quiet_modtag) $@
  304. ifndef CONFIG_MODVERSIONS
  305. cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
  306. else
  307. ASM_PROTOTYPES := $(wildcard $(srctree)/arch/$(SRCARCH)/include/asm/asm-prototypes.h)
  308. ifeq ($(ASM_PROTOTYPES),)
  309. cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
  310. else
  311. # versioning matches the C process described above, with difference that
  312. # we parse asm-prototypes.h C header to get function definitions.
  313. cmd_as_o_S = $(CC) $(a_flags) -c -o $(@D)/.tmp_$(@F) $<
  314. cmd_modversions_S = \
  315. if $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then \
  316. $(call cmd_gensymtypes_S,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \
  317. > $(@D)/.tmp_$(@F:.o=.ver); \
  318. \
  319. $(LD) $(KBUILD_LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \
  320. -T $(@D)/.tmp_$(@F:.o=.ver); \
  321. rm -f $(@D)/.tmp_$(@F) $(@D)/.tmp_$(@F:.o=.ver); \
  322. else \
  323. mv -f $(@D)/.tmp_$(@F) $@; \
  324. fi;
  325. endif
  326. endif
  327. $(obj)/%.o: $(src)/%.S $(objtool_dep) FORCE
  328. $(call if_changed_rule,as_o_S)
  329. targets += $(filter-out $(subdir-obj-y), $(real-obj-y)) $(real-obj-m) $(lib-y)
  330. targets += $(extra-y) $(MAKECMDGOALS) $(always)
  331. # Linker scripts preprocessor (.lds.S -> .lds)
  332. # ---------------------------------------------------------------------------
  333. quiet_cmd_cpp_lds_S = LDS $@
  334. cmd_cpp_lds_S = $(CPP) $(cpp_flags) -P -U$(ARCH) \
  335. -D__ASSEMBLY__ -DLINKER_SCRIPT -o $@ $<
  336. $(obj)/%.lds: $(src)/%.lds.S FORCE
  337. $(call if_changed_dep,cpp_lds_S)
  338. # ASN.1 grammar
  339. # ---------------------------------------------------------------------------
  340. quiet_cmd_asn1_compiler = ASN.1 $@
  341. cmd_asn1_compiler = $(objtree)/scripts/asn1_compiler $< \
  342. $(subst .h,.c,$@) $(subst .c,.h,$@)
  343. $(obj)/%.asn1.c $(obj)/%.asn1.h: $(src)/%.asn1 $(objtree)/scripts/asn1_compiler
  344. $(call cmd,asn1_compiler)
  345. # Build the compiled-in targets
  346. # ---------------------------------------------------------------------------
  347. # To build objects in subdirs, we need to descend into the directories
  348. $(sort $(subdir-obj-y)): $(subdir-ym) ;
  349. #
  350. # Rule to compile a set of .o files into one .o file
  351. #
  352. ifdef builtin-target
  353. # built-in.a archives are made with no symbol table or index which
  354. # makes them small and fast, but unable to be used by the linker.
  355. # scripts/link-vmlinux.sh builds an aggregate built-in.a with a symbol
  356. # table and index.
  357. quiet_cmd_ar_builtin = AR $@
  358. cmd_ar_builtin = rm -f $@; \
  359. $(AR) rcSTP$(KBUILD_ARFLAGS) $@ $(filter $(real-obj-y), $^)
  360. $(builtin-target): $(real-obj-y) FORCE
  361. $(call if_changed,ar_builtin)
  362. targets += $(builtin-target)
  363. endif # builtin-target
  364. #
  365. # Rule to create modules.order file
  366. #
  367. # Create commands to either record .ko file or cat modules.order from
  368. # a subdirectory
  369. modorder-cmds = \
  370. $(foreach m, $(modorder), \
  371. $(if $(filter %/modules.order, $m), \
  372. cat $m;, echo kernel/$m;))
  373. $(modorder-target): $(subdir-ym) FORCE
  374. $(Q)(cat /dev/null; $(modorder-cmds)) > $@
  375. #
  376. # Rule to compile a set of .o files into one .a file
  377. #
  378. ifdef lib-target
  379. quiet_cmd_link_l_target = AR $@
  380. # lib target archives do get a symbol table and index
  381. cmd_link_l_target = rm -f $@; $(AR) rcsTP$(KBUILD_ARFLAGS) $@ $(lib-y)
  382. $(lib-target): $(lib-y) FORCE
  383. $(call if_changed,link_l_target)
  384. targets += $(lib-target)
  385. dummy-object = $(obj)/.lib_exports.o
  386. ksyms-lds = $(dot-target).lds
  387. quiet_cmd_export_list = EXPORTS $@
  388. cmd_export_list = $(OBJDUMP) -h $< | \
  389. sed -ne '/___ksymtab/s/.*+\([^ ]*\).*/EXTERN(\1)/p' >$(ksyms-lds);\
  390. rm -f $(dummy-object);\
  391. echo | $(CC) $(a_flags) -c -o $(dummy-object) -x assembler -;\
  392. $(LD) $(ld_flags) -r -o $@ -T $(ksyms-lds) $(dummy-object);\
  393. rm $(dummy-object) $(ksyms-lds)
  394. $(obj)/lib-ksyms.o: $(lib-target) FORCE
  395. $(call if_changed,export_list)
  396. targets += $(obj)/lib-ksyms.o
  397. endif
  398. #
  399. # Rule to link composite objects
  400. #
  401. # Composite objects are specified in kbuild makefile as follows:
  402. # <composite-object>-objs := <list of .o files>
  403. # or
  404. # <composite-object>-y := <list of .o files>
  405. # or
  406. # <composite-object>-m := <list of .o files>
  407. # The -m syntax only works if <composite object> is a module
  408. link_multi_deps = \
  409. $(filter $(addprefix $(obj)/, \
  410. $($(subst $(obj)/,,$(@:.o=-objs))) \
  411. $($(subst $(obj)/,,$(@:.o=-y))) \
  412. $($(subst $(obj)/,,$(@:.o=-m)))), $^)
  413. quiet_cmd_link_multi-m = LD [M] $@
  414. cmd_link_multi-m = $(LD) $(ld_flags) -r -o $@ $(link_multi_deps) $(cmd_secanalysis)
  415. $(multi-used-m): FORCE
  416. $(call if_changed,link_multi-m)
  417. @{ echo $(@:.o=.ko); echo $(link_multi_deps); \
  418. $(cmd_undef_syms); } > $(MODVERDIR)/$(@F:.o=.mod)
  419. $(call multi_depend, $(multi-used-m), .o, -objs -y -m)
  420. targets += $(multi-used-m)
  421. targets := $(filter-out $(PHONY), $(targets))
  422. # Add intermediate targets:
  423. # When building objects with specific suffix patterns, add intermediate
  424. # targets that the final targets are derived from.
  425. intermediate_targets = $(foreach sfx, $(2), \
  426. $(patsubst %$(strip $(1)),%$(sfx), \
  427. $(filter %$(strip $(1)), $(targets))))
  428. # %.asn1.o <- %.asn1.[ch] <- %.asn1
  429. # %.dtb.o <- %.dtb.S <- %.dtb <- %.dts
  430. # %.lex.o <- %.lex.c <- %.l
  431. # %.tab.o <- %.tab.[ch] <- %.y
  432. targets += $(call intermediate_targets, .asn1.o, .asn1.c .asn1.h) \
  433. $(call intermediate_targets, .dtb.o, .dtb.S .dtb) \
  434. $(call intermediate_targets, .lex.o, .lex.c) \
  435. $(call intermediate_targets, .tab.o, .tab.c .tab.h)
  436. # Descending
  437. # ---------------------------------------------------------------------------
  438. PHONY += $(subdir-ym)
  439. $(subdir-ym):
  440. $(Q)$(MAKE) $(build)=$@ need-builtin=$(if $(findstring $@,$(subdir-obj-y)),1)
  441. # Add FORCE to the prequisites of a target to force it to be always rebuilt.
  442. # ---------------------------------------------------------------------------
  443. PHONY += FORCE
  444. FORCE:
  445. # Read all saved command lines and dependencies for the $(targets) we
  446. # may be building above, using $(if_changed{,_dep}). As an
  447. # optimization, we don't need to read them if the target does not
  448. # exist, we will rebuild anyway in that case.
  449. cmd_files := $(wildcard $(foreach f,$(sort $(targets)),$(dir $(f)).$(notdir $(f)).cmd))
  450. ifneq ($(cmd_files),)
  451. include $(cmd_files)
  452. endif
  453. ifneq ($(KBUILD_SRC),)
  454. # Create directories for object files if they do not exist
  455. obj-dirs := $(sort $(obj) $(patsubst %/,%, $(dir $(targets))))
  456. # If cmd_files exist, their directories apparently exist. Skip mkdir.
  457. exist-dirs := $(sort $(patsubst %/,%, $(dir $(cmd_files))))
  458. obj-dirs := $(strip $(filter-out $(exist-dirs), $(obj-dirs)))
  459. ifneq ($(obj-dirs),)
  460. $(shell mkdir -p $(obj-dirs))
  461. endif
  462. endif
  463. # Some files contained in $(targets) are intermediate artifacts.
  464. # We never want them to be removed automatically.
  465. .SECONDARY: $(targets)
  466. .PHONY: $(PHONY)