#!/bin/bash

#====== XML files ===========
APP="exampleDemo_DOLC"
MAPXML="../mapping.xml"

#============= binary options ===========
if [ "$@""a" == "a" ]; then
  # no arg ==> default option
  opt="--limit 500"
else 
  opt="$@"
fi

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

source $DC2BTV20_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

echo "========================================="
echo "========================================="
echo "========================================="
echo "========================================="
echo "      PERFORM:  BIP ----> bip.C (C++)     "
echo "========================================="
echo "========================================="

$BIP2_HOME/bin/bipc -f ${APP_APSW}.bip --genC-execute > /dev/null 2> /dev/null
res=$?
if ((res!=GOOD)); then 
  exit 1
fi

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


