#!/bin/sh

####
#### A script to run xchek
####

##
## read global and user configuration files if they exist
##
if [ -f /etc/xchek.conf ] ; then 
    . /etc/xchek.conf
fi

if [ -f $HOME/.xchekrc ] ; then
    . $HOME/.xchekrc 
fi

###
### find xchek root directory
###

PRG="$0"
XCHEK_ROOT=`dirname $PRG`/..

CURRENT_DIR=`pwd`

### For knowing how to get to CVCL
OS=linux
arch=i386

###
### go to the root directory
###
#cd $XCHEK_ROOT 

###
### setup environment variables
###
if [ -z "$ROOT" ] ; then
 source $XCHEK_ROOT/bin/env.sh `pwd` > /dev/null
fi

###
### now we are ready to run
###
if [ "$DEBUG" == "no" ] ; then
    unset ASSERT
else
    ASSERT=-ea
fi
MEMORY_MIN=${MEMORY_MIN:-512m}
MEMORY_MAX=${MEMORY_MAX:-512m}

echo "ms: $MEMORY_MIN, mx: $MEMORY_MAX"

if [ -n "$PROFILE" ] ; then
  YJP=-agentlib:yjpagent=cpu=times,onexit=cpu,dir=$ROOT
else
  unset YJP
fi

if [ "$SHOW_STDERR" == "no" ] ; then
    java $ASSERT $YJP -Xms$MEMORY_MIN -Xmx$MEMORY_MAX -Duser.dir="$CURRENT_DIR" -Dcvcl.cmd="$ROOT/runtime/$OS/$arch/cvcl" $JAVA_OPT edu.toronto.cs.yasm.YasmApp "$@" 2>/dev/null
else
    java $ASSERT $YJP -Xms$MEMORY_MIN -Xmx$MEMORY_MAX -Duser.dir="$CURRENT_DIR" -Dcvcl.cmd="$ROOT/runtime/$OS/$arch/cvcl" $JAVA_OPT edu.toronto.cs.yasm.YasmApp "$@"
fi
    
###
### return to parent directory
###
cd $CURRENT_DIR



