#! /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
# If PRG is a symlink, trace it to the real home directory

while [ -L "$PRG" ]
do
    newprg=`expr "\`/bin/ls -l "$PRG"\`" : ".*$PRG -> \(.*\)"`
    expr "$newprg" : / >/dev/null || newprg="`dirname $PRG`/$newprg"
    PRG="$newprg"
done

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="$JAVA_HOME/classes:$JAVA_HOME/lib/classes.zip:$CLASSPATH"
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="$JAVA_HOME/lib/${ARCH}/$THREADS_TYPE:$LD_LIBRARY_PATH"
      
progname=`basename $0`
orig_progname="${progname}"
if [ -n "$NS_JAVA" ]
then
    progname="${progname}_ns"
elif [ -n "$DYN_JAVA" ]
then
    progname="${progname}_dyn"
fi

prog=$JAVA_HOME/bin/${ARCH}/${THREADS_TYPE}/${progname}

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