#!/bin/ksh -p

#
# @(#)java_wrapper.sh	1.50 99/02/01
#
# Copyright 1999 Sun Microsystems, Inc. All rights reserved.
# Copyright 1999 Sun Microsystems, Inc. Tous droits rservs.
# 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
# 
#
# This software is the confidential and proprietary information
# of Sun Microsystems, Inc. ("Confidential Information").  You
# shall not disclose such Confidential Information and shall use
# it only in accordance with the terms of the license agreement
# you entered into with Sun.
#

#===================================================================
# THIS SCRIPT AND JAVA WILL NOT RUN UNDER SUNOS4.X, AKA SOLARIS 1.X.  
#===================================================================

PRG=`whence $0` >/dev/null 2>&1
progname=`/usr/bin/basename $0`
proc=`/usr/bin/uname -p`

# Resolve symlinks, so that the pathname computations below find the
# directory structure they expect.
while [ -h "$PRG" ]; do
	# Get the target of the symlink.  N.B.:  We assume that neither the
	# link's value nor the pathname leading to it contains "-> ".
	ls=`/usr/bin/ls -ld "$PRG"`
	link=`/usr/bin/expr "$ls" : '^.*-> \(.*\)$'`
	# If the link is absolute, use it as is; otherwise, substitute it
	# into the leafname part of $PRG.
	if /usr/bin/expr "$link" : '^/' > /dev/null; then
		prg="$link"
	else
		prg="`/usr/bin/dirname $PRG`/$link"
	fi
	PRG=`whence "$prg"` >/dev/null 2>&1
done

APPHOME=`/usr/bin/dirname "$PRG"`/..
JREHOME=$APPHOME/jre

# Where is JRE?
unset jre
if [ -f "${JREHOME}/lib/${proc}/libjava.so" ]; then
    jre="${JREHOME}"
fi
if [ -f "${APPHOME}/lib/${proc}/libjava.so" ]; then
    jre="${APPHOME}"
fi
if [ "x${jre}" = "x" ]; then
    echo "Error: can't find libjava.so."
    exit 1
fi

# We must eat any green/native/hotspot/classic flags.  There's a judgement
# call here, that this VM is sufficiently different from the classic VM that
# an explicit request for the classic VM should be rejected.
if [ "$1" = "-green" ]; then
    echo >&2 "Green threads support not available"
    exit 1
fi
if [ "$1" = "-native" ]; then
    shift 1
fi
if [ "$1" = "-hotspot" ]; then
    echo >&2 "Hotspot support not available"
    exit 1
fi
if [ "$1" = "-classic" ]; then
    echo >&2 "Classic VM support not available"
    exit 1
fi

# Set shared library path.
if [ -n "$LD_LIBRARY_PATH" ]; then
	LD_LIBRARY_PATH="${jre}/lib/${proc}:$LD_LIBRARY_PATH"
else
	LD_LIBRARY_PATH="${jre}/lib/${proc}"
fi
export LD_LIBRARY_PATH

prog="$APPHOME/bin/${proc}/native_threads/${progname}"

# Run.
if [ -x "$prog" ]
then
     # Calling: exec $DEBUG_PROG "$prog" "$@"
     exec $DEBUG_PROG "$prog" "$@"
else
    echo >&2 "$progname was not found in ${prog}"
    exit 1
fi
