#! /bin/sh

#
# Driver script for Kaffe.
# This script invokes the "Kaffe" executable after modifying
# CLASSPATH and LD_LIBRARY_PATH as needed.
#
# We prepend kaffe's lib directory to LD_LIBRARY_PATH.
#
# KAFFELIBRARYPATH is defined to kaffe's native lib directory
# (lib/kaffe) if not set.
#
# The effective CLASSPATH is made up of four parts, which 
# are composed in the following order:
#
#	1. a user-specified CLASSPATH or .
#	2. Klasses.jar in $datadir/kaffe
#	3. pizza.jar in $datadir/kaffe
#	4. classes.zip in $datadir/kaffe iff it exists.
#

# If KAFFE_DEBUG is set to either gdb or emacs, a debugging session
# will be started.  gdb will be started so that the current working
# directory and the argument list are correct.

prefix="@prefix@"
exec_prefix="@exec_prefix@"
: ${KAFFE_BINDIR="@bindir@"}
: ${KAFFE_CLASSDIR="@datadir@/kaffe"}
: ${KAFFE_NATIVE_LIBRARY_DIR="@nativedir@"}
: ${KAFFE_OLD_NATIVE_LIBRARY_DIR="$KAFFE_CLASSDIR/lib/@KAFFE_ARCHOS@"}
: ${KAFFE_LIB="@libdir@"}
CLASSPATH="${CLASSPATH-.}:$KAFFE_CLASSDIR/Klasses.jar:$KAFFE_CLASSDIR/pizza.jar"
if test -f "$KAFFE_CLASSDIR/classes.zip"; then
  CLASSPATH="$CLASSPATH:$KAFFE_CLASSDIR/classes.zip"
fi
export CLASSPATH
LD_LIBRARY_PATH="$KAFFE_LIB"${LD_LIBRARY_PATH+":$LD_LIBRARY_PATH"}
export LD_LIBRARY_PATH
KAFFELIBRARYPATH="$KAFFE_NATIVE_LIBRARY_DIR"${KAFFELIBRARYPATH+":$KAFFELIBRARYPATH"}":${LD_LIBRARY_PATH}"
if test -d "$KAFFE_OLD_NATIVE_LIBRARY_DIR"; then
  KAFFELIBRARYPATH="$KAFFELIBRARYPATH:$KAFFE_OLD_NATIVE_LIBRARY_DIR"
fi
export KAFFELIBRARYPATH

if test x"${KAFFE_DEBUG+set}"x != x"set"x; then
    exec $KAFFE_BINDIR/Kaffe ${1+"$@"}
else
    case `"$KAFFE_DEBUG" --version </dev/null 2>/dev/null` in
    "GDB"*|"GNU gdb"*)
	# start command-line gdb within the correct working directory,
	# and set up the specified argument list
	{
	    echo "shell rm -f /tmp/.gdbinit.$$"
	    echo "cd `pwd`"
	    echo "set args $*"
	} >/tmp/.gdbinit.$$
	exec "$KAFFE_DEBUG" -command /tmp/.gdbinit.$$ $KAFFE_BINDIR/Kaffe
	rm -f /tmp/.gdbinit.$$;;
    "GNU Emacs"*)
	# start gdb within GNU Emacs, move into the current working
	# directory and set up the specified argument list
	exec "$KAFFE_DEBUG" -eval "(progn (gdb \"gdb $KAFFE_BINDIR/Kaffe\") (gud-call \"cd `pwd`\") (gud-call \"set args $*\"))";;
    XEmacs*)
	# start gdb within XEmacs, move into the current working
	# directory and set up the specified argument list
	exec "$KAFFE_DEBUG" -eval "(progn (gdb \"$KAFFE_BINDIR/Kaffe\") (gdb-call \"cd `pwd`\") (gdb-call \"set args $*\"))";;
    *) echo you must set KAFFE_DEBUG to either emacs or gdb >&2;;
    esac
fi
exit 1
