#!/bin/sh

SYM_OPT="-s"

#
# Check out how we can do an echo without a newline
#
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


#
# Work out the target and see if there's a directory there already
#

echo
TARG=`scripts/sys-arch` 
echo "Target ${TARG}"
if test -d targets/${TARG}
then 
  exit 0
fi


#
# Build the target dir
#

if test ! -d targets
then 
	mkdir targets 
fi 
mkdir targets/${TARG}
mkdir targets/${TARG}/lib
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 
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
