History

kbuild: move vmlinux.a build rule to scripts/Makefile.vmlinux_a

Move the build rule for vmlinux.a to a separate file in preparation for supporting distributed builds with Clang ThinLTO.

Masahiro Yamada committed 5 months ago

Commit 9c72d261 parent d7231d82 files · +52 −10Browse files

Unified · Split

2 files
  1. Makefile +6 −10
  2. scripts/Makefile.vmlinux_a +46 −0
Makefile+6−10
@@ -1291,7 +1291,7 @@ export ARCH_DRIVERS := $(drivers-y) $(drivers-m) · 1290 unmodified lines
12911291 KBUILD_VMLINUX_OBJS := built-in.a $(patsubst %/, %/lib.a, $(filter %/, $(libs-y)))
12921292 KBUILD_VMLINUX_LIBS := $(filter-out %/, $(libs-y))
12931293
1294−export KBUILD_VMLINUX_LIBS
1294+export KBUILD_VMLINUX_OBJS KBUILD_VMLINUX_LIBS
12951295 export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds
12961296
12971297 ifdef CONFIG_TRIM_UNUSED_KSYMS
@@ -1300,16 +1300,12 @@ ifdef CONFIG_TRIM_UNUSED_KSYMS · 2 unmodified lines
13001300 KBUILD_MODULES := y
13011301 endif
13021302
1303−# '$(AR) mPi' needs 'T' to workaround the bug of llvm-ar <= 14
1304−quiet_cmd_ar_vmlinux.a = AR $@
1305− cmd_ar_vmlinux.a = \
1306− rm -f $@; \
1307− $(AR) cDPrST $@ $(KBUILD_VMLINUX_OBJS); \
1308− $(AR) mPiT $$($(AR) t $@ | sed -n 1p) $@ $$($(AR) t $@ | grep -F -f $(srctree)/scripts/head-object-list.txt)
1303+PHONY += vmlinux_a
1304+vmlinux_a: $(KBUILD_VMLINUX_OBJS) scripts/head-object-list.txt FORCE
1305+ $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vmlinux_a
13091306
1310−targets += vmlinux.a
1311−vmlinux.a: $(KBUILD_VMLINUX_OBJS) scripts/head-object-list.txt FORCE
1312− $(call if_changed,ar_vmlinux.a)
1307+vmlinux.a: vmlinux_a
1308+ @:
13131309
13141310 PHONY += vmlinux_o
13151311 vmlinux_o: vmlinux.a $(KBUILD_VMLINUX_LIBS)
scripts/Makefile.vmlinux_a+46−0
@@ -0,0 +1,46 @@
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+# '$(AR) mPi' needs 'T' to workaround the bug of llvm-ar <= 14
14+quiet_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+
20+targets += built-in-fixup.a
21+built-in-fixup.a: $(KBUILD_VMLINUX_OBJS) scripts/head-object-list.txt FORCE
22+ $(call if_changed,ar_builtin_fixup)
23+
24+# vmlinux.a
25+# ---------------------------------------------------------------------------
26+
27+targets += vmlinux.a
28+vmlinux.a: built-in-fixup.a FORCE
29+ $(call if_changed,copy)
30+
31+# Add FORCE to the prerequisites of a target to force it to be always rebuilt.
32+# ---------------------------------------------------------------------------
33+
34+PHONY += FORCE
35+FORCE:
36+
37+# Read all saved command lines and dependencies for the $(targets) we
38+# may be building above, using $(if_changed{,_dep}). As an
39+# optimization, we don't need to read them if the target does not
40+# exist, we will rebuild anyway in that case.
41+
42+existing-targets := $(wildcard $(sort $(targets)))
43+
44+-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
45+
46+.PHONY: $(PHONY)