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

test "$*" || exec "$0" -help

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

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

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

#append the global CLASSPATH
if $_cygwin; then
  CP=`cygpath --path --windows "$CP"`
  JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
  CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
  CP="$CP;$CLASSPATH"
else
  CP="$CP:$CLASSPATH"
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" gov.nasa.jpf.JPF +jpf.basedir="$JPF_HOME" "$@"


# StateSpaceDot tool options
if test -z $SSDOT_FLAGS; then
  SSDOT_FLAGS="-show-source -transition-numbers"
fi

java $JVM_FLAGS -classpath "$CP" gov.nasa.jpf.tools.StateSpaceDot +jpf.basedir="$JPF_HOME" $SSDOT_FLAGS $@
