Makefile.build 19 KB

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