#!/bin/sh

DoCreate() {
	echo "creating directory structure..."
	for DIR in def obj src sym; do
		if ! test -d $DIR
		then
			if ! mkdir $DIR
			then
				echo "Error making $DIR subdirectory"
				exit 1
			fi
		fi
	done
	echo "creating appropriate redirection file..."
	cat >xc.red  <<EOTXT
xc.*   = $XDSDIR/bin
*.tem  = $XDSDIR/bin
*.sym  = ./sym;$XDSDIR/sym/x86
*.a    = .;$XDSDIR/lib/x86
*.o    = ./obj
*.def  = ./def
*.mod  = ./src
*.ob2  = ./src
*.prj  = .
EOTXT
	echo
	echo    "DONE"
	echo
}

echo
echo "==============================================================="
echo " Native XDS-x86 2.4 Linux Edition."
echo " Copyright (c) 1999 Excelsior. All Rights Reserved"
echo " Copyright (c) 1991-1998 XDS Ltd. All Rights Reserved"
echo "---------------------------------------------------------------"
echo " This script creates appropriate subdirectories and redirection "
echo " file in the current directory."
echo "==============================================================="
echo

case $# in
0) XDSDIR=`dirname $0`; XDSDIR=`dirname $XDSDIR` ;;
1) XDSDIR=$1 ;;
*) Usage; exit 1 ;;
esac

if test -d $XDSDIR # && test -x $XDSDIR/bin/xc
then
	echo "Are you sure you want to create directories and redirection file"
	echo "in $PWD? (Y/N)"
	while :
	do
		read YN
		case $YN in
		Y|y) DoCreate; exit ;;
	        N|n) exit ;;
	        esac
		echo "Please type Y or N"
	done
        exit

else

	echo
	echo    "Usage:"
	echo    "  xcwork [ path_to_XDS_installation_directory ]"
	echo
	echo    "Example:"
	echo    "  xcwork /usr/local/xds"
	echo
	echo    "-------------------------------------------------------------"

fi
