fix kernel features detection - GENERIC_PLATFORM_DIR is unset at DUMP time
[openwrt/staging/yousong.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
41 ifeq ($(DUMP),1)
42 all: dumpinfo
43 else
44 all: compile
45 endif
46
47 ifneq (,$(findstring uml,$(BOARD)))
48 LINUX_KARCH:=um
49 else
50 LINUX_KARCH:=$(shell echo $(ARCH) | sed -e 's/i[3-9]86/i386/' \
51 -e 's/mipsel/mips/' \
52 -e 's/mipseb/mips/' \
53 -e 's/powerpc/ppc/' \
54 -e 's/sh[234]/sh/' \
55 -e 's/armeb/arm/' \
56 )
57 endif
58
59 KERNELNAME=
60 ifneq (,$(findstring x86,$(BOARD)))
61 KERNELNAME="bzImage"
62 endif
63 ifneq (,$(findstring rdc,$(BOARD)))
64 KERNELNAME="bzImage"
65 endif
66 ifneq (,$(findstring ppc,$(BOARD)))
67 KERNELNAME="uImage"
68 endif
69
70
71 define Kernel/Prepare/Default
72 bzcat $(DL_DIR)/$(LINUX_SOURCE) | tar -C $(KERNEL_BUILD_DIR) $(TAR_OPTIONS)
73 if [ -d $(GENERIC_PLATFORM_DIR)/patches ]; then $(PATCH) $(LINUX_DIR) $(GENERIC_PLATFORM_DIR)/patches; fi
74 if [ -d ./files ]; then $(CP) ./files/* $(LINUX_DIR)/; fi
75 if [ -d ./patches ]; then $(PATCH) $(LINUX_DIR) ./patches; fi
76 endef
77 define Kernel/Prepare
78 $(call Kernel/Prepare/Default)
79 endef
80
81 KERNEL_MAKEOPTS := -C $(LINUX_DIR) \
82 CROSS_COMPILE="$(KERNEL_CROSS)" \
83 ARCH="$(LINUX_KARCH)" \
84 CONFIG_SHELL="$(BASH)"
85
86 define Kernel/Configure/2.4
87 $(SED) "s,\-mcpu=,\-mtune=,g;" $(LINUX_DIR)/arch/mips/Makefile
88 $(MAKE) $(KERNEL_MAKEOPTS) CC="$(KERNEL_CC)" oldconfig include/linux/compile.h include/linux/version.h
89 $(MAKE) $(KERNEL_MAKEOPTS) dep
90 endef
91 define Kernel/Configure/2.6
92 $(MAKE) $(KERNEL_MAKEOPTS) CC="$(KERNEL_CC)" oldconfig prepare scripts
93 endef
94 define Kernel/Configure/Default
95 @if [ -f "./config/profile-$(PROFILE)" ]; then \
96 $(SCRIPT_DIR)/config.pl '+' $(GENERIC_PLATFORM_DIR)/config-template '+' $(LINUX_CONFIG) ./config/profile-$(PROFILE) > $(LINUX_DIR)/.config; \
97 else \
98 $(SCRIPT_DIR)/config.pl '+' $(GENERIC_PLATFORM_DIR)/config-template $(LINUX_CONFIG) > $(LINUX_DIR)/.config; \
99 fi
100 endef
101 define Kernel/Configure
102 $(call Kernel/Configure/Default)
103 endef
104
105
106 define Kernel/CompileModules/Default
107 $(MAKE) -j$(CONFIG_JLEVEL) $(KERNEL_MAKEOPTS) CC="$(KERNEL_CC)" modules
108 $(MAKE) $(KERNEL_MAKEOPTS) CC="$(KERNEL_CC)" DEPMOD=true INSTALL_MOD_PATH=$(KERNEL_BUILD_DIR)/modules modules_install
109 endef
110 define Kernel/CompileModules
111 $(call Kernel/CompileModules/Default)
112 endef
113
114
115 ifeq ($(KERNEL),2.6)
116 ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
117 define Kernel/SetInitramfs
118 mv $(LINUX_DIR)/.config $(LINUX_DIR)/.config.old
119 grep -v INITRAMFS $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
120 echo 'CONFIG_INITRAMFS_SOURCE="../../root"' >> $(LINUX_DIR)/.config
121 echo 'CONFIG_INITRAMFS_ROOT_UID=0' >> $(LINUX_DIR)/.config
122 echo 'CONFIG_INITRAMFS_ROOT_GID=0' >> $(LINUX_DIR)/.config
123 mkdir -p $(BUILD_DIR)/root/etc/init.d
124 $(CP) $(GENERIC_PLATFORM_DIR)/files/init $(BUILD_DIR)/root/
125 endef
126 else
127 define Kernel/SetInitramfs
128 mv $(LINUX_DIR)/.config $(LINUX_DIR)/.config.old
129 grep -v INITRAMFS $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
130 rm -f $(BUILD_DIR)/root/init $(BUILD_DIR)/root/etc/init.d/S00initramfs
131 echo 'CONFIG_INITRAMFS_SOURCE=""' >> $(LINUX_DIR)/.config
132 endef
133 endif
134 endif
135 define Kernel/CompileImage/Default
136 $(call Kernel/SetInitramfs)
137 $(MAKE) -j$(CONFIG_JLEVEL) $(KERNEL_MAKEOPTS) CC="$(KERNEL_CC)" $(KERNELNAME)
138 $(KERNEL_CROSS)objcopy -O binary -R .reginfo -R .note -R .comment -R .mdebug -S $(LINUX_DIR)/vmlinux $(LINUX_KERNEL)
139 endef
140 define Kernel/CompileImage
141 $(call Kernel/CompileImage/Default)
142 endef
143
144 define Kernel/Clean/Default
145 rm -f $(LINUX_DIR)/.linux-compile
146 rm -f $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)/.configured
147 rm -f $(LINUX_KERNEL)
148 $(MAKE) -C $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION) clean
149 endef
150
151 define Kernel/Clean
152 $(call Kernel/Clean/Default)
153 endef
154
155 define BuildKernel
156 ifneq ($(LINUX_SITE),)
157 $(DL_DIR)/$(LINUX_SOURCE):
158 -mkdir -p $(DL_DIR)
159 $(SCRIPT_DIR)/download.pl $(DL_DIR) $(LINUX_SOURCE) $(LINUX_KERNEL_MD5SUM) $(LINUX_SITE)
160 endif
161
162 $(LINUX_DIR)/.prepared: $(DL_DIR)/$(LINUX_SOURCE)
163 -rm -rf $(KERNEL_BUILD_DIR)
164 -mkdir -p $(KERNEL_BUILD_DIR)
165 $(call Kernel/Prepare)
166 touch $$@
167
168 $(LINUX_DIR)/.configured: $(LINUX_DIR)/.prepared $(LINUX_CONFIG)
169 $(call Kernel/Configure)
170 $(call Kernel/Configure/$(KERNEL))
171 touch $$@
172
173 $(LINUX_DIR)/.modules: $(LINUX_DIR)/.configured
174 rm -rf $(KERNEL_BUILD_DIR)/modules
175 @rm -f $(BUILD_DIR)/linux
176 ln -sf $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION) $(BUILD_DIR)/linux
177 $(call Kernel/CompileModules)
178 touch $$@
179
180 $(LINUX_DIR)/.image: $(LINUX_DIR)/.configured FORCE
181 $(call Kernel/CompileImage)
182 touch $$@
183
184 mostlyclean: FORCE
185 $(call Kernel/Clean)
186
187 ifeq ($(DUMP),1)
188 dumpinfo:
189 @echo 'Target: $(BOARD)-$(KERNEL)'
190 @echo 'Target-Name: $(BOARDNAME) [$(KERNEL)]'
191 @echo 'Target-Path: $(subst $(TOPDIR)/,,$(PWD))'
192 @echo 'Target-Arch: $(ARCH)'
193 @echo 'Target-Features: $(FEATURES)'
194 @echo 'Linux-Version: $(LINUX_VERSION)'
195 @echo 'Linux-Release: $(LINUX_RELEASE)'
196 @echo 'Linux-Kernel-Arch: $(LINUX_KARCH)'
197 @echo 'Target-Description:'
198 @getvar $(call shvar,Target/Description)
199 @echo '@@'
200 @echo 'Default-Packages: $(DEFAULT_PACKAGES)'
201 ifneq ($(DUMPINFO),)
202 @$(DUMPINFO)
203 endif
204 endif
205
206 define BuildKernel
207 endef
208 endef
209
210 define Profile/Default
211 NAME:=
212 PACKAGES:=
213 endef
214
215 confname=$(subst .,_,$(subst -,_,$(1)))
216 define Profile
217 $(eval $(call Profile/Default))
218 $(eval $(call Profile/$(1)))
219 $(eval $(call shexport,Profile/$(1)/Description))
220 DUMPINFO += \
221 echo "Target-Profile: $(1)"; \
222 echo "Target-Profile-Name: $(NAME)"; \
223 echo "Target-Profile-Packages: $(PACKAGES)"; \
224 if [ -f ./config/profile-$(1) ]; then \
225 echo "Target-Profile-Kconfig: yes"; \
226 fi; \
227 echo "Target-Profile-Description:"; \
228 getvar "$(call shvar,Profile/$(1)/Description)"; \
229 echo "@@"; \
230 echo;
231 ifeq ($(CONFIG_LINUX_$(call confname,$(KERNEL)_$(1))),y)
232 PROFILE=$(1)
233 endif
234 endef
235
236 $(eval $(call shexport,Target/Description))
237
238 download: $(DL_DIR)/$(LINUX_SOURCE)
239 prepare: $(LINUX_DIR)/.configured $(TMP_DIR)/.kernel.mk
240 compile: $(LINUX_DIR)/.modules
241 menuconfig: $(LINUX_DIR)/.prepared FORCE
242 $(call Kernel/Configure)
243 $(SCRIPT_DIR)/config.pl '+' $(GENERIC_PLATFORM_DIR)/config-template $(LINUX_CONFIG) > $(LINUX_DIR)/.config
244 $(MAKE) -C $(LINUX_DIR) $(KERNEL_MAKEOPTS) menuconfig
245 $(SCRIPT_DIR)/config.pl '>' $(GENERIC_PLATFORM_DIR)/config-template $(LINUX_DIR)/.config > $(LINUX_CONFIG)
246
247 install: $(LINUX_DIR)/.image
248
249 clean: FORCE
250 rm -f $(STAMP_DIR)/.linux-compile
251 rm -rf $(KERNEL_BUILD_DIR)
252
253 rebuild: FORCE
254 @$(MAKE) mostlyclean
255 @if [ -f $(LINUX_KERNEL) ]; then \
256 $(MAKE) clean; \
257 fi
258 @$(MAKE) compile
259
260