include ../Rules_trunk.mak
MAKE=$(shell which make)


SUBDIRS =

ifeq ($(KERNEL_VERSION),2.4.x)
SUBDIRS += busybox-2.4
else
SUBDIRS += busybox-1.1.0
endif

ifeq ($(WAN_TYPE),ADSL)
ifeq ($(KERNEL_VERSION),2.4.x)
SUBDIRS += bridge-utils-0.9.5
else
SUBDIRS += bridge-utils-1.2
endif
SUBDIRS += linux-atm-2.4.0
endif

SUBDIRS += cron
SUBDIRS += ez-ipupdate-3.0.11b8

ifeq ($(KERNEL_VERSION),2.4.x)
SUBDIRS += iptables-1.2.8
SUBDIRS += fw_modules-2.4
SUBDIRS += syslogd
else
ifeq ($(KERNEL_COTEAU),KERNEL_2_6_15)
SUBDIRS += iptables-2.6.15+
else
SUBDIRS += iptables-2.6
endif
SUBDIRS += fw_modules-2.6
SUBDIRS += syslogd-1.1
endif

SUBDIRS += libupnp-1.2.1
SUBDIRS += gateway

ifeq ($(WAN_TYPE),ADSL)
SUBDIRS += ppp-2.4.1.pppoe4.orig
else
SUBDIRS += ppp
endif

SUBDIRS += udhcpd
SUBDIRS += netkit-routedv2-0.1

ifeq ($(QoS),1)
SUBDIRS += iproute2-2.6.11-050330 
endif

ifeq ($(SNMP),1)
SUBDIRS += snmp
endif

SUBDIRS += mini_httpd-1.17beta1
SUBDIRS += nbtscan-1.5.1a

ifeq ($(MULTI_PVC_SUPPORT),1)
SUBDIRS += br2684ctl-0.1
endif 

ifeq ($(BPA),1)
SUBDIRS += bpalogin-2.0
endif

ifeq ($(RAS),1)
SUBDIRS += ras
endif

ifeq ($(L2TP),1)
SUBDIRS += l2tpd-0.67
endif

ifeq ($(PPTP),1)
SUBDIRS += pptp-linux-1.3.1
endif

ifeq ($(VOIP),1)
SUBDIRS += voice_app 
SUBDIRS += provisioning
endif

ifeq ($(PPTPSERVER),1)
SUBDIRS += pptpd-1.2.1
SUBDIRS += ppp-2.4.1
SUBDIRS += pptpinfo
endif

ifeq ($(WIFI),ATH)
SUBDIRS +=wlctl
SUBDIRS +=nas
endif

ifeq ($(WIFI),RALINK_RT2880)
SUBDIRS +=shared
SUBDIRS += libupgrade
SUBDIRS += uclib
SUBDIRS += wsc_upnp
SUBDIRS +=  wireless_tools-28
SUBDIRS += led_ctrl
SUBDIRS += 802.1x
SUBDIRS += sercomm_dl_rt
endif

$(SUBDIRS)::
	@echo $(WAN_TYPE)
	@for i in $(SUBDIRS) ; do $(MAKE) -C $$i || exit 1; done
ifeq ($(VPN),1)
	$(MAKE) -C gmp-4.2.1
	$(MAKE) -C gmp-4.2.1 install
	$(MAKE) -C openswan-2.4.6rc3 programs
endif

all:$(SUBDIRS)

etc_symlink:
	ln -sf ../resolv.conf ./etc/ppp/resolv.conf
	ln -sf /usr/sbin/restore_config.cgi ./etc/restore_config.cgi
	ln -sf /usr/sbin/setup.cgi ./etc/setup.cgi
	ln -sf /usr/sbin/upgrade_flash.cgi ./etc/upgrade_flash.cgi
	ln -sf /usr/etc/default ./etc/default
	
busybox_build:
	cd ./busybox; $(MAKE) PREFIX=$(INSTALLDIR) uninstall;\
        make clean;\
        $(MAKE)
busybox_clean:
	cd ./busybox; make clean

busybox_install:
	cd ./busybox; $(MAKE) PREFIX=$(INSTALL_ROOT) install

voice_symlink:
ifeq ($(VOIP),1)
	ln -sf Makefile.flat ./voice_app/Makefile
	ln -sf ../voice/pform/ar7l0vdsp/micro/linux/sfgnu/prod/ ./voice_app/prod
	ln -sf d24.ld ./voice_app/dsp_images/dspimage.ld
endif

clean:	
	@for i in $(SUBDIRS) ; do $(MAKE) -C $$i clean || exit 1; done
ifeq ($(VPN),1)	
	$(MAKE) -C openswan-2.4.6rc3 clean
endif

install:
	@for i in $(SUBDIRS) ; do $(MAKE) -C $$i install || exit 1; done
ifeq ($(VPN),1)	
	rm -rf openswan-2.4.6rc3/temp
	$(MAKE) -C openswan-2.4.6rc3 DESTDIR=$(TOP)/apps/openswan-2.4.6rc3/temp install
endif	
