#!/bin/sh
#
# $Revision: 1.3 $ $Date: 2000/01/07 00:43:03 $ $Author: kreilede $

THREADS_TYPE=${THREADS_FLAG:-green}_threads
export THREADS_TYPE

progname=`basename $0`
ARCH=`arch`

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

if [ -z "$JAVA_HOME" ]
then
    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

    JAVA_HOME=`dirname $PRG`/..
    export JAVA_HOME
fi

#
# For some programs like appletviewer, it is important that "." not be
# in the classpath by default (unless the user set the CLASSPATH
# explicitly). Applications that fit in this list are ones that load
# classes through a ClassLoader, where classes coming off . will end
# up being system classes. For now we know of only appletviewer.
#
NO_DOT_LIST="appletviewer"
DEFAULT_CLASSPATH="."
for excluded in ${NO_DOT_LIST}; do
    if [ ${excluded} = ${progname} ]; then
        DEFAULT_CLASSPATH="";
    fi
done

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

LD_LIBRARY_PATH="$JAVA_HOME/lib/${ARCH}/$THREADS_TYPE:$LD_LIBRARY_PATH"
export LD_LIBRARY_PATH

XFILESEARCHPATH="$JAVA_HOME/lib/locale/%L/%T/%N%C%S:$JAVA_HOME/lib/locale/%l/%T/%N%C%S:$JAVA_HOME/lib/locale/%T/%N%C%S:$JAVA_HOME/lib/locale/%L/%T/%N%S:$JAVA_HOME/lib/locale/%l/%T/%N%S:$JAVA_HOME/lib/locale/%T/%N%S:$XFILESEARCHPATH:%D"
export XFILESEARCHPATH

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

LD_BIND_NOW=true
export LD_BIND_NOW

if [ -f "$prog" ]
then
    exec $DEBUG_PROG "$prog" $opts "$@"
else
    prog="$JAVA_HOME/bin/${ARCH}/${THREADS_TYPE}/${progname}"
    if [ -f "$prog" ]
    then
        exec $DEBUG_PROG "$prog" $opts "$@"
    fi
fi

echo >&2 "$progname was not found in ${prog}"
exit 1

