#!/bin/sh
set -e

backend="$GHDL_BACKEND"

if [ ! -x "/usr/bin/ghdl-$backend" ]; then
	if [ -x /usr/bin/ghdl-mcode ]; then
		backend=mcode
	elif [ -x /usr/bin/ghdl-gcc ]; then
		backend=gcc
	elif [ -x /usr/bin/ghdl-llvm ]; then
		backend=llvm
	else
		echo >&2 "Error: No installed ghdl backend found. Terminating!"
		exit 2
	fi
fi

exec "/usr/bin/ghdl-$backend" "$@"
