diff mbox series

kbuild: make modules_install copy modules.builtin(.modinfo)

Message ID 20230615111743.883891-1-masahiroy@kernel.org (mailing list archive)
State New, archived
Headers show
Series kbuild: make modules_install copy modules.builtin(.modinfo) | expand

Commit Message

Masahiro Yamada June 15, 2023, 11:17 a.m. UTC
Josh Triplett reports that initramfs-tools needs modules.builtin and
modules.builtin.modinfo to create a working initramfs for a non-modular
kernel.

If this is a general tooling issue not limited to Debian, I think it
makes sense to change modules_install.

This commit changes the targets as follows when CONFIG_MODULES=n.

In-tree builds:
  make modules          -> no-op
  make modules_install  -> install modules.builtin(.modinfo)

External module builds:
  make modules          -> show error message like before
  make modules_install  -> show error message like before

Link: https://lore.kernel.org/lkml/36a4014c73a52af27d930d3ca31d362b60f4461c.1686356364.git.josh@joshtriplett.org/
Reported-by: Josh Triplett <josh@joshtriplett.org>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 Makefile | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

Comments

Nicolas Schier June 19, 2023, 12:34 p.m. UTC | #1
On Thu, Jun 15, 2023 at 08:17:43PM +0900 Masahiro Yamada wrote:
> Josh Triplett reports that initramfs-tools needs modules.builtin and
> modules.builtin.modinfo to create a working initramfs for a non-modular
> kernel.
> 
> If this is a general tooling issue not limited to Debian, I think it
> makes sense to change modules_install.
> 
> This commit changes the targets as follows when CONFIG_MODULES=n.
> 
> In-tree builds:
>   make modules          -> no-op
>   make modules_install  -> install modules.builtin(.modinfo)
> 
> External module builds:
>   make modules          -> show error message like before
>   make modules_install  -> show error message like before
> 
> Link: https://lore.kernel.org/lkml/36a4014c73a52af27d930d3ca31d362b60f4461c.1686356364.git.josh@joshtriplett.org/
> Reported-by: Josh Triplett <josh@joshtriplett.org>
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> ---

Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
Tested-by: Nicolas Schier <nicolas@fjasle.eu>

>  Makefile | 26 ++++++++++++++++----------
>  1 file changed, 16 insertions(+), 10 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index cc3fe09c4dec..f18d59c81241 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -1545,6 +1545,8 @@ modules_sign_only := y
>  endif
>  endif
>  
> +endif # CONFIG_MODULES
> +
>  modinst_pre :=
>  ifneq ($(filter modules_install,$(MAKECMDGOALS)),)
>  modinst_pre := __modinst_pre
> @@ -1555,18 +1557,18 @@ PHONY += __modinst_pre
>  __modinst_pre:
>  	@rm -rf $(MODLIB)/kernel
>  	@rm -f $(MODLIB)/source
> -	@mkdir -p $(MODLIB)/kernel
> +	@mkdir -p $(MODLIB)
> +ifdef CONFIG_MODULES
>  	@ln -s $(abspath $(srctree)) $(MODLIB)/source
>  	@if [ ! $(objtree) -ef  $(MODLIB)/build ]; then \
>  		rm -f $(MODLIB)/build ; \
>  		ln -s $(CURDIR) $(MODLIB)/build ; \
>  	fi
>  	@sed 's:^\(.*\)\.o$$:kernel/\1.ko:' modules.order > $(MODLIB)/modules.order
> +endif
>  	@cp -f modules.builtin $(MODLIB)/
>  	@cp -f $(objtree)/modules.builtin.modinfo $(MODLIB)/
>  
> -endif # CONFIG_MODULES
> -
>  ###
>  # Cleaning is done on three levels.
>  # make clean     Delete most generated files
> @@ -1908,6 +1910,13 @@ help:
>  	@echo  '  clean           - remove generated files in module directory only'
>  	@echo  ''
>  
> +__external_modules_error:
> +	@echo >&2 '***'
> +	@echo >&2 '*** The present kernel disabled CONFIG_MODULES.'
> +	@echo >&2 '*** You cannot build or install external modules.'
> +	@echo >&2 '***'
> +	@false
> +
>  endif # KBUILD_EXTMOD
>  
>  # ---------------------------------------------------------------------------
> @@ -1944,13 +1953,10 @@ else # CONFIG_MODULES
>  # Modules not configured
>  # ---------------------------------------------------------------------------
>  
> -modules modules_install:
> -	@echo >&2 '***'
> -	@echo >&2 '*** The present kernel configuration has modules disabled.'
> -	@echo >&2 '*** To use the module feature, please run "make menuconfig" etc.'
> -	@echo >&2 '*** to enable CONFIG_MODULES.'
> -	@echo >&2 '***'
> -	@exit 1
> +PHONY += __external_modules_error
> +
> +modules modules_install: __external_modules_error
> +	@:
>  
>  KBUILD_MODULES :=
>  
> -- 
> 2.39.2
Josh Triplett June 22, 2023, 7:11 p.m. UTC | #2
On Thu, Jun 15, 2023 at 08:17:43PM +0900, Masahiro Yamada wrote:
> Josh Triplett reports that initramfs-tools needs modules.builtin and
> modules.builtin.modinfo to create a working initramfs for a non-modular
> kernel.
> 
> If this is a general tooling issue not limited to Debian, I think it
> makes sense to change modules_install.
> 
> This commit changes the targets as follows when CONFIG_MODULES=n.
> 
> In-tree builds:
>   make modules          -> no-op
>   make modules_install  -> install modules.builtin(.modinfo)
> 
> External module builds:
>   make modules          -> show error message like before
>   make modules_install  -> show error message like before
> 
> Link: https://lore.kernel.org/lkml/36a4014c73a52af27d930d3ca31d362b60f4461c.1686356364.git.josh@joshtriplett.org/
> Reported-by: Josh Triplett <josh@joshtriplett.org>
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

