#!/bin/bash

BUILD="obj"
DEFAULT_PYTHON="python-2.6.1"
PYTHON=/build/toolchain/lin32/${DEFAULT_PYTHON}/bin/python

RUN_DEBUG=0
newCmdLine=""
for OPTION in "$@"
do
   case $OPTION in
      -c)
         echo "Compiling DRM apps... "
         cd ..
         scons BUILDTYPE=${BUILD} PRODUCT=vcenter drm-apps
         cd bora
         ;;
       -D)
         RUN_DEBUG=1
         ;;
       *)
         if [ "$newCmdLine" == "" ]; then
             newCmdLine="$OPTION"
         else
             newCmdLine="$newCmdLine $OPTION"
         fi
   esac
done

USE_STRIPPED=true

if [ ! "${DRMAPPS}" ]; then
   DRMAPPS="${PWD}"/build/vcenter/"${BUILD}"/drm-apps
   USE_STRIPPED=false
fi

if [ ${USE_STRIPPED} = true ]; then
   REPLAY_BIN=${DRMAPPS}/bin/drmreplay
   APPS_LIBS=${DRMAPPS}/lib
else
   REPLAY_BIN=${PWD}/build/build/drmreplay/obj/linux64/drmreplay
   source ${DRMAPPS}/ldconfig
   APPS_LIBS=${DEBUG_LIBS}:${DRMAPPS}/lib
fi

if [ ${RUN_DEBUG} -eq 1 ];then
    LD_LIBRARY_PATH=${APPS_LIBS} gdb --args ${REPLAY_BIN} ${newCmdLine}
else
    LD_LIBRARY_PATH=${APPS_LIBS} ${REPLAY_BIN} ${newCmdLine}
fi
