3193e9d185919376352336601b95bc1eca4c9f8f
[openwrt.git] / include / kernel-build.mk
1 #
2 # Copyright (C) 2006 OpenWrt.org
3 #
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6 #
7 KERNEL_BUILD:=1
8
9 include $(INCLUDE_DIR)/kernel-version.mk
10 include $(INCLUDE_DIR)/host.mk
11 include $(INCLUDE_DIR)/kernel.mk
12 include $(INCLUDE_DIR)/prereq.mk
13
14 LINUX_CONFIG ?= ./config/default
15
16 -include $(TOPDIR)/target/linux/generic-$(KERNEL)/config-template
17 -include $(LINUX_CONFIG)
18
19 ifneq ($(CONFIG_ATM),)
20 FEATURES += atm
21 endif
22 ifneq ($(CONFIG_PCI),)
23 FEATURES += pci
24 endif
25 ifneq ($(CONFIG_USB),)
26 FEATURES += usb
27 endif
28 ifneq ($(CONFIG_PCMCIA),)
29 FEATURES += pcmcia
30 endif
31 ifneq ($(CONFIG_VIDEO_DEV),)
32 FEATURES += video
33 endif
34
35 # remove duplicates
36 FEATURES:=$(sort $(FEATURES))
37
38 # For target profile selection - the default set
39 DEFAULT_PACKAGES:=base-files libgcc uclibc bridge busybox dnsmasq dropbear iptables mtd ppp ppp-mod-pppoe mtd kmod-ipt-nathelper
40 ifneq ($(KERNEL),2.4)
41 DEFAULT_PACKAGES+=udevtrigger hotplug2
42 endif
43
44 ifeq ($(DUMP),1)
45 all: dumpinfo
46 else
47 all: compile
48 endif
49
50 ifneq (,$(findstring uml,$(BOARD)))
51 LINUX_KARCH:=um
52 else
53 LINUX_KARCH:=$(shell echo $(ARCH) | sed -e 's/i[3-9]86/i386/' \
54 -e 's/mipsel/mips/' \
55 -e 's/mipseb/mips/' \
56 -e 's/powerpc/ppc/' \
57 -e 's/sh[234]/sh/' \
58 -e 's/armeb/arm/' \
59 )
60 endif
61
62 KERNELNAME=
63 ifneq (,$(findstring x86,$(BOARD)))
64 KERNELNAME="bzImage"
65 endif
66 ifneq (,$(findstring rdc,$(BOARD)))
67 KERNELNAME="bzImage"
68 endif
69 ifneq (,$(findstring ppc,$(BOARD)))
70 KERNELNAME="uImage"
71 endif
72
73
74 define Kernel/Prepare/Default
75 bzcat $(DL_DIR)/$(LINUX_SOURCE) | tar -C $(KERNEL_BUILD_DIR) $(TAR_OPTIONS)
76 if [ -d $(GENERIC_PLATFORM_DIR)/patches ]; then $(PATCH) $(LINUX_DIR) $(GENERIC_PLATFORM_DIR)/patches; fi
77 if [ -d ./files ]; then $(CP) ./files/* $(LINUX_DIR)/; fi
78 if [ -d ./patches ]; then $(PATCH) $(LINUX_DIR) ./patches; fi
79 endef
80 define Kernel/Prepare
81 $(call Kernel/Prepare/Default)
82 endef
83
84 KERNEL_MAKEOPTS := -C $(LINUX_DIR) \
85 CROSS_COMPILE="$(KERNEL_CROSS)" \
86 ARCH="$(LINUX_KARCH)" \
87 CONFIG_SHELL="$(BASH)"
88
89 define Kernel/Configure/2.4
90 $(SED) "s,\-mcpu=,\-mtune=,g;" $(LINUX_DIR)/arch/mips/Makefile
91 $(MAKE) $(KERNEL_MAKEOPTS) CC="$(KERNEL_CC)" oldconfig include/linux/compile.h include/linux/version.h
92 $(MAKE) $(KERNEL_MAKEOPTS) dep
93 endef
94 define Kernel/Configure/2.6
95 $(MAKE) $(KERNEL_MAKEOPTS) CC="$(KERNEL_CC)" oldconfig prepare scripts
96 endef
97 define Kernel/Configure/Default
98 @if [ -f "./config/profile-$(PROFILE)" ]; then \
99 $(SCRIPT_DIR)/config.pl '+' $(GENERIC_PLATFORM_DIR)/config-template '+' $(LINUX_CONFIG) ./config/profile-$(PROFILE) > $(LINUX_DIR)/.config; \
100 else \
101 $(SCRIPT_DIR)/config.pl '+' $(GENERIC_PLATFORM_DIR)/config-template $(LINUX_CONFIG) > $(LINUX_DIR)/.config; \
102 fi
103 endef
104 define Kernel/Configure
105 $(call Kernel/Configure/Default)
106 endef
107
108
109 define Kernel/CompileModules/Default
110 $(MAKE) -j$(CONFIG_JLEVEL) $(KERNEL_MAKEOPTS) CC="$(KERNEL_CC)" modules
111 $(MAKE) $(KERNEL_MAKEOPTS) CC="$(KERNEL_CC)" DEPMOD=true INSTALL_MOD_PATH=$(KERNEL_BUILD_DIR)/modules modules_install
112 endef
113 define Kernel/CompileModules
114 $(call Kernel/CompileModules/Default)
115 endef
116
117
118 ifeq ($(KERNEL),2.6)
119 ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
120 define Kernel/SetInitramfs
121 mv $(LINUX_DIR)/.config $(LINUX_DIR)/.config.old
122 grep -v INITRAMFS $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
123 echo 'CONFIG_INITRAMFS_SOURCE="../../root"' >> $(LINUX_DIR)/.config
124 echo 'CONFIG_INITRAMFS_ROOT_UID=0' >> $(LINUX_DIR)/.config
125 echo 'CONFIG_INITRAMFS_ROOT_GID=0' >> $(LINUX_DIR)/.config
126 mkdir -p $(BUILD_DIR)/root/etc/init.d
127 $(CP) $(GENERIC_PLATFORM_DIR)/files/init $(BUILD_DIR)/root/
128 endef
129 else
130 define Kernel/SetInitramfs
131 mv $(LINUX_DIR)/.config $(LINUX_DIR)/.config.old
132 grep -v INITRAMFS $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
133 rm -f $(BUILD_DIR)/root/init $(BUILD_DIR)/root/etc/init.d/S00initramfs
134 echo 'CONFIG_INITRAMFS_SOURCE=""' >> $(LINUX_DIR)/.config
135 endef
136 endif
137 endif
138 define Kernel/CompileImage/Default
139 $(call Kernel/SetInitramfs)
140 $(MAKE) -j$(CONFIG_JLEVEL) $(KERNEL_MAKEOPTS) CC="$(KERNEL_CC)" $(KERNELNAME)
141 $(KERNEL_CROSS)objcopy -O binary -R .reginfo -R .note -R .comment -R .mdebug -S $(LINUX_DIR)/vmlinux $(LINUX_KERNEL)
142 $(KERNEL_CROSS)objcopy -R .reginfo -R .note -R .comment -R .mdebug -S $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/vmlinux.elf
143 endef
144 define Kernel/CompileImage
145 $(call Kernel/CompileImage/Default)
146 endef
147
148 define Kernel/Clean/Default
149 rm -f $(LINUX_DIR)/.linux-compile
150 rm -f $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)/.configured
151 rm -f $(LINUX_KERNEL)
152 $(MAKE) -C $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION) clean
153 endef
154
155 define Kernel/Clean
156 $(call Kernel/Clean/Default)
157 endef
158
159 define BuildKernel
160 ifneq ($(LINUX_SITE),)
161 $(DL_DIR)/$(LINUX_SOURCE):
162 -mkdir -p $(DL_DIR)
163 $(SCRIPT_DIR)/download.pl $(DL_DIR) $(LINUX_SOURCE) $(LINUX_KERNEL_MD5SUM) $(LINUX_SITE)
164 endif
165
166 $(LINUX_DIR)/.prepared: $(DL_DIR)/$(LINUX_SOURCE)
167 -rm -rf $(KERNEL_BUILD_DIR)
168 -mkdir -p $(KERNEL_BUILD_DIR)
169 $(call Kernel/Prepare)
170 touch $$@
171
172 $(LINUX_DIR)/.configured: $(LINUX_DIR)/.prepared $(LINUX_CONFIG)
173 $(call Kernel/Configure)
174 $(call Kernel/Configure/$(KERNEL))
175 touch $$@
176
177 $(LINUX_DIR)/.modules: $(LINUX_DIR)/.configured
178 rm -rf $(KERNEL_BUILD_DIR)/modules
179 @rm -f $(BUILD_DIR)/linux
180 ln -sf $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION) $(BUILD_DIR)/linux
181 $(call Kernel/CompileModules)
182 touch $$@
183
184 $(LINUX_DIR)/.image: $(LINUX_DIR)/.configured FORCE
185 $(call Kernel/CompileImage)
186 touch $$@
187
188 mostlyclean: FORCE
189 $(call Kernel/Clean)
190
191 ifeq ($(DUMP),1)
192 dumpinfo:
193 @echo 'Target: $(BOARD)-$(KERNEL)'
194 @echo 'Target-Name: $(BOARDNAME) [$(KERNEL)]'
195 @echo 'Target-Path: $(subst $(TOPDIR)/,,$(PWD))'
196 @echo 'Target-Arch: $(ARCH)'
197 @echo 'Target-Features: $(FEATURES)'
198 @echo 'Linux-Version: $(LINUX_VERSION)'
199 @echo 'Linux-Release: $(LINUX_RELEASE)'
200 @echo 'Linux-Kernel-Arch: $(LINUX_KARCH)'
201 @echo 'Target-Description:'
202 @getvar $(call shvar,Target/Description)
203 @echo '@@'
204 @echo 'Default-Packages: $(DEFAULT_PACKAGES)'
205 ifneq ($(DUMPINFO),)
206 @$(DUMPINFO)
207 endif
208 endif
209
210 define BuildKernel
211 endef
212 endef
213
214 define Profile/Default
215 NAME:=
216 PACKAGES:=
217 endef
218
219 confname=$(subst .,_,$(subst -,_,$(1)))
220 define Profile
221 $(eval $(call Profile/Default))
222 $(eval $(call Profile/$(1)))
223 $(eval $(call shexport,Profile/$(1)/Description))
224 DUMPINFO += \
225 echo "Target-Profile: $(1)"; \
226 echo "Target-Profile-Name: $(NAME)"; \
227 echo "Target-Profile-Packages: $(PACKAGES)"; \
228 if [ -f ./config/profile-$(1) ]; then \
229 echo "Target-Profile-Kconfig: yes"; \
230 fi; \
231 echo "Target-Profile-Description:"; \
232 getvar "$(call shvar,Profile/$(1)/Description)"; \
233 echo "@@"; \
234 echo;
235 ifeq ($(CONFIG_LINUX_$(call confname,$(KERNEL)_$(1))),y)
236 PROFILE=$(1)
237 endif
238 endef
239
240 $(eval $(call shexport,Target/Description))
241
242 download: $(DL_DIR)/$(LINUX_SOURCE)
243 prepare: $(LINUX_DIR)/.configured $(TMP_DIR)/.kernel.mk
244 compile: $(LINUX_DIR)/.modules
245 menuconfig: $(LINUX_DIR)/.prepared FORCE
246 $(call Kernel/Configure)
247 $(SCRIPT_DIR)/config.pl '+' $(GENERIC_PLATFORM_DIR)/config-template $(LINUX_CONFIG) > $(LINUX_DIR)/.config
248 $(MAKE) -C $(LINUX_DIR) $(KERNEL_MAKEOPTS) menuconfig
249 $(SCRIPT_DIR)/config.pl '>' $(GENERIC_PLATFORM_DIR)/config-template $(LINUX_DIR)/.config > $(LINUX_CONFIG)
250
251 install: $(LINUX_DIR)/.image
252
253 clean: FORCE
254 rm -f $(STAMP_DIR)/.linux-compile
255 rm -rf $(KERNEL_BUILD_DIR)
256
257 rebuild: FORCE
258 @$(MAKE) mostlyclean
259 @if [ -f $(LINUX_KERNEL) ]; then \
260 $(MAKE) clean; \
261 fi
262 @$(MAKE) compile
263
264
This page took 0.046324 seconds and 3 git commands to generate.