#!/bin/sh

# Script for starting Qtopia on OS X
#
# 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=""
error=0

# Loop over all args
echo ""
echo "***** qpe.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
		;;
	*)
		error=2
		;;
	esac
done

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

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

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

# start QVFB
echo ""
echo "***** qpe.sh: starting qpe ..."
echo ""
cd "$abssrcdir"/qtopia.mac/qt-x11*
export QTDIR="$PWD"
cd ../qt-embedded*
export QTEDIR="$PWD"
cd ../qtopia*
export QPEDIR="$PWD"
export PATH="$QPEDIR/bin":"$QTEDIR/bin":"$QTDIR/bin":"$PATH"
export DYLD_LIBRARY_PATH="$QPEDIR/lib":"$QTEDIR/lib":"$QTDIR/lib"
export QTDIR="$QTEDIR"
qpe &
