#!/bin/bash

# change to the script's directory (not from whatever directory we were in)
#SCRIPT_DIR=`echo $0 | sed -e 's/[/][^/]*$//'`
SCRIPT_DIR=`dirname "$0"`
echo "DaphneLoader Launcher : Script dir is $SCRIPT_DIR"
cd "$SCRIPT_DIR"

# point to our linked libs that user may not have
export LD_LIBRARY_PATH=./lib

# try to run the loader
./daphneloader.bin "$@"

EXIT_CODE=$?

if [ "$EXIT_CODE" -ne "0" ] ; then
	if [ "$EXIT_CODE" -eq "127" ]; then
		echo ""
		echo "DaphneLoader failed to start."
		echo "Check to make sure that you have the following libraries installed:"
		echo "  GTK v2"
		echo "  SDL v1.2"
		echo "You _may_ need g++ 3.4 installed."
		echo ""
	else
		echo "DaphneLoader failed with an unknown exit code : $EXIT_CODE."
	fi
fi
