OSDN Git Service

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