#!/data/data/com.termux/files/usr/bin/sh

#
# This script runs an installed version of Ardour. It sets a few environment variables
# and does a few checks before exec'ing the real executable.
# 

## Memlock check

MLOCK_LIMIT=$(ulimit -l)
if [ "$MLOCK_LIMIT" != "unlimited" ]; then
	echo "WARNING: Your system has a limit for maximum amount of locked memory!"
	echo "         This might cause Ardour to run out of memory before your system runs"
	echo "         out of memory. You can view the memory limit with 'ulimit -l', and it"
	echo "         is normally controlled by /etc/security/limits.conf"
	echo ""

fi

#
# Running Ardour requires these 3 variables to be set
#

export ARDOUR_DATA_PATH=/data/data/com.termux/files/usr/share/ardour8
export ARDOUR_CONFIG_PATH=/data/data/com.termux/files/usr/etc/ardour8
export ARDOUR_DLL_PATH=/data/data/com.termux/files/usr/lib/ardour8

#
# disable ubuntu global menu, causes crash in libappmenu-gtk-module.so
#
export UBUNTU_MENUPROXY=""

#
# NSM needs a path to this script
#

export ARDOUR_SELF=$(basename "$0")

#
# VAMP has its own lookup path
# 

export VAMP_PATH=/data/data/com.termux/files/usr/lib/ardour8/vamp${VAMP_PATH:+:$VAMP_PATH}

if [ $# -gt 0 ] ; then
    case $1 in
        --ddd)    DEBUGGER=ddd; shift ;;
        -g|--gdb) DEBUGGER=gdb; shift ;;
        --lldb)   DEBUGGER=lldb; shift ;;
    esac
fi

exec $DEBUGGER /data/data/com.termux/files/usr/lib/ardour8/ardour-8.12.0 "$@"
