projects/linux·blob v7.2-rc7 · refs

82 lines · 2.3 KiB

1# SPDX-License-Identifier: GPL-2.0-only
2
3PHONY := __default
4__default: vmlinux.a
5
6include include/config/auto.conf
7include $(srctree)/scripts/Kbuild.include
8include $(srctree)/scripts/Makefile.lib
9
10# Link of built-in-fixup.a
11# ---------------------------------------------------------------------------
12
13quiet_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
19targets += built-in-fixup.a
20built-in-fixup.a: $(KBUILD_VMLINUX_OBJS) scripts/head-object-list.txt FORCE
21 $(call if_changed,ar_builtin_fixup)
22
23ifdef CONFIG_LTO_CLANG_THIN_DIST
24
25quiet_cmd_builtin.order = GEN $@
26 cmd_builtin.order = $(AR) t $< > $@
27
28targets += builtin.order
29builtin.order: built-in-fixup.a FORCE
30 $(call if_changed,builtin.order)
31
32quiet_cmd_ld_thinlto_index = LD $@
33 cmd_ld_thinlto_index = \
34 $(LD) $(KBUILD_LDFLAGS) -r --thinlto-index-only=$@ @$<
35
36targets += vmlinux.thinlto-index
37vmlinux.thinlto-index: builtin.order FORCE
38 $(call if_changed,ld_thinlto_index)
39
40quiet_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
51targets += vmlinux.a
52vmlinux.a: builtin.order vmlinux.thinlto-index FORCE
53 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.thinlto
54 $(call if_changed,ar_vmlinux.a)
55
56else
57
58# vmlinux.a
59# ---------------------------------------------------------------------------
60
61targets += vmlinux.a
62vmlinux.a: built-in-fixup.a FORCE
63 $(call if_changed,copy)
64
65endif
66
67# Add FORCE to the prerequisites of a target to force it to be always rebuilt.
68# ---------------------------------------------------------------------------
69
70PHONY += FORCE
71FORCE:
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
78existing-targets := $(wildcard $(sort $(targets)))
79
80-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
81
82.PHONY: $(PHONY)