#!/bin/bash
cmd=$(readlink -f "$0")
tmp=$(basename "$cmd")
prog=${tmp%%.run}
DIR=$(dirname "$cmd")

D=""
for d in {,/usr}/lib64 /usr/lib64/R/lib {,/usr}/lib/x86_64-linux-gnu {,/usr}/lib; do
    if [ -d "$d" ]; then
	if [ -z "$D" ]; then
	    D="$d"
	else
	    D="$D:$d"
	fi
    fi
done
export LD_LIBRARY_PATH="$DIR/first:$D:$DIR:$LD_LIBRARY_PATH"

if [ "${INLA_DEBUG}XX" != "XX" ]; then
    echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
    ldd -r "$DIR/$prog"
fi

exec "$DIR/$prog" "$@"
