#!/bin/bash
#
# unix shell script to run jpf
#

JPF_HOME=`dirname $0`/..

_cygwin=false;
case "`uname`" in
  CYGWIN*) _cygwin=true;;
esac

#if we have class files, we probably want to use those first
CP=$JPF_HOME/build/jpf
CP=$CP:$JPF_HOME/build/test

#add (recursively) any *.jar or *.zip that's under $JPF_HOME/lib
#note that those take precedence over what already is in the classpath
if test -d $JPF_HOME/lib; then
  CP=$CP:`find $JPF_HOME/lib \( -name "*.jar" -or -name "*.zip" \) -exec echo -n {}":" \;`
fi

if test -d $JPF_HOME/extensions; then
  CP=$CP:`find $JPF_HOME/extensions \( -name "*.jar" -or -name "*.zip" \) -exec echo -n {}":" \;`
fi

#add junit*.jar from build-tools/lib
if test -d $JPF_HOME/build-tools/lib; then
  CP=$CP:`find $JPF_HOME/build-tools/lib -name "junit*.jar" -exec echo -n {}":" \;`
fi


#our standard native peer environment (just the peer, NOT the model classes)
CP=$CP:$JPF_HOME/build/env/jvm

#classes that can be explicitly used in applications
CP=$CP:$JPF_HOME/build/app

#Examples
CP=$CP:$JPF_HOME/build/examples

#prepend the global CLASSPATH (so that we can override)
if $_cygwin; then
  CP=`cygpath --path --windows "$CP"`
  JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
  CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
  CP="$CLASSPATH;$CP"
else
  CP="$CLASSPATH:$CP"
fi

#now check if we find our mandatory jars
if test ! `expr "$CP" : ".*\(bcel.jar\).*"`; then
  echo "*** you don't seem to have bcel.jar in your CLASSPATH, please fix ***"
  exit
fi

if test -z "$JVM_FLAGS"; then
  JVM_FLAGS="-Xmx1024m -ea"
fi

java $JVM_FLAGS -classpath "$CP"  "$@"


