Skip to content

Commit

Permalink
Allow overriding /lib/modules via MODDIR
Browse files Browse the repository at this point in the history
With many distributions moving from /lib/modules to /usr/lib/modules,
allow for the builder to select their option. For backwards
compatibility the default is still /lib/modules.

As result distros for example Arch don't need to patch the project.
Plus this nicely aligns with kmod, which recently allowed for similar
change.

Note: the tests still use the original path. If needed that can be
changed as follow-up.

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
  • Loading branch information
evelikov-work authored and evelikov committed Feb 1, 2024
1 parent 77442f4 commit 6b76c7f
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 21 deletions.
30 changes: 29 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,44 @@ SHELL=bash

SBIN = /usr/sbin
LIBDIR = /usr/lib/dkms
MODDIR = /lib/modules
KCONF = /etc/kernel
SYSTEMD = /usr/lib/systemd/system

#Define the top-level build directory
BUILDDIR := $(shell pwd)

all: dkms dkms.8 dkms_autoinstaller dkms.service kernel_install.d_dkms kernel_postinst.d_dkms
all: \
dkms \
dkms.8 \
dkms_autoinstaller \
dkms.bash-completion \
dkms_common.postinst \
dkms_framework.conf \
dkms.service \
kernel_install.d_dkms \
kernel_postinst.d_dkms \
kernel_prerm.d_dkms

clean:
-rm -rf dist/
-rm -rf dkms
-rm -rf dkms.8
-rm -rf dkms_autoinstaller
-rm -rf dkms.bash-completion
-rm -rf dkms_common.postinst
-rm -rf dkms_framework.conf
-rm -rf dkms.service
-rm -rf kernel_install.d_dkms
-rm -rf kernel_postinst.d_dkms
-rm -rf kernel_prerm.d_dkms

SED_PROCESS = \
sed -e 's,@RELEASE_STRING@,$(RELEASE_STRING),g' \
-e 's,@RELEASE_DATE@,$(RELEASE_DATE),g' \
-e 's,@SBINDIR@,$(SBIN),g' \
-e 's,@KCONFDIR@,$(KCONF),g' \
-e 's,@MODDIR@,$(MODDIR),g' \
-e 's,@LIBDIR@,$(LIBDIR),g' $^ > $@

dkms: dkms.in
Expand All @@ -42,6 +58,15 @@ dkms.8: dkms.8.in
dkms_autoinstaller: dkms_autoinstaller.in
$(SED_PROCESS)

dkms.bash-completion: dkms.bash-completion.in
$(SED_PROCESS)

dkms_common.postinst: dkms_common.postinst.in
$(SED_PROCESS)

dkms_framework.conf: dkms_framework.conf.in
$(SED_PROCESS)

dkms.service: dkms.service.in
$(SED_PROCESS)

Expand All @@ -51,6 +76,9 @@ kernel_install.d_dkms: kernel_install.d_dkms.in
kernel_postinst.d_dkms: kernel_postinst.d_dkms.in
$(SED_PROCESS)

kernel_prerm.d_dkms: kernel_prerm.d_dkms.in
$(SED_PROCESS)

