Makefile.build 19 KB

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