Makefile.build 18 KB

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