autodetect atm, pci, usb, pcmcia features from kernel config file
[openwrt/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-$(KERNEL)/patches ] && $(PATCH) $(LINUX_DIR) ../generic-$(KERNEL)/patches
67 [ -d ./patches ] && $(PATCH) $(LINUX_DIR) ./patches
68 endef
69 define Kernel/Prepare
70 $(call Kernel/Prepare/Default)
71 endef
72
73
74 define Kernel/Configure/2.4
75 $(SED) "s,\-mcpu=,\-mtune=,g;" $(LINUX_DIR)/arch/mips/Makefile
76 $(MAKE) -C $(LINUX_DIR) CROSS_COMPILE="$(KERNEL_CROSS)" CC="$(KERNEL_CC)" ARCH=$(LINUX_KARCH) oldconfig include/linux/compile.h include/linux/version.h
77 $(MAKE) -C $(LINUX_DIR) CROSS_COMPILE="$(KERNEL_CROSS)" ARCH=$(LINUX_KARCH) dep
78 endef
79 define Kernel/Configure/2.6
80 $(MAKE) -C $(LINUX_DIR) CROSS_COMPILE="$(KERNEL_CROSS)" CC="$(KERNEL_CC)" ARCH=$(LINUX_KARCH) oldconfig prepare scripts
81 endef
82 define Kernel/Configure/Default
83 @$(CP) $(LINUX_CONFIG) $(LINUX_DIR)/.config
84 $(call Kernel/Configure/$(KERNEL))
85 endef
86 define Kernel/Configure
87 $(call Kernel/Configure/Default)
88 endef
89
90
91 define Kernel/CompileModules/Default
92 $(MAKE) -j$(CONFIG_JLEVEL) -C "$(LINUX_DIR)" CROSS_COMPILE="$(KERNEL_CROSS)" CC="$(KERNEL_CC)" ARCH=$(LINUX_KARCH) modules
93 $(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
94 endef
95 define Kernel/CompileModules
96 $(call Kernel/CompileModules/Default)
97 endef
98
99
100 ifeq ($(KERNEL),2.6)
101 ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
102 define Kernel/SetInitramfs
103 mv $(LINUX_DIR)/.config $(LINUX_DIR)/.config.old
104 grep -v INITRAMFS $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
105 echo 'CONFIG_INITRAMFS_SOURCE="../../root"' >> $(LINUX_DIR)/.config
106 echo 'CONFIG_INITRAMFS_ROOT_UID=0' >> $(LINUX_DIR)/.config
107 echo 'CONFIG_INITRAMFS_ROOT_GID=0' >> $(LINUX_DIR)/.config
108 mkdir -p $(BUILD_DIR)/root/etc/init.d
109 $(CP) ../generic-2.6/files/init $(BUILD_DIR)/root/
110 endef
111 else
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 rm -f $(BUILD_DIR)/root/init $(BUILD_DIR)/root/etc/init.d/S00initramfs
116 echo 'CONFIG_INITRAMFS_SOURCE=""' >> $(LINUX_DIR)/.config
117 endef
118 endif
119 endif
120 define Kernel/CompileImage/Default
121 $(call Kernel/SetInitramfs)
122 $(MAKE) -j$(CONFIG_JLEVEL) -C $(LINUX_DIR) CROSS_COMPILE="$(KERNEL_CROSS)" CC="$(KERNEL_CC)" ARCH=$(LINUX_KARCH) $(KERNELNAME)
123 $(KERNEL_CROSS)objcopy -O binary -R .reginfo -R .note -R .comment -R .mdebug -S $(LINUX_DIR)/vmlinux $(LINUX_KERNEL)
124 endef
125 define Kernel/CompileImage
126 $(call Kernel/CompileImage/Default)
127 endef
128
129 define Kernel/Clean/Default
130 rm -f $(LINUX_DIR)/.linux-compile
131 rm -f $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)/.configured
132 rm -f $(LINUX_KERNEL)
133 $(MAKE) -C $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION) clean
134 endef
135
136 define Kernel/Clean
137 $(call Kernel/Clean/Default)
138 endef
139
140 define BuildKernel
141 ifneq ($(LINUX_SITE),)
142 $(DL_DIR)/$(LINUX_SOURCE):
143 -mkdir -p $(DL_DIR)
144 $(SCRIPT_DIR)/download.pl $(DL_DIR) $(LINUX_SOURCE) $(LINUX_KERNEL_MD5SUM) $(LINUX_SITE)
145 endif
146
147 $(LINUX_DIR)/.prepared: $(DL_DIR)/$(LINUX_SOURCE)
148 -rm -rf $(KERNEL_BUILD_DIR)
149 -mkdir -p $(KERNEL_BUILD_DIR)
150 $(call Kernel/Prepare)
151 touch $$@
152
153 $(LINUX_DIR)/.configured: $(LINUX_DIR)/.prepared $(LINUX_CONFIG)
154 $(call Kernel/Configure)
155 touch $$@
156
157 $(LINUX_DIR)/.modules: $(LINUX_DIR)/.configured
158 rm -rf $(KERNEL_BUILD_DIR)/modules
159 @rm -f $(BUILD_DIR)/linux
160 ln -sf $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION) $(BUILD_DIR)/linux
161 $(call Kernel/CompileModules)
162 touch $$@
163
164 $(LINUX_DIR)/.image: $(LINUX_DIR)/.configured FORCE
165 $(call Kernel/CompileImage)
166 touch $$@
167
168 mostlyclean: FORCE
169 $(call Kernel/Clean)
170
171 ifeq ($(DUMP),1)
172 dumpinfo:
173 @echo 'Target: $(BOARD)-$(KERNEL)'
174 @echo 'Target-Name: $(BOARDNAME) [$(KERNEL)]'
175 @echo 'Target-Path: $(subst $(TOPDIR)/,,$(PWD))'
176 @echo 'Target-Arch: $(ARCH)'
177 @echo 'Target-Features: $(FEATURES)'
178 @echo 'Linux-Version: $(LINUX_VERSION)'
179 @echo 'Linux-Release: $(LINUX_RELEASE)'
180 @echo 'Linux-Kernel-Arch: $(LINUX_KARCH)'
181 @echo 'Target-Description:'
182 @getvar $(call shvar,Target/Description)
183 @echo '@@'
184 @echo 'Default-Packages: $(DEFAULT_PACKAGES)'
185 ifneq ($(DUMPINFO),)
186 @$(DUMPINFO)
187 endif
188 endif
189
190 define BuildKernel
191 endef
192 endef
193
194 define Profile/Default
195 NAME:=
196 PACKAGES:=
197 endef
198
199 define Profile
200 $(eval $(call Profile/Default))
201 $(eval $(call Profile/$(1)))
202 DUMPINFO += \
203 echo "Target-Profile: $(1)"; \
204 echo "Target-Profile-Name: $(NAME)"; \
205 echo "Target-Profile-Packages: $(PACKAGES)";
206 endef
207
208 $(eval $(call shexport,Target/Description))
209
210 download: $(DL_DIR)/$(LINUX_SOURCE)
211 prepare: $(LINUX_DIR)/.configured $(TMP_DIR)/.kernel.mk
212 compile: $(LINUX_DIR)/.modules
213 install: $(LINUX_DIR)/.image
214
215 clean: FORCE
216 rm -f $(STAMP_DIR)/.linux-compile
217 rm -rf $(KERNEL_BUILD_DIR)
218
219 rebuild: FORCE
220 @$(MAKE) mostlyclean
221 @if [ -f $(LINUX_KERNEL) ]; then \
222 $(MAKE) clean; \
223 fi
224 @$(MAKE) compile
225
226