diff --git a/config/BoardConfigKernel.mk b/config/BoardConfigKernel.mk index c81db38c..9fb56683 100644 --- a/config/BoardConfigKernel.mk +++ b/config/BoardConfigKernel.mk @@ -1,4 +1,4 @@ -# Copyright (C) 2018-2020 The LineageOS Project +# Copyright (C) 2018-2022 The LineageOS Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -28,6 +28,9 @@ # x86_64-linux-android- for x86 # # TARGET_KERNEL_CLANG_COMPILE = Compile kernel with clang, defaults to true +# TARGET_KERNEL_VERSION = Reported kernel version in top level kernel +# makefile. Can be overriden in device trees +# in the event of prebuilt kernel. # # KERNEL_TOOLCHAIN_PREFIX = Overrides TARGET_KERNEL_CROSS_COMPILE_PREFIX, # Set this var in shell to override @@ -49,6 +52,10 @@ else KERNEL_ARCH := $(TARGET_KERNEL_ARCH) endif +KERNEL_VERSION := $(shell grep "^VERSION = " $(TARGET_KERNEL_SOURCE)/Makefile | awk '{ print $$3 }') +KERNEL_PATCHLEVEL := $(shell grep "^PATCHLEVEL = " $(TARGET_KERNEL_SOURCE)/Makefile | awk '{ print $$3 }') +TARGET_KERNEL_VERSION ?= $(shell echo $(KERNEL_VERSION)"."$(KERNEL_PATCHLEVEL)) + CLANG_PREBUILTS := $(BUILD_TOP)/prebuilts/clang/host/$(HOST_PREBUILT_TAG)/clang-r416183b1 GCC_PREBUILTS := $(BUILD_TOP)/prebuilts/gcc/$(HOST_PREBUILT_TAG) # arm64 toolchain @@ -147,6 +154,13 @@ KERNEL_MAKE_CMD := $(BUILD_TOP)/prebuilts/build-tools/$(HOST_PREBUILT_TAG)/bin/m KERNEL_MAKE_FLAGS += HOSTCC=$(CLANG_PREBUILTS)/bin/clang KERNEL_MAKE_FLAGS += HOSTCXX=$(CLANG_PREBUILTS)/bin/clang++ +# Use LLVM's substitutes for GNU binutils if compatible kernel version. +ifneq ($(TARGET_KERNEL_CLANG_COMPILE), false) +ifneq (,$(filter 5.4, $(TARGET_KERNEL_VERSION))) + KERNEL_MAKE_FLAGS += LLVM=1 LLVM_IAS=1 +endif +endif + # Since Linux 4.16, flex and bison are required KERNEL_MAKE_FLAGS += LEX=$(BUILD_TOP)/prebuilts/build-tools/$(HOST_PREBUILT_TAG)/bin/flex KERNEL_MAKE_FLAGS += YACC=$(BUILD_TOP)/prebuilts/build-tools/$(HOST_PREBUILT_TAG)/bin/bison