#!/bin/sh
CHARMBIN=`dirname $0`

STANDALONE=""

processArgs() {
while [ ! $# -eq 0 ]
do
  arg="$1"
  case "$arg" in
  -show)
     echo "charmc"
     exit 0
     ;;
  -standalone)
     STANDALONE="true"
     ;;
  *)
     ;;
  esac
  shift
done
}

eval processArgs "$@"

charmarch=$(cat $CHARMBIN/../tmp/.gdir)

AMPICC_EXTRA_OPTIONS=""

if test "$charmarch" = "mpi"
then
    dirName=ampicc.inc.$$
    mkdir $dirName
    cp -n $CHARMBIN/../include/mpi.h $dirName/mpi.h   2>/dev/null
    AMPICC_EXTRA_OPTIONS="-I./$dirName"
fi

[ -f $CHARMBIN/../lib/libampiromio.a -a -z "$STANDALONE" ] && ROMIO=-lampiromio

$CHARMBIN/charmc -language ampi -default-to-aout $AMPICC_EXTRA_OPTIONS $@ $ROMIO
status=$?

if test "$charmarch" = "mpi"
then
    /bin/rm -f $dirName/mpi.h 2>/dev/null
    rmdir $dirName
fi

# Copy ampirun, but do not overwrite it if it already exists.
[ $status -eq 0 ] && cp -n $CHARMBIN/ampirun .

exit $status
