#!/bin/bash

#====== XML files ===========
APP=app_threetasks
MAPXML=mappingTTS.xml

MY_MAKE=Makefile.LAUNCH  # to include external C++ code and -pthread option

#------ options --------------
if [ "$@""a" == "a" ]; then
  # default options:
  #   - do not print BIP simulation details
  opt="--quiet"
else 
  opt="$@"
fi

#****************************************************
APP_APSW=${APP}_SWModel
GOOD=0

source $DC2BTV30_ROOT/sourceme.rc

echo "========================================="
echo "========================================="
echo "========================================="
echo "========================================="
echo "      PERFORM: DOLC ---> BIP             "
echo "========================================="
echo "========================================="
$DOL2BIP -f ${APP}.xml --create-scheduler $MAPXML --thread_map_output thread_map.txt
res=$?
if ((res!=GOOD)); then 
  exit 1
fi


echo "========================================="
echo "========================================="
echo "========================================="
echo "========================================="
echo "      PRFORM:  BIP ----> bip.C (C++)     "
echo "========================================="
echo "========================================="
export BIP2_HOME=$MULTI_BIP2_HOME
$BIP2_HOME/bin/bipc -f ${APP_APSW}.bip --genC-multi --threadmap thread_map.txt
res=$?
if ((res!=GOOD)); then 
  exit 1
fi

#exit 1

echo "========================================="
echo "========================================="
echo "========================================="
echo "========================================="
echo "      PRFORM:  make binary.x             "
echo "========================================="
echo "========================================="
make -f ${MY_MAKE}
res=$?
if ((res!=GOOD)); then 
  exit 1
fi

# clean up
#rm ${APP_APSW}.bip.C ${APP_APSW}.bip.h ${APP_APSW}.bip.mk ${APP_APSW}.bip.o ${APP_APSW}.model ${APP_APSW}.timod

echo "========================================="
echo "========================================="
echo "========================================="
echo "========================================="
echo "      PRFORM: exec  binary.x --realtime $opt       "
echo "        note:  must run in realtime mode "
echo "========================================="
echo "========================================="
./${APP_APSW}.bip.x --realtime $opt

