Skip to content

Commit

Permalink
drbd,dkms: try to find gcc used to build kernel
Browse files Browse the repository at this point in the history
Some distributions use a separate (newer) compiler to build specific kernels.
This is a problem as the kernel config then often includes flags that the
default compiler does not understand.

Try to detect that in the DKMS build, sourcing the software collection that
contains a "good enough" compiler.
  • Loading branch information
WanzenBug committed Dec 10, 2024
1 parent 8524eaa commit 7b44dde
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions misc/dkms.conf
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,27 @@ BUILT_MODULE_LOCATION[$IDX]="./src/drbd/build-current/drbd-kernel-compat/handsha
DEST_MODULE_LOCATION[$IDX]="/kernel/net/handshake"
fi
fi

# On some distros (OL8 for example), the default cc is not the one used to build the kernel.
# In this case, the gcc is installed as a "Software Collection" which can be enabled.
# So we try to find a compiler that matches the version used to build the original kernel.
get_cc_version() {
if [ -n "$1" ]; then
scl run "$1" -- "/lib/modules/$kernelver/build/scripts/cc-version.sh" cc | cut -d' ' -f2
else
"/lib/modules/$kernelver/build/scripts/cc-version.sh" cc | cut -d' ' -f2
fi
}

if [ -e "/lib/modules/$kernelver/build/scripts/cc-version.sh" ]; then
KERNEL_GCC_VERSION="$(grep ^CONFIG_GCC_VERSION= "/lib/modules/$kernelver/build/.config" | cut -d= -f2)"

if [ "$KERNEL_GCC_VERSION" -gt "$(get_cc_version)" ] && command -v scl >/dev/null; then
for COLLECTION in $(scl list-collections); do
if [ "$KERNEL_GCC_VERSION" -le "$(get_cc_version "$COLLECTION")" ]; then
MAKE="scl run $COLLECTION -- $MAKE"
break
fi
done
fi
fi

0 comments on commit 7b44dde

Please sign in to comment.