#
# Corega-Linux version
#
# quick start:
#
# 1) prepare sources to $DISTDIR which is default to ./distfiles  
#
#   # cp CDROM_MOUNT_POINT/distfiles/* distfiles
#
# 2) extract and patch the source
#
#   # make source
#
# 3) compile
#
#   # make static
#   or
#   # make shared
#
# 4) install
#
#   # make install_static
#   or
#   # make install_shared
#
# 5) build filesystem image
#
#   # ./buildimage_jffs2.sh image.jffs2
#
SYSTYPE=normal
INSTDIR=/home/yoshida/Embedded/corega/adm/lbstd2pu/coregalinux/userland

all: shared

ifeq ($(COREGALINUX_BASEDIR),)
	COREGALINUX_BASEDIR:=$(shell pwd)
endif

ifeq ($(INSTDIR),)
	INSTDIR:=$(shell pwd)install_root
else
	ifneq ($(shell echo $(INSTDIR) | cut -c 1),/)
		override INSTDIR:=$(shell pwd)/$(INSTDIR)
	endif
endif
export INSTDIR
OPT_ARGS="INSTDIR=$(INSTDIR)"

ifneq ($(WORKDIR),)
	ifneq ($(shell echo $(WORKDIR) | cut -c 1),/)
		override WORKDIR:=$(shell pwd)/$(WORKDIR)
	endif
	export WORKDIR
	OPT_ARGS+="WORKDIR=$(WORKDIR)"
endif

ifneq ($(DISTDIR),)
	ifneq ($(shell echo $(DISTDIR) | cut -c 1),/)
		override DISTDIR:=$(shell pwd)/$(DISTDIR)
	endif
	export DISTDIR
	OPT_ARGS+="DISTDIR=$(DISTDIR)"
endif

ifneq ($(LINUX),)
	ifneq ($(shell echo $(LINUX) | cut -c 1),/)
		override LINUX:=$(shell pwd)/$(LINUX)
	endif
	OPT_ARGS+="LINUX=$(LINUX)"
endif


ifeq ($(SUBDIR),)
	SUBDIR=rootbase
	SUBDIR+=pdksh
	SUBDIR+=bdflush
	SUBDIR+=which
	SUBDIR+=sysvinit
	SUBDIR+=textutils
	SUBDIR+=fileutils
	SUBDIR+=modutils
	SUBDIR+=grep
	SUBDIR+=sed
	SUBDIR+=tar
	SUBDIR+=gzip
	SUBDIR+=diffutils
	SUBDIR+=procps
	SUBDIR+=sysklogd
	SUBDIR+=net-tools
	SUBDIR+=nvi
	SUBDIR+=MAKEDEV
	SUBDIR+=lib
	SUBDIR+=ncurses
	SUBDIR+=openssl 	# ssh 
	SUBDIR+=tinylogin
	SUBDIR+=pcmcia-cs
	SUBDIR+=util-linux
	SUBDIR+=e2fsprogs
	SUBDIR+=sh-utils
	SUBDIR+=mtd-util
	SUBDIR+=gawk
#	SUBDIR+=wireless_tools	# Wireless Network
	SUBDIR+=netkit-base
	SUBDIR+=netkit-telnet
	SUBDIR+=netkit-ftp
	SUBDIR+=dhcp
	SUBDIR+=iptables	# Router
ifeq ($(SYSTYPE),pppoe)
	SUBDIR+=pcap
	SUBDIR+=ppp 		# depends on libpcap
endif
ifeq ($(SYSTYPE),pppoeun)
	SUBDIR+=pcap
	SUBDIR+=ppp 		# depends on libpcap
endif
#	SUBDIR+=linux-ftpd
#	SUBDIR+=thttpd
	SUBDIR+=mini_httpd
#	SUBDIR+=openssh		# depend openssl
	SUBDIR+=busybox
#	SUBDIR+=busybox-ar
	SUBDIR+=cpio
	SUBDIR+=debootstrap	# need root privilidge
	SUBDIR+=diffutils
	SUBDIR+=dirtree
#	SUBDIR+=fbset
#	SUBDIR+=ffmpeg
	SUBDIR+=findutils
#	SUBDIR+=hdparm
#	SUBDIR+=hpt3xx		# depend on kernel version 2.4
	SUBDIR+=mktemp
#	SUBDIR+=net-snmp
#	SUBDIR+=httpd
#	SUBDIR+=nbench
	SUBDIR+=psmisc
#	SUBDIR+=samba
#	SUBDIR+=strace
	SUBDIR+=wget
	SUBDIR+=bridge-utils	# eth0 eth1 bridge
	SUBDIR+=textutils-addfunc	# TEXT Utils Add Function
	SUBDIR+=ifupdown	# Debian eth Interface Up/Down
	SUBDIR+=readline
	SUBDIR+=bash
	SUBDIR+=resolvconf
	SUBDIR+=post_work
	SUBDIR+=etc
	SUBDIR+=powerled
	SUBDIR+=corega
endif


source clean-source shared static clean fetch install_static install_shared bin_archive:
	@for i in $(SUBDIR); do\
		(cd $$i && echo ======\> $$i && $(MAKE) $(OPT_ARGS) $@) || exit;\
	done


.PHONY: source static shared install_static install_shared clean clean-source
