public inbox for linux-kbuild@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonas Zeiger <jonas.zeiger@talpidae.net>
To: linux-kbuild@vger.kernel.org
Cc: Masahiro Yamada <masahiroy@kernel.org>,
	Michal Marek <michal.lkml@markovi.net>
Subject: [PATCH] Makefile: allow modules_install if CONFIG_MODULES=n
Date: Thu, 28 May 2020 06:39:33 +0200	[thread overview]
Message-ID: <288d045f9429fc4cfd9ffb244e1be2f8@talpidae.net> (raw)

Many applications check for available kernel features via:

  * /proc/modules (loaded modules, present if CONFIG_MODULES=y)
  * $(MODLIB)/modules.builtin (builtin modules)

They fail to detect features if the kernel was built with 
CONFIG_MODULES=n
and modules.builtin isn't installed.

Therefore, allow the Makefile's modules_install target to be used 
always.

Tested Makefile targets with different CONFIG_MODULES states:

  * (CONFIG_MODULES=n) modules_install: install modules.builtin etc.
  * (CONFIG_MODULES=y) modules_install: produce same result as before
  * (CONFIG_MODULES=y) modules_install: still fail if no modules.order
  * (CONFIG_MODULES=y) modules: build modules, as before
  * (CONFIG_MODULES=n) modules: still fail and warn

Signed-off-by: Jonas Zeiger <jonas.zeiger@talpidae.net>
---

  Makefile |   60 
++++++++++++++++++++++++++++++++----------------------------
  1 file changed, 32 insertions(+), 28 deletions(-)

diff -up linux/Makefile{.orig,}
--- linux/Makefile.orig	2020-05-28 04:27:34.341394622 +0200
+++ linux/Makefile	2020-05-28 05:18:00.540108227 +0200
@@ -1309,31 +1309,7 @@ dt_binding_check: scripts_dtc
  # 
---------------------------------------------------------------------------
  # Modules

-ifdef CONFIG_MODULES
-
-# By default, build modules as well
-
-all: modules
-
-# Build modules
-#
-# A module can be listed more than once in obj-m resulting in
-# duplicate lines in modules.order files.  Those are removed
-# using awk while concatenating to the final file.
-
-PHONY += modules
-modules: $(if $(KBUILD_BUILTIN),vmlinux) modules.order
-	$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
-	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh
-
-modules.order: descend
-	$(Q)$(AWK) '!x[$$0]++' $(addsuffix /$@, $(build-dirs)) > $@
-
-# Target to prepare building external modules
-PHONY += modules_prepare
-modules_prepare: prepare
-
-# Target to install modules
+# Target to install modules and accompanying files
  PHONY += modules_install
  modules_install: _modinst_ _modinst_post

@@ -1347,10 +1323,14 @@ _modinst_:
  		rm -f $(MODLIB)/build ; \
  		ln -s $(CURDIR) $(MODLIB)/build ; \
  	fi
-	@sed 's:^:kernel/:' modules.order > $(MODLIB)/modules.order
  	@cp -f modules.builtin $(MODLIB)/
  	@cp -f $(objtree)/modules.builtin.modinfo $(MODLIB)/
+ifdef CONFIG_MODULES
+	@sed 's:^:kernel/:' modules.order > $(MODLIB)/modules.order
  	$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst
+else
+	@touch $(MODLIB)/modules.order
+endif

  # This depmod is only for convenience to give the initial
  # boot a modules.dep even before / is mounted read-write.  However the
@@ -1359,6 +1339,30 @@ PHONY += _modinst_post
  _modinst_post: _modinst_
  	$(call cmd,depmod)

+ifdef CONFIG_MODULES
+
+# By default, build modules as well
+
+all: modules
+
+# Build modules
+#
+# A module can be listed more than once in obj-m resulting in
+# duplicate lines in modules.order files.  Those are removed
+# using awk while concatenating to the final file.
+
+PHONY += modules
+modules: $(if $(KBUILD_BUILTIN),vmlinux) modules.order
+	$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
+	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh
+
+modules.order: descend
+	$(Q)$(AWK) '!x[$$0]++' $(addsuffix /$@, $(build-dirs)) > $@
+
+# Target to prepare building external modules
+PHONY += modules_prepare
+modules_prepare: prepare
+
  ifeq ($(CONFIG_MODULE_SIG), y)
  PHONY += modules_sign
  modules_sign:
@@ -1370,8 +1374,8 @@ else # CONFIG_MODULES
  # Modules not configured
  # 
---------------------------------------------------------------------------

-PHONY += modules modules_install
-modules modules_install:
+PHONY += modules
+modules:
  	@echo >&2
  	@echo >&2 "The present kernel configuration has modules disabled."
  	@echo >&2 "Type 'make config' and enable loadable module support."

             reply	other threads:[~2020-05-28  4:50 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-28  4:39 Jonas Zeiger [this message]
2020-05-31 18:16 ` [PATCH] Makefile: allow modules_install if CONFIG_MODULES=n Masahiro Yamada
2020-06-03 13:28   ` Jonas Zeiger
2020-06-03 13:34   ` [PATCH v2] Makefile: install modules.builtin even " Jonas Zeiger
2020-06-04  0:33     ` Masahiro Yamada
2020-06-09 16:38     ` Doug Anderson
2020-06-09 17:31       ` Guenter Roeck
2020-06-12  6:56         ` Masahiro Yamada
2020-06-12 13:31           ` Guenter Roeck
2020-06-12 15:35           ` Jonas Zeiger
2020-06-13  2:58             ` Masahiro Yamada

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=288d045f9429fc4cfd9ffb244e1be2f8@talpidae.net \
    --to=jonas.zeiger@talpidae.net \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=michal.lkml@markovi.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox