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