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