Reviewed-by: Josh Triplett <josh@joshtriplett.org>
Tested-by: Josh Triplett <josh@joshtriplett.org>

I'll send a followup patch that makes the Debian packaging script use
`make modules_install` unconditionally.
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index cc3fe09c4dec..f18d59c81241 100644
--- a/Makefile
+++ b/Makefile
@@ -1545,6 +1545,8 @@  modules_sign_only := y
 endif
 endif
 
+endif # CONFIG_MODULES
+
 modinst_pre :=
 ifneq ($(filter modules_install,$(MAKECMDGOALS)),)
 modinst_pre := __modinst_pre
@@ -1555,18 +1557,18 @@  PHONY += __modinst_pre
 __modinst_pre:
 	@rm -rf $(MODLIB)/kernel
 	@rm -f $(MODLIB)/source
-	@mkdir -p $(MODLIB)/kernel
+	@mkdir -p $(MODLIB)
+ifdef CONFIG_MODULES
 	@ln -s $(abspath $(srctree)) $(MODLIB)/source
 	@if [ ! $(objtree) -ef  $(MODLIB)/build ]; then \
 		rm -f $(MODLIB)/build ; \
 		ln -s $(CURDIR) $(MODLIB)/build ; \
 	fi
 	@sed 's:^\(.*\)\.o$$:kernel/\1.ko:' modules.order > $(MODLIB)/modules.order
+endif
 	@cp -f modules.builtin $(MODLIB)/
 	@cp -f $(objtree)/modules.builtin.modinfo $(MODLIB)/
 
-endif # CONFIG_MODULES
-
 ###
 # Cleaning is done on three levels.
 # make clean     Delete most generated files
@@ -1908,6 +1910,13 @@  help:
 	@echo  '  clean           - remove generated files in module directory only'
 	@echo  ''
 
+__external_modules_error:
+	@echo >&2 '***'
+	@echo >&2 '*** The present kernel disabled CONFIG_MODULES.'
+	@echo >&2 '*** You cannot build or install external modules.'
+	@echo >&2 '***'
+	@false
+
 endif # KBUILD_EXTMOD
 
 # ---------------------------------------------------------------------------
@@ -1944,13 +1953,10 @@  else # CONFIG_MODULES
 # Modules not configured
 # ---------------------------------------------------------------------------
 
-modules modules_install:
-	@echo >&2 '***'
-	@echo >&2 '*** The present kernel configuration has modules disabled.'
-	@echo >&2 '*** To use the module feature, please run "make menuconfig" etc.'
-	@echo >&2 '*** to enable CONFIG_MODULES.'
-	@echo >&2 '***'
-	@exit 1
+PHONY += __external_modules_error
+
+modules modules_install: __external_modules_error
+	@:
 
 KBUILD_MODULES :=