Rashed Abdel-Tawab | a836d79 | 2018-09-20 15:19:57 -0700 | [diff] [blame] | 1 | # 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 | |
| 39 | BUILD_TOP := $(shell pwd) |
| 40 | |
| 41 | TARGET_AUTO_KDIR := $(shell echo $(TARGET_DEVICE_DIR) | sed -e 's/^device/kernel/g') |
| 42 | TARGET_KERNEL_SOURCE ?= $(TARGET_AUTO_KDIR) |
| 43 | ifneq ($(TARGET_PREBUILT_KERNEL),) |
| 44 | TARGET_KERNEL_SOURCE := |
| 45 | endif |
| 46 | |
| 47 | TARGET_KERNEL_ARCH := $(strip $(TARGET_KERNEL_ARCH)) |
| 48 | ifeq ($(TARGET_KERNEL_ARCH),) |
| 49 | KERNEL_ARCH := $(TARGET_ARCH) |
| 50 | else |
| 51 | KERNEL_ARCH := $(TARGET_KERNEL_ARCH) |
| 52 | endif |
| 53 | |
| 54 | TARGET_KERNEL_CROSS_COMPILE_PREFIX := $(strip $(TARGET_KERNEL_CROSS_COMPILE_PREFIX)) |
| 55 | ifneq ($(TARGET_KERNEL_CROSS_COMPILE_PREFIX),) |
| 56 | KERNEL_TOOLCHAIN_PREFIX ?= $(TARGET_KERNEL_CROSS_COMPILE_PREFIX) |
| 57 | else ifeq ($(KERNEL_ARCH),arm64) |
| 58 | KERNEL_TOOLCHAIN_PREFIX ?= aarch64-linux-androidkernel- |
| 59 | else ifeq ($(KERNEL_ARCH),arm) |
| 60 | KERNEL_TOOLCHAIN_PREFIX ?= arm-linux-androidkernel- |
| 61 | else ifeq ($(KERNEL_ARCH),x86) |
| 62 | KERNEL_TOOLCHAIN_PREFIX ?= x86_64-linux-androidkernel- |
| 63 | endif |
| 64 | |
| 65 | ifeq ($(KERNEL_TOOLCHAIN),) |
| 66 | KERNEL_TOOLCHAIN_PATH := $(KERNEL_TOOLCHAIN_PREFIX) |
| 67 | else |
| 68 | ifneq ($(KERNEL_TOOLCHAIN_PREFIX),) |
| 69 | KERNEL_TOOLCHAIN_PATH := $(KERNEL_TOOLCHAIN)/$(KERNEL_TOOLCHAIN_PREFIX) |
| 70 | endif |
| 71 | endif |
| 72 | |
| 73 | ifneq ($(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 |
| 82 | endif |
| 83 | |
| 84 | ifeq ($(TARGET_KERNEL_CLANG_COMPILE),true) |
| 85 | KERNEL_CROSS_COMPILE := CROSS_COMPILE="$(KERNEL_TOOLCHAIN_PATH)" |
| 86 | else |
| 87 | KERNEL_CROSS_COMPILE := CROSS_COMPILE="$(CCACHE_BIN) $(KERNEL_TOOLCHAIN_PATH)" |
| 88 | endif |
| 89 | |
| 90 | # Needed for CONFIG_COMPAT_VDSO, safe to set for all arm64 builds |
| 91 | ifeq ($(KERNEL_ARCH),arm64) |
| 92 | KERNEL_CROSS_COMPILE += CROSS_COMPILE_ARM32="arm-linux-androidkernel-" |
| 93 | endif |
| 94 | |
| 95 | # Clear this first to prevent accidental poisoning from env |
| 96 | KERNEL_MAKE_FLAGS := |
| 97 | |
| 98 | ifeq ($(KERNEL_ARCH),arm) |
| 99 | # Avoid "Unknown symbol _GLOBAL_OFFSET_TABLE_" errors |
| 100 | KERNEL_MAKE_FLAGS += CFLAGS_MODULE="-fno-pic" |
| 101 | endif |
| 102 | |
| 103 | ifeq ($(KERNEL_ARCH),arm64) |
| 104 | # Avoid "unsupported RELA relocation: 311" errors (R_AARCH64_ADR_GOT_PAGE) |
| 105 | KERNEL_MAKE_FLAGS += CFLAGS_MODULE="-fno-pic" |
| 106 | endif |
| 107 | |
| 108 | ifeq ($(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 |
| 111 | endif |