#!/bin/sh
set -eu
base=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
# The system's loader when it resolves every library (with the system's OpenGL drivers); else the bundled one.
if [ -z "${NN_DOSBOX_BUNDLED_ONLY:-}" ] && [ -x /lib64/ld-linux-x86-64.so.2 ] &&
   ! /lib64/ld-linux-x86-64.so.2 --library-path "$base/lib" --list "$base/bin/dosbox-x" 2>&1 | grep -q -e 'not found' -e 'No such file'; then
    exec /lib64/ld-linux-x86-64.so.2 --library-path "$base/lib" "$base/bin/dosbox-x" -conf "$base/portable.conf" "$@"
fi
exec "$base/lib/core/ld-linux-x86-64.so.2" --library-path "$base/lib:$base/lib/core" "$base/bin/dosbox-x" -conf "$base/portable.conf" "$@"
