#!/bin/sh
#
# This will end up in ${CMAKE_INSTALL_PREFIX}/installed/share/bin
# for both release and work areas.
#
# In each build environment the variable ${TDAQ_RUNNER} will be
# defined to point to this script.
# set(TDAQ_RUNNER "env CMTCONFIG=${BINARY_TAG} ${CMAKE_INSTALL_PREFIX}/installed/share/bin/tdaq_run")
#
# It is supposed to be used in tests which require the normal
# TDAQ environment setup. It assumes that CMTCONFIG is set
# in the environment for the setup script
#
# add_test(NAME mytest COMMAND ${TDAQ_RUNNER} pm_part_hlt.py -p mypartition)
#
# A list of variable assignments that occure before the command will
# be evaluated after the sourcing of the setup script. This allows
# to override environment variables that are unconditionally set
# by setup.sh
#

# Get installed/ directory
_this=$(dirname $(dirname $(dirname $(readlink -f $0))))
_tmp=$(mktemp)
source ${_this}/setup.sh > ${_tmp}
_ret=$?
if [ ${_ret} -ne 0 ]; then
   cat ${_tmp}
   rm -f ${_tmp}
   exit ${_ret}
fi
rm -f ${_tmp}
while [ $# -gt 0 ]
do
   case $1 in
     *=*)
       export $1
       shift
       ;;
     *)
       break
       ;;
   esac
done
exec $*
