#!/bin/sh

# This script can be called from anywhere, provided the user's
# has systemsim-cell in their PATH. If they do not, it should still
# run the old way, but only from a subdirectory under 'run'.

# Please note that you will still have to specify the path to the
# .gsystemsim.tcl file using the -f option if you want to see the
# GUI.

SYSTEMSIM_TOP=
for TOP in 		../../..		\
			`/usr/bin/which $0`
do
   TOP=`dirname $TOP`
   #echo -n "Trying $TOP ..."
   if [ -f $TOP/../systemsim ]; then
      #echo passed.
      SYSTEMSIM_TOP=$TOP/../..
      break
   fi
   #echo failed.
done

if [ ! -z $SYSTEMSIM_TOP ]; then
   export SYSTEMSIM_TOP
   #echo "SYSTEMSIM_TOP is $SYSTEMSIM_TOP, running $TOP/../systemsim -cell $* -g"
   # Old script: SYSTEMSIM_TOP=../../.. ../../systemsim -cell $* -g
   $TOP/../systemsim -cell $* -g
fi
