summaryrefslogtreecommitdiff
path: root/mk/kernel-build.mk
blob: 65d3baba959ae86e2bad6c55634799098624e1a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# This file is part of the OpenADK project. OpenADK is copyrighted
# material, please see the LICENCE file in the top-level directory.

include $(ADK_TOPDIR)/rules.mk
include $(ADK_TOPDIR)/mk/kernel-ver.mk
include $(ADK_TOPDIR)/mk/linux.mk
include $(ADK_TOPDIR)/mk/kernel-vars.mk

ifeq ($(ADK_TARGET_KERNEL_USE_CUSTOMCONFIG),y)
KERNEL_MODULES_USED:=$(shell grep -s =m $(ADK_TOPDIR)/$(ADK_TARGET_KERNEL_CUSTOMCONFIG_PATH))
else
KERNEL_MODULES_USED:=$(shell grep ^ADK_KERNEL $(ADK_TOPDIR)/.config|grep =m)
endif

KERNEL_FILE:=$(ADK_TARGET_KERNEL)
KERNEL_TARGET:=$(ADK_TARGET_KERNEL)
ifeq ($(ADK_TARGET_KERNEL_LINUXBIN),y)
KERNEL_FILE:=vmlinux
KERNEL_TARGET:=$(ADK_TARGET_KERNEL)
endif
ifeq ($(ADK_TARGET_KERNEL_ZIMAGE),y)
KERNEL_FILE:=vmlinux
KERNEL_TARGET:=$(ADK_TARGET_KERNEL)
endif
ifeq ($(ADK_TARGET_KERNEL_BZIMAGE),y)
KERNEL_FILE:=vmlinux
KERNEL_TARGET:=all
endif
ifeq ($(ADK_TARGET_KERNEL_IMAGE),y)
KERNEL_FILE:=vmlinux
KERNEL_TARGET:=$(ADK_TARGET_KERNEL)
endif

ifeq ($(ADK_RUNTIME_DEV_UDEV),y)
ADK_DEPMOD:=$(STAGING_HOST_DIR)/usr/bin/depmod
else
ADK_DEPMOD:=true
endif

$(LINUX_DIR)/.prepared: $(TOOLCHAIN_BUILD_DIR)/w-$(PKG_NAME)-$(PKG_VERSION)-$(PKG_RELEASE)/linux-$(KERNEL_FILE_VER)/.patched
	ln -sf $(TOOLCHAIN_BUILD_DIR)/w-$(PKG_NAME)-$(PKG_VERSION)-$(PKG_RELEASE)/linux-$(KERNEL_FILE_VER) $(LINUX_DIR)
	mkdir -p $(LINUX_BUILD_DIR)/kmod-control
	touch $@

ifeq ($(ADK_TARGET_KERNEL_USE_MINICONFIG),y)
$(LINUX_DIR)/.config: $(BUILD_DIR)/.kernelconfig
endif

ifeq ($(ADK_TARGET_KERNEL_USE_CUSTOMCONFIG),y)
$(ADK_TOPDIR)/$(ADK_TARGET_KERNEL_CUSTOMCONFIG_PATH):
$(LINUX_DIR)/.config: $(ADK_TOPDIR)/$(ADK_TARGET_KERNEL_CUSTOMCONFIG_PATH)
endif

$(LINUX_DIR)/.config: $(LINUX_DIR)/.prepared
	$(START_TRACE) "target/$(ADK_TARGET_ARCH)-kernel-configure.. "
	-for f in $(TARGETS);do if [ -f $$f ];then rm $$f;fi;done
	echo "-${KERNEL_RELEASE}" >${LINUX_DIR}/localversion
ifeq ($(ADK_TARGET_KERNEL_USE_DEFCONFIG),y)
	${KERNEL_MAKE_ENV} $(MAKE) -C "${LINUX_DIR}" ${KERNEL_MAKE_OPTS} $(ADK_TARGET_KERNEL_DEFCONFIG) $(MAKE_TRACE)
