#!/bin/sh

# Script for creating environment settings for native/cross development
#
# The location you got this script from should contain complete
# instructions about how to use this script. Do not run without
# these instructions!
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

srcdir=""
workdir=""
error=0

# Loop over all args
echo ""
echo "***** makeenv.sh: checking parameters ..."
echo ""
while :
do

# Break out if there are no more args
	case $# in
	0)
		break
		;;
	esac

# Get the first arg, and shuffle
	option=$1
	shift

# Make all options have two hyphens
	orig_option=$option	# Save original for error messages
	case $option in
	--*) ;;
	-*) option=-$option ;;
	esac

# Process an option
	case $option in
	--srcdir)
		case $# in
		0)
			error=1
			;;
		*)
			srcdir=$1
			shift
			;;
		esac
		;;
	--workdir)
		case $# in
		0)
			error=2
			;;
		*)
			workdir=$1
			shift
			;;
		esac
		;;
	*)
		error=3
		;;
	esac
done

# Check if all options are present
if [ x"$srcdir" = x ] || [ x"$workdir" = x ] ; then
	error=4
fi

# Output an error message if args are wrong
if [ $error != 0 ] ; then
	echo "Error $error"
	echo "Usage: makeenv.sh --srcdir <source directory> --workdir <work directory>"
	echo "--"
	echo "The source and work directories are the same as for the cross-compiler scripts."
	exit 1
fi

# Construct absolute paths for all dirs
echo ""
echo "***** makeenv.sh: checking the specified directories ..."
echo ""
origdir=`pwd`
cd "$srcdir" || exit 1
abssrcdir=`pwd`
cd "$origdir"
cd "$workdir" || exit 1
absworkdir=`pwd`

# output the environment files
echo ""
echo "***** makeenv.sh: creating files to set the environment ..."
echo ""

cd "$absworkdir"/tmake*
tmakedir=`pwd`
cd "$abssrcdir"/qtopia.mac/qt-x11*
QTNATIVEDIR=`pwd`
cd "$abssrcdir"/qtopia.mac/qt-embedded*
QTEDIR=`pwd`
cd ../qtopia*
QPEDIR=`pwd`
cd "$origdir"
echo "setenv QTEDIR \"$QTEDIR\""					>native.env
echo "setenv QTDIR \"$QTEDIR\""						>>native.env
echo "setenv QPEDIR \"$QPEDIR\""					>>native.env
echo "setenv QTNATIVEDIR \"$QTNATIVEDIR\""			>>native.env
echo "setenv PATH \"$QPEDIR/bin\":\"$absworkdir/opt/Embedix/tools/bin\":\"$PATH\""	>>native.env
if [ x"$DYLD_LIBRARY_PATH" = x ] ; then
echo "setenv DYLD_LIBRARY_PATH \"$QPEDIR/lib\":\"$QTEDIR/lib\":\"$QTNATIVEDIR/lib\""	>>native.env
else
echo "setenv DYLD_LIBRARY_PATH \"$QPEDIR/lib\":\"$QTEDIR/lib\":\"$QTNATIVEDIR/lib\":\"$DYLD_LIBRARY_PATH\""	>>native.env
fi
echo "setenv TMAKEPATH \"$tmakedir/lib/qws/qtopia-macx-g++\""	>>native.env
echo "alias tmake perl \"$tmakedir/bin/tmake\""	>>native.env

cd "$abssrcdir"/qtopia.cross/qt-embedded*
QTEDIR=`pwd`
cd ../qtopia*
QPEDIR=`pwd`
cd "$origdir"
echo "setenv QTEDIR \"$QTEDIR\""					>cross.env
echo "setenv QTDIR \"$QTEDIR\""						>>cross.env
echo "setenv QPEDIR \"$QPEDIR\""					>>cross.env
echo "setenv QTNATIVEDIR \"$QTNATIVEDIR\""			>>cross.env
echo "setenv PATH \"$absworkdir/opt/Embedix/tools/bin\":\"$PATH\""	>>cross.env
if [ x"$DYLD_LIBRARY_PATH" = x ] ; then
echo "setenv DYLD_LIBRARY_PATH \"$QTNATIVEDIR/lib\""	>>cross.env
else
echo "setenv DYLD_LIBRARY_PATH \"$QTNATIVEDIR/lib\":\"$DYLD_LIBRARY_PATH\""	>>cross.env
fi
echo "setenv TMAKEPATH \"$tmakedir/lib/qws/qtopia-sharp-g++\""	>>cross.env
echo "alias tmake perl \"$tmakedir/bin/tmake\""	>>cross.env

