#!/bin/sh

export THREADS_TYPE=${THREADS_FLAG:-green}_threads

PROG=`basename $0`
ARCH=`uname -m`

case $1 in
-native)
    THREADS_TYPE=native_threads
    shift
    ;;
-green)
    THREADS_TYPE=green_threads
    shift
    ;;
esac

if [ -z "$JAVA_HOME" ]
then
    DIR=`dirname $0`
    export JAVA_HOME=`cd $DIR/..; pwd`
fi

if [ -z "$CLASSPATH" ]
then
    export CLASSPATH=$JAVA_HOME/lib/rt.jar:$JAVA_HOME/lib/i18n.jar
    CLASSPATH=$JAVA_HOME/classes:$JAVA_HOME/lib/classes.zip:$CLASSPATH
fi

export LD_LIBRARY_PATH=$JAVA_HOME/lib/$ARCH/$THREADS_TYPE:$LD_LIBRARY_PATH

# If an 'X' version exists and DISPLAY is set, then use the X version.
if [ -x $JAVA_HOME/bin/$ARCH/$THREADS_TYPE/${PROG}_X \
     -a "X${DISPLAY}" != "X" ]
then
    exec $JAVA_HOME/bin/$ARCH/$THREADS_TYPE/${PROG}_X "$@"
else
    exec $JAVA_HOME/bin/$ARCH/$THREADS_TYPE/$PROG "$@"
fi
