blob: 74f3413b68e0e794fd95cb3397e8b5293a655e62 [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)
58KERNEL_TOOLCHAIN_PREFIX ?= aarch64-linux-androidkernel-
59else ifeq ($(KERNEL_ARCH),arm)
60KERNEL_TOOLCHAIN_PREFIX ?= arm-linux-androidkernel-
61else ifeq ($(KERNEL_ARCH),x86)
62KERNEL_TOOLCHAIN_PREFIX ?= x86_64-linux-androidkernel-
63endif
64
65ifeq ($(KERNEL_TOOLCHAIN),)
66KERNEL_TOOLCHAIN_PATH := $(KERNEL_TOOLCHAIN_PREFIX)
67else
68ifneq ($(KERNEL_TOOLCHAIN_PREFIX),)
69KERNEL_TOOLCHAIN_PATH := $(KERNEL_TOOLCHAIN)/$(KERNEL_TOOLCHAIN_PREFIX)
70endif
71endif
72
73ifneq ($(USE_CCACHE),)
74 # Detect if the system already has ccache installed to use instead of the prebuilt
75 CCACHE_BIN := $(shell which ccache)
76
77 ifeq ($(CCACHE_BIN),)
78 CCACHE_BIN := $(BUILD_TOP)/prebuilts/misc/$(HOST_PREBUILT_TAG)/ccache/ccache
79 # Check that the executable is here.
80 CCACHE_BIN := $(strip $(wildcard $(CCACHE_BIN)))
81 endif
82endif
83
84ifeq ($(TARGET_KERNEL_CLANG_COMPILE),true)
85 KERNEL_CROSS_COMPILE := CROSS_COMPILE="$(KERNEL_TOOLCHAIN_PATH)"
86else
87 KERNEL_CROSS_COMPILE := CROSS_COMPILE="$(CCACHE_BIN) $(KERNEL_TOOLCHAIN_PATH)"
88endif
89
90# Needed for CONFIG_COMPAT_VDSO, safe to set for all arm64 builds
91ifeq ($(KERNEL_ARCH),arm64)
92 KERNEL_CROSS_COMPILE += CROSS_COMPILE_ARM32="arm-linux-androidkernel-"
93endif
94
95# Clear this first to prevent accidental poisoning from env
96KERNEL_MAKE_FLAGS :=
97
98ifeq ($(KERNEL_ARCH),arm)
99 # Avoid "Unknown symbol _GLOBAL_OFFSET_TABLE_" errors
100 KERNEL_MAKE_FLAGS += CFLAGS_MODULE="-fno-pic"
101endif
102
103ifeq ($(KERNEL_ARCH),arm64)
104 # Avoid "unsupported RELA relocation: 311" errors (R_AARCH64_ADR_GOT_PAGE)
105 KERNEL_MAKE_FLAGS += CFLAGS_MODULE="-fno-pic"
106endif
107
108ifeq ($(HOST_OS),darwin)
109 KERNEL_MAKE_FLAGS += C_INCLUDE_PATH=$(BUILD_TOP)/external/elfutils/libelf:/usr/local/opt/openssl/include
110 KERNEL_MAKE_FLAGS += LIBRARY_PATH=/usr/local/opt/openssl/lib
111endif