-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support kernel compilation with Clang/LLVM
- Loading branch information
Showing
2 changed files
with
26 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,14 @@ function run_kernel_make_internal() { | |
# Add the distcc envs, if any. | ||
common_make_envs+=("${DISTCC_EXTRA_ENVS[@]}") | ||
|
||
if [[ "${KERNEL_COMPILER}" == "clang" ]]; then | ||
llvm_flag="LLVM=1" | ||
cc_name="CC" | ||
extra_warnings="-Wno-error=unused-command-line-argument -Wno-error=unknown-warning-option" # downgrade errors to warnings | ||
else | ||
cc_name="CROSS_COMPILE" | ||
extra_warnings="" | ||
fi | ||
common_make_params_quoted=( | ||
# @TODO: introduce O=path/to/binaries, so sources and bins are not in the same dir; this has high impact in headers packaging though. | ||
|
||
|
@@ -45,8 +53,8 @@ function run_kernel_make_internal() { | |
"ARCH=${ARCHITECTURE}" # Key param. Everything depends on this. | ||
"LOCALVERSION=-${BRANCH}-${LINUXFAMILY}" # Change the internal kernel version to include the family. Changing this causes recompiles # @TODO change hack at .config; that might handles mtime better | ||
|
||
"CROSS_COMPILE=${CCACHE} ${DISTCC_CROSS_COMPILE_PREFIX[@]} ${KERNEL_COMPILER}" # added as prefix to every compiler invocation by make | ||
"KCFLAGS=-fdiagnostics-color=always -Wno-error=misleading-indentation ${KERNEL_EXTRA_CFLAGS:-""}" # Force GCC colored messages, downgrade misleading indentation to warning | ||
"${cc_name}=${CCACHE} ${DISTCC_CROSS_COMPILE_PREFIX[@]} ${KERNEL_COMPILER}" # added as prefix to every compiler invocation by make | ||
"KCFLAGS=-fdiagnostics-color=always -Wno-error=misleading-indentation ${extra_warnings} ${KERNEL_EXTRA_CFLAGS:-""}" # Force GCC colored messages, downgrade misleading indentation to warning | ||
|
||
"SOURCE_DATE_EPOCH=${kernel_base_revision_ts}" # https://reproducible-builds.org/docs/source-date-epoch/ and https://www.kernel.org/doc/html/latest/kbuild/reproducible-builds.html | ||
"KBUILD_BUILD_TIMESTAMP=${kernel_base_revision_date}" # https://www.kernel.org/doc/html/latest/kbuild/kbuild.html#kbuild-build-timestamp | ||
|
@@ -55,6 +63,9 @@ function run_kernel_make_internal() { | |
|
||
"KGZIP=pigz" "KBZIP2=pbzip2" # Parallel compression, use explicit parallel compressors https://lore.kernel.org/lkml/[email protected]/ # @TODO: what about XZ? | ||
) | ||
if [[ -n "${llvm_flag}" ]]; then | ||
common_make_params_quoted+=("${llvm_flag}") | ||
fi | ||
|
||
# last statement, so it passes the result to calling function. "env -i" is used for empty env | ||
full_command=("${KERNEL_MAKE_RUNNER:-run_host_command_logged}" "env" "-i" "${common_make_envs[@]}" | ||
|
@@ -87,6 +98,11 @@ function kernel_determine_toolchain() { | |
[[ -z $toolchain ]] && exit_with_error "Could not find required toolchain" "${KERNEL_COMPILER}gcc $KERNEL_USE_GCC" | ||
fi | ||
|
||
kernel_compiler_version="$(eval env PATH="${toolchain}:${PATH}" "${KERNEL_COMPILER}gcc" -dumpfullversion -dumpversion)" | ||
display_alert "Compiler version" "${KERNEL_COMPILER}gcc ${kernel_compiler_version}" "info" | ||
if [[ "${KERNEL_COMPILER}" == "clang" ]]; then | ||
KERNEL_COMPILER_FULL="${KERNEL_COMPILER}" | ||
else | ||
KERNEL_COMPILER_FULL="${KERNEL_COMPILER}gcc" | ||
fi | ||
kernel_compiler_version="$(eval env PATH="${toolchain}:${PATH}" "${KERNEL_COMPILER_FULL}" -dumpfullversion -dumpversion)" | ||
display_alert "Compiler version" "${KERNEL_COMPILER_FULL} ${kernel_compiler_version}" "info" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters