#!/bin/sh

BINARIES_DIR="${0%/*}/"
# shellcheck disable=SC2164
cd "${BINARIES_DIR}"

mode_serial=false
mode_sys_qemu=false
while [ "$1" ]; do
    case "$1" in
    --serial-only|serial-only) mode_serial=true; shift;;
    --use-system-qemu) mode_sys_qemu=true; shift;;
    --) shift; break;;
    *) echo "unknown option: $1" >&2; exit 1;;
    esac
done

if ${mode_serial}; then
    EXTRA_ARGS='@SERIAL_ARGS@'
else
    EXTRA_ARGS='@DEFAULT_ARGS@'
fi

if ! ${mode_sys_qemu}; then
    export PATH="@HOST_DIR@/bin:${PATH}"
fi

exec @QEMU_CMD_LINE@ ${EXTRA_ARGS} "$@"
