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