at commit 3110d09b

1 # SPDX-License-Identifier: GPL-2.0-only
2
3 PHONY := __default
4 __default: vmlinux.a
5
6 include include/config/auto.conf
7 include $(srctree)/scripts/Kbuild.include
8 include $(srctree)/scripts/Makefile.lib
9
10 # Link of built-in-fixup.a
11 # ---------------------------------------------------------------------------
12
13 quiet_cmd_ar_builtin_fixup = AR $@
14 cmd_ar_builtin_fixup = \
15 rm -f $@; \
16 $(AR) cDPrST $@ $(KBUILD_VMLINUX_OBJS); \
17 $(AR) mPi $$($(AR) t $@ | sed -n 1p) $@ $$($(AR) t $@ | grep -F -f $(srctree)/scripts/head-object-list.txt)
18
19 targets += built-in-fixup.a
20 built-in-fixup.a: $(KBUILD_VMLINUX_OBJS) scripts/head-object-list.txt FORCE
21 $(call if_changed,ar_builtin_fixup)
22
23 ifdef CONFIG_LTO_CLANG_THIN_DIST
24
25 quiet_cmd_builtin.order = GEN $@
26 cmd_builtin.order = $(AR) t $< > $@
27
28 targets += builtin.order
29 builtin.order: built-in-fixup.a FORCE
30 $(call if_changed,builtin.order)
31
32 quiet_cmd_ld_thinlto_index = LD $@
33 cmd_ld_thinlto_index = \
34 $(LD) $(KBUILD_LDFLAGS) -r --thinlto-index-only=$@ @$<
35
36 targets += vmlinux.thinlto-index
37 vmlinux.thinlto-index: builtin.order FORCE
38 $(call if_changed,ld_thinlto_index)
39
40 quiet_cmd_ar_vmlinux.a = GEN $@
41 cmd_ar_vmlinux.a = \
42 rm -f $@; \
43 while read -r obj; do \
44 if grep -Fqx $${obj} $(word 2, $^); then \
45 echo $${obj%.o}.thinlto-native.o; \
46 else \
47 echo $${obj}; \
48 fi; \
49 done < $< | xargs $(AR) cDPrS --thin $@
50
51 targets += vmlinux.a
52 vmlinux.a: builtin.order vmlinux.thinlto-index FORCE
53 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.thinlto
54 $(call if_changed,ar_vmlinux.a)
55
56 else
57
58 # vmlinux.a
59 # ---------------------------------------------------------------------------
60
61 targets += vmlinux.a
62 vmlinux.a: built-in-fixup.a FORCE
63 $(call if_changed,copy)
64
65 endif
66
67 # Add FORCE to the prerequisites of a target to force it to be always rebuilt.
68 # ---------------------------------------------------------------------------
69
70 PHONY += FORCE
71 FORCE:
72
73 # Read all saved command lines and dependencies for the $(targets) we
74 # may be building above, using $(if_changed{,_dep}). As an
75 # optimization, we don't need to read them if the target does not
76 # exist, we will rebuild anyway in that case.
77
78 existing-targets := $(wildcard $(sort $(targets)))
79
80 -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
81
82 .PHONY: $(PHONY)