initial commit of arptables-0.0.3-2
[15.05/openwrt.git] / obsolete-buildroot / make / openwrt.mk
1 # Makefile for to build the base openwrt
2 #
3 # Copyright (C) 2004 Manuel Novoa III <mjn3@uclibc.org>
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 #
19 ######################################################################
20 #
21 # WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING!
22 #
23 # Currently the dependencies are not all handled.  But that's true of
24 # our buildroot in general, since it wasn't really set up for end users.
25
26 OPENWRT_TARGETS:= openwrt-linux openwrt-kmodules.tar.bz2 \
27         openwrt-shared openwrt-mtd openwrt-nvram openwrt-wlconf \
28         bridge dnsmasq1 iptables wtools busybox \
29         openwrt-rootprep
30
31 .PHONY: $(OPENWRT_TARGETS) openwrt-code.bin
32
33 openwrt-base: $(OPENWRT_TARGETS)
34
35 ######################################################################
36
37 ifneq ($(filter $(TARGETS),openwrt-base),)
38
39 # WRT54G_SOURCE=wrt54gv2.2.02.2.tgz
40 # WRT54G_SITE=http://www.linksys.com/support/opensourcecode/wrt54gv2/2.02.2
41
42 # WRT54G_SOURCE=wrt54g.2.02.7.tgz
43 # WRT54G_SITE=http://www.linksys.com/support/opensourcecode/wrt54gv2/2.02.7
44 # WRT54G_DIR=$(BUILD_DIR)/WRT54G
45
46 WRT54G_SOURCE=wrt54gs.2.07.1.tgz
47 WRT54G_SITE=http://www.linksys.com/support/opensourcecode/wrt54gs/2.07.1
48
49 WRT54G_DIR=$(BUILD_DIR)/WRT54GS
50
51 # OPENWRT_ROOT=openwrt-root.tar.bz2
52 # OPENWRT_SITE=http://127.0.0.1
53 # OPENWRT_DIR=$(BUILD_DIR)/openwrt
54
55 LINUX_DIR=$(WRT54G_DIR)/release/src/linux/linux
56 LINUX_FORMAT=zImage
57 LINUX_BINLOC=arch/mips/brcm-boards/bcm947xx/compressed/vmlinuz
58
59 TARGET_MODULES_DIR:=$(TARGET_DIR)/lib/modules/2.4.20
60
61 $(LINUX_DIR)/.unpacked: $(WRT54G_DIR)/.prepared
62         -(cd $(BUILD_DIR); ln -sf $(LINUX_DIR) linux)
63         # preserve the binary-only driver
64         #mv $(LINUX_DIR)/drivers/net/mac/mac.o \
65         #       $(LINUX_DIR)/drivers/net/mac/mac.o-saved
66         touch $(LINUX_DIR)/.unpacked
67
68 $(LINUX_DIR)/.patched: $(WRT54G_DIR)/.prepared
69         $(SOURCE_DIR)/patch-kernel.sh $(LINUX_DIR)/../.. $(SOURCE_DIR) openwrt-linux-netfilter.patch
70         $(SOURCE_DIR)/patch-kernel.sh $(LINUX_DIR)/../.. $(SOURCE_DIR) openwrt-wrt54g-linux.patch
71         # use replacement diag module code
72         cp -f $(SOURCE_DIR)/openwrt-diag.c $(LINUX_DIR)/drivers/net/diag/diag_led.c
73         cp -f $(SOURCE_DIR)/openwrt-wrt54g-linux.config $(LINUX_DIR)/.config
74         -(cd $(BUILD_DIR); ln -sf $(LINUX_DIR) linux)
75         touch $(LINUX_DIR)/.patched
76
77 $(LINUX_DIR)/.configured: $(LINUX_DIR)/.patched $(LINUX_DIR)/.nf-patched
78         $(SED) "s,^CROSS_COMPILE.*,CROSS_COMPILE=$(KERNEL_CROSS),g;" $(LINUX_DIR)/Makefile
79         $(SED) "s,^CROSS_COMPILE.*,CROSS_COMPILE=$(KERNEL_CROSS),g;" $(LINUX_DIR)/arch/mips/Makefile
80         $(SED) "s,\-mcpu=,\-mtune=,g;" $(LINUX_DIR)/arch/mips/Makefile
81         make -C $(LINUX_DIR) oldconfig include/linux/version.h
82         touch $(LINUX_DIR)/.configured
83
84 $(LINUX_DIR)/.depend_done:  $(LINUX_DIR)/.configured $(GCC_BUILD_DIR2)/.installed
85         $(MAKE) -C $(LINUX_DIR) dep
86         touch $(LINUX_DIR)/.depend_done
87
88 $(LINUX_DIR)/$(LINUX_BINLOC): $(LINUX_DIR)/.depend_done
89         $(MAKE) -C $(LINUX_DIR) $(LINUX_FORMAT)
90
91 openwrt-kmodules.tar.bz2: $(LINUX_DIR)/$(LINUX_BINLOC)
92         $(MAKE) -C $(LINUX_DIR) modules
93         $(MAKE) -C $(LINUX_DIR) DEPMOD=/bin/true \
94                 INSTALL_MOD_PATH=$(LINUX_DIR)/modules modules_install
95         tar -C $(LINUX_DIR)/modules/lib -cjf openwrt-kmodules.tar.bz2 modules
96
97 openwrt-linux: $(LINUX_DIR)/$(LINUX_BINLOC)
98
99 $(DL_DIR)/$(WRT54G_SOURCE):
100         $(WGET) -P $(DL_DIR) $(WRT54G_SITE)/$(WRT54G_SOURCE)
101
102 $(WRT54G_DIR)/.source: $(DL_DIR)/$(WRT54G_SOURCE)
103         #zcat $(DL_DIR)/$(WRT54G_SOURCE) | tar -C $(BUILD_DIR) -xvf - WRT54G/README.TXT WRT54G/release
104         zcat $(DL_DIR)/$(WRT54G_SOURCE) | tar -C $(BUILD_DIR) -xvf - WRT54GS/README.TXT WRT54GS/release
105         touch $(WRT54G_DIR)/.source
106
107 $(WRT54G_DIR)/.prepared: $(WRT54G_DIR)/.source
108         $(SOURCE_DIR)/patch-kernel.sh $(WRT54G_DIR) $(SOURCE_DIR) openwrt-wrt54g-router.patch
109         $(SOURCE_DIR)/patch-kernel.sh $(WRT54G_DIR) $(SOURCE_DIR) openwrt-wrt54g-shared.patch
110         touch $(WRT54G_DIR)/.prepared
111
112 ######################################################################
113
114 OPENWRT_ROOT_SKEL:=root.tar.gz
115 OPENWRT_SITE=http://openwrt.ksilebo.net/cgi-bin/viewcvs.cgi/root
116
117 $(DL_DIR)/$(OPENWRT_ROOT_SKEL):
118         $(WGET) -P $(DL_DIR) $(OPENWRT_SITE)/$(OPENWRT_ROOT_SKEL)
119
120 ######################################################################
121
122 OPENWRT_SRCBASE:=$(WRT54G_DIR)/release/src
123 OPENWRT_SHARED_BUILD_DIR:=$(OPENWRT_SRCBASE)/router/shared
124 OPENWRT_SHARED_TARGET_BINARY:=usr/lib/libshared.so
125
126 $(TARGET_DIR)/$(OPENWRT_SHARED_TARGET_BINARY): $(WRT54G_DIR)/.source
127         $(MAKE) -C $(OPENWRT_SHARED_BUILD_DIR) -f Makefile-openwrt \
128                 SRCBASE=$(OPENWRT_SRCBASE) INSTALLDIR=$(TARGET_DIR) \
129                 CC=$(TARGET_CC) LD=$(TARGET_CROSS)ld STRIP="$(STRIP)" \
130                 CFLAGS="$(TARGET_CFLAGS) -I. -I$(OPENWRT_SRCBASE)/include -Wall -I$(OPENWRT_SRCBASE)/" \
131                 install
132
133 openwrt-shared: $(TARGET_DIR)/$(OPENWRT_SHARED_TARGET_BINARY)
134
135 openwrt-shared-clean:
136         -$(MAKE) -C $(OPENWRT_SHARED_BUILD_DIR) clean
137
138 ######################################################################
139
140 OPENWRT_NVRAM_BUILD_DIR:=$(OPENWRT_SRCBASE)/router/nvram
141 OPENWRT_NVRAM_TARGET_BINARY:=usr/sbin/nvram
142
143 $(TARGET_DIR)/$(OPENWRT_NVRAM_TARGET_BINARY): $(WRT54G_DIR)/.source
144         $(MAKE) -C $(OPENWRT_NVRAM_BUILD_DIR) \
145                 SRCBASE=$(OPENWRT_SRCBASE) INSTALLDIR=$(TARGET_DIR) \
146                 CC=$(TARGET_CC) LD=$(TARGET_CROSS)ld STRIP="$(STRIP)" \
147                 CFLAGS="$(TARGET_CFLAGS) -I. -I$(OPENWRT_SRCBASE)/include -Wall -DOPENWRT_NVRAM" \
148                 install
149
150
151 openwrt-nvram: $(TARGET_DIR)/$(OPENWRT_NVRAM_TARGET_BINARY)
152
153 openwrt-nvram-clean:
154         -$(MAKE) -C $(OPENWRT_NVRAM_BUILD_DIR) clean
155
156 ######################################################################
157
158 OPENWRT_MTD_BUILD_DIR:=$(OPENWRT_SRCBASE)/router/rc
159 OPENWRT_MTD_TARGET_BINARY:=sbin/mtd
160
161 $(TARGET_DIR)/$(OPENWRT_MTD_TARGET_BINARY): $(WRT54G_DIR)/.source $(TARGET_DIR)/$(OPENWRT_NVRAM_TARGET_BINARY) # need libnvram
162         $(MAKE) -C $(OPENWRT_MTD_BUILD_DIR) -f Makefile-openwrt \
163                 TOP=$(OPENWRT_SRCBASE)/router \
164                 SRCBASE=$(OPENWRT_SRCBASE) INSTALLDIR=$(TARGET_DIR) \
165                 CC=$(TARGET_CC) LD=$(TARGET_CROSS)ld STRIP="$(STRIP)" \
166                 CFLAGS="$(TARGET_CFLAGS) -I. -I$(OPENWRT_SRCBASE)/router/shared -I$(OPENWRT_SRCBASE)/include -Wall -I$(OPENWRT_SRCBASE)/" \
167                 install
168
169 openwrt-mtd: $(TARGET_DIR)/$(OPENWRT_MTD_TARGET_BINARY)
170
171 openwrt-mtd-clean:
172         -$(MAKE) -C $(OPENWRT_MTD_BUILD_DIR) clean
173
174 ######################################################################
175
176 OPENWRT_WLCONF_BUILD_DIR:=$(OPENWRT_SRCBASE)/router/wlconf
177 OPENWRT_WLCONF_TARGET_BINARY:=usr/sbin/wlconf
178
179 $(TARGET_DIR)/$(OPENWRT_WLCONF_TARGET_BINARY): $(WRT54G_DIR)/.source
180         $(MAKE) -C $(OPENWRT_WLCONF_BUILD_DIR) \
181                 TOP=$(OPENWRT_SRCBASE)/router \
182                 SRCBASE=$(OPENWRT_SRCBASE) INSTALLDIR=$(TARGET_DIR) \
183                 CC=$(TARGET_CC) LD=$(TARGET_CROSS)ld STRIP="$(STRIP)" \
184                 CFLAGS="$(TARGET_CFLAGS) -I. -I$(OPENWRT_SRCBASE)/router/shared -I$(OPENWRT_SRCBASE)/include -Wall" \
185                 install
186
187
188 openwrt-wlconf: $(TARGET_DIR)/$(OPENWRT_WLCONF_TARGET_BINARY)
189
190 openwrt-wlconf-clean:
191         -$(MAKE) -C $(OPENWRT_WLCONF_BUILD_DIR) clean
192
193 ######################################################################
194
195 openwrt-rootprep:
196         # tmp
197         mkdir -p $(TARGET_DIR)/tmp
198         chmod a+rwxt $(TARGET_DIR)/tmp
199         ln -sf /tmp $(TARGET_DIR)/var
200         rm -f $(TARGET_DIR)/usr/tmp
201         ln -sf ../tmp $(TARGET_DIR)/usr/tmp
202         # dev
203         mkdir -p $(TARGET_DIR)/dev
204         # etc
205         mkdir -p $(TARGET_DIR)/etc
206         ln -sf /tmp/resolv.conf $(TARGET_DIR)/etc/resolv.conf
207         # miscellaneous
208         mkdir -p $(TARGET_DIR)/mnt
209         mkdir -p $(TARGET_DIR)/proc
210         mkdir -p $(TARGET_DIR)/jffs
211         mkdir -p $(TARGET_DIR)/rom
212         # modules
213         mkdir -p $(TARGET_MODULES_DIR)
214         cp $(LINUX_DIR)/drivers/net/wl/wl.o $(TARGET_MODULES_DIR)
215         #cp $(LINUX_DIR)/drivers/net/et.4702/et.4702.o $(TARGET_MODULES_DIR)
216         cp $(LINUX_DIR)/drivers/net/et/et.o $(TARGET_MODULES_DIR)
217         cp $(LINUX_DIR)/drivers/net/diag/diag.o $(TARGET_MODULES_DIR)
218
219 ######################################################################
220
221 openwrt-prune: 
222         -@find $(TARGET_DIR) -type f -perm +111 | xargs $(STRIP) 2>/dev/null || true;
223         # remove unneeded uClibc libs
224         rm -rf $(TARGET_DIR)/lib/libthread_db*
225         rm -rf $(TARGET_DIR)/lib/libpthread*
226         # remove unneeded uClibc utils
227         rm -f $(TARGET_DIR)/sbin/ldconfig
228         rm -f $(TARGET_DIR)/usr/bin/ldd
229         # remove other unneeded files
230         rm -f $(TARGET_DIR)/usr/sbin/iptables-save
231         rm -f $(TARGET_DIR)/usr/sbin/iptables-restore
232         rm -f $(TARGET_DIR)/usr/sbin/ip6tables
233
234 ######################################################################
235
236 openwrt-linux.trx:  openwrt-prune squashfsroot
237         $(WRT54G_DIR)/release/tools/trx -o openwrt-linux.trx \
238                 $(LINUX_DIR)/$(LINUX_BINLOC) $(IMAGE)
239
240 openwrt-gs-code.bin: openwrt-linux.trx
241         $(WRT54G_DIR)/release/tools/addpattern -i openwrt-linux.trx \
242                 -o openwrt-gs-code.bin -g
243
244 openwrt-g-code.bin: openwrt-gs-code.bin
245         sed -e "1s,^W54S,W54G," < openwrt-gs-code.bin > openwrt-g-code.bin
246
247 openwrt-code.bin: openwrt-gs-code.bin openwrt-g-code.bin
248
249 ######################################################################
250
251 openwrt-sourceball:
252         tar cjf buildroot-openwrt.tar.bz2 \
253                 README.openwrt \
254                 Makefile \
255                 Makefile-openwrt \
256                 make/openwrt.mk \
257                 make/uclibc.mk \
258                 make/busybox.mk \
259                 sources/uClibc.config \
260                 sources/uClibc.config-openwrt \
261                 sources/busybox-openwrt-*.patch \
262                 sources/busybox.config \
263                 sources/busybox.config-openwrt \
264                 sources/dnsmasq1-openwrt.patch \
265                 sources/iptables-openwrt-extensions.patch \
266                 sources/openwrt-wrt54g-linux.config \
267                 sources/openwrt-wrt54g-*.patch \
268                 sources/openwrt-diag.c
269
270 endif