make the kernel compile process more generic
[openwrt.git] / target / linux / linux-2.4 / Makefile
1 #############################################################
2 # $Id$
3 #
4 # Linux 2.4 kernel target for the OpenWRT project
5 #
6 # patches are sorted by numbers
7 # 0xx needed patches for board, cpu, filesystem
8 # 1xx addon patches for new features (netfilter, ebtables, cifs,..)
9 # 2xx compile fixes, driver fixes
10 #
11 #############################################################
12
13 include $(TOPDIR)/rules.mk
14 include ../rules.mk
15
16 # for testing
17 ifeq ($(BOARD),)
18 BOARD:=brcm
19 endif
20
21 LINUX_VERSION:=2.4.30
22 MODULES_SUBDIR:=lib/modules/$(LINUX_VERSION)
23 LINUX_KCONFIG:=./config/$(BOARD)
24 LINUX_BUILD_DIR:=$(BUILD_DIR)/linux-2.4-$(BOARD)
25 LINUX_TARGET_DIR:=$(LINUX_BUILD_DIR)/root
26 LINUX_KERNEL:=$(LINUX_BUILD_DIR)/vmlinux
27 LINUX_KARCH:=$(shell echo $(ARCH) | sed -e 's/i[3-9]86/i386/' \
28 -e 's/mipsel/mips/' \
29 -e 's/powerpc/ppc/' \
30 -e 's/sh[234]/sh/' \
31 )
32
33 LINUX_BINARY_DRIVER_SITE := http://openwrt.org/downloads/
34 LINUX_SOURCE := linux-$(LINUX_VERSION).tar.bz2
35 LINUX_SOURCE_DIR := $(LINUX_BUILD_DIR)/linux-$(LINUX_VERSION)
36 MODULES_DIR := $(LINUX_BUILD_DIR)/modules/$(MODULES_SUBDIR)
37 TARGET_MODULES_DIR := $(TARGET_DIR)/lib/modules/$(LINUX_VERSION)
38 IPKG_KERNEL:=IPKG_TMP=$(BUILD_DIR)/tmp IPKG_INSTROOT=$(LINUX_TARGET_DIR) IPKG_CONF_DIR=$(LINUX_BUILD_DIR) $(SCRIPT_DIR)/ipkg -force-defaults -force-depends
39
40 PKG_BUILD_DIR := $(LINUX_BUILD_DIR)/linux-modules
41 PKG_RELEASE := 1
42
43 KERNEL_IPKG:=$(LINUX_BUILD_DIR)/kernel_$(LINUX_VERSION)-$(BOARD)-$(PKG_RELEASE)_$(ARCH).ipk
44 KERNEL_IDIR:=$(LINUX_BUILD_DIR)/kernel-ipkg
45
46 include $(LINUX_KCONFIG)
47 ifeq ($(BOARD),brcm)
48 include ./broadcom.mk
49 endif
50
51 TARGETS :=
52 INSTALL_TARGETS := $(KERNEL_IPKG)
53
54 $(eval $(call KMOD_template,DIAG,diag,\
55 $(MODULES_DIR)/kernel/drivers/net/diag/diag.o \
56 ))
57 $(eval $(call KMOD_template,BRCM_WL,brcm-wl,\
58 $(MODULES_DIR)/kernel/drivers/net/wl/wl.o \
59 ,CONFIG_WL))
60 $(eval $(call KMOD_template,B44,b44,\
61 $(MODULES_DIR)/kernel/drivers/net/b44.o \
62 ,CONFIG_B44))
63 $(eval $(call KMOD_template,BRCM_ET,brcm-et,\
64 $(MODULES_DIR)/kernel/drivers/net/et/et.o \
65 ,CONFIG_ET))
66 $(eval $(call KMOD_template,ARPT,arptables,\
67 $(MODULES_DIR)/kernel/net/ipv4/netfilter/arp*.o \
68 ,CONFIG_IP_NF_ARPTABLES))
69 $(eval $(call KMOD_template,EBT,ebtables,\
70 $(MODULES_DIR)/kernel/net/bridge/netfilter/*.o \
71 ,CONFIG_BRIDGE_NF_EBTABLES))
72 $(eval $(call KMOD_template,IPTABLES_V4_EXTRA,iptables-extra,\
73 $(MODULES_DIR)/kernel/net/ipv4/netfilter/ip*.o \
74 ))
75 $(eval $(call KMOD_template,IPTABLES_V6,ip6tables,\
76 $(MODULES_DIR)/kernel/net/ipv6/netfilter/ip*.o \
77 ,CONFIG_IP6_NF_IPTABLES,kmod-ipv6))
78 $(eval $(call KMOD_template,IPV6,ipv6,\
79 $(MODULES_DIR)/kernel/net/ipv6/ipv6.o \
80 ,CONFIG_IPV6))
81 $(eval $(call KMOD_template,CIFS,cifs,\
82 $(MODULES_DIR)/kernel/fs/cifs/cifs.o \
83 ,CONFIG_CIFS))
84 $(eval $(call KMOD_template,NFS,nfs,\
85 $(MODULES_DIR)/kernel/fs/lockd/*.o \
86 $(MODULES_DIR)/kernel/fs/nfs/*.o \
87 $(MODULES_DIR)/kernel/net/sunrpc/*.o \
88 ,CONFIG_NFS_FS))
89 $(eval $(call KMOD_template,USB,usb-core,\
90 $(MODULES_DIR)/kernel/drivers/usb/usbcore.o \
91 ,CONFIG_USB))
92 $(eval $(call KMOD_template,USB_UHCI,usb-uhci,\
93 $(MODULES_DIR)/kernel/drivers/usb/host/uhci.o \
94 ,CONFIG_USB_UHCI_ALT,kmod-usb-core))
95 $(eval $(call KMOD_template,USB_OHCI,usb-ohci,\
96 $(MODULES_DIR)/kernel/drivers/usb/host/usb-ohci.o \
97 ,CONFIG_USB_OHCI,kmod-usb-core))
98 $(eval $(call KMOD_template,USB2,usb2,\
99 $(MODULES_DIR)/kernel/drivers/usb/host/ehci-hcd.o \
100 ,CONFIG_USB_EHCI_HCD,kmod-usb-core))
101 $(eval $(call KMOD_template,USB_STORAGE,usb-storage,\
102 $(MODULES_DIR)/kernel/drivers/scsi/*.o \
103 $(MODULES_DIR)/kernel/drivers/usb/storage/*.o \
104 ,CONFIG_USB_STORAGE))
105 $(eval $(call KMOD_template,USB_PRINTER,usb-printer,\
106 $(MODULES_DIR)/kernel/drivers/usb/printer.o \
107 ,CONFIG_USB_PRINTER))
108 $(eval $(call KMOD_template,LP,lp,\
109 $(MODULES_DIR)/kernel/drivers/parport/parport.o \
110 $(MODULES_DIR)/kernel/drivers/parport/parport_splink.o \
111 $(MODULES_DIR)/kernel/drivers/char/lp.o \
112 ,CONFIG_PARPORT))
113 $(eval $(call KMOD_template,IDE,ide,\
114 $(MODULES_DIR)/kernel/drivers/ide/*.o \
115 $(MODULES_DIR)/kernel/drivers/ide/*/*.o \
116 ,CONFIG_IDE))
117 $(eval $(call KMOD_template,EXT2,ext2,\
118 $(MODULES_DIR)/kernel/fs/ext2/*.o \
119 ,CONFIG_EXT2_FS))
120 $(eval $(call KMOD_template,EXT3,ext3,\
121 $(MODULES_DIR)/kernel/fs/ext3/*.o \
122 $(MODULES_DIR)/kernel/fs/jbd/*.o \
123 ,CONFIG_EXT3_FS))
124 $(eval $(call KMOD_template,XFS,xfs,\
125 $(MODULES_DIR)/kernel/fs/xfs/*.o \
126 ,CONFIG_XFS_FS))
127 $(eval $(call KMOD_template,HFSPLUS,hfsplus,\
128 $(MODULES_DIR)/kernel/fs/hfsplus/*.o \
129 ,CONFIG_HFSPLUS_FS))
130 $(eval $(call KMOD_template,VFAT,vfat,\
131 $(MODULES_DIR)/kernel/fs/vfat/vfat.o \
132 $(MODULES_DIR)/kernel/fs/fat/fat.o \
133 ,CONFIG_VFAT_FS))
134 $(eval $(call KMOD_template,CRYPTO,crypto,\
135 $(MODULES_DIR)/kernel/crypto/*.o \
136 ))
137 $(eval $(call KMOD_template,PPP,ppp,\
138 $(MODULES_DIR)/kernel/drivers/net/ppp_async.o \
139 $(MODULES_DIR)/kernel/drivers/net/ppp_generic.o \
140 $(MODULES_DIR)/kernel/drivers/net/slhc.o \
141 ,CONFIG_PPP))
142 $(eval $(call KMOD_template,MPPE,mppe,\
143 $(MODULES_DIR)/kernel/drivers/net/ppp_mppe_mppc.o \
144 ,CONFIG_PPP_MPPE_MPPC))
145 $(eval $(call KMOD_template,PPPOE,pppoe,\
146 $(MODULES_DIR)/kernel/drivers/net/pppoe.o \
147 $(MODULES_DIR)/kernel/drivers/net/pppox.o \
148 ,CONFIG_PPPOE))
149 $(eval $(call KMOD_template,TUN,tun,\
150 $(MODULES_DIR)/kernel/drivers/net/tun.o \
151 ,CONFIG_TUN))
152 $(eval $(call KMOD_template,GRE,gre,\
153 $(MODULES_DIR)/kernel/net/ipv4/ip_gre.o \
154 ,CONFIG_NET_IPGRE))
155 $(eval $(call KMOD_template,SCHED,sched,\
156 $(MODULES_DIR)/kernel/net/sched/*.o \
157 ))
158
159 $(TARGETS): $(PACKAGE_DIR)
160
161 $(PACKAGE_DIR):
162 mkdir -p $(PACKAGE_DIR)
163
164 $(LINUX_DIR)/.unpacked: $(DL_DIR)/$(LINUX_SOURCE) $(DL_DIR)/$(LINUX_BINARY_WL_DRIVER) $(DL_DIR)/$(LINUX_ET_DRIVER)
165 -mkdir -p $(LINUX_BUILD_DIR)
166 bzcat $(DL_DIR)/$(LINUX_SOURCE) | tar -C $(LINUX_BUILD_DIR) $(TAR_OPTIONS) -
167 rm -f $(LINUX_DIR)
168 ln -s $(LINUX_BUILD_DIR)/linux-$(LINUX_VERSION) $(LINUX_DIR)
169 touch $(LINUX_DIR)/.unpacked
170
171 $(LINUX_DIR)/.patched: $(LINUX_DIR)/.unpacked
172 [ -d ./patches/$(BOARD) ] && $(PATCH) $(LINUX_DIR) ./patches/$(BOARD)
173 $(PATCH) $(LINUX_DIR) ./patches/generic
174 touch $(LINUX_DIR)/.patched
175
176 $(LINUX_DIR)/.configured: $(LINUX_DIR)/.patched
177 -cp $(LINUX_KCONFIG) $(LINUX_DIR)/.config
178 $(SED) "s,^CROSS_COMPILE.*,CROSS_COMPILE=$(KERNEL_CROSS),g;" \
179 $(LINUX_DIR)/Makefile \
180 $(LINUX_DIR)/arch/mips/Makefile
181 $(SED) "s,\-mcpu=,\-mtune=,g;" $(LINUX_DIR)/arch/mips/Makefile
182 $(MAKE) -C $(LINUX_DIR) ARCH=$(LINUX_KARCH) oldconfig include/linux/version.h
183 touch $(LINUX_DIR)/.configured
184
185 $(LINUX_DIR)/.depend_done: $(LINUX_DIR)/.configured
186 $(MAKE) -C $(LINUX_DIR) ARCH=$(LINUX_KARCH) dep
187 touch $(LINUX_DIR)/.depend_done
188
189 $(LINUX_DIR)/vmlinux: $(LINUX_DIR)/.depend_done
190 $(MAKE) -C $(LINUX_DIR) ARCH=$(LINUX_KARCH) PATH=$(TARGET_PATH)
191
192 $(LINUX_KERNEL): $(LINUX_DIR)/vmlinux
193 $(TARGET_CROSS)objcopy -O binary -R .reginfo -R .note -R .comment -R .mdebug -S $< $@
194 touch -c $(LINUX_KERNEL)
195
196 $(LINUX_DIR)/.modules_done: $(LINUX_KERNEL) $(LINUX_IMAGE)
197 rm -rf $(LINUX_BUILD_DIR)/modules
198 $(MAKE) -C $(LINUX_DIR) ARCH=$(LINUX_KARCH) PATH=$(TARGET_PATH) modules
199 $(MAKE) -C $(LINUX_DIR) DEPMOD=true INSTALL_MOD_PATH=$(LINUX_BUILD_DIR)/modules modules_install
200 touch $(LINUX_DIR)/.modules_done
201
202 $(STAGING_DIR)/include/linux/version.h: $(LINUX_DIR)/.configured
203 mkdir -p $(STAGING_DIR)/include
204 tar -ch -C $(LINUX_DIR)/include -f - linux | tar -xf - -C $(STAGING_DIR)/include/
205 tar -ch -C $(LINUX_DIR)/include -f - asm | tar -xf - -C $(STAGING_DIR)/include/
206
207 $(TARGET_MODULES_DIR):
208 -mkdir -p $(TARGET_MODULES_DIR)
209
210 $(KERNEL_IPKG):
211 rm -rf $(KERNEL_IDIR)
212 mkdir -p $(KERNEL_IDIR)/etc
213 $(SCRIPT_DIR)/make-ipkg-dir.sh $(KERNEL_IDIR) ../control/kernel.control $(LINUX_VERSION)-$(BOARD)-$(PKG_RELEASE) $(ARCH)
214 if [ -f ./config/$(BOARD).modules ]; then \
215 cp ./config/$(BOARD).modules $(KERNEL_IDIR)/etc/modules; \
216 fi
217 $(IPKG_BUILD) $(KERNEL_IDIR) $(LINUX_BUILD_DIR)
218
219 source: $(DL_DIR)/$(LINUX_SOURCE)
220 prepare: $(LINUX_DIR)/.configured
221 compile: $(LINUX_DIR)/.modules_done $(TARGETS)
222 ln -sf $(LINUX_BUILD_DIR)/linux-$(LINUX_VERSION) $(LINUX_DIR)
223 $(MAKE) -C $(TOPDIR)/target/linux/package \
224 BOARD="$(BOARD)" \
225 TARGET_DIR="$(LINUX_TARGET_DIR)" \
226 BUILD_DIR="$(LINUX_BUILD_DIR)" \
227 KERNEL_DIR="$(LINUX_SOURCE_DIR)" \
228 LINUX_VERSION="$(LINUX_VERSION)" \
229 KERNEL_RELEASE="$(PKG_RELEASE)"
230
231 install: compile $(TARGET_MODULES_DIR) $(KERNEL_IPKG)
232 rm -rf $(LINUX_BUILD_DIR)/root*
233 cp -a $(BUILD_DIR)/root $(LINUX_BUILD_DIR)/
234 echo -e 'dest root /\noption offline_root $(LINUX_BUILD_DIR)/root' > $(LINUX_BUILD_DIR)/ipkg.conf
235 [ "$(INSTALL_TARGETS)" != "" ] && $(IPKG_KERNEL) install $(INSTALL_TARGETS) || true
236
237 mostlyclean:
238 rm -f $(LINUX_BUILD_DIR)/linux-$(LINUX_VERSION)/.{drivers-unpacked,modules_done}
239 $(MAKE) -C $(LINUX_BUILD_DIR)/linux-$(LINUX_VERSION) clean
240 rm -f $(LINUX_KERNEL) $(LINUX_IMAGE)
241
242 rebuild:
243 -$(MAKE) mostlyclean
244 if [ -f $(LINUX_KERNEL) ]; then \
245 $(MAKE) clean; \
246 fi
247 $(MAKE) compile
248
249 clean:
250 rm -rf $(LINUX_BUILD_DIR)
251 rm -f $(TARGETS)
This page took 0.056909 seconds and 5 git commands to generate.