#!/bin/sh

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

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 $*"
   # Old script: SYSTEMSIM_TOP=../../.. ../../systemsim -cell $*
   exec $TOP/../systemsim -cell $*
fi
