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