else ifeq ($(ADK_TARGET_KERNEL_USE_CUSTOMCONFIG),y)
	@if [ ! -f $(ADK_TOPDIR)/$(ADK_TARGET_KERNEL_CUSTOMCONFIG_PATH) ];then \
		echo "no kernel configuration found in $(ADK_TOPDIR)/$(ADK_TARGET_KERNEL_CUSTOMCONFIG_PATH)"; \
		exit 1; \
	fi
	${KERNEL_MAKE_ENV} $(MAKE) -C "${LINUX_DIR}" ${KERNEL_MAKE_OPTS} KCONFIG_ALLCONFIG=$(ADK_TOPDIR)/$(ADK_TARGET_KERNEL_CUSTOMCONFIG_PATH) allnoconfig $(MAKE_TRACE)
else
	$(CP) $(BUILD_DIR)/.kernelconfig $(LINUX_DIR)/mini.config
	${KERNEL_MAKE_ENV} $(MAKE) -C "${LINUX_DIR}" ${KERNEL_MAKE_OPTS} KCONFIG_ALLCONFIG=mini.config allnoconfig $(MAKE_TRACE)
endif
	touch -c $(LINUX_DIR)/.config
	$(CMD_TRACE) " done"
	$(END_TRACE)

$(LINUX_DIR)/$(KERNEL_FILE): $(LINUX_DIR)/.config
	$(START_TRACE) "target/$(ADK_TARGET_ARCH)-kernel-compile.. "
	${KERNEL_MAKE_ENV} $(MAKE) -C "${LINUX_DIR}" ${KERNEL_MAKE_OPTS} -j${ADK_MAKE_JOBS} $(KERNEL_TARGET) $(MAKE_TRACE)
	touch -c $(LINUX_DIR)/$(KERNEL_FILE)
	$(CMD_TRACE) " done"
	$(END_TRACE)

$(LINUX_BUILD_DIR)/modules: $(LINUX_DIR)/$(KERNEL_FILE)
	$(START_TRACE) "target/$(ADK_TARGET_ARCH)-kernel-modules-compile.. "
	${KERNEL_MAKE_ENV} $(MAKE) -C "${LINUX_DIR}" ${KERNEL_MAKE_OPTS} -j${ADK_MAKE_JOBS} modules $(MAKE_TRACE)
	$(CMD_TRACE) " done"
	$(END_TRACE)
	$(START_TRACE) "target/$(ADK_TARGET_ARCH)-kernel-modules-install.. "
	rm -rf $(LINUX_BUILD_DIR)/modules
	${KERNEL_MAKE_ENV} $(MAKE) -C "${LINUX_DIR}" ${KERNEL_MAKE_OPTS} \
		DEPMOD=$(ADK_DEPMOD) \
		INSTALL_MOD_PATH=$(LINUX_BUILD_DIR)/modules \
		modules_install $(MAKE_TRACE)
	$(CMD_TRACE) " done"
	$(END_TRACE)
ifneq ($(ADK_RUNTIME_DEV_UDEV),y)
	$(START_TRACE) "target/$(ADK_TARGET_ARCH)-create-packages.. "
	@mkdir -p ${PACKAGE_DIR}
	PATH='${HOST_PATH}' ${BASH} ${SCRIPT_DIR}/make-module-ipkgs.sh \
		"${ADK_TARGET_CPU_ARCH}" \
		"${KERNEL_VERSION}" \
		"${LINUX_BUILD_DIR}" \
		"${PKG_BUILD}" \
		"${PACKAGE_DIR}"
	$(CMD_TRACE) " done"
	$(END_TRACE)
endif

prepare:
ifneq ($(KERNEL_MODULES_USED),)
compile: $(LINUX_BUILD_DIR)/modules
else
compile: $(LINUX_DIR)/$(KERNEL_FILE)
endif
install: compile
ifneq ($(KERNEL_MODULES_USED),)
	$(START_TRACE) "target/${ADK_TARGET_ARCH}-modules-install.. "
ifeq ($(ADK_TARGET_PACKAGE_IPKG)$(ADK_TARGET_PACKAGE_OPKG),y)
	$(PKG_INSTALL) $(wildcard ${PACKAGE_DIR}/kmod-*) $(MAKE_TRACE)
else
	$(foreach pkg,$(wildcard ${PACKAGE_DIR}/kmod-*),$(shell $(PKG_INSTALL) $(pkg)))
endif
	$(CMD_TRACE) " done"
	$(END_TRACE)
endif

clean:
	rm -rf $(LINUX_BUILD_DIR)
	rm -f $(wildcard ${PACKAGE_DIR}/kmod-*) $(wildcard ${PACKAGE_DIR}/kernel_*)