#! /bin/sh
#
#     @(#)java_wrapper.sh	1.22 97/01/06
#
#===================================================================
# THIS SCRIPT AND JAVA WILL NOT RUN UNDER SUNOS4.X, AKA SOLARIS 1.X.  
#===================================================================

# Set up default variable values if not supplied by the user.

PRG=`type -p $0` >/dev/null 2>&1
J_HOME=`dirname $PRG`/..
ARCH=`arch`

if [ -z "$JAVA_HOME" ] ; then
    export JAVA_HOME
    JAVA_HOME=$J_HOME
fi

CLASSPATH="${CLASSPATH-.}"
if [ -z "${CLASSPATH}" ] ; then
    CLASSPATH="$JAVA_HOME/classes:$JAVA_HOME/lib/classes.zip"
else
    CLASSPATH="$CLASSPATH:$JAVA_HOME/classes:$JAVA_HOME/lib/classes.zip"
fi
export CLASSPATH

# Default THREADS_TYPE is "green_threads". 
# This introduces a dependency of this wrapper on the policy used to do builds.
# e.g. the usage of the name "green_threads" here is dependent on the build
# scripts which use the same name. Since this is somewhat analogous to the
# wrapper already depending on the build scripts putting the executable in
# a specific place (JAVA_HOME/bin/${ARCH}), the new dependency does not
# seem all that bad.

THREADS_TYPE=green_threads
if [ ${THREADS_FLAG-foo} = native ] ;\
	then THREADS_TYPE=native_threads;\
fi
export THREADS_TYPE
#echo "Using executables built for $THREADS_TYPE"

export LD_LIBRARY_PATH
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$JAVA_HOME/lib/${ARCH}/$THREADS_TYPE"
      
progname=`basename $0`
prog=$JAVA_HOME/bin/${ARCH}/${THREADS_TYPE}/${progname}

if [ -f $prog ]
then
    eval exec $DEBUG_PROG $prog $opts '"$@"'
else
    echo >&2 "$progname was not found in ${prog}"
    exit 1
fi
