Blob Blame History Raw
From bb1a83cf109eee56c8dee26f7910c772f8c246fc Mon Sep 17 00:00:00 2001
From: Michal Suchanek <msuchanek@suse.de>
Date: Thu, 29 Jun 2023 17:47:16 +0200
Subject: [PATCH] depmod: Handle installing modules under a prefix

References: bsc#1212835
Patch-mainline: Never, upstream rejected

Some distributions aim at shipping all files in /usr.

The path under which kernel modules are installed is hardcoded to /lib
which conflicts with this goal.

When kmod provides the config command, use it to determine the correct
module installation path.

With kmod that does not provide the config command /lib/modules is used
as before.

Note: users can use

make MODLIB='$(INSTALL_MOD_PATH)/usr/lib/modules/$(KERNELRELEASE)'

to install modules from mainline kernel on usrmerged system.
Not great for KMPs, though

Signed-off-by: Michal Suchanek <msuchanek@suse.de>
Nacked-by: Masahiro Yamada <masahiroy@kernel.org>
---
v2: Avoid error on systems with kmod that does not support config
command
v3: More verbose commit message
v4:
  - Document jq requirement
  - fix bashism
  - Update to getting full module path, not just additional prefix
v5: switch to pkgconfig
---
 Makefile | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 658ec2b8aa74..5a1889fc43c7 100644
--- a/Makefile
+++ b/Makefile
@@ -1165,7 +1165,9 @@ export INSTALL_DTBS_PATH ?= $(INSTALL_PATH)/dtbs/$(KERNELRELEASE)
 # makefile but the argument can be passed to make if needed.
 #
 
-MODLIB	= $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE)
+export KERNEL_MODULE_DIRECTORY := $(shell pkg-config --print-variables kmod 2>/dev/null | grep '^module_directory$$' >/dev/null && pkg-config --variable=module_directory kmod || echo /lib/modules)
+
+MODLIB	= $(INSTALL_MOD_PATH)$(KERNEL_MODULE_DIRECTORY)/$(KERNELRELEASE)
 export MODLIB
 
 PHONY += prepare0
-- 
2.41.0