From: Tom Stellard <tstellar(a)redhat.com>
[redhat] spec: Add %bcond_with toolchain_clang option
This option can be enabled by passing --with toolchain_clang to rpmbuild
or mock. Enabling this option will cause the kernel to be built with
clang instead of gcc.
Signed-off-by: Tom Stellard <tstellar(a)redhat.com>
diff a/redhat/kernel.spec.template b/redhat/kernel.spec.template
--- a/redhat/kernel.spec.template
+++ b/redhat/kernel.spec.template
@@ -6,6 +6,12 @@
# Disable LTO in userspace packages.
%global _lto_cflags %{nil}
+# Option to enable compiling with clang instead of gcc.
+%bcond_with toolchain_clang
+
+%if %{with toolchain_clang}
+%global toolchain clang
+%endif
# Cross compile on copr for arm
# See
https://bugzilla.redhat.com/1879599
@@ -228,6 +234,10 @@ Summary: The Linux kernel
%define make_opts -s
%endif
+%if %{with toolchain_clang}
+%global make_opts %{make_opts} HOSTCC=clang CC=clang
+%endif
+
# turn off debug kernel and kabichk for gcov builds
%if %{with_gcov}
%define with_debug 0
@@ -432,6 +442,14 @@ Summary: The Linux kernel
%define with_configchecks 0
%endif
+# Setting the compiler to clang enables some different config options
+# than what is expected, so disable this check for now.
+# TODO: What's the best way to fix this? Do wee need a different set of
+# configs for clang?
+%if %{with toolchain_clang}
+%define with_configchecks 0
+%endif
+
# To temporarily exclude an architecture from being built, add it to
# %%nobuildarches. Do _NOT_ use the ExclusiveArch: line, because if we
# don't build kernel-headers then the new build system will no longer let
@@ -596,6 +614,10 @@ BuildRequires: xmlto
BuildRequires: asciidoc
%endif
+%if %{with toolchain_clang}
+BuildRequires: clang
+%endif
+
# Because this is the kernel, it's hard to get a single upstream URL
# to represent the base without needing to do a bunch of patching. This
# tarball is generated from a src-git tree. If you want to see the
--
https://gitlab.com/cki-project/kernel-ark/-/merge_requests/894