From 2a06ad8e0aa254a12cdb43659d098e3d449b039c Mon Sep 17 00:00:00 2001 From: Jacek Szafarkiewicz Date: Sun, 22 Jan 2023 21:45:50 +0100 Subject: [PATCH 1/5] Use $kernel_config instead of $kernel_source_dir/.config Signed-off-by: Jacek Szafarkiewicz --- dkms.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dkms.in b/dkms.in index 486da5a1..28f57263 100644 --- a/dkms.in +++ b/dkms.in @@ -1036,8 +1036,8 @@ prepare_build() $"Check $build_dir for more information." done - if [[ -e $kernel_source_dir/.config ]]; then - cc=$(sed -n 's|^CONFIG_CC_VERSION_TEXT="\([^ ]*\) .*"|\1|p' $kernel_source_dir/.config) + if [[ -e "${kernel_config}" ]]; then + cc=$(sed -n 's|^CONFIG_CC_VERSION_TEXT="\([^ ]*\) .*"|\1|p' "${kernel_config}") if command -v "$cc" >/dev/null; then export CC="$cc" fi From 5c5462b075dbb63a5eca68c78ff52a0d57be0aa7 Mon Sep 17 00:00:00 2001 From: Jacek Szafarkiewicz Date: Sun, 22 Jan 2023 21:47:22 +0100 Subject: [PATCH 2/5] Export KERNEL_CC when exporting CC Signed-off-by: Jacek Szafarkiewicz --- dkms.in | 1 + 1 file changed, 1 insertion(+) diff --git a/dkms.in b/dkms.in index 28f57263..485b4a4a 100644 --- a/dkms.in +++ b/dkms.in @@ -1040,6 +1040,7 @@ prepare_build() cc=$(sed -n 's|^CONFIG_CC_VERSION_TEXT="\([^ ]*\) .*"|\1|p' "${kernel_config}") if command -v "$cc" >/dev/null; then export CC="$cc" + export KERNEL_CC="$cc" fi fi From 484009979fe3344dba6ef626f7ef1d3fc5348b2d Mon Sep 17 00:00:00 2001 From: Jacek Szafarkiewicz Date: Sun, 22 Jan 2023 21:47:49 +0100 Subject: [PATCH 3/5] Export LD and KERNEL_LD as ld.lld when CONFIG_LD_IS_LLD=y is set Signed-off-by: Jacek Szafarkiewicz --- dkms.in | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dkms.in b/dkms.in index 485b4a4a..e3a35a25 100644 --- a/dkms.in +++ b/dkms.in @@ -1042,6 +1042,14 @@ prepare_build() export CC="$cc" export KERNEL_CC="$cc" fi + + if grep -q 'CONFIG_LD_IS_LLD=y' "${kernel_config}"; then + ld=ld.lld + if command -v "$ld" >/dev/null; then + export LD="$ld" + export KERNEL_LD="$ld" + fi + fi fi # Run the pre_build script From 4729aefebb98d229e542609c2b6c92545c7a69d8 Mon Sep 17 00:00:00 2001 From: Jacek Szafarkiewicz Date: Tue, 24 Jan 2023 10:15:01 +0100 Subject: [PATCH 4/5] Better way to detect clang compiler Signed-off-by: Jacek Szafarkiewicz --- dkms.in | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/dkms.in b/dkms.in index e3a35a25..417a4082 100644 --- a/dkms.in +++ b/dkms.in @@ -1037,10 +1037,12 @@ prepare_build() done if [[ -e "${kernel_config}" ]]; then - cc=$(sed -n 's|^CONFIG_CC_VERSION_TEXT="\([^ ]*\) .*"|\1|p' "${kernel_config}") - if command -v "$cc" >/dev/null; then - export CC="$cc" - export KERNEL_CC="$cc" + if grep -q 'CONFIG_CC_IS_CLANG=y' "${kernel_config}"; then + cc=clang + if command -v "$cc" >/dev/null; then + export CC="$cc" + export KERNEL_CC="$cc" + fi fi if grep -q 'CONFIG_LD_IS_LLD=y' "${kernel_config}"; then From ab65154e4880f75544df1d662614043e4ab9e339 Mon Sep 17 00:00:00 2001 From: Jacek Szafarkiewicz Date: Tue, 24 Jan 2023 10:15:28 +0100 Subject: [PATCH 5/5] Change cc and ld to local variables Signed-off-by: Jacek Szafarkiewicz --- dkms.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dkms.in b/dkms.in index 417a4082..f5a1f1c1 100644 --- a/dkms.in +++ b/dkms.in @@ -1038,7 +1038,7 @@ prepare_build() if [[ -e "${kernel_config}" ]]; then if grep -q 'CONFIG_CC_IS_CLANG=y' "${kernel_config}"; then - cc=clang + local cc=clang if command -v "$cc" >/dev/null; then export CC="$cc" export KERNEL_CC="$cc" @@ -1046,7 +1046,7 @@ prepare_build() fi if grep -q 'CONFIG_LD_IS_LLD=y' "${kernel_config}"; then - ld=ld.lld + local ld=ld.lld if command -v "$ld" >/dev/null; then export LD="$ld" export KERNEL_LD="$ld"