	# Set up your environment before running this file.

	CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
		  else if [ -x /bin/bash ]; then echo /bin/bash; \
		  else if [ -x /usr/bin/bash ]; then echo /usr/bin/bash; \
		  else if [ -x /usr/local/bin/bash ]; then echo /usr/local/bin/bash; \
		  else echo sh; fi ; fi ; fi ; fi)

	TOPDIR = $(shell cd ..;pwd)
	include ${TOPDIR}/brecis/Makefile.brecis
	sinclude .config

#---------------
DESTBIN = ${CWD}/bin
DESTETC = ${CWD}/etc
DESTINFO = ${CWD}/info
DESTLIBEXEC = ${CWD}/libexec
DESTSBIN = ${CWD}/sbin
DESTSHARE = ${CWD}/share
DESTVAR = ${CWD}/var
DESTWWW = ${CWD}/www
DESTMAN = ${CWD}/man
DESTETC = ${CWD}/etc
DESTLIB = ${CWD}/lib
DESTUSR = ${CWD}/usr
#---------------
SUBLIBS =
SUBLIBS += libns/libns.a
#---------------
SUBDIRS :=
SUBDIRS- =
SUBDIRS-y =
SUBDIRS-$(CONFIG_UCSRC_AGETTY) += agetty
#SUBDIRS-$(CONFIG_UCSRC_HTTPD) += httpd
SUBDIRS-$(CONFIG_UCSRC_INIT) += init
SUBDIRS-$(CONFIG_UCSRC_INETD) += inetd
SUBDIRS-$(CONFIG_UCSRC_PING) += ping
SUBDIRS-$(CONFIG_UCSRC_TELNETD) += telnetd
SUBDIRS-$(CONFIG_UCSRC_TELNET) += telnet
SUBDIRS-$(CONFIG_UCSRC_MOUNT) += mount
#----
#SUBDIRS-$(CONFIG_UCSRC_PPPD) += pppd
SUBDIRS-$(CONFIG_UCSRC_TTY) += tty
#SUBDIRS-$(CONFIG_UCSRC_LEVEE) += levee
SUBDIRS-$(CONFIG_UCSRC_FILEUTILS) += fileutils
SUBDIRS-$(CONFIG_UCSRC_SHUTILS) += shutils
SUBDIRS-$(CONFIG_UCSRC_SYSUTILS) += sysutils
#SUBDIRS-$(CONFIG_UCSRC_IFATTACH) += ifattach
#SUBDIRS-$(CONFIG_UCSRC_IPFWADM) += ipfwadm
#SUBDIRS-$(CONFIG_UCSRC_TFTP) += tftp
#SUBDIRS-$(CONFIG_UCSRC_TFTPD) += tftpd
SUBDIRS-$(CONFIG_UCSRC_FTP) += ftp
#SUBDIRS-$(CONFIG_UCSRC_AFTPD) += aftpd
SUBDIRS-$(CONFIG_UCSRC_SH) += sh
SUBDIRS-$(CONFIG_UCSRC_SASH) += sash
SUBDIRS-$(CONFIG_UCSRC_ROUTE) += route
#SUBDIRS-$(CONFIG_UCSRC_PORTMAP) += portmap
SUBDIRS-$(CONFIG_UCSRC_MODUTILS) += modutils
SUBDIRS-$(CONFIG_UCSRC_KMED) += kmed
#
SUBDIRS-$(CONFIG_UCSRC_NEWMOUNT) += newmount
#-----------------------------------------------------------------------------
# lots of little commands all in one program executable.
#SUBDIRS-$(CONFIG_UCSRC_BUSYBOX) += busybox
#-----------------------------------------------------------------------------
#SUBDIRS-$(CONFIG_UCSRC_THTTPD) += thttpd
#SUBDIRS-$(CONFIG_UCSRC_pppd) += pppd-2.4.1
#SUBDIRS-$(CONFIG_UCSRC_pppoe) += pppoe-0.3
SUBDIRS-$(CONFIG_UCSRC_ACCESS) += access
#-----------------------------------------------------------------------------
# add amit program item
# amit utilities Subdirectries start
SUBDIRS-y += amit_syslogd #added by Lily
SUBDIRS-y += amit_dhcpd #added by Max
SUBDIRS-y += amit_l2tpd #add by rotor
SUBDIRS-y += amit_pptp_client #added by Joe
SUBDIRS-y += amit_pptp_server #added by Joe
SUBDIRS-y += amit_dhcpcd
SUBDIRS-y += amit_routedv1
SUBDIRS-y += amit_routedv2
SUBDIRS-y += amit_ipqueue

