Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 1 | # Copyright (C) 2012 The CyanogenMod Project |
Dan Pasanen | 0344771 | 2016-12-19 11:22:55 -0600 | [diff] [blame] | 2 | # (C) 2017 The LineageOS Project |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
| 17 | # Android makefile to build kernel as a part of Android Build |
| 18 | # |
| 19 | # Configuration |
| 20 | # ============= |
| 21 | # |
| 22 | # These config vars are usually set in BoardConfig.mk: |
| 23 | # |
| 24 | # TARGET_KERNEL_SOURCE = Kernel source dir, optional, defaults |
| 25 | # to kernel/$(TARGET_DEVICE_DIR) |
| 26 | # TARGET_KERNEL_CONFIG = Kernel defconfig |
| 27 | # TARGET_KERNEL_VARIANT_CONFIG = Variant defconfig, optional |
| 28 | # TARGET_KERNEL_SELINUX_CONFIG = SELinux defconfig, optional |
| 29 | # TARGET_KERNEL_ADDITIONAL_CONFIG = Additional defconfig, optional |
| 30 | # TARGET_KERNEL_ARCH = Kernel Arch |
| 31 | # TARGET_KERNEL_HEADER_ARCH = Optional Arch for kernel headers if |
| 32 | # different from TARGET_KERNEL_ARCH |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 33 | # TARGET_KERNEL_CROSS_COMPILE_PREFIX = Compiler prefix (e.g. arm-eabi-) |
Michael Bestas | 1d55ece | 2016-09-28 20:16:25 +0300 | [diff] [blame] | 34 | # defaults to arm-linux-androidkernel- for arm |
| 35 | # aarch64-linux-androidkernel- for arm64 |
| 36 | # x86_64-linux-androidkernel- for x86 |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 37 | # |
Dan Pasanen | edc1ceb | 2017-01-24 15:46:13 -0600 | [diff] [blame] | 38 | # BOARD_KERNEL_IMAGE_NAME = Built image name |
| 39 | # for ARM use: zImage |
| 40 | # for ARM64 use: Image.gz |
| 41 | # for uncompressed use: Image |
| 42 | # If using an appended DT, append '-dtb' |
| 43 | # to the end of the image name. |
| 44 | # For example, for ARM devices, |
| 45 | # use zImage-dtb instead of zImage. |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 46 | # |
| 47 | # KERNEL_TOOLCHAIN_PREFIX = Overrides TARGET_KERNEL_CROSS_COMPILE_PREFIX, |
| 48 | # Set this var in shell to override |
| 49 | # toolchain specified in BoardConfig.mk |
| 50 | # KERNEL_TOOLCHAIN = Path to toolchain, if unset, assumes |
| 51 | # TARGET_KERNEL_CROSS_COMPILE_PREFIX |
| 52 | # is in PATH |
| 53 | # USE_CCACHE = Enable ccache (global Android flag) |
| 54 | # |
| 55 | # NEED_KERNEL_MODULE_ROOT = Optional, if true, install kernel |
| 56 | # modules in root instead of system |
| 57 | |
| 58 | |
| 59 | TARGET_AUTO_KDIR := $(shell echo $(TARGET_DEVICE_DIR) | sed -e 's/^device/kernel/g') |
| 60 | |
| 61 | ## Externally influenced variables |
| 62 | # kernel location - optional, defaults to kernel/<vendor>/<device> |
| 63 | TARGET_KERNEL_SOURCE ?= $(TARGET_AUTO_KDIR) |
| 64 | KERNEL_SRC := $(TARGET_KERNEL_SOURCE) |
| 65 | # kernel configuration - mandatory |
| 66 | KERNEL_DEFCONFIG := $(TARGET_KERNEL_CONFIG) |
| 67 | VARIANT_DEFCONFIG := $(TARGET_KERNEL_VARIANT_CONFIG) |
| 68 | SELINUX_DEFCONFIG := $(TARGET_KERNEL_SELINUX_CONFIG) |
| 69 | |
| 70 | ## Internal variables |
| 71 | KERNEL_OUT := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ |
| 72 | KERNEL_CONFIG := $(KERNEL_OUT)/.config |
| 73 | KERNEL_OUT_STAMP := $(KERNEL_OUT)/.mkdir_stamp |
| 74 | |
| 75 | TARGET_KERNEL_ARCH := $(strip $(TARGET_KERNEL_ARCH)) |
| 76 | ifeq ($(TARGET_KERNEL_ARCH),) |
| 77 | KERNEL_ARCH := $(TARGET_ARCH) |
| 78 | else |
| 79 | KERNEL_ARCH := $(TARGET_KERNEL_ARCH) |
| 80 | endif |
| 81 | |
| 82 | ifeq ($(KERNEL_ARCH),x86_64) |
| 83 | KERNEL_DEFCONFIG_ARCH := x86 |
| 84 | else |
| 85 | KERNEL_DEFCONFIG_ARCH := $(KERNEL_ARCH) |
| 86 | endif |
| 87 | KERNEL_DEFCONFIG_SRC := $(KERNEL_SRC)/arch/$(KERNEL_DEFCONFIG_ARCH)/configs/$(KERNEL_DEFCONFIG) |
| 88 | |
| 89 | TARGET_KERNEL_HEADER_ARCH := $(strip $(TARGET_KERNEL_HEADER_ARCH)) |
| 90 | ifeq ($(TARGET_KERNEL_HEADER_ARCH),) |
| 91 | KERNEL_HEADER_ARCH := $(KERNEL_ARCH) |
| 92 | else |
| 93 | KERNEL_HEADER_ARCH := $(TARGET_KERNEL_HEADER_ARCH) |
| 94 | endif |
| 95 | |
| 96 | KERNEL_HEADER_DEFCONFIG := $(strip $(KERNEL_HEADER_DEFCONFIG)) |
| 97 | ifeq ($(KERNEL_HEADER_DEFCONFIG),) |
| 98 | KERNEL_HEADER_DEFCONFIG := $(KERNEL_DEFCONFIG) |
| 99 | endif |
| 100 | |
Dan Pasanen | edc1ceb | 2017-01-24 15:46:13 -0600 | [diff] [blame] | 101 | ifeq ($(BOARD_KERNEL_IMAGE_NAME),) |
| 102 | $(error BOARD_KERNEL_IMAGE_NAME not defined.) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 103 | endif |
Dan Pasanen | edc1ceb | 2017-01-24 15:46:13 -0600 | [diff] [blame] | 104 | ifneq ($(TARGET_USES_UNCOMPRESSED_KERNEL),) |
| 105 | $(error TARGET_USES_UNCOMPRESSED_KERNEL is deprecated.) |
| 106 | endif |
| 107 | ifneq ($(TARGET_KERNEL_APPEND_DTB),) |
| 108 | $(error TARGET_KERNEL_APPEND_DTB is deprecated.) |
| 109 | endif |
| 110 | TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/$(KERNEL_ARCH)/boot/$(BOARD_KERNEL_IMAGE_NAME) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 111 | |
| 112 | # Clear this first to prevent accidental poisoning from env |
| 113 | MAKE_FLAGS := |
| 114 | |
Ziyan | 54648c2 | 2017-01-12 18:47:54 +0100 | [diff] [blame] | 115 | ifeq ($(KERNEL_ARCH),arm) |
| 116 | # Avoid "Unknown symbol _GLOBAL_OFFSET_TABLE_" errors |
| 117 | MAKE_FLAGS += CFLAGS_MODULE="-fno-pic" |
| 118 | endif |
| 119 | |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 120 | ifeq ($(KERNEL_ARCH),arm64) |
| 121 | # Avoid "unsupported RELA relocation: 311" errors (R_AARCH64_ADR_GOT_PAGE) |
| 122 | MAKE_FLAGS += CFLAGS_MODULE="-fno-pic" |
| 123 | ifeq ($(TARGET_ARCH),arm) |
| 124 | KERNEL_CONFIG_OVERRIDE := CONFIG_ANDROID_BINDER_IPC_32BIT=y |
| 125 | endif |
| 126 | endif |
| 127 | |
| 128 | ifneq ($(TARGET_KERNEL_ADDITIONAL_CONFIG),) |
| 129 | KERNEL_ADDITIONAL_CONFIG := $(TARGET_KERNEL_ADDITIONAL_CONFIG) |
| 130 | KERNEL_ADDITIONAL_CONFIG_SRC := $(KERNEL_SRC)/arch/$(KERNEL_ARCH)/configs/$(KERNEL_ADDITIONAL_CONFIG) |
| 131 | ifeq ("$(wildcard $(KERNEL_ADDITIONAL_CONFIG_SRC))","") |
| 132 | $(warning TARGET_KERNEL_ADDITIONAL_CONFIG '$(TARGET_KERNEL_ADDITIONAL_CONFIG)' doesn't exist) |
| 133 | KERNEL_ADDITIONAL_CONFIG_SRC := /dev/null |
| 134 | endif |
| 135 | else |
| 136 | KERNEL_ADDITIONAL_CONFIG_SRC := /dev/null |
| 137 | endif |
| 138 | |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 139 | ifeq "$(wildcard $(KERNEL_SRC) )" "" |
| 140 | ifneq ($(TARGET_PREBUILT_KERNEL),) |
| 141 | HAS_PREBUILT_KERNEL := true |
| 142 | NEEDS_KERNEL_COPY := true |
| 143 | else |
| 144 | $(foreach cf,$(PRODUCT_COPY_FILES), \ |
| 145 | $(eval _src := $(call word-colon,1,$(cf))) \ |
| 146 | $(eval _dest := $(call word-colon,2,$(cf))) \ |
| 147 | $(ifeq kernel,$(_dest), \ |
| 148 | $(eval HAS_PREBUILT_KERNEL := true))) |
| 149 | endif |
| 150 | |
| 151 | ifneq ($(HAS_PREBUILT_KERNEL),) |
| 152 | $(warning ***************************************************************) |
| 153 | $(warning * Using prebuilt kernel binary instead of source *) |
| 154 | $(warning * THIS IS DEPRECATED, AND WILL BE DISCONTINUED *) |
| 155 | $(warning * Please configure your device to download the kernel *) |
| 156 | $(warning * source repository to $(KERNEL_SRC)) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 157 | $(warning * for more information *) |
| 158 | $(warning ***************************************************************) |
| 159 | FULL_KERNEL_BUILD := false |
| 160 | KERNEL_BIN := $(TARGET_PREBUILT_KERNEL) |
| 161 | else |
| 162 | $(warning ***************************************************************) |
| 163 | $(warning * *) |
| 164 | $(warning * No kernel source found, and no fallback prebuilt defined. *) |
| 165 | $(warning * Please make sure your device is properly configured to *) |
| 166 | $(warning * download the kernel repository to $(KERNEL_SRC)) |
| 167 | $(warning * and add the TARGET_KERNEL_CONFIG variable to BoardConfig.mk *) |
| 168 | $(warning * *) |
| 169 | $(warning * As an alternative, define the TARGET_PREBUILT_KERNEL *) |
| 170 | $(warning * variable with the path to the prebuilt binary kernel image *) |
| 171 | $(warning * in your BoardConfig.mk file *) |
| 172 | $(warning * *) |
| 173 | $(warning ***************************************************************) |
| 174 | $(error "NO KERNEL") |
| 175 | endif |
| 176 | else |
| 177 | NEEDS_KERNEL_COPY := true |
| 178 | ifeq ($(TARGET_KERNEL_CONFIG),) |
| 179 | $(warning **********************************************************) |
| 180 | $(warning * Kernel source found, but no configuration was defined *) |
| 181 | $(warning * Please add the TARGET_KERNEL_CONFIG variable to your *) |
| 182 | $(warning * BoardConfig.mk file *) |
| 183 | $(warning **********************************************************) |
| 184 | # $(error "NO KERNEL CONFIG") |
| 185 | else |
| 186 | #$(info Kernel source found, building it) |
| 187 | FULL_KERNEL_BUILD := true |
| 188 | KERNEL_BIN := $(TARGET_PREBUILT_INT_KERNEL) |
| 189 | endif |
| 190 | endif |
| 191 | |
| 192 | ifeq ($(FULL_KERNEL_BUILD),true) |
| 193 | |
| 194 | KERNEL_HEADERS_INSTALL := $(KERNEL_OUT)/usr |
| 195 | KERNEL_HEADERS_INSTALL_STAMP := $(KERNEL_OUT)/.headers_install_stamp |
| 196 | |
| 197 | ifeq ($(NEED_KERNEL_MODULE_ROOT),true) |
| 198 | KERNEL_MODULES_INSTALL := root |
| 199 | KERNEL_MODULES_OUT := $(TARGET_ROOT_OUT)/lib/modules |
| 200 | else |
| 201 | KERNEL_MODULES_INSTALL := system |
| 202 | KERNEL_MODULES_OUT := $(TARGET_OUT)/lib/modules |
| 203 | endif |
| 204 | |
| 205 | TARGET_KERNEL_CROSS_COMPILE_PREFIX := $(strip $(TARGET_KERNEL_CROSS_COMPILE_PREFIX)) |
| 206 | ifneq ($(TARGET_KERNEL_CROSS_COMPILE_PREFIX),) |
| 207 | KERNEL_TOOLCHAIN_PREFIX ?= $(TARGET_KERNEL_CROSS_COMPILE_PREFIX) |
Zhao Wei Liew | 9689bb9 | 2016-11-10 20:02:58 +0800 | [diff] [blame] | 208 | else ifeq ($(KERNEL_ARCH),arm64) |
Michael Bestas | 1d55ece | 2016-09-28 20:16:25 +0300 | [diff] [blame] | 209 | KERNEL_TOOLCHAIN_PREFIX ?= aarch64-linux-androidkernel- |
Zhao Wei Liew | 9689bb9 | 2016-11-10 20:02:58 +0800 | [diff] [blame] | 210 | else ifeq ($(KERNEL_ARCH),arm) |
Michael Bestas | 1d55ece | 2016-09-28 20:16:25 +0300 | [diff] [blame] | 211 | KERNEL_TOOLCHAIN_PREFIX ?= arm-linux-androidkernel- |
Zhao Wei Liew | 9689bb9 | 2016-11-10 20:02:58 +0800 | [diff] [blame] | 212 | else ifeq ($(KERNEL_ARCH),x86) |
Michael Bestas | 1d55ece | 2016-09-28 20:16:25 +0300 | [diff] [blame] | 213 | KERNEL_TOOLCHAIN_PREFIX ?= x86_64-linux-androidkernel- |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 214 | endif |
| 215 | |
| 216 | ifeq ($(KERNEL_TOOLCHAIN),) |
| 217 | KERNEL_TOOLCHAIN_PATH := $(KERNEL_TOOLCHAIN_PREFIX) |
| 218 | else |
| 219 | ifneq ($(KERNEL_TOOLCHAIN_PREFIX),) |
| 220 | KERNEL_TOOLCHAIN_PATH := $(KERNEL_TOOLCHAIN)/$(KERNEL_TOOLCHAIN_PREFIX) |
| 221 | endif |
| 222 | endif |
| 223 | |
| 224 | ifneq ($(USE_CCACHE),) |
Steve Kondik | 6a37828 | 2016-09-25 22:37:01 -0700 | [diff] [blame] | 225 | # Detect if the system already has ccache installed to use instead of the prebuilt |
| 226 | ccache := $(shell which ccache) |
| 227 | |
| 228 | ifeq ($(ccache),) |
| 229 | ccache := $(ANDROID_BUILD_TOP)/prebuilts/misc/$(HOST_PREBUILT_TAG)/ccache/ccache |
| 230 | # Check that the executable is here. |
| 231 | ccache := $(strip $(wildcard $(ccache))) |
| 232 | endif |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 233 | endif |
| 234 | |
| 235 | KERNEL_CROSS_COMPILE := CROSS_COMPILE="$(ccache) $(KERNEL_TOOLCHAIN_PATH)" |
| 236 | ccache = |
| 237 | |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 238 | ifeq ($(HOST_OS),darwin) |
Christopher N. Hesse | 1e7c3f0 | 2017-04-12 00:57:44 +0200 | [diff] [blame] | 239 | MAKE_FLAGS += C_INCLUDE_PATH=$(ANDROID_BUILD_TOP)/external/elfutils/libelf:/usr/local/opt/openssl/include |
Rashed Abdel-Tawab | 7fb9251 | 2017-03-16 14:37:07 -0400 | [diff] [blame] | 240 | MAKE_FLAGS += LIBRARY_PATH=/usr/local/opt/openssl/lib |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 241 | endif |
| 242 | |
| 243 | ifeq ($(TARGET_KERNEL_MODULES),) |
Tom Marshall | f15c371 | 2017-11-10 01:00:18 +0100 | [diff] [blame] | 244 | TARGET_KERNEL_MODULES := INSTALLED_KERNEL_MODULES |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 245 | endif |
| 246 | |
| 247 | $(KERNEL_OUT_STAMP): |
| 248 | $(hide) mkdir -p $(KERNEL_OUT) |
| 249 | $(hide) rm -rf $(KERNEL_MODULES_OUT) |
| 250 | $(hide) mkdir -p $(KERNEL_MODULES_OUT) |
| 251 | $(hide) touch $@ |
| 252 | |
| 253 | KERNEL_ADDITIONAL_CONFIG_OUT := $(KERNEL_OUT)/.additional_config |
| 254 | |
| 255 | .PHONY: force_additional_config |
| 256 | $(KERNEL_ADDITIONAL_CONFIG_OUT): force_additional_config |
| 257 | $(hide) cmp -s $(KERNEL_ADDITIONAL_CONFIG_SRC) $@ || cp $(KERNEL_ADDITIONAL_CONFIG_SRC) $@; |
| 258 | |
| 259 | $(KERNEL_CONFIG): $(KERNEL_OUT_STAMP) $(KERNEL_DEFCONFIG_SRC) $(KERNEL_ADDITIONAL_CONFIG_OUT) |
| 260 | @echo "Building Kernel Config" |
| 261 | $(MAKE) $(MAKE_FLAGS) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) VARIANT_DEFCONFIG=$(VARIANT_DEFCONFIG) SELINUX_DEFCONFIG=$(SELINUX_DEFCONFIG) $(KERNEL_DEFCONFIG) |
| 262 | $(hide) if [ ! -z "$(KERNEL_CONFIG_OVERRIDE)" ]; then \ |
| 263 | echo "Overriding kernel config with '$(KERNEL_CONFIG_OVERRIDE)'"; \ |
| 264 | echo $(KERNEL_CONFIG_OVERRIDE) >> $(KERNEL_OUT)/.config; \ |
| 265 | $(MAKE) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) oldconfig; fi |
Sam Mortimer | b0cecb7 | 2016-10-01 09:56:52 -0700 | [diff] [blame] | 266 | # Create defconfig build artifact |
| 267 | $(hide) $(MAKE) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) savedefconfig |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 268 | $(hide) if [ ! -z "$(KERNEL_ADDITIONAL_CONFIG)" ]; then \ |
| 269 | echo "Using additional config '$(KERNEL_ADDITIONAL_CONFIG)'"; \ |
| 270 | $(KERNEL_SRC)/scripts/kconfig/merge_config.sh -m -O $(KERNEL_OUT) $(KERNEL_OUT)/.config $(KERNEL_SRC)/arch/$(KERNEL_ARCH)/configs/$(KERNEL_ADDITIONAL_CONFIG); \ |
| 271 | $(MAKE) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) KCONFIG_ALLCONFIG=$(KERNEL_OUT)/.config alldefconfig; fi |
| 272 | |
| 273 | TARGET_KERNEL_BINARIES: $(KERNEL_OUT_STAMP) $(KERNEL_CONFIG) $(KERNEL_HEADERS_INSTALL_STAMP) |
| 274 | @echo "Building Kernel" |
Dan Pasanen | edc1ceb | 2017-01-24 15:46:13 -0600 | [diff] [blame] | 275 | $(MAKE) $(MAKE_FLAGS) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(BOARD_KERNEL_IMAGE_NAME) |
Tom Marshall | f15c371 | 2017-11-10 01:00:18 +0100 | [diff] [blame] | 276 | $(hide) if grep -q '^CONFIG_OF=y' $(KERNEL_CONFIG); then \ |
| 277 | echo "Building DTBs"; \ |
| 278 | $(MAKE) $(MAKE_FLAGS) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) dtbs; \ |
| 279 | fi |
| 280 | $(hide) if grep -q '^CONFIG_MODULES=y' $(KERNEL_CONFIG); then \ |
| 281 | echo "Building Kernel Modules"; \ |
| 282 | $(MAKE) $(MAKE_FLAGS) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) modules; \ |
| 283 | fi |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 284 | |
Tom Marshall | f15c371 | 2017-11-10 01:00:18 +0100 | [diff] [blame] | 285 | .PHONY: INSTALLED_KERNEL_MODULES |
| 286 | INSTALLED_KERNEL_MODULES: |
| 287 | $(hide) if grep -q '^CONFIG_MODULES=y' $(KERNEL_CONFIG); then \ |
| 288 | echo "Installing Kernel Modules"; \ |
| 289 | $(MAKE) $(MAKE_FLAGS) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) INSTALL_MOD_PATH=../../$(KERNEL_MODULES_INSTALL) modules_install && \ |
| 290 | mofile=$$(find $(KERNEL_MODULES_OUT) -type f -name modules.order) && \ |
| 291 | mpath=$$(dirname $$mofile) && \ |
| 292 | for f in $$(find $$mpath/kernel -type f -name '*.ko'); do \ |
| 293 | $(KERNEL_TOOLCHAIN_PATH)strip --strip-unneeded $$f; \ |
| 294 | mv $$f $(KERNEL_MODULES_OUT); \ |
| 295 | done && \ |
| 296 | rm -rf $$mpath; \ |
| 297 | fi |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 298 | |
| 299 | $(TARGET_KERNEL_MODULES): TARGET_KERNEL_BINARIES |
| 300 | |
| 301 | $(TARGET_PREBUILT_INT_KERNEL): $(TARGET_KERNEL_MODULES) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 302 | |
| 303 | $(KERNEL_HEADERS_INSTALL_STAMP): $(KERNEL_OUT_STAMP) $(KERNEL_CONFIG) |
| 304 | @echo "Building Kernel Headers" |
| 305 | $(hide) if [ ! -z "$(KERNEL_HEADER_DEFCONFIG)" ]; then \ |
| 306 | rm -f ../$(KERNEL_CONFIG); \ |
| 307 | $(MAKE) $(MAKE_FLAGS) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_HEADER_ARCH) $(KERNEL_CROSS_COMPILE) VARIANT_DEFCONFIG=$(VARIANT_DEFCONFIG) SELINUX_DEFCONFIG=$(SELINUX_DEFCONFIG) $(KERNEL_HEADER_DEFCONFIG); \ |
| 308 | $(MAKE) $(MAKE_FLAGS) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_HEADER_ARCH) $(KERNEL_CROSS_COMPILE) headers_install; fi |
| 309 | $(hide) if [ "$(KERNEL_HEADER_DEFCONFIG)" != "$(KERNEL_DEFCONFIG)" ]; then \ |
| 310 | echo "Used a different defconfig for header generation"; \ |
| 311 | rm -f ../$(KERNEL_CONFIG); \ |
| 312 | $(MAKE) $(MAKE_FLAGS) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) VARIANT_DEFCONFIG=$(VARIANT_DEFCONFIG) SELINUX_DEFCONFIG=$(SELINUX_DEFCONFIG) $(KERNEL_DEFCONFIG); fi |
| 313 | $(hide) if [ ! -z "$(KERNEL_CONFIG_OVERRIDE)" ]; then \ |
| 314 | echo "Overriding kernel config with '$(KERNEL_CONFIG_OVERRIDE)'"; \ |
| 315 | echo $(KERNEL_CONFIG_OVERRIDE) >> $(KERNEL_OUT)/.config; \ |
| 316 | $(MAKE) $(MAKE_FLAGS) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) oldconfig; fi |
| 317 | $(hide) if [ ! -z "$(KERNEL_ADDITIONAL_CONFIG)" ]; then \ |
| 318 | echo "Using additional config '$(KERNEL_ADDITIONAL_CONFIG)'"; \ |
| 319 | $(KERNEL_SRC)/scripts/kconfig/merge_config.sh -m -O $(KERNEL_OUT) $(KERNEL_OUT)/.config $(KERNEL_SRC)/arch/$(KERNEL_ARCH)/configs/$(KERNEL_ADDITIONAL_CONFIG); \ |
| 320 | $(MAKE) $(MAKE_FLAGS) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) KCONFIG_ALLCONFIG=$(KERNEL_OUT)/.config alldefconfig; fi |
| 321 | $(hide) touch $@ |
| 322 | |
| 323 | # provide this rule because there are dependencies on this throughout the repo |
| 324 | $(KERNEL_HEADERS_INSTALL): $(KERNEL_HEADERS_INSTALL_STAMP) |
| 325 | |
| 326 | kerneltags: $(KERNEL_OUT_STAMP) $(KERNEL_CONFIG) |
| 327 | $(MAKE) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) tags |
| 328 | |
| 329 | kernelconfig: KERNELCONFIG_MODE := menuconfig |
| 330 | kernelxconfig: KERNELCONFIG_MODE := xconfig |
| 331 | kernelxconfig kernelconfig: $(KERNEL_OUT_STAMP) |
| 332 | $(MAKE) $(MAKE_FLAGS) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(KERNEL_DEFCONFIG) |
| 333 | env KCONFIG_NOTIMESTAMP=true \ |
| 334 | $(MAKE) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(KERNELCONFIG_MODE) |
| 335 | env KCONFIG_NOTIMESTAMP=true \ |
| 336 | $(MAKE) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) savedefconfig |
| 337 | cp $(KERNEL_OUT)/defconfig $(KERNEL_DEFCONFIG_SRC) |
| 338 | |
Michael Bestas | 296008c | 2017-07-12 20:56:35 +0300 | [diff] [blame] | 339 | kernelsavedefconfig: $(KERNEL_OUT_STAMP) |
| 340 | $(MAKE) $(MAKE_FLAGS) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(KERNEL_DEFCONFIG) |
| 341 | env KCONFIG_NOTIMESTAMP=true \ |
| 342 | $(MAKE) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) savedefconfig |
| 343 | cp $(KERNEL_OUT)/defconfig $(KERNEL_DEFCONFIG_SRC) |
| 344 | |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 345 | alldefconfig: $(KERNEL_OUT_STAMP) |
| 346 | env KCONFIG_NOTIMESTAMP=true \ |
| 347 | $(MAKE) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) alldefconfig |
| 348 | |
| 349 | endif # FULL_KERNEL_BUILD |
| 350 | |
| 351 | ## Install it |
| 352 | |
| 353 | ifeq ($(NEEDS_KERNEL_COPY),true) |
| 354 | file := $(INSTALLED_KERNEL_TARGET) |
| 355 | ALL_PREBUILT += $(file) |
| 356 | $(file) : $(KERNEL_BIN) | $(ACP) |
| 357 | $(transform-prebuilt-to-target) |
| 358 | |
| 359 | ALL_PREBUILT += $(INSTALLED_KERNEL_TARGET) |
| 360 | endif |
| 361 | |
| 362 | .PHONY: kernel |
| 363 | kernel: $(INSTALLED_KERNEL_TARGET) |