[KINETIC][LUNAR][PATCH] UBUNTU: [Packaging] Set explicit CC in the headers package

Dimitri John Ledkov dimitri.ledkov at canonical.com
Thu Dec 15 09:11:51 UTC 2022


BugLink: https://bugs.launchpad.net/bugs/1999750

Currently Ubuntu Linux kernel header packages use stock Makefile as
shipped by upstream kernel. During linux kernel package build however
HOSTCC and CC are typically overridden to use explicit complier
version $(DEB_HOST_GNU_TYPE)-gcc-12. This can lead to dkms module
build failures as despite all efforts to reuse matching gcc version
out of .config, various shell scripts / build systems / makefiles do
not pass the CC variable as a make variable to the end make call that
is used to build dkms modules. To avoid this, hardcode the correct
compiler in the linux headers package shipped Makefile. This is
similar to the Makefile includes that debian ships, albeit with less
indirections.

Tested by applying this patch to the hwe-5.19 kernel, rebuilding it,
and testing that dkms module building is using expected compilers now.

Signed-off-by: Dimitri John Ledkov <dimitri.ledkov at canonical.com>
---
 debian/rules.d/2-binary-arch.mk | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/debian/rules.d/2-binary-arch.mk b/debian/rules.d/2-binary-arch.mk
index 60513c43b9..ecc5afbc97 100644
--- a/debian/rules.d/2-binary-arch.mk
+++ b/debian/rules.d/2-binary-arch.mk
@@ -318,8 +318,15 @@ endif
 	cp $(builddir)/build-$*/.config $(hdrdir)
 	chmod 644 $(hdrdir)/.config
 	$(kmake) O=$(hdrdir) -j1 syncconfig prepare scripts
-	# We'll symlink this stuff
+	# Makefile may need per-arch-flavour CC settings, which are
+	# normally set via $(kmake) during build
 	rm -f $(hdrdir)/Makefile
+	cp -a $(indep_hdrdir)/Makefile $(hdrdir)/Makefile
+	sed -i 's|\(^HOSTCC	= \)gcc$$|\1$(gcc)|' $(hdrdir)/Makefile
+	sed -i 's|\(^CC		= $$(CROSS_COMPILE)\)gcc$$|\1$(gcc)|' $(hdrdir)/Makefile
+	# Quick check for successful substitutions
+	grep '^HOSTCC	.*$(gcc)$$' $(hdrdir)/Makefile
+	grep '^CC	.*$(gcc)$$' $(hdrdir)/Makefile
 	rm -rf $(hdrdir)/include2 $(hdrdir)/source
 	# We do not need the retpoline information.
 	find $(hdrdir) -name \*.o.ur-\* | xargs rm -f
-- 
2.34.1




More information about the kernel-team mailing list