Makefile.build 19 KB

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