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