#!/usr/bin/env bash

# Wrapper script to run Boogie.exe on non-Windows systems using Mono
#
# Adapted from https://github.com/Microsoft/dafny/blob/master/Binaries/dafny

MONO=$(which mono)

# find the source directory for this script even if it's been symlinked
# from https://stackoverflow.com/questions/59895/
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do
    DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
    SOURCE="$(readlink "$SOURCE")"
    [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done
BOOGIE_ROOT="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
BOOGIE="$BOOGIE_ROOT/Boogie.exe"

if [[ ! -x "$MONO" ]]; then
    echo "Error: Boogie requires Mono to run on non-Windows systems."
    exit 1
fi

if [[ ! -e "$BOOGIE" ]]; then
    echo "Error: Boogie.exe not found at $BOOGIE."
    exit 1
fi

"$MONO" "$BOOGIE" "$@"
