############################################################################
#
# Top level Makefile for esl.  This only sets up a target tree for the
# current platform.  It doesn't do any other part of the build.
#
#						bambi
############################################################################

#
# Note : If the current box doesn't support sym-links with "ln -s" then
#	 set the ln option required below.  If it doesn't support
#	 sym-links at all, set the option to be nothing. This'll force
#	 hard links.

SYM_OPT= -s


SHELL=/bin/sh

all:
	@ echo ""; echo "You have not read the installation procedures.";\
	echo "Please read the README file for build instructions.";\
	echo

target:
	@if echo '\c' | grep -s c >/dev/null 2>&1 ;\
	then \
		ECHO_N="echo -n" ;\
		ECHO_C="" ;\
	else \
		ECHO_N="echo" ;\
		ECHO_C='\c' ;\
	fi ;\
	echo ;\
	TARG=`scripts/sys-arch`  ;\
	if test -d targets/$${TARG} ;\
	then \
		$${ECHO_N} "Target directory for $${TARG} exists! $${ECHO_C}" ;\
		$${ECHO_N} "Clear it? [y/n] $${ECHO_C} "; \
		read ANS ;\
		if test $${ANS}"." = "y." ;\
		then \
			echo "Clearing old target directory for $${TARG}" ;\
			rm -rf targets/$${TARG} ;\
		else \
			echo ;\
			echo "You'll have to use "make -i" to refresh the target directory" ;\
			echo ;\
		fi \
	fi ;\
	if test ! -d targets ;\
	then \
		mkdir targets ;\
	fi ;\
	mkdir targets/$${TARG} ;\
	echo; echo Making target directory for $${TARG};\
	cd targets/$${TARG};\
	echo; echo Building directory tree. ;\
	for DIR in `find ../../src ! -name CVS -type d -print | sed "s,^../../src/,,"`;\
	do \
		if test $${DIR} != "../../src" ;\
		then \
			echo "	Adding $$DIR" ;\
			mkdir $${DIR} ;\
		fi ;\
	done ;\
	mkdir bin ;\
	mkdir lib ;\
	echo; echo Adding sym-links ;\
	for FILE in `find ../../src ! -type d -print | grep -v "/CVS/" | sed "s,^../../src/,,"`;\
	do \
		$${ECHO_N} ".$${ECHO_C}";\
		OFFSET=`echo $$FILE | sed "s,[^/],,g" | sed "s,/,../,g"` ;\
		ln $(SYM_OPT) ../../$$OFFSET/src/$$FILE $$FILE ;\
	done ;\
	echo; echo; echo Build of target directory for $$TARG complete ; echo


dist:
	@ echo; echo -n "Full Distribution - Enter archive file name : " ;\
	read TAR_FILE ;\
	DIR=`pwd | sed "s,.*/,,"` ; \
	cd ..;\
	rm -f /tmp/dist.files ;\
	for FILE in `find ${DIR} ! -type d -print | egrep -v "/targets/|CVS"` ;\
	do \
		echo $$FILE >> /tmp/dist.files ;\
	done ;\
	tar -cvf $$TAR_FILE -I /tmp/dist.files ;\
	echo; echo "Archive of full distribution complete"
