[PATCH v2 3/3] kbuild: move scripts/mod target out of single-build

From: Vincent Mailhol

Date: Fri Nov 13 2026 - 13:51:14 EST


The scripts/mod target is currently built by prepare0, even when
compiling a single object that does not need modpost.

Introduce modpost_prepare between prepare and modules_prepare, and make
in-tree modpost depend on it. Move the scripts/mod build from prepare0
to this new target. This keeps scripts/mod out of single-object builds
that do not need modpost.

Signed-off-by: Vincent Mailhol <mailhol@xxxxxxxxxx>
---
Makefile | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index 2c1289a44c56..86b9100af854 100644
--- a/Makefile
+++ b/Makefile
@@ -1405,7 +1405,7 @@ scripts: scripts_basic scripts_dtc
# archprepare is used in arch Makefiles and when processed asm symlink,
# version.h and scripts_basic is processed / created.

-PHONY += prepare archprepare
+PHONY += prepare archprepare modpost_prepare

archprepare: outputmakefile archheaders archscripts scripts include/config/kernel.release \
asm-generic $(version_h) include/generated/utsrelease.h \
@@ -1414,6 +1414,8 @@ archprepare: outputmakefile archheaders archscripts scripts include/config/kerne

prepare0: archprepare
$(Q)$(MAKE) $(build)=. prepare $(if $(single-build),,prepare_checks)
+
+modpost_prepare: prepare
$(Q)$(MAKE) $(build)=scripts/mod

# All the preparing..
@@ -1765,7 +1767,7 @@ endif
modules: modules_prepare

# Target to prepare building external modules
-modules_prepare: prepare
+modules_prepare: modpost_prepare
$(Q)$(MAKE) $(build)=scripts scripts/module.lds

endif # CONFIG_MODULES
@@ -2189,7 +2191,8 @@ KBUILD_MODULES :=
endif # CONFIG_MODULES

PHONY += modpost
-modpost: $(if $(single-build),, $(if $(KBUILD_BUILTIN), vmlinux.o)) \
+modpost: $(if $(KBUILD_EXTMOD),,modpost_prepare) \
+ $(if $(single-build),, $(if $(KBUILD_BUILTIN), vmlinux.o)) \
$(if $(KBUILD_MODULES), modules_check)
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost


--
2.56.1