Makefile.build 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  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. $(patsubst y,-R,$(CONFIG_MODULE_REL_CRCS)) \
  133. $(if $(KBUILD_PRESERVE),-p) \
  134. -r $(firstword $(wildcard $(2:.symtypes=.symref) /dev/null))
  135. quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@
  136. cmd_cc_symtypes_c = \
  137. set -e; \
  138. $(call cmd_gensymtypes_c,true,$@) >/dev/null; \
  139. test -s $@ || rm -f $@
  140. $(obj)/%.symtypes : $(src)/%.c FORCE
  141. $(call cmd,cc_symtypes_c)
  142. # LLVM assembly
  143. # Generate .ll files from .c
  144. quiet_cmd_cc_ll_c = CC $(quiet_modtag) $@
  145. cmd_cc_ll_c = $(CC) $(c_flags) -emit-llvm -S -o $@ $<
  146. $(obj)/%.ll: $(src)/%.c FORCE
  147. $(call if_changed_dep,cc_ll_c)
  148. # C (.c) files
  149. # The C file is compiled and updated dependency information is generated.
  150. # (See cmd_cc_o_c + relevant part of rule_cc_o_c)
  151. quiet_cmd_cc_o_c = CC $(quiet_modtag) $@
  152. ifndef CONFIG_MODVERSIONS
  153. cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
  154. else
  155. # When module versioning is enabled the following steps are executed:
  156. # o compile a .tmp_<file>.o from <file>.c
  157. # o if .tmp_<file>.o doesn't contain a __ksymtab version, i.e. does
  158. # not export symbols, we just rename .tmp_<file>.o to <file>.o and
  159. # are done.
  160. # o otherwise, we calculate symbol versions using the good old
  161. # genksyms on the preprocessed source and postprocess them in a way
  162. # that they are usable as a linker script
  163. # o generate <file>.o from .tmp_<file>.o using the linker to
  164. # replace the unresolved symbols __crc_exported_symbol with
  165. # the actual value of the checksum generated by genksyms
  166. cmd_cc_o_c = $(CC) $(c_flags) -c -o $(@D)/.tmp_$(@F) $<
  167. cmd_modversions_c = \
  168. if $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then \
  169. $(call cmd_gensymtypes_c,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \
  170. > $(@D)/.tmp_$(@F:.o=.ver); \
  171. \
  172. $(LD) $(LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \
  173. -T $(@D)/.tmp_$(@F:.o=.ver); \
  174. rm -f $(@D)/.tmp_$(@F) $(@D)/.tmp_$(@F:.o=.ver); \
  175. else \
  176. mv -f $(@D)/.tmp_$(@F) $@; \
  177. fi;
  178. endif
  179. ifdef CONFIG_FTRACE_MCOUNT_RECORD
  180. ifdef BUILD_C_RECORDMCOUNT
  181. ifeq ("$(origin RECORDMCOUNT_WARN)", "command line")
  182. RECORDMCOUNT_FLAGS = -w
  183. endif
  184. # Due to recursion, we must skip empty.o.
  185. # The empty.o file is created in the make process in order to determine
  186. # the target endianness and word size. It is made before all other C
  187. # files, including recordmcount.
  188. sub_cmd_record_mcount = \
  189. if [ $(@) != "scripts/mod/empty.o" ]; then \
  190. $(objtree)/scripts/recordmcount $(RECORDMCOUNT_FLAGS) "$(@)"; \
  191. fi;
  192. recordmcount_source := $(srctree)/scripts/recordmcount.c \
  193. $(srctree)/scripts/recordmcount.h
  194. else
  195. sub_cmd_record_mcount = set -e ; perl $(srctree)/scripts/recordmcount.pl "$(ARCH)" \
  196. "$(if $(CONFIG_CPU_BIG_ENDIAN),big,little)" \
  197. "$(if $(CONFIG_64BIT),64,32)" \
  198. "$(OBJDUMP)" "$(OBJCOPY)" "$(CC) $(KBUILD_CFLAGS)" \
  199. "$(LD)" "$(NM)" "$(RM)" "$(MV)" \
  200. "$(if $(part-of-module),1,0)" "$(@)";
  201. recordmcount_source := $(srctree)/scripts/recordmcount.pl
  202. endif
  203. cmd_record_mcount = \
  204. if [ "$(findstring $(CC_FLAGS_FTRACE),$(_c_flags))" = \
  205. "$(CC_FLAGS_FTRACE)" ]; then \
  206. $(sub_cmd_record_mcount) \
  207. fi;
  208. endif
  209. ifdef CONFIG_STACK_VALIDATION
  210. ifneq ($(SKIP_STACK_VALIDATION),1)
  211. __objtool_obj := $(objtree)/tools/objtool/objtool
  212. objtool_args = check
  213. ifndef CONFIG_FRAME_POINTER
  214. objtool_args += --no-fp
  215. endif
  216. # 'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory
  217. # 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file
  218. # 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file
  219. cmd_objtool = $(if $(patsubst y%,, \
  220. $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \
  221. $(__objtool_obj) $(objtool_args) "$(@)";)
  222. objtool_obj = $(if $(patsubst y%,, \
  223. $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \
  224. $(__objtool_obj))
  225. endif # SKIP_STACK_VALIDATION
  226. endif # CONFIG_STACK_VALIDATION
  227. define rule_cc_o_c
  228. $(call echo-cmd,checksrc) $(cmd_checksrc) \
  229. $(call cmd_and_fixdep,cc_o_c) \
  230. $(cmd_modversions_c) \
  231. $(call echo-cmd,objtool) $(cmd_objtool) \
  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. $(cmd_modversions_S) \
  237. $(call echo-cmd,objtool) $(cmd_objtool)
  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_obj) 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_obj) 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-objs-m) : modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE)
  265. $(real-objs-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,-s _,$(CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX)) \
  286. $(patsubst y,-R,$(CONFIG_MODULE_REL_CRCS)) \
  287. $(if $(KBUILD_PRESERVE),-p) \
  288. -r $(firstword $(wildcard $(2:.symtypes=.symref) /dev/null))
  289. quiet_cmd_cc_symtypes_S = SYM $(quiet_modtag) $@
  290. cmd_cc_symtypes_S = \
  291. set -e; \
  292. $(call cmd_gensymtypes_S,true,$@) >/dev/null; \
  293. test -s $@ || rm -f $@
  294. $(obj)/%.symtypes : $(src)/%.S FORCE
  295. $(call cmd,cc_symtypes_S)
  296. quiet_cmd_cpp_s_S = CPP $(quiet_modtag) $@
  297. cmd_cpp_s_S = $(CPP) $(a_flags) -o $@ $<
  298. $(obj)/%.s: $(src)/%.S FORCE
  299. $(call if_changed_dep,cpp_s_S)
  300. quiet_cmd_as_o_S = AS $(quiet_modtag) $@
  301. ifndef CONFIG_MODVERSIONS
  302. cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
  303. else
  304. ASM_PROTOTYPES := $(wildcard $(srctree)/arch/$(SRCARCH)/include/asm/asm-prototypes.h)
  305. ifeq ($(ASM_PROTOTYPES),)
  306. cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
  307. else
  308. # versioning matches the C process described above, with difference that
  309. # we parse asm-prototypes.h C header to get function definitions.
  310. cmd_as_o_S = $(CC) $(a_flags) -c -o $(@D)/.tmp_$(@F) $<
  311. cmd_modversions_S = \
  312. if $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then \
  313. $(call cmd_gensymtypes_S,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \
  314. > $(@D)/.tmp_$(@F:.o=.ver); \
  315. \
  316. $(LD) $(LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \
  317. -T $(@D)/.tmp_$(@F:.o=.ver); \
  318. rm -f $(@D)/.tmp_$(@F) $(@D)/.tmp_$(@F:.o=.ver); \
  319. else \
  320. mv -f $(@D)/.tmp_$(@F) $@; \
  321. fi;
  322. endif
  323. endif
  324. $(obj)/%.o: $(src)/%.S $(objtool_obj) FORCE
  325. $(call if_changed_rule,as_o_S)
  326. targets += $(real-objs-y) $(real-objs-m) $(lib-y)
  327. targets += $(extra-y) $(MAKECMDGOALS) $(always)
  328. # Linker scripts preprocessor (.lds.S -> .lds)
  329. # ---------------------------------------------------------------------------
  330. quiet_cmd_cpp_lds_S = LDS $@
  331. cmd_cpp_lds_S = $(CPP) $(cpp_flags) -P -C -U$(ARCH) \
  332. -D__ASSEMBLY__ -DLINKER_SCRIPT -o $@ $<
  333. $(obj)/%.lds: $(src)/%.lds.S FORCE
  334. $(call if_changed_dep,cpp_lds_S)
  335. # ASN.1 grammar
  336. # ---------------------------------------------------------------------------
  337. quiet_cmd_asn1_compiler = ASN.1 $@
  338. cmd_asn1_compiler = $(objtree)/scripts/asn1_compiler $< \
  339. $(subst .h,.c,$@) $(subst .c,.h,$@)
  340. .PRECIOUS: $(objtree)/$(obj)/%-asn1.c $(objtree)/$(obj)/%-asn1.h
  341. $(obj)/%-asn1.c $(obj)/%-asn1.h: $(src)/%.asn1 $(objtree)/scripts/asn1_compiler
  342. $(call cmd,asn1_compiler)
  343. # Build the compiled-in targets
  344. # ---------------------------------------------------------------------------
  345. # To build objects in subdirs, we need to descend into the directories
  346. $(sort $(subdir-obj-y)): $(subdir-ym) ;
  347. #
  348. # Rule to compile a set of .o files into one .o file
  349. #
  350. ifdef builtin-target
  351. ifdef CONFIG_THIN_ARCHIVES
  352. cmd_make_builtin = rm -f $@; $(AR) rcSTP$(KBUILD_ARFLAGS)
  353. cmd_make_empty_builtin = rm -f $@; $(AR) rcSTP$(KBUILD_ARFLAGS)
  354. quiet_cmd_link_o_target = AR $@
  355. else
  356. cmd_make_builtin = $(LD) $(ld_flags) -r -o
  357. cmd_make_empty_builtin = rm -f $@; $(AR) rcs$(KBUILD_ARFLAGS)
  358. quiet_cmd_link_o_target = LD $@
  359. endif
  360. # If the list of objects to link is empty, just create an empty built-in.o
  361. cmd_link_o_target = $(if $(strip $(obj-y)),\
  362. $(cmd_make_builtin) $@ $(filter $(obj-y), $^) \
  363. $(cmd_secanalysis),\
  364. $(cmd_make_empty_builtin) $@)
  365. $(builtin-target): $(obj-y) FORCE
  366. $(call if_changed,link_o_target)
  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. ifdef CONFIG_THIN_ARCHIVES
  386. cmd_link_l_target = rm -f $@; $(AR) rcsTP$(KBUILD_ARFLAGS) $@ $(lib-y)
  387. else
  388. cmd_link_l_target = rm -f $@; $(AR) rcs$(KBUILD_ARFLAGS) $@ $(lib-y)
  389. endif
  390. $(lib-target): $(lib-y) FORCE
  391. $(call if_changed,link_l_target)
  392. targets += $(lib-target)
  393. dummy-object = $(obj)/.lib_exports.o
  394. ksyms-lds = $(dot-target).lds
  395. ifdef CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX
  396. ref_prefix = EXTERN(_
  397. else
  398. ref_prefix = EXTERN(
  399. endif
  400. quiet_cmd_export_list = EXPORTS $@
  401. cmd_export_list = $(OBJDUMP) -h $< | \
  402. sed -ne '/___ksymtab/s/.*+\([^ ]*\).*/$(ref_prefix)\1)/p' >$(ksyms-lds);\
  403. rm -f $(dummy-object);\
  404. echo | $(CC) $(a_flags) -c -o $(dummy-object) -x assembler -;\
  405. $(LD) $(ld_flags) -r -o $@ -T $(ksyms-lds) $(dummy-object);\
  406. rm $(dummy-object) $(ksyms-lds)
  407. $(obj)/lib-ksyms.o: $(lib-target) FORCE
  408. $(call if_changed,export_list)
  409. targets += $(obj)/lib-ksyms.o
  410. endif
  411. #
  412. # Rule to link composite objects
  413. #
  414. # Composite objects are specified in kbuild makefile as follows:
  415. # <composite-object>-objs := <list of .o files>
  416. # or
  417. # <composite-object>-y := <list of .o files>
  418. # or
  419. # <composite-object>-m := <list of .o files>
  420. # The -m syntax only works if <composite object> is a module
  421. link_multi_deps = \
  422. $(filter $(addprefix $(obj)/, \
  423. $($(subst $(obj)/,,$(@:.o=-objs))) \
  424. $($(subst $(obj)/,,$(@:.o=-y))) \
  425. $($(subst $(obj)/,,$(@:.o=-m)))), $^)
  426. cmd_link_multi-link = $(LD) $(ld_flags) -r -o $@ $(link_multi_deps) $(cmd_secanalysis)
  427. ifdef CONFIG_THIN_ARCHIVES
  428. quiet_cmd_link_multi-y = AR $@
  429. cmd_link_multi-y = rm -f $@; $(AR) rcSTP$(KBUILD_ARFLAGS) $@ $(link_multi_deps)
  430. else
  431. quiet_cmd_link_multi-y = LD $@
  432. cmd_link_multi-y = $(cmd_link_multi-link)
  433. endif
  434. quiet_cmd_link_multi-m = LD [M] $@
  435. cmd_link_multi-m = $(cmd_link_multi-link)
  436. $(multi-used-y): FORCE
  437. $(call if_changed,link_multi-y)
  438. $(call multi_depend, $(multi-used-y), .o, -objs -y)
  439. $(multi-used-m): FORCE
  440. $(call if_changed,link_multi-m)
  441. @{ echo $(@:.o=.ko); echo $(link_multi_deps); \
  442. $(cmd_undef_syms); } > $(MODVERDIR)/$(@F:.o=.mod)
  443. $(call multi_depend, $(multi-used-m), .o, -objs -y -m)
  444. targets += $(multi-used-y) $(multi-used-m)
  445. # Descending
  446. # ---------------------------------------------------------------------------
  447. PHONY += $(subdir-ym)
  448. $(subdir-ym):
  449. $(Q)$(MAKE) $(build)=$@
  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. targets := $(wildcard $(sort $(targets)))
  459. cmd_files := $(wildcard $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
  460. ifneq ($(cmd_files),)
  461. include $(cmd_files)
  462. endif
  463. # Declare the contents of the .PHONY variable as phony. We keep that
  464. # information in a variable se we can use it in if_changed and friends.
  465. .PHONY: $(PHONY)