summaryrefslogtreecommitdiff
path: root/scripts/Makefile.vmlinux_a
diff options
context:
space:
mode:
authorMasahiro Yamada <masahiroy@kernel.org>2026-05-29 11:53:44 -0700
committerNathan Chancellor <nathan@kernel.org>2026-05-29 13:44:29 -0700
commit9c72d26e9fe3be79dd1d8a2ba00a033503ffd27d (patch)
tree7582dadc4a28f0a04395e1a8cf73205df617646e /scripts/Makefile.vmlinux_a
parentd7231d8cb262b1e350c00271bf53d54414b4f3b1 (diff)
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. Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Tested-by: Rong Xu <xur@google.com> Tested-by: Piotr Gorski <piotrgorski@cachyos.org> Tested-by: Nathan Chancellor <nathan@kernel.org> Signed-off-by: Rong Xu <xur@google.com> Link: https://patch.msgid.link/20260529185347.2418373-2-xur@google.com [nathan: Squash in forward fix from Rong around '--thin' to $(AR) https://patch.msgid.link/20260529185347.2418373-3-xur@google.com] Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Diffstat (limited to 'scripts/Makefile.vmlinux_a')
-rw-r--r--scripts/Makefile.vmlinux_a46
1 files changed, 46 insertions, 0 deletions
diff --git a/scripts/Makefile.vmlinux_a b/scripts/Makefile.vmlinux_a
new file mode 100644
index 000000000000..650d44330d1f
--- /dev/null
+++ b/scripts/Makefile.vmlinux_a
@@ -0,0 +1,46 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+PHONY := __default
+__default: vmlinux.a
+
+include include/config/auto.conf
+include $(srctree)/scripts/Kbuild.include
+include $(srctree)/scripts/Makefile.lib
+
+# Link of built-in-fixup.a
+# ---------------------------------------------------------------------------
+
+# '$(AR) mPi' needs 'T' to workaround the bug of llvm-ar <= 14
+quiet_cmd_ar_builtin_fixup = AR $@
+ cmd_ar_builtin_fixup = \
+ rm -f $@; \
+ $(AR) cDPrST $@ $(KBUILD_VMLINUX_OBJS); \
+ $(AR) mPiT $$($(AR) t $@ | sed -n 1p) $@ $$($(AR) t $@ | grep -F -f $(srctree)/scripts/head-object-list.txt)
+
+targets += built-in-fixup.a
+built-in-fixup.a: $(KBUILD_VMLINUX_OBJS) scripts/head-object-list.txt FORCE
+ $(call if_changed,ar_builtin_fixup)
+
+# vmlinux.a
+# ---------------------------------------------------------------------------
+
+targets += vmlinux.a
+vmlinux.a: built-in-fixup.a FORCE
+ $(call if_changed,copy)
+
+# Add FORCE to the prerequisites of a target to force it to be always rebuilt.
+# ---------------------------------------------------------------------------
+
+PHONY += FORCE
+FORCE:
+
+# Read all saved command lines and dependencies for the $(targets) we
+# may be building above, using $(if_changed{,_dep}). As an
+# optimization, we don't need to read them if the target does not
+# exist, we will rebuild anyway in that case.
+
+existing-targets := $(wildcard $(sort $(targets)))
+
+-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
+
+.PHONY: $(PHONY)