blob: d8d42aad543a69e0a32e8dde61a4e5336b9a8979 [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)
71else
72ifneq ($(KERNEL_TOOLCHAIN_PREFIX),)
73KERNEL_TOOLCHAIN_PATH := $(KERNEL_TOOLCHAIN)/$(KERNEL_TOOLCHAIN_PREFIX)
74endif
75endif
76
77ifneq ($(USE_CCACHE),)
78 # Detect if the system already has ccache installed to use instead of the prebuilt
79 CCACHE_BIN := $(shell which ccache)
80
81 ifeq ($(CCACHE_BIN),)
82 CCACHE_BIN := $(BUILD_TOP)/prebuilts/misc/$(HOST_PREBUILT_TAG)/ccache/ccache
83 # Check that the executable is here.
84 CCACHE_BIN := $(strip $(wildcard $(CCACHE_BIN)))
85 endif
86endif
87
88ifeq ($(TARGET_KERNEL_CLANG_COMPILE),true)
89 KERNEL_CROSS_COMPILE := CROSS_COMPILE="$(KERNEL_TOOLCHAIN_PATH)"
90else
91 KERNEL_CROSS_COMPILE := CROSS_COMPILE="$(CCACHE_BIN) $(KERNEL_TOOLCHAIN_PATH)"
92endif
93
94# Needed for CONFIG_COMPAT_VDSO, safe to set for all arm64 builds
95ifeq ($(KERNEL_ARCH),arm64)
Rashed Abdel-Tawab8613ea02019-06-03 22:00:42 -070096 KERNEL_CROSS_COMPILE += CROSS_COMPILE_ARM32="arm-linux-androideabi-"
Rashed Abdel-Tawaba836d792018-09-20 15:19:57 -070097endif
98
99# Clear this first to prevent accidental poisoning from env
100KERNEL_MAKE_FLAGS :=
101
Ethan Chen995aff22019-02-09 14:59:56 -0800102# Add back threads, ninja cuts this to $(nproc)/2
103KERNEL_MAKE_FLAGS += -j$$(nproc)
104
Rashed Abdel-Tawaba836d792018-09-20 15:19:57 -0700105ifeq ($(KERNEL_ARCH),arm)
106 # Avoid "Unknown symbol _GLOBAL_OFFSET_TABLE_" errors
107 KERNEL_MAKE_FLAGS += CFLAGS_MODULE="-fno-pic"
108endif
109
110ifeq ($(KERNEL_ARCH),arm64)
111 # Avoid "unsupported RELA relocation: 311" errors (R_AARCH64_ADR_GOT_PAGE)
112 KERNEL_MAKE_FLAGS += CFLAGS_MODULE="-fno-pic"
113endif
114
115ifeq ($(HOST_OS),darwin)
116 KERNEL_MAKE_FLAGS += C_INCLUDE_PATH=$(BUILD_TOP)/external/elfutils/libelf:/usr/local/opt/openssl/include
117 KERNEL_MAKE_FLAGS += LIBRARY_PATH=/usr/local/opt/openssl/lib
118endif
Rashed Abdel-Tawab60fe9352019-05-16 14:01:19 -0700119
120# Set DTBO image locations so the build system knows to build them
121ifeq ($(TARGET_NEEDS_DTBOIMAGE),true)
122BOARD_PREBUILT_DTBOIMAGE ?= $(PRODUCT_OUT)/dtbo/arch/$(KERNEL_ARCH)/boot/dtbo.img
123else ifeq ($(BOARD_KERNEL_SEPARATED_DTBO),true)
124BOARD_PREBUILT_DTBOIMAGE ?= $(PRODUCT_OUT)/dtbo-pre.img
125endif