OSDN Git Service

kernel.mk: use the prebuilt binaries of AOSP
[android-x86/device-generic-common.git] / build / tasks / kernel.mk
1 #
2 # Copyright (C) 2014-2017 The Android-x86 Open Source Project
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
11 ifneq ($(TARGET_NO_KERNEL),true)
12 ifeq ($(TARGET_PREBUILT_KERNEL),)
13
14 KERNEL_DIR ?= kernel
15
16 ifneq ($(filter x86%,$(TARGET_ARCH)),)
17 TARGET_KERNEL_ARCH ?= $(TARGET_ARCH)
18 KERNEL_TARGET := bzImage
19 TARGET_KERNEL_CONFIG ?= android-$(TARGET_KERNEL_ARCH)_defconfig
20 KERNEL_CONFIG_DIR := arch/x86/configs
21 endif
22 ifeq ($(TARGET_ARCH),arm)
23 KERNEL_TARGET := zImage
24 TARGET_KERNEL_CONFIG ?= goldfish_defconfig
25 KERNEL_CONFIG_DIR := arch/arm/configs
26 endif
27
28 ifeq ($(BUILD_KERNEL_WITH_CLANG),true)
29 CROSS_COMPILE := x86_64-linux-androidkernel-
30 KERNEL_CLANG_CLAGS := CC=clang HOSTCC=clang CLANG_TRIPLE=x86_64-linux-gnu- PATH=$(abspath $(LLVM_PREBUILTS_BASE)/$(BUILD_OS)-x86/$(LLVM_PREBUILTS_VERSION)/bin):$$PATH
31 else
32 ifeq ($(TARGET_KERNEL_ARCH),x86_64)
33 ifeq ($(HOST_OS),darwin)
34 CROSS_COMPILE ?= $(abspath prebuilts/gcc/darwin-x86/host/i686-apple-darwin-4.2.1/bin)/i686-apple-darwin11-
35 else
36 CROSS_COMPILE ?= $(abspath prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6/bin)/x86_64-linux-
37 endif
38 else
39 CROSS_COMPILE ?= $(abspath $(TARGET_TOOLS_PREFIX))
40 endif
41 endif
42
43 KBUILD_OUTPUT := $(abspath $(TARGET_OUT_INTERMEDIATES)/kernel)
44 mk_kernel := + $(hide) $(MAKE) $(if $(filter darwin,$(HOST_OS)),-j$$(sysctl -n hw.ncpu) -l$$(($$(sysctl -n hw.ncpu)+2)),-j$$(nproc) -l$$(($$(nproc)+2))) \
45         -C $(KERNEL_DIR) O=$(KBUILD_OUTPUT) ARCH=$(TARGET_ARCH) CROSS_COMPILE="$(abspath $(CC_WRAPPER)) $(CROSS_COMPILE)" $(if $(SHOW_COMMANDS),V=1) \
46         YACC=$(abspath $(BISON)) LEX=$(abspath $(LEX)) \
47         $(KERNEL_CLANG_CLAGS)
48
49 KERNEL_CONFIG_FILE := $(if $(wildcard $(TARGET_KERNEL_CONFIG)),$(TARGET_KERNEL_CONFIG),$(KERNEL_DIR)/$(KERNEL_CONFIG_DIR)/$(TARGET_KERNEL_CONFIG))
50
51 MOD_ENABLED := $(shell grep ^CONFIG_MODULES=y $(KERNEL_CONFIG_FILE))
52 FIRMWARE_ENABLED := $(shell grep ^CONFIG_FIRMWARE_IN_KERNEL=y $(KERNEL_CONFIG_FILE))
53
54 # I understand Android build system discourage to use submake,
55 # but I don't want to write a complex Android.mk to build kernel.
56 # This is the simplest way I can think.
57 KERNEL_DOTCONFIG_FILE := $(KBUILD_OUTPUT)/.config
58 KERNEL_ARCH_CHANGED := $(if $(filter 0,$(shell grep -s ^$(if $(filter x86,$(TARGET_KERNEL_ARCH)),\#.)CONFIG_64BIT $(KERNEL_DOTCONFIG_FILE) | wc -l)),FORCE)
59 $(KERNEL_DOTCONFIG_FILE): $(KERNEL_CONFIG_FILE) $(wildcard $(TARGET_KERNEL_DIFFCONFIG)) $(KERNEL_ARCH_CHANGED)
60         $(hide) mkdir -p $(@D) && cat $(wildcard $^) > $@
61         $(hide) ln -sf ../../../../../../external $(@D)
62         $(mk_kernel) oldnoconfig
63
64 BUILT_KERNEL_TARGET := $(KBUILD_OUTPUT)/arch/$(TARGET_ARCH)/boot/$(KERNEL_TARGET)
65 $(BUILT_KERNEL_TARGET): $(KERNEL_DOTCONFIG_FILE)
66         $(mk_kernel) $(KERNEL_TARGET) $(if $(MOD_ENABLED),modules)
67         $(if $(FIRMWARE_ENABLED),$(mk_kernel) INSTALL_MOD_PATH=$(abspath $(TARGET_OUT)) firmware_install)
68
69 ifneq ($(MOD_ENABLED),)
70 KERNEL_MODULES_DEP := $(firstword $(wildcard $(TARGET_OUT)/lib/modules/*/modules.dep))
71 KERNEL_MODULES_DEP := $(if $(KERNEL_MODULES_DEP),$(KERNEL_MODULES_DEP),$(TARGET_OUT)/lib/modules)
72
73 ALL_EXTRA_MODULES := $(patsubst %,$(TARGET_OUT_INTERMEDIATES)/kmodule/%,$(TARGET_EXTRA_KERNEL_MODULES))
74 $(ALL_EXTRA_MODULES): $(TARGET_OUT_INTERMEDIATES)/kmodule/%: $(BUILT_KERNEL_TARGET)
75         @echo Building additional kernel module $*
76         $(hide) mkdir -p $(@D) && $(ACP) -fr $(EXTRA_KERNEL_MODULE_PATH_$*) $(@D)
77         $(mk_kernel) M=$(abspath $@) modules
78
79 $(KERNEL_MODULES_DEP): $(BUILT_KERNEL_TARGET) $(ALL_EXTRA_MODULES)
80         $(hide) rm -rf $(TARGET_OUT)/lib/modules
81         $(mk_kernel) INSTALL_MOD_PATH=$(abspath $(TARGET_OUT)) modules_install
82         + $(hide) for kmod in $(TARGET_EXTRA_KERNEL_MODULES) ; do \
83                 echo Installing additional kernel module $${kmod} ; \
84                 $(subst +,,$(subst $(hide),,$(mk_kernel))) INSTALL_MOD_PATH=$(abspath $(TARGET_OUT)) M=$(abspath $(TARGET_OUT_INTERMEDIATES))/kmodule/$${kmod} modules_install ; \
85         done
86         $(hide) rm -f $(TARGET_OUT)/lib/modules/*/{build,source}
87 endif
88
89 $(BUILT_SYSTEMIMAGE): $(KERNEL_MODULES_DEP)
90
91 # rules to get source of Broadcom 802.11a/b/g/n hybrid device driver
92 # based on broadcomsetup.sh of Kyle Evans
93 WL_PATH := $(KERNEL_DIR)/drivers/net/wireless/broadcom/wl
94 ifeq ($(wildcard $(WL_PATH)/build.mk),)
95 WL_PATH := $(KERNEL_DIR)/drivers/net/wireless/wl
96 endif
97 -include $(WL_PATH)/build.mk
98
99 installclean: FILES += $(KBUILD_OUTPUT) $(INSTALLED_KERNEL_TARGET)
100
101 TARGET_PREBUILT_KERNEL := $(BUILT_KERNEL_TARGET)
102
103 .PHONY: kernel $(if $(KERNEL_ARCH_CHANGED),$(KERNEL_HEADERS_COMMON)/linux/binder.h)
104 kernel: $(INSTALLED_KERNEL_TARGET)
105
106 endif # TARGET_PREBUILT_KERNEL
107
108 ifndef LINEAGE_BUILD
109 $(INSTALLED_KERNEL_TARGET): $(TARGET_PREBUILT_KERNEL) | $(ACP)
110         $(copy-file-to-new-target)
111 ifdef TARGET_PREBUILT_MODULES
112         mkdir -p $(TARGET_OUT)/lib
113         $(hide) cp -r $(TARGET_PREBUILT_MODULES) $(TARGET_OUT)/lib
114 endif
115 endif # LINEAGE_BUILD
116 endif # KBUILD_OUTPUT