#!/bin/bash

#====== XML files ===========
APP=appl_aper
MAPXML=sched.xml


#============= binary options ===========
if [ "$@""a" == "a" ]; then
  # - run for 2000 iterations
  # - dont print scheduler events
  opt="--limit 2000 --quiet"   
else 
  opt="$@"
fi

#****************************************************
APP_APSW=${APP}_SWModel
MY_MAKE=${APP_APSW}.bip.mk
#MY_MAKE=Makefile.RUN # to include external C++ code
GOOD=0

source $DC2BTV30_ROOT/sourceme.rc

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

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

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 $opt        "
echo "        note:  you can provide alternative options to this script "
echo "========================================="
echo "========================================="
./${APP_APSW}.bip.x $opt

