#!/bin/sh
set -e

GERBIL_GSI="gsi"

if [ -z "$GERBIL_HOME" ]; then
    # The path below is set by configure --prefix=...
    GERBIL_HOME=$(cd ${0%/*}; echo "${PWD%/*}") # Won't work if a symlink; use configure --prefix then.
    export GERBIL_HOME
fi

if [ $# -gt 0 ]; then
    case $1 in
        -:*)
            GSIOPTIONS=$1
            shift
            ;;
    esac
fi

if [ $# -eq 0 ]; then
    exec "$GERBIL_GSI" $GSIOPTIONS -e '(include "~~lib/_gambit#.scm")' "$GERBIL_HOME/lib/gxi-init" "$GERBIL_HOME/lib/gxi-interactive" -
else
    exec "$GERBIL_GSI" $GSIOPTIONS -e '(include "~~lib/_gambit#.scm")' "$GERBIL_HOME/lib/gxi-init" "$@"
fi
