add added files
[bcm963xx.git] / Makefile
1 #****************************************************************************
2 #
3 #  Copyright (c) 2001, 2002, 2003, 2004  Broadcom Corporation
4 #  All Rights Reserved
5 #  No portions of this material may be reproduced in any form without the
6 #  written permission of:
7 #          Broadcom Corporation
8 #          16251 Laguna Canyon Road
9 #          Irvine, California 92618
10 #  All information contained in this document is Broadcom Corporation
11 #  company private, proprietary, and trade secret.
12 #
13 #****************************************************************************
14
15 # Top-level Makefile for all commengine xDSL platforms
16
17 include version.make
18
19 BRCM_RELEASETAG=$(BRCM_VERSION).$(BRCM_RELEASE)L.$(BRCM_EXTRAVERSION)
20
21
22 ###########################################
23 #
24 # Define Basic Variables
25 #
26 ###########################################
27 BUILD_DIR = $(shell pwd)
28 KERNEL_VER = 2.6
29 ifeq ($(strip $(KERNEL_VER)),2.6)
30 INC_KERNEL_BASE = $(BUILD_DIR)/kernel
31 ORIGINAL_KERNEL = linuxmips.tar.bz2
32 endif
33 KERNEL_DIR = $(INC_KERNEL_BASE)/linux
34 BRCMDRIVERS_DIR = $(BUILD_DIR)/bcmdrivers
35 USERAPPS_DIR = $(BUILD_DIR)/userapps
36 LINUXDIR = $(INC_KERNEL_BASE)/linux
37 HOSTTOOLS_DIR = $(BUILD_DIR)/hostTools
38 IMAGES_DIR = $(BUILD_DIR)/images
39 TARGETS_DIR = $(BUILD_DIR)/targets
40 DEFAULTCFG_DIR = $(TARGETS_DIR)/defaultcfg
41 XCHANGE_DIR = $(BUILD_DIR)/xChange
42 FSSRC_DIR = $(TARGETS_DIR)/fs.src
43 CFE_FILE = $(TARGETS_DIR)/cfe/cfe$(BRCM_CHIP).bin
44 CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
45           else if [ -x /bin/bash ]; then echo /bin/bash; \
46           else echo sh; fi ; fi)
47 GENDEFCONFIG_CMD = $(HOSTTOOLS_DIR)/scripts/gendefconfig
48 RUN_NOISE=0
49
50
51
52 ###########################################
53 #
54 # Import Build Profiles
55 #
56 ###########################################
57 BRCM_BOARD=bcm963xx
58 LAST_PROFILE=$(shell find targets -name vmlinux | sed -e "s?targets/??" -e "s?/.*??" -e "q")
59 ifeq ($(strip $(PROFILE)),)
60 PROFILE=$(LAST_PROFILE)
61 export PROFILE
62 endif
63 ifneq ($(strip $(PROFILE)),)
64 include $(TARGETS_DIR)/$(PROFILE)/$(PROFILE)
65 export BRCM_CHIP
66 export BRCM_FLASHPSI_SIZE
67 export BRCM_DRIVER_WIRELESS_PCMCIA_DATASWAP BRCM_DRIVER_WIRELESS_EBI_DMA
68 export BRCM_DRIVER_USB BRCM_DRIVER_ETHERNET_CONFIG
69 export BRCM_DEFAULTCFG
70 export BRCM_KERNEL_NF_FIREWALL BRCM_KERNEL_NF_MANGLE BRCM_KERNEL_NF_NAT
71 endif
72
73 ###########################################
74 #
75 # Define Toolchain
76 #
77 ###########################################
78 ifeq ($(strip $(BRCM_UCLIBC)),y)
79 NTC=1
80 ifeq ($(strip $(NTC)),1)
81 TOOLCHAIN=/opt/toolchains/uclibc-crosstools
82 CROSS_COMPILE = $(TOOLCHAIN)/bin/mips-linux-uclibc-
83 else
84 TOOLCHAIN=/opt/toolchains/uclibc
85 CROSS_COMPILE = $(TOOLCHAIN)/bin/mips-uclibc-
86 endif
87 else
88 TOOLCHAIN=/usr/crossdev/mips
89 CROSS_COMPILE = $(TOOLCHAIN)/bin/mips-linux-
90 endif
91
92 AR              = $(CROSS_COMPILE)ar
93 AS              = $(CROSS_COMPILE)as
94 LD              = $(CROSS_COMPILE)ld
95 CC              = $(CROSS_COMPILE)gcc
96 CXX             = $(CROSS_COMPILE)g++
97 CPP             = $(CROSS_COMPILE)cpp
98 NM              = $(CROSS_COMPILE)nm
99 STRIP           = $(CROSS_COMPILE)strip
100 SSTRIP          = $(CROSS_COMPILE)sstrip
101 OBJCOPY         = $(CROSS_COMPILE)objcopy
102 OBJDUMP         = $(CROSS_COMPILE)objdump
103 RANLIB          = $(CROSS_COMPILE)ranlib
104
105 LIB_PATH        = $(TOOLCHAIN)/mips-linux/lib
106 LIBDIR          = $(TOOLCHAIN)/mips-linux/lib
107 LIBCDIR         = $(TOOLCHAIN)/mips-linux
108
109 ###########################################
110 #
111 # Application-specific settings
112 #
113 ###########################################
114 INSTALL_DIR = $(TARGETS_DIR)/fs.src
115 TARGET_FS = $(TARGETS_DIR)/$(PROFILE)/fs
116 PROFILE_DIR = $(TARGETS_DIR)/$(PROFILE)
117 PROFILE_PATH = $(TARGETS_DIR)/$(PROFILE)/$(PROFILE)
118 VENDOR_NAME = USR
119 FS_KERNEL_IMAGE_NAME = $(VENDOR_NAME)$(PROFILE)_fs_kernel
120 CFE_FS_KERNEL_IMAGE_NAME = $(VENDOR_NAME)$(PROFILE)_cfe_fs_kernel
121 FLASH_IMAGE_NAME = $(VENDOR_NAME)$(PROFILE)_flash_image_$(BRCM_BOARD_ID)
122 INC_BRCMDRIVER_PUB_PATH=$(BRCMDRIVERS_DIR)/opensource/include
123 INC_BRCMDRIVER_PRIV_PATH=$(BRCMDRIVERS_DIR)/broadcom/include
124 INC_BRCMBOARDPARMS_PATH=$(TARGETS_DIR)/boardparms
125 INC_ENDPOINT_PATH=$(BRCMDRIVERS_DIR)/broadcom/char/endpoint/bcm9$(BRCM_CHIP)/inc
126 #INC_ADSLDRV_PATH=$(BRCMDRIVERS_DIR)/broadcom/char/adsl/bcm9$(BRCM_CHIP)
127 INC_ADSLDRV_PATH=$(BRCMDRIVERS_DIR)/broadcom/char/adsl/impl1
128 BROADCOM_CFM_DIR=$(BROADCOM_DIR)/cfm
129 INC_BRCMCFM_PATH=$(BROADCOM_CFM_DIR)/inc
130 VENDOR_COUNTRY = ALL
131
132
133 ifeq ($(strip $(BRCM_APP_PHONE)),sip)
134 export VOXXXLOAD=1
135 export VOIPLOAD=1
136 export SIPLOAD=1
137 BRCM_RELEASETAG := $(BRCM_RELEASETAG).sip
138 endif
139
140 ifeq ($(strip $(BRCM_APP_PHONE)),mgcp)
141 export VOXXXLOAD=1
142 export VOIPLOAD=1
143 export MGCPLOAD=1
144 BRCM_RELEASETAG := $(BRCM_RELEASETAG).mgcp
145 endif
146
147 ifneq ($(strip $(BUILD_VODSL)),)
148 export VOXXXLOAD=1
149 endif
150
151 BRCM_DSP_HAL := gw
152 BRCM_DSP_HAL_EXTENSION :=
153 XCHANGE_DSP_APP_EXTENSION :=
154 export XCHANGE_DSP_APP=$(BRCM_DSP_CODEC)
155
156 ifeq ($(strip $(BRCM_DSP_PCM)),y)
157 XCHANGE_DSP_APP := dspApp3341_tdm
158 BRCM_DSP_HAL_EXTENSION := _pcm
159 endif
160
161 ifeq ($(strip $(BRCM_DSP_HYBRID)),y)
162 XCHANGE_DSP_APP := dspApp3341_hybrid
163 BRCM_DSP_HAL_EXTENSION := _hybrid
164 endif
165
166 ifeq ($(strip $(BRCM_DSP_HYBRID_EXT)),y)
167 BRCM_DSP_HAL_EXTENSION := _hybrid
168 XCHANGE_DSP_APP := dspApp3341_hybrid
169 XCHANGE_DSP_APP_EXTENSION := _ext
170 endif
171
172 # APM application with FXO uses the hybrid HAL, as the FXO is provided by TDM port
173 ifeq ($(strip $(BRCM_DSP_APM_FXO)),y)
174 XCHANGE_DSP_APP := dspApp3341
175 BRCM_DSP_HAL_EXTENSION := _hybrid
176 XCHANGE_DSP_APP_EXTENSION := _fxo
177 endif
178
179 ifeq ($(strip $(BRCM_DSP_APM_FXO_EXT)),y)
180 XCHANGE_DSP_APP := dspApp3341
181 BRCM_DSP_HAL_EXTENSION := _hybrid
182 XCHANGE_DSP_APP_EXTENSION := _fxo_ext
183 endif
184
185 ifeq ($(strip $(BRCM_DSP_HYBRID_FXO)),y)
186 XCHANGE_DSP_APP := dspApp3341_hybrid
187 BRCM_DSP_HAL_EXTENSION := _hybrid
188 XCHANGE_DSP_APP_EXTENSION := _fxo
189 endif
190
191 ifeq ($(strip $(BRCM_DSP_HYBRID_FXO_EXT)),y)
192 XCHANGE_DSP_APP := dspApp3341_hybrid
193 BRCM_DSP_HAL_EXTENSION := _fxo
194 XCHANGE_DSP_APP_EXTENSION := _fxo_ext
195 endif
196
197 export BRCM_DSP_FXO
198 export XCHANGE_BUILD_APP=Bcm$(BRCM_CHIP)$(BRCM_DSP_HAL)$(BRCM_DSP_HAL_EXTENSION)
199 export XCHANGE_DSP_APP_EXTENSION
200 export BRCM_DSP_HAL_EXTENSION
201 BRCM_RELEASETAG := $(BRCM_RELEASETAG).$(XCHANGE_DSP_APP)
202
203 # If no codec is selected, build G.711 load.
204 # Any XCHANGE_BUILD_APP directory would be OK
205 # because G.711 is included with all the voice DSP images.
206 ifneq ($(strip $(BUILD_VODSL)),)
207 ifeq ($(strip $(XCHANGE_DSP_APP)),)
208 export XCHANGE_BUILD_APP=Bcm$(BRCM_CHIP)gw
209 export XCHANGE_DSP_APP=g711
210 BRCM_RELEASETAG := $(BRCM_RELEASETAG).g711
211 endif
212 endif
213                                                                                 
214 ifeq ($(strip $(XCHG_LE9502_SLIC)),y)
215 ifeq ($(strip $(BRCM_DSP_FXO)),y)
216 export XCHANGE_BUILD_APP=Bcm$(BRCM_CHIP)_Le9502FXO
217 BRCM_RELEASETAG := $(BRCM_RELEASETAG)._LE9502
218 BRCM_DSP_HAL := LE9502_FXO
219 else
220 export XCHANGE_BUILD_APP=Bcm$(BRCM_CHIP)_Le9502
221 BRCM_RELEASETAG := $(BRCM_RELEASETAG)._LE9502
222 BRCM_DSP_HAL := LE9502
223 endif
224 export XCHG_LE9502_SLIC
225 endif
226                                                                                 
227                                                                                 
228 #Set up ADSL standard
229 export ADSL=$(BRCM_ADSL_STANDARD)
230
231 #Set up ADSL_PHY_MODE  {file | obj}
232 export ADSL_PHY_MODE=file
233
234 #Set up ADSL_SELF_TEST
235 export ADSL_SELF_TEST=$(BRCM_ADSL_SELF_TEST)
236
237 ###########################################
238 #
239 # Complete list of applications
240 #
241 ###########################################
242 export OPENSOURCE_DIR=$(USERAPPS_DIR)/opensource
243 SUBDIRS_OPENSOURCE = $(OPENSOURCE_DIR)/atm2684/pvc2684ctl \
244         $(OPENSOURCE_DIR)/bridge-utils \
245         $(OPENSOURCE_DIR)/ppp/pppoe \
246         $(OPENSOURCE_DIR)/udhcp \
247         $(OPENSOURCE_DIR)/iptables \
248         $(OPENSOURCE_DIR)/ebtables \
249         $(OPENSOURCE_DIR)/reaim  \
250         $(OPENSOURCE_DIR)/gdbserver  \
251         $(OPENSOURCE_DIR)/siproxd \
252         $(OPENSOURCE_DIR)/zebra  \
253         $(OPENSOURCE_DIR)/net-snmp  \
254         $(OPENSOURCE_DIR)/ftpd \
255         $(OPENSOURCE_DIR)/libcreduction \
256         $(OPENSOURCE_DIR)/busybox
257
258 #In future, we need to add soap when it
259 #is decoupled from cli
260
261 export BROADCOM_DIR=$(USERAPPS_DIR)/broadcom
262 SUBDIRS_BROADCOM = $(BROADCOM_DIR)/nvram \
263         $(BROADCOM_DIR)/cfm \
264         $(BROADCOM_DIR)/upnp/router/upnp \
265         $(BROADCOM_DIR)/nas \
266         $(BROADCOM_DIR)/wlctl \
267         $(BROADCOM_DIR)/vodsl \
268         $(BROADCOM_DIR)/atmctl \
269         $(BROADCOM_DIR)/adslctl \
270         $(BROADCOM_DIR)/netctl \
271         $(BROADCOM_DIR)/dnsprobe \
272         $(BROADCOM_DIR)/igmp \
273         $(BROADCOM_DIR)/dhcpr \
274         $(BROADCOM_DIR)/sntp \
275         $(BROADCOM_DIR)/ippd \
276         $(BROADCOM_DIR)/ddnsd \
277         $(BROADCOM_DIR)/ethctl \
278         $(BROADCOM_DIR)/hotplug \
279         $(BROADCOM_DIR)/epittcp \
280         $(BROADCOM_DIR)/ses 
281
282 SUBDIRS_APP = $(SUBDIRS_BROADCOM) $(SUBDIRS_OPENSOURCE)
283 SUBDIRS = $(foreach dir, $(SUBDIRS_APP), $(shell if [ -d "$(dir)" ]; then echo $(dir); fi))
284
285 OPENSOURCE_APPS = pvc2684ctl pvc2684d brctl pppd udhcp iptables ebtables \
286                   reaim siproxd snmp zebra bftpd busybox gdbserver
287
288 BROADCOM_APPS = nvram cfm upnp nas wlctl vodsl atmctl adslctl netctl dnsprobe \
289                 igmp dhcpr diagapp sntp ddnsd ilmi ippd hotplug ethctl epittcp ses
290 LIBC_OPTIMIZATION = libcreduction
291
292 BUSYBOX_DIR = $(OPENSOURCE_DIR)/busybox
293
294 BRCMAPPS = $(BROADCOM_APPS) $(OPENSOURCE_APPS) $(LIBC_OPTIMIZATION)
295
296 all: sanity_check profile_check kernelbuild modbuild app hosttools buildimage
297
298 menuconfig:
299         @cd $(INC_KERNEL_BASE); \
300         if [ ! -e linux/CREDITS ]; then \
301           echo Untarring original Linux kernel source...; \
302           (tar xkfj $(ORIGINAL_KERNEL) 2> /dev/null || true); \
303         fi
304         $(MAKE) -C $(KERNEL_DIR)/scripts/lxdialog HOSTCC=gcc
305         $(CONFIG_SHELL) $(HOSTTOOLS_DIR)/scripts/Menuconfig $(TARGETS_DIR)/config.in
306
307 sanity_check:
308         @if [ "$(PROFILE)" = "" ]; then \
309           echo You need to specify build profile name from $(TARGETS_DIR) using 'make PROFILE=<profile name>...'; exit 1; \
310         fi
311
312 profile_check:
313         @if [ "$(LAST_PROFILE)" != "" ] && [ "$(LAST_PROFILE)" != "$(PROFILE)" ]; then \
314                 echo "The specified profile, $(PROFILE), differs from the last one built, $(LAST_PROFILE)."; \
315                 echo "The entire image must be rebuilt."; \
316                 read -p "Press ENTER to rebuild the entire image or CTRL-C to abort. " ; \
317                 $(MAKE) PROFILE=$(LAST_PROFILE) clean; \
318                 $(MAKE) PROFILE=$(PROFILE); \
319                 echo "Ignore the make exit error, Error 1"; \
320                 exit 1; \
321         fi
322
323 $(KERNEL_DIR)/vmlinux:
324         $(GENDEFCONFIG_CMD) $(PROFILE_PATH)
325         cd $(KERNEL_DIR); \
326         cp -f $(KERNEL_DIR)/arch/mips/defconfig $(KERNEL_DIR)/.config; \
327         $(MAKE) oldconfig; $(MAKE); $(MAKE) modules_install
328
329 kernelbuild:
330 ifeq ($(wildcard $(KERNEL_DIR)/vmlinux),)
331         @cd $(INC_KERNEL_BASE); \
332         if [ ! -e linux/CREDITS ]; then \
333           echo Untarring original Linux kernel source...; \
334           (tar xkfj $(ORIGINAL_KERNEL) 2> /dev/null || true); \
335         fi
336         $(GENDEFCONFIG_CMD) $(PROFILE_PATH)
337         cd $(KERNEL_DIR); \
338         cp -f $(KERNEL_DIR)/arch/mips/defconfig $(KERNEL_DIR)/.config; \
339         $(MAKE) oldconfig; $(MAKE)
340 else
341         cd $(KERNEL_DIR); $(MAKE)
342 endif
343
344 kernel: profile_check kernelbuild hosttools buildimage
345
346 ifeq ($(strip $(VOXXXLOAD)),1)
347 modbuild: touch_voice_files
348         cd $(KERNEL_DIR); $(MAKE) modules && $(MAKE) modules_install
349 else
350 modbuild:
351         cd $(KERNEL_DIR); $(MAKE) modules && $(MAKE) modules_install
352 endif
353
354 modules: profile_check modbuild hosttools buildimage
355
356 app: profile_check prebuild $(BRCMAPPS) hosttools buildimage
357
358 prebuild:
359         mkdir -p $(INSTALL_DIR)/bin $(INSTALL_DIR)/lib
360
361 # touch_voice_files doesn't clean up voice, just enables incremental build of voice code
362 touch_voice_files:
363         find bcmdrivers/broadcom/char/endpoint/ \( -name '*.o' -o -name '*.a' -o -name '*.lib' -o -name '*.ko' -o -name '*.cmd' -o -name '.*.cmd' -o -name '*.c' -o -name '*.mod' \) -print -exec rm -f "{}" ";"
364         rm -rf kernel/linux/.tmp_versions/endpointdd.mod
365         rm -rf kernel/linux/arch/mips/defconfig
366         rm -rf kernel/linux/include/config/bcm/endpoint/
367         rm -rf kernel/linux/include/asm-mips/offset.h
368         rm -rf kernel/linux/include/asm-mips/reg.h
369         find kernel/linux/lib/ -name '*.o' -print -exec rm -f "{}" ";"
370         find kernel/linux/lib/ -name '*.lib' -print -exec rm -f "{}" ";"
371
372 # Build user applications depending on if they are
373 # specified in the profile
374 ifneq ($(strip $(BUILD_PVC2684CTL)),)
375 export BUILD_PVC2684D=$(BUILD_PVC2684CTL)
376 pvc2684d:
377 pvc2684ctl:
378         $(MAKE) -C $(OPENSOURCE_DIR)/atm2684/pvc2684ctl $(BUILD_PVC2684CTL)
379 else
380 pvc2684ctl:
381 endif
382
383 ifneq ($(strip $(BUILD_BRCTL)),)
384 brctl:
385         cd $(OPENSOURCE_DIR);   (tar xkfj bridge-utils.tar.bz2 2> /dev/null || true)
386         $(MAKE) -C $(OPENSOURCE_DIR)/bridge-utils $(BUILD_BRCTL)
387 else
388 brctl:
389 endif
390
391 ifneq ($(strip $(BUILD_VCONFIG)),)
392 export BUILD_VCONFIG=y
393 endif
394
395 ifneq ($(strip $(BUILD_CFM)),)
396
397 ifneq ($(strip $(BUILD_CFM_MENU)),)
398 export BUILD_CFM_MENU=y
399 endif
400
401 cfm:
402         $(MAKE) -C $(BROADCOM_DIR)/cfm $(BUILD_CFM)
403 else
404 cfm:
405 endif
406
407 # iptables is dependent on kernel netfilter modules
408 ifneq ($(strip $(BRCM_KERNEL_NETFILTER)),)
409 ifneq ($(strip $(BUILD_IPTABLES)),)
410 iptables:
411         cd $(OPENSOURCE_DIR);   (tar xkfj iptables.tar.bz2 2> /dev/null || true)
412         $(MAKE) -C $(OPENSOURCE_DIR)/iptables $(BUILD_IPTABLES)
413 iptables-build:
414         cd $(OPENSOURCE_DIR);   (tar xkfj iptables.tar.bz2 2> /dev/null || true)
415         $(MAKE) -C $(OPENSOURCE_DIR)/iptables static
416 else
417 iptables:
418 endif
419 else
420 iptables:
421         @echo Warning: You need to enable netfilter in the kernel !!!!!
422 endif
423
424 ifneq ($(strip $(BUILD_EBTABLES)),)
425 ebtables:
426         cd $(OPENSOURCE_DIR);   (tar xkfj ebtables.tar.bz2 2> /dev/null || true)
427         $(MAKE) -C $(OPENSOURCE_DIR)/ebtables $(BUILD_EBTABLES)
428 else
429 ebtables:
430 endif
431
432 ifneq ($(strip $(BUILD_PPPD)),)
433 pppd:
434         $(MAKE) -C $(OPENSOURCE_DIR)/ppp/pppoe $(BUILD_PPPD)
435 else
436 pppd:
437 endif
438
439 ifneq ($(strip $(BUILD_REAIM)),)
440 reaim:
441         cd $(OPENSOURCE_DIR);   (tar xkfj reaim.tar.bz2 2> /dev/null || true)
442         $(MAKE) -C $(OPENSOURCE_DIR)/reaim $(BUILD_REAIM)
443 else
444 reaim:
445 endif
446
447 ifneq ($(strip $(BUILD_GDBSERVER)),)
448 gdbserver:
449         $(MAKE) -C $(OPENSOURCE_DIR)/gdbserver dynamic
450 else
451 gdbserver:
452 endif
453
454 ifneq ($(strip $(BUILD_ETHWAN)),)
455 export BUILD_ETHWAN=y
456 endif
457
458 ifneq ($(strip $(BUILD_UDHCP)),)
459 udhcp:
460         $(MAKE) -C $(OPENSOURCE_DIR)/udhcp $(BUILD_UDHCP)
461 else
462 udhcp:
463 endif
464
465 # UPNP is dependent on iptables
466 ifneq ($(strip $(BUILD_IPTABLES)),)
467 ifneq ($(strip $(BUILD_UPNP)),)
468 upnp: iptables-build
469         $(MAKE) -C $(BROADCOM_DIR)/upnp/router/upnp  $(BUILD_UPNP)
470 else
471 upnp:
472 endif
473 else
474 upnp:
475         @echo Warning: You need to build iptables first !!!!!
476 endif
477
478
479 ifneq ($(strip $(BUILD_SIPROXD)),)
480 siproxd:
481         cd $(OPENSOURCE_DIR);   (tar xkfj libosip2.tar.bz2 2> /dev/null || true)
482         cd $(OPENSOURCE_DIR);   (tar xkfj siproxd.tar.bz2 2> /dev/null || true)
483         $(MAKE) -C $(OPENSOURCE_DIR)/siproxd $(BUILD_SIPROXD)
484 else
485 siproxd:
486 endif
487
488 ifneq ($(strip $(BUILD_SNMP)),)
489
490 ifneq ($(strip $(BUILD_SNMP_SET)),)
491 export BUILD_SNMP_SET=1
492 else
493 export BUILD_SNMP_SET=0
494 endif
495
496 ifneq ($(strip $(BUILD_SNMP_ADSL_MIB)),)
497 export BUILD_SNMP_ADSL_MIB=1
498 else
499 export BUILD_SNMP_ADSL_MIB=0
500 endif
501
502 ifneq ($(strip $(BUILD_SNMP_ATM_MIB)),)
503 export BUILD_SNMP_ATM_MIB=1
504 else
505 export BUILD_SNMP_ATM_MIB=0
506 endif
507
508 ifneq ($(strip $(BUILD_SNMP_AT_MIB)),)
509 export BUILD_SNMP_AT_MIB=1
510 else
511 export BUILD_SNMP_AT_MIB=0
512 endif
513
514 ifneq ($(strip $(BUILD_SNMP_SYSOR_MIB)),)
515 export BUILD_SNMP_SYSOR_MIB=1
516 else
517 export BUILD_SNMP_SYSOR_MIB=0
518 endif
519
520 ifneq ($(strip $(BUILD_SNMP_TCP_MIB)),)
521 export BUILD_SNMP_TCP_MIB=1
522 else
523 export BUILD_SNMP_TCP_MIB=0
524 endif
525
526 ifneq ($(strip $(BUILD_SNMP_UDP_MIB)),)
527 export BUILD_SNMP_UDP_MIB=1
528 else
529 export BUILD_SNMP_UDP_MIB=0
530 endif
531
532 ifneq ($(strip $(BUILD_SNMP_IP_MIB)),)
533 export BUILD_SNMP_IP_MIB=1
534 else
535 export BUILD_SNMP_IP_MIB=0
536 endif
537
538 ifneq ($(strip $(BUILD_SNMP_ICMP_MIB)),)
539 export BUILD_SNMP_ICMP_MIB=1
540 else
541 export BUILD_SNMP_ICMP_MIB=0
542 endif
543
544 ifneq ($(strip $(BUILD_SNMP_SNMP_MIB)),)
545 export BUILD_SNMP_SNMP_MIB=1
546 else
547 export BUILD_SNMP_SNMP_MIB=0
548 endif
549
550 ifneq ($(strip $(BUILD_SNMP_ATMFORUM_MIB)),)
551 export BUILD_SNMP_ATMFORUM_MIB=1
552 else
553 export BUILD_SNMP_ATMFORUM_MIB=0
554 endif
555
556 snmp:
557         cd $(OPENSOURCE_DIR);   (tar xkfj net-snmp.tar.bz2 2> /dev/null || true)
558         $(MAKE) -C $(OPENSOURCE_DIR)/net-snmp $(BUILD_SNMP)
559 else
560 snmp:
561 endif
562
563 ifneq ($(strip $(BUILD_ILMI)),)
564 ilmi:
565         cd $(OPENSOURCE_DIR);   (tar xkfj net-snmp.tar.bz2 2> /dev/null || true)
566         $(MAKE) -C $(BROADCOM_DIR)/ilmi $(BUILD_ILMI)
567 else
568 ilmi:
569 endif
570
571 ifneq ($(strip $(BUILD_VODSL)),)
572 vodsl:
573         $(MAKE) -C $(BROADCOM_DIR)/vodsl $(BUILD_VODSL)
574 else
575 vodsl:
576 endif
577
578 # Leave it for the future when soap server is decoupled from cfm
579 ifneq ($(strip $(BUILD_SOAP)),)
580 ifeq ($(strip $(BUILD_SOAP_VER)),2)
581 soapserver:
582         $(MAKE) -C $(BROADCOM_DIR)/SoapToolkit/SoapServer $(BUILD_SOAP)
583 else
584 soap:
585         $(MAKE) -C $(BROADCOM_DIR)/soap $(BUILD_SOAP)
586 endif
587 else
588 soap:
589 endif
590
591 ifneq ($(strip $(BUILD_NAS)),)
592 export WIRELESS=1
593 nas:
594         $(MAKE) -C $(BROADCOM_DIR)/nas $(BUILD_NAS)
595
596 #add hotplug here, for nas use only
597 hotplug:
598         $(MAKE) -C $(BROADCOM_DIR)/hotplug $(BUILD_NAS)
599         
600 else
601 export WIRELESS=0
602 nas:
603 #add hotplug here, for nas use only
604 hotplug:
605 endif
606
607 ifneq ($(strip $(BUILD_WLCTL)),)
608 export WIRELESS=1
609 wlctl:
610         $(MAKE) -C $(BROADCOM_DIR)/wlctl $(BUILD_WLCTL)
611 else
612 export WIRELESS=0
613 wlctl:
614 endif
615
616 #Always compile Ethernet control utility
617 ethctl:
618         $(MAKE) -C $(BROADCOM_DIR)/ethctl dynamic
619
620 ifneq ($(strip $(BUILD_DNSPROBE)),)
621 dnsprobe:
622         $(MAKE) -C $(BROADCOM_DIR)/dnsprobe $(BUILD_DNSPROBE)
623 else
624 dnsprobe:
625 endif
626
627 ifneq ($(strip $(BUILD_IGMP)),)
628 igmp:
629         $(MAKE) -C $(BROADCOM_DIR)/igmp $(BUILD_IGMP)
630 else
631 igmp:
632 endif
633
634 ifneq ($(strip $(BUILD_DHCPR)),)
635 dhcpr:
636         $(MAKE) -C $(BROADCOM_DIR)/dhcpr $(BUILD_DHCPR)
637 else
638 dhcpr:
639 endif
640
641 ifneq ($(strip $(BUILD_ZEBRA)),)
642 zebra:
643         cd $(OPENSOURCE_DIR);   (tar xkfj zebra.tar.bz2 2> /dev/null || true)
644         $(MAKE) -C $(OPENSOURCE_DIR)/zebra $(BUILD_ZEBRA)
645 else
646 zebra:
647 endif
648
649 ifneq ($(strip $(BUILD_ATMCTL)),)
650 atmctl:
651         $(MAKE) -C $(BROADCOM_DIR)/atmctl $(BUILD_ATMCTL)
652 else
653 atmctl:
654 endif
655
656 ifneq ($(strip $(BUILD_ADSLCTL)),)
657 adslctl:
658         $(MAKE) -C $(BROADCOM_DIR)/adslctl $(BUILD_ADSLCTL)
659 else
660 adslctl:
661 endif
662
663 ifeq ($(strip $(BUILD_CFM_CLI)),y)
664 ifneq ($(strip $(BUILD_NETCTL)),)
665 netctl:
666         $(MAKE) -C $(BROADCOM_DIR)/netctl $(BUILD_NETCTL)
667 else
668 netctl:
669 endif
670 else
671 netctl:
672 endif
673
674 ifneq ($(strip $(BUILD_BUSYBOX)),)
675 busybox:
676         cd $(OPENSOURCE_DIR); (tar xkfj busybox.tar.bz2 2> /dev/null || true)
677 #       $(MAKE) -C $(OPENSOURCE_DIR)/busybox $(BUILD_BUSYBOX)
678         cd $(OPENSOURCE_DIR)/busybox; cp -f brcm.config .config
679         $(MAKE) -C $(OPENSOURCE_DIR)/busybox install
680 else
681 busybox:
682 endif
683
684 ifneq ($(strip $(BUILD_LIBCREDUCTION)),)
685 libcreduction:
686         mkdir -p $(OPENSOURCE_DIR)/libcreduction/uclibc
687         $(MAKE) -C $(OPENSOURCE_DIR)/libcreduction install
688 else
689 libcreduction:
690 endif
691
692 ifneq ($(strip $(BUILD_DIAGAPP)),)
693 diagapp:
694         $(MAKE) -C $(BROADCOM_DIR)/diagapp $(BUILD_DIAGAPP)
695 else
696 diagapp:
697 endif
698
699 ifneq ($(strip $(BUILD_FTPD)),)
700 bftpd:
701         cd $(OPENSOURCE_DIR);   (tar xkfj ftpd.tar.bz2 2> /dev/null || true)
702         $(MAKE) -C $(OPENSOURCE_DIR)/ftpd $(BUILD_FTPD)
703 else
704 bftpd:
705 endif
706
707 ifneq ($(strip $(BUILD_DDNSD)),)
708 ddnsd:
709         $(MAKE) -C $(BROADCOM_DIR)/ddnsd $(BUILD_DDNSD)
710 else
711 ddnsd:
712 endif
713
714 ifneq ($(strip $(BUILD_SNTP)),)
715 sntp:
716         $(MAKE) -C $(BROADCOM_DIR)/sntp $(BUILD_SNTP)
717 else
718 sntp:
719 endif
720
721 ifneq ($(strip $(BUILD_EPITTCP)),)
722 epittcp:
723         $(MAKE) -C $(BROADCOM_DIR)/epittcp $(BUILD_EPITTCP)
724 else
725 epittcp:
726 endif
727
728 ifneq ($(strip $(BUILD_SES)),)
729 ses:
730         $(MAKE) -C $(BROADCOM_DIR)/ses $(BUILD_SES)
731 else
732 ses:
733 endif
734
735 ifneq ($(strip $(BUILD_NVRAM)),)
736 nvram:
737         $(MAKE) -C $(BROADCOM_DIR)/nvram $(BUILD_NVRAM)
738 else
739 nvram:
740 endif
741
742 ifneq ($(strip $(BUILD_IPPD)),)
743 ippd:
744         $(MAKE) -C $(BROADCOM_DIR)/ippd $(BUILD_IPPD)
745 else
746 ippd:
747 endif
748
749 hosttools:
750         $(MAKE) -C $(HOSTTOOLS_DIR)
751
752
753 buildimage: $(KERNEL_DIR)/vmlinux
754         su --command="cd $(TARGETS_DIR); ./buildFS"
755 ifeq ($(strip $(BRCM_KERNEL_ROOTFS)),squashfs)
756         #$(HOSTTOOLS_DIR)/mksquashfs $(TARGET_FS) $(PROFILE_DIR)/rootfs.img -noappend -be -always-use-fragments -gzip
757         $(HOSTTOOLS_DIR)/mksquashfs $(TARGET_FS) $(PROFILE_DIR)/rootfs.img -noappend -be -lzma -no-fragments -noI
758 else
759  ifeq ($(strip $(BRCM_KERNEL_ROOTFS)),cramfs)
760 #       $(HOSTTOOLS_DIR)/mkcramfs -r -g $(TARGET_FS) $(PROFILE_DIR)/rootfs.img
761         $(HOSTTOOLS_DIR)/mkcramfs -r $(TARGET_FS) $(PROFILE_DIR)/rootfs.img
762  else
763   ifeq ($(strip $(BRCM_KERNEL_ROOTFS)),jffs2)
764         $(HOSTTOOLS_DIR)/mkfs.jffs2 -b -p -e $(BRCM_FLASHBLK_SIZE) -r $(TARGET_FS) -o $(PROFILE_DIR)/rootfs.img
765   endif
766  endif
767 endif
768
769 ifneq ($(strip $(BRCM_KERNEL_ROOTFS)),nfs)
770         cd $(PROFILE_DIR); \
771         cp $(KERNEL_DIR)/vmlinux . ; \
772         $(STRIP) --remove-section=.note --remove-section=.comment vmlinux; \
773         $(OBJCOPY) -O binary vmlinux vmlinux.bin; \
774         $(HOSTTOOLS_DIR)/cmplzma -k -2 vmlinux vmlinux.bin vmlinux.lz;\
775         $(HOSTTOOLS_DIR)/bcmImageBuilder --output $(FS_KERNEL_IMAGE_NAME) --chip $(BRCM_CHIP) --board $(BRCM_BOARD_ID) --blocksize $(BRCM_FLASHBLK_SIZE) --cfefile $(CFE_FILE) --rootfsfile rootfs.img --kernelfile vmlinux.lz; \
776         $(HOSTTOOLS_DIR)/bcmImageBuilder --output $(CFE_FS_KERNEL_IMAGE_NAME) --chip $(BRCM_CHIP) --board $(BRCM_BOARD_ID) --blocksize $(BRCM_FLASHBLK_SIZE) --cfefile $(CFE_FILE) --rootfsfile rootfs.img --kernelfile vmlinux.lz --include-cfe; \
777         $(HOSTTOOLS_DIR)/createimg -b $(BRCM_BOARD_ID) -n $(BRCM_NUM_MAC_ADDRESSES) -m $(BRCM_BASE_MAC_ADDRESS) -i $(CFE_FS_KERNEL_IMAGE_NAME) -o $(FLASH_IMAGE_NAME) -l $(VENDOR_COUNTRY); \
778         $(HOSTTOOLS_DIR)/addvtoken $(FLASH_IMAGE_NAME) $(FLASH_IMAGE_NAME).w
779         @mkdir -p $(IMAGES_DIR)
780         @cp $(PROFILE_DIR)/$(FS_KERNEL_IMAGE_NAME) $(IMAGES_DIR)/$(FS_KERNEL_IMAGE_NAME)_$(BRCM_RELEASETAG)-$(shell date '+%y%m%d_%H%M')
781         @echo
782         @echo -e "Done! Image $(PROFILE) has been built in $(IMAGES_DIR)."
783 else
784         cd $(PROFILE_DIR); \
785         cp $(KERNEL_DIR)/vmlinux . ; \
786         $(STRIP) --remove-section=.note --remove-section=.comment vmlinux
787         @echo
788         @echo -e "\t=== Following the below steps to start your NFS root file system on host ==="
789         @echo -e "Step 1: Copy $(PROFILE_DIR)/vmlinux to your TFTP server boot directory, such as /tftpboot"
790         @echo -e "Step 2: Add \"$(PROFILE_DIR)/fs *(rw,no_root_squash)\" to /etc/exports"
791         @echo -e "Step 3: Become root and restart your nfs server, such as \"service nfs restart\""
792         @echo -e "Step 4: Reboot your board and break into CFE bootloader, choose h on \"Run from flash/host\" and vmlinux on \"Default host run file name\""
793 endif
794
795
796 ###########################################
797 #
798 # System code clean-up
799 #
800 ###########################################     
801         
802 subdirs: $(patsubst %, _dir_%, $(SUBDIRS))
803
804 $(patsubst %, _dir_%, $(SUBDIRS)) :
805         $(MAKE) -C $(patsubst _dir_%, %, $@) $(TGT)
806
807 clean: target_clean app_clean kernel_clean hosttools_clean
808         rm -f .tmpconfig*
809
810 fssrc_clean:
811         rm -fr $(INSTALL_DIR)/bin
812         rm -fr $(INSTALL_DIR)/sbin
813         rm -fr $(INSTALL_DIR)/lib
814         rm -fr $(INSTALL_DIR)/upnp
815         rm -fr $(INSTALL_DIR)/docs
816         rm -fr $(INSTALL_DIR)/webs
817         rm -fr $(INSTALL_DIR)/usr
818         rm -fr $(INSTALL_DIR)/linuxrc
819
820 kernel_clean: sanity_check
821         $(MAKE) -C $(KERNEL_DIR) mrproper
822         rm -f $(KERNEL_DIR)/arch/mips/defconfig
823         rm -f $(HOSTTOOLS_DIR)/lzma/decompress/*.o
824         rm -rf $(XCHANGE_DIR)/dslx/lib/LinuxKernel
825         rm -rf $(XCHANGE_DIR)/dslx/obj/LinuxKernel
826
827 app_clean: sanity_check fssrc_clean
828         $(MAKE) subdirs TGT=clean
829         rm -rf $(XCHANGE_DIR)/dslx/lib/LinuxUser
830         rm -rf $(XCHANGE_DIR)/dslx/obj/LinuxUser
831
832 target_clean: sanity_check
833         rm -f $(PROFILE_DIR)/rootfs.img
834         rm -f $(PROFILE_DIR)/vmlinux
835         rm -f $(PROFILE_DIR)/vmlinux.bin
836         rm -f $(PROFILE_DIR)/vmlinux.lz
837         rm -f $(PROFILE_DIR)/$(FS_KERNEL_IMAGE_NAME)
838         rm -f $(PROFILE_DIR)/$(CFE_FS_KERNEL_IMAGE_NAME)
839         rm -f $(PROFILE_DIR)/$(FLASH_IMAGE_NAME)
840         rm -f $(PROFILE_DIR)/$(FLASH_IMAGE_NAME).w
841         rm -fr $(PROFILE_DIR)/modules
842         find targets -name vmlinux -print -exec rm -f "{}" ";"
843         su --command="rm -fr $(TARGET_FS)"
844
845 hosttools_clean:
846         $(MAKE) -C $(HOSTTOOLS_DIR) clean
847         
848 ###########################################
849 #
850 # System-wide exported variables
851 #
852 ###########################################     
853
854 export  BRCM_VERSION BRCM_RELEASE BRCM_EXTRAVERSION BRCM_RELEASETAG BRCM_BOARD RUN_NOISE \
855         INC_KERNEL_BASE KERNEL_DIR BRCMDRIVERS_DIR USERAPPS_DIR HOSTTOOLS_DIR TARGETS_DIR DEFAULTCFG_DIR XCHANGE_DIR FSSRC_DIR BUSYBOX_DIR \
856         PROFILE_DIR INSTALL_DIR LINUXDIR INC_BRCMDRIVER_PUB_PATH INC_BRCMDRIVER_PRIV_PATH INC_BRCMBOARDPARMS_PATH INC_ENDPOINT_PATH INC_ADSLDRV_PATH BROADCOM_CFM_DIR INC_BRCMCFM_PATH BRCM_KERNEL_ROOTFS BRCMAPPS \
857         BRCM_UCLIBC CROSS_COMPILE TOOLCHAIN AS LD CC CXX AR NM STRIP SSTRIP OBJCOPY OBJDUMP RANLIB LIB_PATH LIBCDIR LIBDIR  \
858         BUILD_BR2684CTL BUILD_PVC2684CTL BUILD_RT2684D BUILD_BRCTL BUILD_CFM BUILD_CFM_CLI BUILD_IPTABLES BUILD_EBTABLES BUILD_VODSL BUILD_SIPROXD \
859         BRCM_APP_PHONE BUILD_SOAP BUILD_SOAP_VER BRCM_DSP_CODEC_G711 BRCM_DSP_CODEC_G723 BRCM_DSP_CODEC_G726 BRCM_DSP_CODEC_G729 \
860    BRCM_DSP_CODEC_G7xx BRCM_DSP_PCM BRCM_DSP_HYBRID BRCM_DSP_HYBRID_EXT BRCM_DSP_APM_FXO BRCM_DSP_APM_FXO_EXT BRCM_DSP_HYBRID_FXO \
861    BRCM_DSP_HYBRID_FXO_EXT BRCM_DSP_CODEC_T38_EXT BRCM_DSP_CODEC_T38_INT BRCM_DSP_HAL BRCM_DSP_HAL_EXTENSION  XCHANGE_DSP_APP_EXTENSION BRCM_VOICE_COUNTRY_JAPAN BRCM_VOICE_GLOBAL_CFLAGS \
862         BUILD_PPPD BUILD_REAIM BUILD_GDBSERVER BUILD_UDHCP BUILD_DHCPR BUILD_UPNP BUILD_SNMP BUILD_NAS BUILD_WLCTL BUILD_BUSYBOX BUILD_DNSPROBE BUILD_SLACTEST BUILD_VCONFIG BUILD_ETHWAN \
863         BUILD_ZEBRA BUILD_ATMCTL BUILD_ADSLCTL BUILD_NETCTL BUILD_IGMP BRCM_PTHREADS BUILD_DIAGAPP \
864         BUILD_CFM_TELNETD BUILD_CFM_SSHD BUILD_SSHD_MIPS_GENKEY BUILD_FTPD BRCM_DRIVER_PCI \
865         BRCM_PSI_VERSION WEB_POPUP BUILD_DIR BUILD_DDNSD BUILD_SNTP BUILD_TOD BUILD_IPPD BUILD_VCONFIG JTAG_KERNEL_DEBUG \
866         BUILD_EPITTCP BUILD_NVRAM BUILD_SES