#!/bin/sh
#
# md380-emu is a static ARM32 binary.  Run it natively on armhf and through
# qemu-user everywhere else; the package depends on qemu-user-static for the
# latter.

set -eu

EMU=/opt/md380-emu/md380-emu
ARCH=$(dpkg --print-architecture 2>/dev/null || true)

if [ "$ARCH" = "armhf" ]; then
    exec "$EMU" "$@"
fi

for qemu in qemu-arm-static qemu-arm; do
    if command -v "$qemu" >/dev/null 2>&1; then
        exec "$qemu" "$EMU" "$@"
    fi
done

echo "md380-emu: qemu-arm-static not found; install qemu-user-static" >&2
exit 1
