#!/usr/bin/env sh
SCRIPT="$0"
if command -v readlink >/dev/null 2>&1; then
  while [ -L "$SCRIPT" ]; do
    LINK="$(readlink "$SCRIPT")"
    case "$LINK" in
      /*) SCRIPT="$LINK" ;;
      *) SCRIPT="$(dirname "$SCRIPT")/$LINK" ;;
    esac
  done
fi

ROOT="$(cd "$(dirname "$SCRIPT")" && pwd)"
TEZZC="$ROOT/build/tezzc"
if [ ! -x "$TEZZC" ]; then
  TEZZC="$ROOT/bin/tezzc-linux-x64"
fi
if [ ! -x "$TEZZC" ]; then
  TEZZC="$ROOT/tezzc"
fi
if [ ! -x "$TEZZC" ]; then
  echo "tezz: compiler not found (expected build/tezzc or bin/tezzc-linux-x64)."
  exit 1
fi
TOOL="$ROOT/tools/tezz.tn"
if [ ! -f "$TOOL" ]; then
  echo "tezz: tools/tezz.tn not found next to launcher."
  exit 1
fi
exec "$TEZZC" run "$TOOL" -- "$@"
