#!/bin/sh
#
# usage: testml [options]
#
# where options are
#
#	-64 or -32              - specify word size for machines that support both 32
#				  64-bit executables.
#	-load <name>		- specify the prefix of the heap image to load
#
# all other options are passed to runtime system
#


this=$0
cmddir=`dirname $0`
cmddir=`cd "$cmddir"; pwd`
bindir=`cd "$cmddir/../../bin"; pwd`

ARGS=""

# default to 64-bits, since that is our primary development architecture
#
SIZE_OPT="-64"

HEAP_IMAGE=sml

# Process command-line arguments
#
while [ "$#" != "0" ] ; do
    arg=$1; shift
    case $arg in
    -32) SIZE_OPT=$arg ;;
    -64) SIZE_OPT=$arg ;;
    -load)
	if [ "$#" = "0" ]; then
	    echo "$this: missing argument for \"-load\" option"
	    exit 1
	fi
	HEAP_IMAGE="$1"; shift
	;;
    *)
	ARGS="$ARGS $arg"
	;;
    esac
done

#
# use the arch-n-opsys script to determine the ARCH/OS if possible
#
if [ -f $twoup/bin/.arch-n-opsys ]; then
    ARCH_N_OPSYS=`"$bindir/.arch-n-opsys" $SIZE_OPT`
    if [ "$?" = "0" ]; then
	eval $ARCH_N_OPSYS
    fi
fi

heapdir=`dirname $HEAP_IMAGE`
[ -f "$heapdir/$HEAP_IMAGE.$HEAP_SUFFIX" ] || heapdir="$cmddir/$heapdir"
HEAP_IMAGE=`cd "$heapdir"; pwd`/$HEAP_IMAGE

LIB_DIR="${HEAP_IMAGE}.lib"
LPC="${LIB_DIR}/local_pathconfig"

rm -f "$LPC"
cp ../../config/extrapathconfig "$LPC"

CM_PATHCONFIG="$LIB_DIR/pathconfig" CM_LOCAL_PATHCONFIG="$LPC" \
    "$bindir/sml" $SIZE_OPT @SMLload="$HEAP_IMAGE" "$@"
