#!/bin/sh

# get path of this script
BINDIR=`dirname "$0"`
# strip "bin" to get base directory
BASEDIR=`dirname "$BINDIR"`
LIBDIR=$BASEDIR/lib

# We want to avoid that multiple system installations of OpenWalnut cause some weird loading of libs. We want ours (relative to our executable) to be loaded:
Libs="libopenwalnut_biosig.so.1 libopenwalnut_eep.so.1 libopenwalnut_niftiio.so.1 libopenwalnut_niftiznz.so.1"
# Well, this one needs to be there! If not, your installation is wrong.
Preloads="$LIBDIR/libopenwalnut.so.1"
# We need to ensure the libs are there. If not, do not add them to the preloads variable                            
for lib in $Libs
do
    libfile=$LIBDIR/$lib
    if [ -e "$libfile" ]; then
        Preloads=$Preloads:$libfile
    fi
done
# Finally, export it
export LD_PRELOAD=$Preloads

# Force C locale. This fixes an issue with newer boost versions. See ticket #130.
export LC_ALL=C

PARAMS="$*"
echo "Parameters: $PARAMS"

# run walnut
kdbg -a "$PARAMS" $BINDIR/openwalnut-qt4