ifeq ($(SNMP), 1)
SUBDIRS-y += amit_ucd-snmp-4.1.2
endif

SUBDIRS-y += amit_pppd-pppoe
#-----------------------------------------------------------------------------
#SUBDIRS-${CONFIG_BRECIS_USR_SRC_GPROF_KERNEL} += ../brecis/usr-src/gprof_kernel
#SUBDIRS-${CONFIG_BRECIS_USR_SRC_BCOPYTST} += ../brecis/usr-src/bcopytst
#-----------------------------------------------------------------------------
# I want reasonable commands.  Many are way too big for embedded system.
SUBDIRS-$(CONFIG_UCSRC_REAL) += real
#-----------------------------------------------------------------------------
# must be built after uClinux/uC-src/real directory (and libbridge library)
SUBDIRS-$(CONFIG_UCSRC_INTERSIL_TOOLS) += intersil-tools
#-----------------------------------------------------------------------------

SUBDIRS += $(SUBDIRS-y)
#-----------------------------------------------------------------------------
ifdef	CONFIG_USE_TEXT_PASSWORDS
  CFLAGS += -D__USE_TEXT_PASSWORDS__
endif

.EXPORT_ALL_VARIABLES:
#---------------
all:	${SUBDIRS}

#---------------
${SUBLIBS}::
	${MAKE} ${MFLAGS} -C `dirname $@` || exit 1
#---------------
${SUBDIRS}:: ${SUBLIBS}
${SUBDIRS}::
	cp amit_bin/support.lib amit_lib
	${MAKE} ${MFLAGS} -C $@ || exit 1
#---------------
install:
	-mkdir -p ${DESTBIN}
	-mkdir -p ${DESTSBIN}
	cp amit_bin/* ${DESTBIN}
	cp amit_sbin/* ${DESTSBIN}
	for i in $(SUBDIRS) ; do ${MAKE} ${MFLAGS} -C $$i install || exit 1; done
#---------------
clean:
	rm -f *.[oa] *~ core
	for i in $(SUBDIRS) ; do ${MAKE} ${MFLAGS} -C $$i clean || exit 1; done
	for i in ${SUBLIBS} ; do ${MAKE} ${MFLAGS} -C `dirname $$i` clean || exit 1; done
	for i in ${SUBDIRS-} ; do ${MAKE} ${MFLAGS} -C $$i clean || exit 1; done
	${SU} "rm -rf ${DESTBIN} ${DESTINFO} ${DESTLIBEXEC} ${DESTSBIN} ${DESTSHARE} ${DESTVAR} ${DESTWWW} ${DESTMAN} ${DESTETC} ${DESTLIB} ${DESTUSR}"
#	rm -f core `find . \( -not -type d \) -and \
#		\( -name '*~' \) -type f -print` TAGS tags 

distclean: clean
	rm -f .config .config.old userlandconf.h


#---------------
oldconfig: 
	$(CONFIG_SHELL) scripts/Configure -d config.in

xconfig: 
	$(MAKE) -C scripts kconfig.tk
	wish -f scripts/kconfig.tk

menuconfig: 
	$(MAKE) -C scripts/lxdialog all
	$(CONFIG_SHELL) scripts/Menuconfig config.in

config:
	$(CONFIG_SHELL) scripts/Configure config.in

#---------------
# End of file Makefile
