blob: 9246da5f0797453477ac9a7fdfb3af07f19def21 [file] [log] [blame]
Rashed Abdel-Tawaba836d792018-09-20 15:19:57 -07001# Copyright (C) 2018 The LineageOS Project
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-Tawab3254caf2018-06-15 22:45:53 -070023# TARGET_KERNEL_ADDITIONAL_FLAGS = Additional make flags, optional
Rashed Abdel-Tawaba836d792018-09-20 15:19:57 -070024# 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
27# aarch64-linux-androidkernel- for arm64
28# x86_64-linux-androidkernel- for x86
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
40BUILD_TOP := $(shell pwd)
41
42TARGET_AUTO_KDIR := $(shell echo $(TARGET_DEVICE_DIR) | sed -e 's/^device/kernel/g')
43TARGET_KERNEL_SOURCE ?= $(TARGET_AUTO_KDIR)
44ifneq ($(TARGET_PREBUILT_KERNEL),)
45TARGET_KERNEL_SOURCE :=
46endif
47
48TARGET_KERNEL_ARCH := $(strip $(TARGET_KERNEL_ARCH))
49ifeq ($(TARGET_KERNEL_ARCH),)
50KERNEL_ARCH := $(TARGET_ARCH)
51else
52KERNEL_ARCH := $(TARGET_KERNEL_ARCH)
53endif
54
55TARGET_KERNEL_CROSS_COMPILE_PREFIX := $(strip $(TARGET_KERNEL_CROSS_COMPILE_PREFIX))
56ifneq ($(TARGET_KERNEL_CROSS_COMPILE_PREFIX),)
57KERNEL_TOOLCHAIN_PREFIX ?= $(TARGET_KERNEL_CROSS_COMPILE_PREFIX)
58else ifeq ($(KERNEL_ARCH),arm64)
Rashed Abdel-Tawab8613ea02019-06-03 22:00:42 -070059ifeq ($(TARGET_KERNEL_CLANG_COMPILE),true)
60 KERNEL_TOOLCHAIN_PREFIX ?= aarch64-linux-android-
61else
62 KERNEL_TOOLCHAIN_PREFIX ?= aarch64-linux-androidkernel-
63endif
Rashed Abdel-Tawaba836d792018-09-20 15:19:57 -070064else ifeq ($(KERNEL_ARCH),arm)
65KERNEL_TOOLCHAIN_PREFIX ?= arm-linux-androidkernel-
66else ifeq ($(KERNEL_ARCH),x86)
67KERNEL_TOOLCHAIN_PREFIX ?= x86_64-linux-androidkernel-
68endif
69
70ifeq ($(KERNEL_TOOLCHAIN),)
71KERNEL_TOOLCHAIN_PATH := $(KERNEL_TOOLCHAIN_PREFIX)
Ethan Chenb7b49cc2019-06-22 19:57:57 -070072else ifneq ($(KERNEL_TOOLCHAIN_PREFIX),)
Rashed Abdel-Tawaba836d792018-09-20 15:19:57 -070073KERNEL_TOOLCHAIN_PATH := $(KERNEL_TOOLCHAIN)/$(KERNEL_TOOLCHAIN_PREFIX)
74endif
Rashed Abdel-Tawaba836d792018-09-20 15:19:57 -070075
76ifneq ($(USE_CCACHE),)
77 # Detect if the system already has ccache installed to use instead of the prebuilt
78 CCACHE_BIN := $(shell which ccache)
79
80 ifeq ($(CCACHE_BIN),)
81 CCACHE_BIN := $(BUILD_TOP)/prebuilts/misc/$(HOST_PREBUILT_TAG)/ccache/ccache
82 # Check that the executable is here.
83 CCACHE_BIN := $(strip $(wildcard $(CCACHE_BIN)))
84 endif
85endif
86
87ifeq ($(TARGET_KERNEL_CLANG_COMPILE),true)
88 KERNEL_CROSS_COMPILE := CROSS_COMPILE="$(KERNEL_TOOLCHAIN_PATH)"
89else
90 KERNEL_CROSS_COMPILE := CROSS_COMPILE="$(CCACHE_BIN) $(KERNEL_TOOLCHAIN_PATH)"
91endif
92
93# Needed for CONFIG_COMPAT_VDSO, safe to set for all arm64 builds
94ifeq ($(KERNEL_ARCH),arm64)
Rashed Abdel-Tawab8613ea02019-06-03 22:00:42 -070095 KERNEL_CROSS_COMPILE += CROSS_COMPILE_ARM32="arm-linux-androideabi-"
Rashed Abdel-Tawaba836d792018-09-20 15:19:57 -070096endif
97
98# Clear this first to prevent accidental poisoning from env
99KERNEL_MAKE_FLAGS :=
100
Ethan Chen995aff22019-02-09 14:59:56 -0800101# Add back threads, ninja cuts this to $(nproc)/2
102KERNEL_MAKE_FLAGS += -j$$(nproc)
103
Rashed Abdel-Tawaba836d792018-09-20 15:19:57 -0700104ifeq ($(KERNEL_ARCH),arm)
105 # Avoid "Unknown symbol _GLOBAL_OFFSET_TABLE_" errors
106 KERNEL_MAKE_FLAGS += CFLAGS_MODULE="-fno-pic"
107endif
108
109ifeq ($(KERNEL_ARCH),arm64)
110 # Avoid "unsupported RELA relocation: 311" errors (R_AARCH64_ADR_GOT_PAGE)
111 KERNEL_MAKE_FLAGS += CFLAGS_MODULE="-fno-pic"
112endif
113
114ifeq ($(HOST_OS),darwin)
115 KERNEL_MAKE_FLAGS += C_INCLUDE_PATH=$(BUILD_TOP)/external/elfutils/libelf:/usr/local/opt/openssl/include
116 KERNEL_MAKE_FLAGS += LIBRARY_PATH=/usr/local/opt/openssl/lib
117endif
Rashed Abdel-Tawab60fe9352019-05-16 14:01:19 -0700118
Rashed Abdel-Tawab3254caf2018-06-15 22:45:53 -0700119ifneq ($(TARGET_KERNEL_ADDITIONAL_FLAGS),)
120 KERNEL_MAKE_FLAGS += $(TARGET_KERNEL_ADDITIONAL_FLAGS)
121endif
122
Rashed Abdel-Tawab60fe9352019-05-16 14:01:19 -0700123# Set DTBO image locations so the build system knows to build them
124ifeq ($(TARGET_NEEDS_DTBOIMAGE),true)
125BOARD_PREBUILT_DTBOIMAGE ?= $(PRODUCT_OUT)/dtbo/arch/$(KERNEL_ARCH)/boot/dtbo.img
126else ifeq ($(BOARD_KERNEL_SEPARATED_DTBO),true)
127BOARD_PREBUILT_DTBOIMAGE ?= $(PRODUCT_OUT)/dtbo-pre.img
128endif