#!/bin/ksh -p

#
# @(#)java_wrapper_solaris.sh	1.63 00/06/23
#
# Copyright 2000 Sun Microsystems, Inc. All rights reserved.
# Copyright 2000 Sun Microsystems, Inc. Tous droits rservs.
#
# This software is the proprietary information of Sun Microsystems, Inc.
# Use is subject to license terms.
#

#===================================================================
# 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. See 4152645.
while [[ -h "$PRG" ]]; do
    ls=`/usr/bin/ls -ld "$PRG"`
    link=`/usr/bin/expr "$ls" : '^.*-> \(.*\)$'`
    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

# Select vm type
ttype=native_threads
if /usr/bin/grep "^$1\$" ${jre}/lib/jvm.cfg > /dev/null; then
    # User specified some VM type known to jvm.cfg.
    vmtype=`echo $1 | /usr/bin/cut -c 2-`
else
    # User didn't specify a VM type, see if default is classic.
    default=`/usr/bin/grep -v '^#' "${jre}/lib/jvm.cfg" | /usr/bin/head -1`
    vmtype=`echo ${default} | /usr/bin/cut -c 2-`
fi


# If jre is in a jre subdir, include parent dir libraries in lib path.  This
# needs to be cleaned up because -Xrun libraries are the ones that need it.
if [ "${jre}" = "$JREHOME" ]; then
   JAVA_LIBRARY_PATH=":${jre}/../lib/${proc}"
fi

# Set LD_LIBRARY_PATH to find libawt.so etc.
JAVA_LIBRARY_PATH="${jre}/lib/${proc}:${JAVA_LIBRARY_PATH}"

# Set LD_LIBRARY_PATH for libjvm.so (necessitated by ld.so bugid 4176579)
# proc/vmtype needs to be in front of just proc (4345224)
JAVA_LIBRARY_PATH="${jre}/lib/${proc}/${vmtype}:$JAVA_LIBRARY_PATH"

LD_LIBRARY_PATH="${JAVA_LIBRARY_PATH}${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
export LD_LIBRARY_PATH

prog="$APPHOME/bin/${proc}/${ttype}/${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
