#!/bin/bash

commandtorun=''
arguments=$@
if [[ "$1" = "--gdb" ]]
    then commandtorun="gdb"
    arguments=''
    echo running command
fi;

if [[ "$1" = "--ldd" ]]
    then commandtorun="ldd"
    arguments=''
    echo running command
fi;

if [[ "$1" = "--callgrind" ]]
    then commandtorun="valgrind --tool=callgrind"
    arguments=''
    echo running command
fi;

if [[ "$1" = "--valgrind" ]]
    then commandtorun="valgrind --error-limit=no"
    arguments=''
    echo running command
fi;



if [[ "$1" = "--gammaray" ]]
    then commandtorun="/home/ian/srcs/debian6-amd64/usr/bin/gammaray"
    arguments=''
    echo running command
fi;

export HIPCHAT_LD_LIBRARY_PATH=$LD_LIBRARY_PATH
export HIPCHAT_QT_PLUGIN_PATH=$QT_PLUGIN_PATH
unset QT_PLUGIN_PATH

thisfile="`readlink -f "$0"`"
thisdirectory="`dirname "$thisfile"`"
hipchatRoot=$thisdirectory/../

#hellocpp needs G++ 4.8.0
#use HipChat-distributed libstdc++ only if needed; using a version older than system causes problems
$thisdirectory/hellocpp
if [[ $? = 0 ]]
    then export LD_LIBRARY_PATH=$hipchatRoot/lib
else
    export LD_LIBRARY_PATH="$hipchatRoot/lib;$hipchatRoot/lib/cpp"
fi


exec -a "$0" $commandtorun "$hipchatRoot/lib/hipchat.bin"  $arguments
