2022-06-15 17:46:57 +02:00
|
|
|
# Copyright (C) 2018-2022 The LineageOS Project
|
2018-09-21 00:19:57 +02:00
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Kernel build configuration variables
|
|
|
|
# ====================================
|
|
|
|
#
|
|
|
|
# These config vars are usually set in BoardConfig.mk:
|
|
|
|
#
|
|
|
|
# TARGET_KERNEL_SOURCE = Kernel source dir, optional, defaults
|
|
|
|
# to kernel/$(TARGET_DEVICE_DIR)
|
|
|
|
# TARGET_KERNEL_ARCH = Kernel Arch
|
|
|
|
# TARGET_KERNEL_CROSS_COMPILE_PREFIX = Compiler prefix (e.g. arm-eabi-)
|
|
|
|
# defaults to arm-linux-androidkernel- for arm
|
2019-09-08 06:44:49 +02:00
|
|
|
# aarch64-linux-android- for arm64
|
|
|
|
# x86_64-linux-android- for x86
|
2018-09-21 00:19:57 +02:00
|
|
|
#
|
2022-03-07 19:29:34 +01:00
|
|
|
# TARGET_KERNEL_CLANG_COMPILE = Compile kernel with clang, defaults to true
|
2022-06-15 17:46:57 +02:00
|
|
|
# TARGET_KERNEL_VERSION = Reported kernel version in top level kernel
|
|
|
|
# makefile. Can be overriden in device trees
|
|
|
|
# in the event of prebuilt kernel.
|
2018-09-21 00:19:57 +02:00
|
|
|
#
|
2022-08-10 05:44:40 +02:00
|
|
|
# TARGET_KERNEL_DTBO_PREFIX = Override path prefix of TARGET_KERNEL_DTBO.
|
|
|
|
# Defaults to empty
|
2022-08-10 04:18:59 +02:00
|
|
|
# TARGET_KERNEL_DTBO = Name of the kernel Makefile target that
|
|
|
|
# generates dtbo.img. Defaults to dtbo.img
|
|
|
|
#
|
2018-09-21 00:19:57 +02:00
|
|
|
# KERNEL_TOOLCHAIN_PREFIX = Overrides TARGET_KERNEL_CROSS_COMPILE_PREFIX,
|
|
|
|
# Set this var in shell to override
|
|
|
|
# toolchain specified in BoardConfig.mk
|
|
|
|
# KERNEL_TOOLCHAIN = Path to toolchain, if unset, assumes
|
|
|
|
# TARGET_KERNEL_CROSS_COMPILE_PREFIX
|
|
|
|
# is in PATH
|
|
|
|
# USE_CCACHE = Enable ccache (global Android flag)
|
|
|
|
|
2021-03-23 18:46:09 +01:00
|
|
|
BUILD_TOP := $(abspath .)
|
2018-09-21 00:19:57 +02:00
|
|
|
|
|
|
|
TARGET_AUTO_KDIR := $(shell echo $(TARGET_DEVICE_DIR) | sed -e 's/^device/kernel/g')
|
|
|
|
TARGET_KERNEL_SOURCE ?= $(TARGET_AUTO_KDIR)
|
|
|
|
|
|
|
|
TARGET_KERNEL_ARCH := $(strip $(TARGET_KERNEL_ARCH))
|
|
|
|
ifeq ($(TARGET_KERNEL_ARCH),)
|
|
|
|
KERNEL_ARCH := $(TARGET_ARCH)
|
|
|
|
else
|
|
|
|
KERNEL_ARCH := $(TARGET_KERNEL_ARCH)
|
|
|
|
endif
|
|
|
|
|
2022-07-08 00:03:22 +02:00
|
|
|
KERNEL_VERSION := $(shell grep -s "^VERSION = " $(TARGET_KERNEL_SOURCE)/Makefile | awk '{ print $$3 }')
|
|
|
|
KERNEL_PATCHLEVEL := $(shell grep -s "^PATCHLEVEL = " $(TARGET_KERNEL_SOURCE)/Makefile | awk '{ print $$3 }')
|
2022-06-15 17:46:57 +02:00
|
|
|
TARGET_KERNEL_VERSION ?= $(shell echo $(KERNEL_VERSION)"."$(KERNEL_PATCHLEVEL))
|
|
|
|
|
2021-10-05 22:28:51 +02:00
|
|
|
CLANG_PREBUILTS := $(BUILD_TOP)/prebuilts/clang/host/$(HOST_PREBUILT_TAG)/clang-r416183b1
|
2020-09-24 12:51:33 +02:00
|
|
|
GCC_PREBUILTS := $(BUILD_TOP)/prebuilts/gcc/$(HOST_PREBUILT_TAG)
|
2019-09-06 23:26:34 +02:00
|
|
|
# arm64 toolchain
|
|
|
|
KERNEL_TOOLCHAIN_arm64 := $(GCC_PREBUILTS)/aarch64/aarch64-linux-android-4.9/bin
|
|
|
|
KERNEL_TOOLCHAIN_PREFIX_arm64 := aarch64-linux-android-
|
|
|
|
# arm toolchain
|
|
|
|
KERNEL_TOOLCHAIN_arm := $(GCC_PREBUILTS)/arm/arm-linux-androideabi-4.9/bin
|
|
|
|
KERNEL_TOOLCHAIN_PREFIX_arm := arm-linux-androidkernel-
|
|
|
|
# x86 toolchain
|
|
|
|
KERNEL_TOOLCHAIN_x86 := $(GCC_PREBUILTS)/x86/x86_64-linux-android-4.9/bin
|
|
|
|
KERNEL_TOOLCHAIN_PREFIX_x86 := x86_64-linux-android-
|
|
|
|
|
2018-09-21 00:19:57 +02:00
|
|
|
TARGET_KERNEL_CROSS_COMPILE_PREFIX := $(strip $(TARGET_KERNEL_CROSS_COMPILE_PREFIX))
|
|
|
|
ifneq ($(TARGET_KERNEL_CROSS_COMPILE_PREFIX),)
|
|
|
|
KERNEL_TOOLCHAIN_PREFIX ?= $(TARGET_KERNEL_CROSS_COMPILE_PREFIX)
|
2019-09-06 23:26:34 +02:00
|
|
|
else
|
|
|
|
KERNEL_TOOLCHAIN ?= $(KERNEL_TOOLCHAIN_$(KERNEL_ARCH))
|
|
|
|
KERNEL_TOOLCHAIN_PREFIX ?= $(KERNEL_TOOLCHAIN_PREFIX_$(KERNEL_ARCH))
|
2018-09-21 00:19:57 +02:00
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(KERNEL_TOOLCHAIN),)
|
|
|
|
KERNEL_TOOLCHAIN_PATH := $(KERNEL_TOOLCHAIN_PREFIX)
|
2019-09-06 23:26:34 +02:00
|
|
|
else
|
2018-09-21 00:19:57 +02:00
|
|
|
KERNEL_TOOLCHAIN_PATH := $(KERNEL_TOOLCHAIN)/$(KERNEL_TOOLCHAIN_PREFIX)
|
|
|
|
endif
|
|
|
|
|
2019-09-10 17:38:34 +02:00
|
|
|
# We need to add GCC toolchain to the path no matter what
|
|
|
|
# for tools like `as`
|
2021-12-11 01:49:53 +01:00
|
|
|
KERNEL_TOOLCHAIN_PATH_gcc := $(KERNEL_TOOLCHAIN_$(KERNEL_ARCH))
|
2019-09-10 17:38:34 +02:00
|
|
|
|
2018-09-21 00:19:57 +02:00
|
|
|
ifneq ($(USE_CCACHE),)
|
2019-09-06 06:26:19 +02:00
|
|
|
ifneq ($(CCACHE_EXEC),)
|
|
|
|
# Android 10+ deprecates use of a build ccache. Only system installed ones are now allowed
|
|
|
|
CCACHE_BIN := $(CCACHE_EXEC)
|
2018-09-21 00:19:57 +02:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2022-03-07 19:29:34 +01:00
|
|
|
ifneq ($(TARGET_KERNEL_CLANG_COMPILE),false)
|
2018-09-21 00:19:57 +02:00
|
|
|
KERNEL_CROSS_COMPILE := CROSS_COMPILE="$(KERNEL_TOOLCHAIN_PATH)"
|
|
|
|
else
|
|
|
|
KERNEL_CROSS_COMPILE := CROSS_COMPILE="$(CCACHE_BIN) $(KERNEL_TOOLCHAIN_PATH)"
|
|
|
|
endif
|
|
|
|
|
|
|
|
# Needed for CONFIG_COMPAT_VDSO, safe to set for all arm64 builds
|
|
|
|
ifeq ($(KERNEL_ARCH),arm64)
|
2019-09-06 23:26:34 +02:00
|
|
|
KERNEL_CROSS_COMPILE += CROSS_COMPILE_ARM32="$(KERNEL_TOOLCHAIN_arm)/$(KERNEL_TOOLCHAIN_PREFIX_arm)"
|
2021-08-04 05:31:47 +02:00
|
|
|
KERNEL_CROSS_COMPILE += CROSS_COMPILE_COMPAT="$(KERNEL_TOOLCHAIN_arm)/$(KERNEL_TOOLCHAIN_PREFIX_arm)"
|
2018-09-21 00:19:57 +02:00
|
|
|
endif
|
|
|
|
|
|
|
|
# Clear this first to prevent accidental poisoning from env
|
|
|
|
KERNEL_MAKE_FLAGS :=
|
|
|
|
|
2019-02-09 23:59:56 +01:00
|
|
|
# Add back threads, ninja cuts this to $(nproc)/2
|
2020-09-16 04:40:57 +02:00
|
|
|
KERNEL_MAKE_FLAGS += -j$(shell prebuilts/tools-lineage/$(HOST_PREBUILT_TAG)/bin/nproc --all)
|
2019-02-09 23:59:56 +01:00
|
|
|
|
2022-06-16 08:58:31 +02:00
|
|
|
ifeq ($(TARGET_KERNEL_CLANG_COMPILE),false)
|
|
|
|
ifeq ($(KERNEL_ARCH),arm)
|
|
|
|
# Avoid "Unknown symbol _GLOBAL_OFFSET_TABLE_" errors
|
|
|
|
KERNEL_MAKE_FLAGS += CFLAGS_MODULE="-fno-pic"
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(KERNEL_ARCH),arm64)
|
|
|
|
# Avoid "unsupported RELA relocation: 311" errors (R_AARCH64_ADR_GOT_PAGE)
|
|
|
|
KERNEL_MAKE_FLAGS += CFLAGS_MODULE="-fno-pic"
|
|
|
|
endif
|
2018-09-21 00:19:57 +02:00
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(HOST_OS),darwin)
|
2020-09-22 23:11:21 +02:00
|
|
|
KERNEL_MAKE_FLAGS += HOSTCFLAGS="-I$(BUILD_TOP)/external/elfutils/libelf -I/usr/local/opt/openssl/include -fuse-ld=lld" HOSTLDFLAGS="-L/usr/local/opt/openssl/lib -fuse-ld=lld"
|
2019-09-06 06:29:27 +02:00
|
|
|
else
|
2020-09-22 23:11:21 +02:00
|
|
|
KERNEL_MAKE_FLAGS += CPATH="/usr/include:/usr/include/x86_64-linux-gnu" HOSTCFLAGS="-fuse-ld=lld" HOSTLDFLAGS="-L/usr/lib/x86_64-linux-gnu -L/usr/lib64 -fuse-ld=lld"
|
2018-09-21 00:19:57 +02:00
|
|
|
endif
|
2019-09-27 15:46:05 +02:00
|
|
|
|
2019-09-30 17:55:58 +02:00
|
|
|
TOOLS_PATH_OVERRIDE := \
|
2020-09-24 12:51:33 +02:00
|
|
|
LD_LIBRARY_PATH=$(BUILD_TOP)/prebuilts/tools-lineage/$(HOST_PREBUILT_TAG)/lib:$$LD_LIBRARY_PATH \
|
2019-09-17 20:17:10 +02:00
|
|
|
PERL5LIB=$(BUILD_TOP)/prebuilts/tools-lineage/common/perl-base
|
2019-09-06 19:44:50 +02:00
|
|
|
|
2021-10-17 15:21:24 +02:00
|
|
|
ifeq ($(KERNEL_ARCH),arm64)
|
|
|
|
# Add 32-bit GCC to PATH so that arm-linux-androidkernel-as is available for CONFIG_COMPAT_VDSO
|
|
|
|
TOOLS_PATH_OVERRIDE += PATH=$(BUILD_TOP)/prebuilts/tools-lineage/$(HOST_PREBUILT_TAG)/bin:$(KERNEL_TOOLCHAIN_arm):$$PATH
|
|
|
|
else
|
|
|
|
TOOLS_PATH_OVERRIDE += PATH=$(BUILD_TOP)/prebuilts/tools-lineage/$(HOST_PREBUILT_TAG)/bin:$$PATH
|
|
|
|
endif
|
|
|
|
|
2019-05-16 23:01:19 +02:00
|
|
|
# Set DTBO image locations so the build system knows to build them
|
2020-08-02 19:08:31 +02:00
|
|
|
ifeq (true,$(filter true, $(TARGET_NEEDS_DTBOIMAGE) $(BOARD_KERNEL_SEPARATED_DTBO)))
|
2022-08-10 05:44:40 +02:00
|
|
|
TARGET_KERNEL_DTBO_PREFIX ?=
|
2022-08-10 04:18:59 +02:00
|
|
|
TARGET_KERNEL_DTBO ?= dtbo.img
|
2022-08-10 05:44:40 +02:00
|
|
|
BOARD_PREBUILT_DTBOIMAGE ?= $(TARGET_OUT_INTERMEDIATES)/DTBO_OBJ/arch/$(KERNEL_ARCH)/boot/$(TARGET_KERNEL_DTBO_PREFIX)$(TARGET_KERNEL_DTBO)
|
2019-05-16 23:01:19 +02:00
|
|
|
endif
|
2019-09-06 06:21:13 +02:00
|
|
|
|
|
|
|
# Set use the full path to the make command
|
2020-09-24 12:51:33 +02:00
|
|
|
KERNEL_MAKE_CMD := $(BUILD_TOP)/prebuilts/build-tools/$(HOST_PREBUILT_TAG)/bin/make
|
2019-09-06 06:24:07 +02:00
|
|
|
|
2020-09-22 23:11:21 +02:00
|
|
|
# Set the full path to the clang command
|
|
|
|
KERNEL_MAKE_FLAGS += HOSTCC=$(CLANG_PREBUILTS)/bin/clang
|
|
|
|
KERNEL_MAKE_FLAGS += HOSTCXX=$(CLANG_PREBUILTS)/bin/clang++
|
2019-09-08 02:01:13 +02:00
|
|
|
|
2022-06-15 17:46:57 +02:00
|
|
|
# Use LLVM's substitutes for GNU binutils if compatible kernel version.
|
|
|
|
ifneq ($(TARGET_KERNEL_CLANG_COMPILE), false)
|
2022-08-10 05:03:02 +02:00
|
|
|
ifneq (,$(filter 5.4 5.10, $(TARGET_KERNEL_VERSION)))
|
2022-06-15 17:46:57 +02:00
|
|
|
KERNEL_MAKE_FLAGS += LLVM=1 LLVM_IAS=1
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2020-03-11 12:05:29 +01:00
|
|
|
# Since Linux 4.16, flex and bison are required
|
2020-09-24 12:51:33 +02:00
|
|
|
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
|
2020-09-13 19:43:00 +02:00
|
|
|
KERNEL_MAKE_FLAGS += M4=$(BUILD_TOP)/prebuilts/build-tools/$(HOST_PREBUILT_TAG)/bin/m4
|
2020-03-11 12:05:29 +01:00
|
|
|
TOOLS_PATH_OVERRIDE += BISON_PKGDATADIR=$(BUILD_TOP)/prebuilts/build-tools/common/bison
|
|
|
|
|
2019-09-08 02:01:13 +02:00
|
|
|
# Set the out dir for the kernel's O= arg
|
|
|
|
# This needs to be an absolute path, so only set this if the standard out dir isn't used
|
|
|
|
OUT_DIR_PREFIX := $(shell echo $(OUT_DIR) | sed -e 's|/target/.*$$||g')
|
|
|
|
KERNEL_BUILD_OUT_PREFIX :=
|
|
|
|
ifeq ($(OUT_DIR_PREFIX),out)
|
|
|
|
KERNEL_BUILD_OUT_PREFIX := $(BUILD_TOP)/
|
|
|
|
endif
|