install: all
$(if $(strip $(VAR)),$(error Setting VAR is not supported))
install -d -m 0755 $(DESTDIR)/var/lib/dkms
Expand Down
14 changes: 7 additions & 7 deletions dkms.8.in
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ This option executes modprobe on the modules upon successful installation.
Using this option you can specify the location of your kernel source
directory. Most likely you will not need to set this if your kernel
source is accessible via
.I /lib/modules/$kernel_version/build.
.I @MODDIR@/$kernel_version/build.
.TP
.B \-\-directive <"cli\-directive=cli\-value">
Using this option, you can specify additional directives from the command
Expand Down Expand Up @@ -421,13 +421,13 @@ Enable verbose output of external commands executed in DKMS.
During the first install of a module for a <kernelversion>,
.B dkms
will search
.I /lib/modules/<kernelversion>
.I @MODDIR@/<kernelversion>
for a pre-existing module of the same name. If one is found, it will automatically
be saved as an "original_module" so that if the newer module is later removed,
.B dkms
will put the original module back in its place. Currently, DKMS searches
for these original modules with first preference going to modules located in
.I /lib/modules/<kernelversion>/updates/
.I @MODDIR@/<kernelversion>/updates/
followed by
.B $DEST_MODULE_LOCATION
(as specified in
Expand Down Expand Up @@ -526,7 +526,7 @@ This directive specifies the destination where a module should be installed to,
is used for finding original_modules. This is a
.B required
directive, except as noted below. This directive must start with the text "/kernel" which is in reference to
/lib/modules/<kernelversion>/kernel.
@MODDIR@/<kernelversion>/kernel.
Note that for each module within a dkms package, the numeric value of
.B #
must be the same for each of BUILT_MODULE_NAME, BUILT_MODULE_LOCATION, DEST_MODULE_NAME and
Expand Down Expand Up @@ -744,12 +744,12 @@ values.
This variable can be used within a directive definition and during use, the actual kernel
version in question will be substituted in its place. This is especially useful in MAKE
commands when specifying which INCLUDE statements should be used when compiling your
module (eg. MAKE="make all INCLUDEDIR=/lib/modules/${kernelver}/build/include").
module (eg. MAKE="make all INCLUDEDIR=@MODDIR@/${kernelver}/build/include").
.TP
.B $kernel_source_dir
This variable holds the value of the location of your kernel source directory. Usually, this
will be
.IR /lib/modules/$kernelver/build ,
.IR @MODDIR@/$kernelver/build ,
unless otherwise specified with the
.B \-\-kernelsourcedir
option.
Expand Down Expand Up @@ -785,7 +785,7 @@ Control which folders DKMS uses for components and artifacts.
Can be set to anything but a null value to enable verbose output of external commands executed in DKMS.
.TP
.B $symlink_modules
Controls whether binary modules are copied to /lib/modules or if only symlinks are created there. Note that these variables can also
Controls whether binary modules are copied to @MODDIR@ or if only symlinks are created there. Note that these variables can also
be manipulated on the command line with \-\-dkmstree, \-\-sourcetree, \-\-installtree
and \-\-symlink-modules options.
.TP
Expand Down
2 changes: 1 addition & 1 deletion dkms.bash-completion → dkms.bash-completion.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#
_kernels()
{
COMPREPLY=( $( cd /lib/modules && compgen -d -- "$cur" ) )
COMPREPLY=( $( cd @MODDIR@ && compgen -d -- "$cur" ) )
}

# complete on full directory names under $1
Expand Down
2 changes: 1 addition & 1 deletion dkms.in
Original file line number Diff line number Diff line change
Expand Up @@ -2394,7 +2394,7 @@ current_os=$(uname -s)
running_distribution=$(distro_version) || exit
dkms_tree="/var/lib/dkms"
source_tree="/usr/src"
install_tree="/lib/modules"
install_tree="@MODDIR@"
tmp_location=${TMPDIR:-/tmp}
verbose=""
symlink_modules=""
Expand Down
2 changes: 1 addition & 1 deletion dkms_autoinstaller.in
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ uname_s=$(uname -s)
_get_kernel_dir() {
KVER=$1
case ${uname_s} in
Linux) DIR="/lib/modules/$KVER/build" ;;
Linux) DIR="@MODDIR@/$KVER/build" ;;
GNU/kFreeBSD) DIR="/usr/src/kfreebsd-headers-$KVER/sys" ;;
esac
echo $DIR
Expand Down
10 changes: 5 additions & 5 deletions dkms_common.postinst → dkms_common.postinst.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ uname_s=$(uname -s)
_get_kernel_dir() {
KVER=$1
case ${uname_s} in
Linux) DIR="/lib/modules/$KVER/build" ;;
Linux) DIR="@MODDIR@/$KVER/build" ;;
GNU/kFreeBSD) DIR="/usr/src/kfreebsd-headers-$KVER/sys" ;;
esac
echo $DIR
Expand All @@ -31,7 +31,7 @@ _check_kernel_dir() {

# Check the existence of a kernel named as $1
_is_kernel_name_correct() {
if [ -e "/lib/modules/$1" ]; then
if [ -e "@MODDIR@/$1" ]; then
echo yes
else
echo no
Expand Down Expand Up @@ -127,7 +127,7 @@ if [ -r /etc/dkms/framework.conf ]; then
. /etc/dkms/framework.conf
fi

KERNELS=$(ls -dv /lib/modules/*/build 2>/dev/null | cut -d/ -f4 || true)
KERNELS=$(ls -dv @MODDIR@/*/build 2>/dev/null | cut -d/ -f4 || true)
CURRENT_KERNEL=$(uname -r)

#We never want to keep an older version side by side to prevent conflicts
Expand Down Expand Up @@ -156,14 +156,14 @@ elif [ -d "/usr/src/$NAME-$VERSION" ]; then
fi

# On 1st installation, let us look for a directory
# in /lib/modules which matches $(uname -r). If none
# in @MODDIR@ which matches $(uname -r). If none
# is found it is possible that buildd is being used
# and that uname -r is giving us the name of the
# kernel used by the buildd machine.
#
# If this is the case we try to build the kernel
# module for each kernel which has a directory in
# /lib/modules. Furthermore we will have to tell
# @MODDIR@. Furthermore we will have to tell
# DKMS which architecture it should build the module
# for (e.g. if the buildd machine is using a
# 2.6.24-23-xen 64bit kernel).
Expand Down
4 changes: 2 additions & 2 deletions dkms_framework.conf → dkms_framework.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
# DKMS Tree Location (default: /var/lib/dkms):
# dkms_tree="/var/lib/dkms"

# Install Tree Location (default: /lib/modules):
# install_tree="/lib/modules"
# Install Tree Location (default: @MODDIR@):
# install_tree="@MODDIR@"

# Temporary folder Location (default: /tmp):
# tmp_location="/tmp"
Expand Down
2 changes: 1 addition & 1 deletion kernel_postinst.d_dkms.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ uname_s=$(uname -s)
_get_kernel_dir() {
KVER=$1
case ${uname_s} in
Linux) DIR="/lib/modules/$KVER/build" ;;
Linux) DIR="@MODDIR@/$KVER/build" ;;
GNU/kFreeBSD) DIR="/usr/src/kfreebsd-headers-$KVER/sys" ;;
esac
echo "$DIR"
Expand Down
4 changes: 2 additions & 2 deletions kernel_prerm.d_dkms → kernel_prerm.d_dkms.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if command -v dkms > /dev/null; then
fi

rmdir --ignore-fail-on-non-empty \
"/lib/modules/$inst_kern/updates/dkms" \
"/lib/modules/$inst_kern/updates" 2>/dev/null
"@MODDIR@/$inst_kern/updates/dkms" \
"@MODDIR@/$inst_kern/updates" 2>/dev/null

exit 0

0 comments on commit 6b76c7f

Please sign in to comment.