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
1291KBUILD_VMLINUX_OBJS := built-in.a $(patsubst %/, %/lib.a, $(filter %/, $(libs-y)))1291KBUILD_VMLINUX_OBJS := built-in.a $(patsubst %/, %/lib.a, $(filter %/, $(libs-y)))
1292KBUILD_VMLINUX_LIBS := $(filter-out %/, $(libs-y))1292KBUILD_VMLINUX_LIBS := $(filter-out %/, $(libs-y))
1293 1293
1294export KBUILD_VMLINUX_LIBS1294export KBUILD_VMLINUX_OBJS KBUILD_VMLINUX_LIBS
1295export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds1295export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds
1296 1296
1297ifdef CONFIG_TRIM_UNUSED_KSYMS1297ifdef CONFIG_TRIM_UNUSED_KSYMS
@@ -1300,16 +1300,12 @@ ifdef CONFIG_TRIM_UNUSED_KSYMS · 2 unmodified lines
1300KBUILD_MODULES := y1300KBUILD_MODULES := y
1301endif1301endif
1302 1302
1303# '$(AR) mPi' needs 'T' to workaround the bug of llvm-ar <= 141303PHONY += vmlinux_a
1304quiet_cmd_ar_vmlinux.a = AR $@1304vmlinux_a: $(KBUILD_VMLINUX_OBJS) scripts/head-object-list.txt FORCE
1305 cmd_ar_vmlinux.a = \1305 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.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)
1309 1306
1310targets += vmlinux.a1307vmlinux.a: vmlinux_a
1311vmlinux.a: $(KBUILD_VMLINUX_OBJS) scripts/head-object-list.txt FORCE1308 @:
1312 $(call if_changed,ar_vmlinux.a)
1313 1309
1314PHONY += vmlinux_o1310PHONY += vmlinux_o
1315vmlinux_o: vmlinux.a $(KBUILD_VMLINUX_LIBS)1311vmlinux_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
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
24# vmlinux.a
25# ---------------------------------------------------------------------------
26
27targets += vmlinux.a
28vmlinux.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
34PHONY += FORCE
35FORCE:
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
42existing-targets := $(wildcard $(sort $(targets)))
43
44-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
45
46.PHONY: $(PHONY)