blob: 01d1e61c9cf032d0f6e44c5a564c699ea4077578 [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)
23# TARGET_KERNEL_ARCH = Kernel Arch
24# TARGET_KERNEL_CROSS_COMPILE_PREFIX = Compiler prefix (e.g. arm-eabi-)
25# defaults to arm-linux-androidkernel- for arm
26# aarch64-linux-androidkernel- for arm64
27# x86_64-linux-androidkernel- for x86
28#
29# TARGET_KERNEL_CLANG_COMPILE = Compile kernel with clang, defaults to false
30#
31# KERNEL_TOOLCHAIN_PREFIX = Overrides TARGET_KERNEL_CROSS_COMPILE_PREFIX,
32# Set this var in shell to override
33# toolchain specified in BoardConfig.mk
34# KERNEL_TOOLCHAIN = Path to toolchain, if unset, assumes
35# TARGET_KERNEL_CROSS_COMPILE_PREFIX
36# is in PATH
37# USE_CCACHE = Enable ccache (global Android flag)
38
39BUILD_TOP := $(shell pwd)
40
41TARGET_AUTO_KDIR := $(shell echo $(TARGET_DEVICE_DIR) | sed -e 's/^device/kernel/g')
42TARGET_KERNEL_SOURCE ?= $(TARGET_AUTO_KDIR)
43ifneq ($(TARGET_PREBUILT_KERNEL),)
44TARGET_KERNEL_SOURCE :=
45endif
46
47TARGET_KERNEL_ARCH := $(strip $(TARGET_KERNEL_ARCH))
48ifeq ($(TARGET_KERNEL_ARCH),)
49KERNEL_ARCH := $(TARGET_ARCH)
50else
51KERNEL_ARCH := $(TARGET_KERNEL_ARCH)
52endif
53
54TARGET_KERNEL_CROSS_COMPILE_PREFIX := $(strip $(TARGET_KERNEL_CROSS_COMPILE_PREFIX))
55ifneq ($(TARGET_KERNEL_CROSS_COMPILE_PREFIX),)
56KERNEL_TOOLCHAIN_PREFIX ?= $(TARGET_KERNEL_CROSS_COMPILE_PREFIX)
57else ifeq ($(KERNEL_ARCH),arm64)
Rashed Abdel-Tawab8613ea02019-06-03 22:00:42 -070058ifeq ($(TARGET_KERNEL_CLANG_COMPILE),true)
59 KERNEL_TOOLCHAIN_PREFIX ?= aarch64-linux-android-
60else
61 KERNEL_TOOLCHAIN_PREFIX ?= aarch64-linux-androidkernel-
62endif
Rashed Abdel-Tawaba836d792018-09-20 15:19:57 -070063else ifeq ($(KERNEL_ARCH),arm)
64KERNEL_TOOLCHAIN_PREFIX ?= arm-linux-androidkernel-
65else ifeq ($(KERNEL_ARCH),x86)
66KERNEL_TOOLCHAIN_PREFIX ?= x86_64-linux-androidkernel-
67endif
68
69ifeq ($(KERNEL_TOOLCHAIN),)
70KERNEL_TOOLCHAIN_PATH := $(KERNEL_TOOLCHAIN_PREFIX)
Ethan Chenb7b49cc2019-06-22 19:57:57 -070071else ifneq ($(KERNEL_TOOLCHAIN_PREFIX),)
Rashed Abdel-Tawaba836d792018-09-20 15:19:57 -070072KERNEL_TOOLCHAIN_PATH := $(KERNEL_TOOLCHAIN)/$(KERNEL_TOOLCHAIN_PREFIX)
73endif
Rashed Abdel-Tawaba836d792018-09-20 15:19:57 -070074
75ifneq ($(USE_CCACHE),)
76 # Detect if the system already has ccache installed to use instead of the prebuilt
77 CCACHE_BIN := $(shell which ccache)
78
79 ifeq ($(CCACHE_BIN),)
80 CCACHE_BIN := $(BUILD_TOP)/prebuilts/misc/$(HOST_PREBUILT_TAG)/ccache/ccache
81 # Check that the executable is here.
82 CCACHE_BIN := $(strip $(wildcard $(CCACHE_BIN)))
83 endif
84endif
85
86ifeq ($(TARGET_KERNEL_CLANG_COMPILE),true)
87 KERNEL_CROSS_COMPILE := CROSS_COMPILE="$(KERNEL_TOOLCHAIN_PATH)"
88else
89 KERNEL_CROSS_COMPILE := CROSS_COMPILE="$(CCACHE_BIN) $(KERNEL_TOOLCHAIN_PATH)"
90endif
91
92# Needed for CONFIG_COMPAT_VDSO, safe to set for all arm64 builds
93ifeq ($(KERNEL_ARCH),arm64)
Rashed Abdel-Tawab8613ea02019-06-03 22:00:42 -070094 KERNEL_CROSS_COMPILE += CROSS_COMPILE_ARM32="arm-linux-androideabi-"
Rashed Abdel-Tawaba836d792018-09-20 15:19:57 -070095endif
96
97# Clear this first to prevent accidental poisoning from env
98KERNEL_MAKE_FLAGS :=
99
Ethan Chen995aff22019-02-09 14:59:56 -0800100# Add back threads, ninja cuts this to $(nproc)/2
101KERNEL_MAKE_FLAGS += -j$$(nproc)
102
Rashed Abdel-Tawaba836d792018-09-20 15:19:57 -0700103ifeq ($(KERNEL_ARCH),arm)
104 # Avoid "Unknown symbol _GLOBAL_OFFSET_TABLE_" errors
105 KERNEL_MAKE_FLAGS += CFLAGS_MODULE="-fno-pic"
106endif
107
108ifeq ($(KERNEL_ARCH),arm64)
109 # Avoid "unsupported RELA relocation: 311" errors (R_AARCH64_ADR_GOT_PAGE)
110 KERNEL_MAKE_FLAGS += CFLAGS_MODULE="-fno-pic"
111endif
112
113ifeq ($(HOST_OS),darwin)
114 KERNEL_MAKE_FLAGS += C_INCLUDE_PATH=$(BUILD_TOP)/external/elfutils/libelf:/usr/local/opt/openssl/include
115 KERNEL_MAKE_FLAGS += LIBRARY_PATH=/usr/local/opt/openssl/lib
116endif
Rashed Abdel-Tawab60fe9352019-05-16 14:01:19 -0700117
118# Set DTBO image locations so the build system knows to build them
119ifeq ($(TARGET_NEEDS_DTBOIMAGE),true)
120BOARD_PREBUILT_DTBOIMAGE ?= $(PRODUCT_OUT)/dtbo/arch/$(KERNEL_ARCH)/boot/dtbo.img
121else ifeq ($(BOARD_KERNEL_SEPARATED_DTBO),true)
122BOARD_PREBUILT_DTBOIMAGE ?= $(PRODUCT_OUT)/dtbo-pre.img
123endif