Rashed Abdel-Tawab | 06539d4 | 2019-09-27 06:46:05 -0700 | [diff] [blame] | 1 | # Copyright (C) 2018-2019 The LineageOS Project |
Rashed Abdel-Tawab | a836d79 | 2018-09-20 15:19:57 -0700 | [diff] [blame] | 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | # |
| 15 | # |
| 16 | # Kernel build configuration variables |
| 17 | # ==================================== |
| 18 | # |
| 19 | # These config vars are usually set in BoardConfig.mk: |
| 20 | # |
| 21 | # TARGET_KERNEL_SOURCE = Kernel source dir, optional, defaults |
| 22 | # to kernel/$(TARGET_DEVICE_DIR) |
Rashed Abdel-Tawab | 3254caf | 2018-06-15 22:45:53 -0700 | [diff] [blame] | 23 | # TARGET_KERNEL_ADDITIONAL_FLAGS = Additional make flags, optional |
Rashed Abdel-Tawab | a836d79 | 2018-09-20 15:19:57 -0700 | [diff] [blame] | 24 | # TARGET_KERNEL_ARCH = Kernel Arch |
| 25 | # TARGET_KERNEL_CROSS_COMPILE_PREFIX = Compiler prefix (e.g. arm-eabi-) |
| 26 | # defaults to arm-linux-androidkernel- for arm |
dianlujitao | bd16a8e | 2019-09-08 12:44:49 +0800 | [diff] [blame] | 27 | # aarch64-linux-android- for arm64 |
| 28 | # x86_64-linux-android- for x86 |
Rashed Abdel-Tawab | a836d79 | 2018-09-20 15:19:57 -0700 | [diff] [blame] | 29 | # |
| 30 | # TARGET_KERNEL_CLANG_COMPILE = Compile kernel with clang, defaults to false |
| 31 | # |
| 32 | # KERNEL_TOOLCHAIN_PREFIX = Overrides TARGET_KERNEL_CROSS_COMPILE_PREFIX, |
| 33 | # Set this var in shell to override |
| 34 | # toolchain specified in BoardConfig.mk |
| 35 | # KERNEL_TOOLCHAIN = Path to toolchain, if unset, assumes |
| 36 | # TARGET_KERNEL_CROSS_COMPILE_PREFIX |
| 37 | # is in PATH |
| 38 | # USE_CCACHE = Enable ccache (global Android flag) |
| 39 | |
| 40 | BUILD_TOP := $(shell pwd) |
| 41 | |
| 42 | TARGET_AUTO_KDIR := $(shell echo $(TARGET_DEVICE_DIR) | sed -e 's/^device/kernel/g') |
| 43 | TARGET_KERNEL_SOURCE ?= $(TARGET_AUTO_KDIR) |
| 44 | ifneq ($(TARGET_PREBUILT_KERNEL),) |
| 45 | TARGET_KERNEL_SOURCE := |
| 46 | endif |
| 47 | |
| 48 | TARGET_KERNEL_ARCH := $(strip $(TARGET_KERNEL_ARCH)) |
| 49 | ifeq ($(TARGET_KERNEL_ARCH),) |
| 50 | KERNEL_ARCH := $(TARGET_ARCH) |
| 51 | else |
| 52 | KERNEL_ARCH := $(TARGET_KERNEL_ARCH) |
| 53 | endif |
| 54 | |
Rashed Abdel-Tawab | 493ad4b | 2019-09-06 14:26:34 -0700 | [diff] [blame] | 55 | GCC_PREBUILTS := $(BUILD_TOP)/prebuilts/gcc/$(HOST_OS)-x86 |
| 56 | # arm64 toolchain |
| 57 | KERNEL_TOOLCHAIN_arm64 := $(GCC_PREBUILTS)/aarch64/aarch64-linux-android-4.9/bin |
| 58 | KERNEL_TOOLCHAIN_PREFIX_arm64 := aarch64-linux-android- |
| 59 | # arm toolchain |
| 60 | KERNEL_TOOLCHAIN_arm := $(GCC_PREBUILTS)/arm/arm-linux-androideabi-4.9/bin |
| 61 | KERNEL_TOOLCHAIN_PREFIX_arm := arm-linux-androidkernel- |
| 62 | # x86 toolchain |
| 63 | KERNEL_TOOLCHAIN_x86 := $(GCC_PREBUILTS)/x86/x86_64-linux-android-4.9/bin |
| 64 | KERNEL_TOOLCHAIN_PREFIX_x86 := x86_64-linux-android- |
| 65 | |
Rashed Abdel-Tawab | a836d79 | 2018-09-20 15:19:57 -0700 | [diff] [blame] | 66 | TARGET_KERNEL_CROSS_COMPILE_PREFIX := $(strip $(TARGET_KERNEL_CROSS_COMPILE_PREFIX)) |
| 67 | ifneq ($(TARGET_KERNEL_CROSS_COMPILE_PREFIX),) |
| 68 | KERNEL_TOOLCHAIN_PREFIX ?= $(TARGET_KERNEL_CROSS_COMPILE_PREFIX) |
Rashed Abdel-Tawab | 493ad4b | 2019-09-06 14:26:34 -0700 | [diff] [blame] | 69 | else |
| 70 | KERNEL_TOOLCHAIN ?= $(KERNEL_TOOLCHAIN_$(KERNEL_ARCH)) |
| 71 | KERNEL_TOOLCHAIN_PREFIX ?= $(KERNEL_TOOLCHAIN_PREFIX_$(KERNEL_ARCH)) |
Rashed Abdel-Tawab | a836d79 | 2018-09-20 15:19:57 -0700 | [diff] [blame] | 72 | endif |
| 73 | |
| 74 | ifeq ($(KERNEL_TOOLCHAIN),) |
| 75 | KERNEL_TOOLCHAIN_PATH := $(KERNEL_TOOLCHAIN_PREFIX) |
Rashed Abdel-Tawab | 493ad4b | 2019-09-06 14:26:34 -0700 | [diff] [blame] | 76 | else |
Rashed Abdel-Tawab | a836d79 | 2018-09-20 15:19:57 -0700 | [diff] [blame] | 77 | KERNEL_TOOLCHAIN_PATH := $(KERNEL_TOOLCHAIN)/$(KERNEL_TOOLCHAIN_PREFIX) |
| 78 | endif |
Rashed Abdel-Tawab | a836d79 | 2018-09-20 15:19:57 -0700 | [diff] [blame] | 79 | |
Rashed Abdel-Tawab | c648519 | 2019-09-10 08:38:34 -0700 | [diff] [blame] | 80 | # We need to add GCC toolchain to the path no matter what |
| 81 | # for tools like `as` |
Rashed Abdel-Tawab | 168fd23 | 2019-09-24 17:22:39 +0200 | [diff] [blame] | 82 | KERNEL_TOOLCHAIN_PATH_gcc := $(KERNEL_TOOLCHAIN_$(KERNEL_ARCH))/$(KERNEL_TOOLCHAIN_PREFIX_$(KERNEL_ARCH)) |
Rashed Abdel-Tawab | c648519 | 2019-09-10 08:38:34 -0700 | [diff] [blame] | 83 | |
Rashed Abdel-Tawab | a836d79 | 2018-09-20 15:19:57 -0700 | [diff] [blame] | 84 | ifneq ($(USE_CCACHE),) |
Rashed Abdel-Tawab | 3ad0e0d | 2019-09-05 21:26:19 -0700 | [diff] [blame] | 85 | ifneq ($(CCACHE_EXEC),) |
| 86 | # Android 10+ deprecates use of a build ccache. Only system installed ones are now allowed |
| 87 | CCACHE_BIN := $(CCACHE_EXEC) |
Rashed Abdel-Tawab | a836d79 | 2018-09-20 15:19:57 -0700 | [diff] [blame] | 88 | endif |
| 89 | endif |
| 90 | |
| 91 | ifeq ($(TARGET_KERNEL_CLANG_COMPILE),true) |
| 92 | KERNEL_CROSS_COMPILE := CROSS_COMPILE="$(KERNEL_TOOLCHAIN_PATH)" |
| 93 | else |
| 94 | KERNEL_CROSS_COMPILE := CROSS_COMPILE="$(CCACHE_BIN) $(KERNEL_TOOLCHAIN_PATH)" |
| 95 | endif |
| 96 | |
| 97 | # Needed for CONFIG_COMPAT_VDSO, safe to set for all arm64 builds |
| 98 | ifeq ($(KERNEL_ARCH),arm64) |
Rashed Abdel-Tawab | 493ad4b | 2019-09-06 14:26:34 -0700 | [diff] [blame] | 99 | KERNEL_CROSS_COMPILE += CROSS_COMPILE_ARM32="$(KERNEL_TOOLCHAIN_arm)/$(KERNEL_TOOLCHAIN_PREFIX_arm)" |
Rashed Abdel-Tawab | a836d79 | 2018-09-20 15:19:57 -0700 | [diff] [blame] | 100 | endif |
| 101 | |
| 102 | # Clear this first to prevent accidental poisoning from env |
| 103 | KERNEL_MAKE_FLAGS := |
| 104 | |
Ethan Chen | 995aff2 | 2019-02-09 14:59:56 -0800 | [diff] [blame] | 105 | # Add back threads, ninja cuts this to $(nproc)/2 |
Luca Stefani | 70207cd | 2019-09-08 13:50:21 -0700 | [diff] [blame] | 106 | KERNEL_MAKE_FLAGS += -j$(shell nproc --all) |
Ethan Chen | 995aff2 | 2019-02-09 14:59:56 -0800 | [diff] [blame] | 107 | |
Rashed Abdel-Tawab | a836d79 | 2018-09-20 15:19:57 -0700 | [diff] [blame] | 108 | ifeq ($(KERNEL_ARCH),arm) |
| 109 | # Avoid "Unknown symbol _GLOBAL_OFFSET_TABLE_" errors |
| 110 | KERNEL_MAKE_FLAGS += CFLAGS_MODULE="-fno-pic" |
| 111 | endif |
| 112 | |
| 113 | ifeq ($(KERNEL_ARCH),arm64) |
| 114 | # Avoid "unsupported RELA relocation: 311" errors (R_AARCH64_ADR_GOT_PAGE) |
| 115 | KERNEL_MAKE_FLAGS += CFLAGS_MODULE="-fno-pic" |
| 116 | endif |
| 117 | |
| 118 | ifeq ($(HOST_OS),darwin) |
LuK1337 | 9d8578b | 2019-09-30 17:55:58 +0200 | [diff] [blame] | 119 | KERNEL_MAKE_FLAGS += HOSTCFLAGS="-I$(BUILD_TOP)/external/elfutils/libelf -I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" |
Rashed Abdel-Tawab | d7e24e3 | 2019-09-05 21:29:27 -0700 | [diff] [blame] | 120 | else |
LuK1337 | 9d8578b | 2019-09-30 17:55:58 +0200 | [diff] [blame] | 121 | KERNEL_MAKE_FLAGS += HOSTCFLAGS="-I/usr/include -I/usr/include/x86_64-linux-gnu -L/usr/lib/x86_64-linux-gnu -L/usr/lib64" |
Rashed Abdel-Tawab | a836d79 | 2018-09-20 15:19:57 -0700 | [diff] [blame] | 122 | endif |
Rashed Abdel-Tawab | 06539d4 | 2019-09-27 06:46:05 -0700 | [diff] [blame] | 123 | |
Rashed Abdel-Tawab | 3254caf | 2018-06-15 22:45:53 -0700 | [diff] [blame] | 124 | ifneq ($(TARGET_KERNEL_ADDITIONAL_FLAGS),) |
| 125 | KERNEL_MAKE_FLAGS += $(TARGET_KERNEL_ADDITIONAL_FLAGS) |
| 126 | endif |
| 127 | |
LuK1337 | 9d8578b | 2019-09-30 17:55:58 +0200 | [diff] [blame] | 128 | TOOLS_PATH_OVERRIDE := \ |
Rashed Abdel-Tawab | dfc3d18 | 2019-09-06 10:44:50 -0700 | [diff] [blame] | 129 | PATH=$(BUILD_TOP)/prebuilts/tools-lineage/$(HOST_OS)-x86/bin:$$PATH \ |
| 130 | LD_LIBRARY_PATH=$(BUILD_TOP)/prebuilts/tools-lineage/$(HOST_OS)-x86/lib:$$LD_LIBRARY_PATH \ |
Rashed Abdel-Tawab | 812efbc | 2019-09-17 11:17:10 -0700 | [diff] [blame] | 131 | PERL5LIB=$(BUILD_TOP)/prebuilts/tools-lineage/common/perl-base |
Rashed Abdel-Tawab | dfc3d18 | 2019-09-06 10:44:50 -0700 | [diff] [blame] | 132 | |
Rashed Abdel-Tawab | 60fe935 | 2019-05-16 14:01:19 -0700 | [diff] [blame] | 133 | # Set DTBO image locations so the build system knows to build them |
| 134 | ifeq ($(TARGET_NEEDS_DTBOIMAGE),true) |
| 135 | BOARD_PREBUILT_DTBOIMAGE ?= $(PRODUCT_OUT)/dtbo/arch/$(KERNEL_ARCH)/boot/dtbo.img |
| 136 | else ifeq ($(BOARD_KERNEL_SEPARATED_DTBO),true) |
| 137 | BOARD_PREBUILT_DTBOIMAGE ?= $(PRODUCT_OUT)/dtbo-pre.img |
| 138 | endif |
Rashed Abdel-Tawab | fb35b9d | 2019-09-05 21:21:13 -0700 | [diff] [blame] | 139 | |
| 140 | # Set use the full path to the make command |
| 141 | KERNEL_MAKE_CMD := $(BUILD_TOP)/prebuilts/build-tools/$(HOST_OS)-x86/bin/make |
Rashed Abdel-Tawab | 21ee598 | 2019-09-05 21:24:07 -0700 | [diff] [blame] | 142 | |
| 143 | # Set the full path to the gcc command |
Rashed Abdel-Tawab | 21ee598 | 2019-09-05 21:24:07 -0700 | [diff] [blame] | 144 | ifeq ($(HOST_OS),darwin) |
Rashed Abdel-Tawab | 493ad4b | 2019-09-06 14:26:34 -0700 | [diff] [blame] | 145 | KERNEL_HOST_TOOLCHAIN_ROOT := $(GCC_PREBUILTS)/host/i686-apple-darwin-4.2.1/bin/i686-apple-darwin11- |
Rashed Abdel-Tawab | 21ee598 | 2019-09-05 21:24:07 -0700 | [diff] [blame] | 146 | else |
Rashed Abdel-Tawab | 493ad4b | 2019-09-06 14:26:34 -0700 | [diff] [blame] | 147 | KERNEL_HOST_TOOLCHAIN_ROOT := $(GCC_PREBUILTS)/host/x86_64-linux-glibc2.17-4.8/bin/x86_64-linux- |
Rashed Abdel-Tawab | 21ee598 | 2019-09-05 21:24:07 -0700 | [diff] [blame] | 148 | endif |
| 149 | KERNEL_MAKE_FLAGS += HOSTCC=$(KERNEL_HOST_TOOLCHAIN_ROOT)gcc |
| 150 | KERNEL_MAKE_FLAGS += HOSTCXX=$(KERNEL_HOST_TOOLCHAIN_ROOT)g++ |
Rashed Abdel-Tawab | ba5ea35 | 2019-09-07 17:01:13 -0700 | [diff] [blame] | 151 | |
dianlujitao | a24144f | 2020-03-11 19:05:29 +0800 | [diff] [blame] | 152 | # Since Linux 4.16, flex and bison are required |
| 153 | KERNEL_MAKE_FLAGS += LEX=$(BUILD_TOP)/prebuilts/build-tools/$(HOST_OS)-x86/bin/flex |
| 154 | KERNEL_MAKE_FLAGS += YACC=$(BUILD_TOP)/prebuilts/build-tools/$(HOST_OS)-x86/bin/bison |
| 155 | TOOLS_PATH_OVERRIDE += BISON_PKGDATADIR=$(BUILD_TOP)/prebuilts/build-tools/common/bison |
| 156 | |
Rashed Abdel-Tawab | ba5ea35 | 2019-09-07 17:01:13 -0700 | [diff] [blame] | 157 | # Set the out dir for the kernel's O= arg |
| 158 | # This needs to be an absolute path, so only set this if the standard out dir isn't used |
| 159 | OUT_DIR_PREFIX := $(shell echo $(OUT_DIR) | sed -e 's|/target/.*$$||g') |
| 160 | KERNEL_BUILD_OUT_PREFIX := |
| 161 | ifeq ($(OUT_DIR_PREFIX),out) |
| 162 | KERNEL_BUILD_OUT_PREFIX := $(BUILD_TOP)/ |
| 163 | endif |