#!/bin/sh
#
# omni wrapper:
#   wrapper command kick omni compiler for backend compiler.
#   backed compiler is select by user with -omnicc comppiler option.
# 

INSTALL_ROOT=${OMNI_HOME:=@wrapperOrgPrefix@}
OMNIDRIVER="$INSTALL_ROOT/lib/openmp/libexec/omniDriver"
PROGNAME=`basename $0`

while   case $# in
    0)  false;;     # no more argument
    *)  true;;
  esac
do
  A="$1"; shift
  case $A in
    -omnicc=*) COMPILER=`expr $A : '-omnicc=\(.*\)'`;;
  esac
  savearg="$savearg $A"
done

case $PROGNAME in
omcc|ompcc)
  LANGTYPE="C"
  ;;
omf77|ompf77)
  LANGTYPE="Fortran"
  ;;
*)
  echo "$PROGNAME: unknown language mode."
  exit 1
  ;;
esac

if [ -x $OMNIDRIVER ] ; then
  if [ "x$COMPILER" != "x" ] ; then
    COMPILER_TYPE=`$OMNIDRIVER -omniQueryCompilerType -omnilang=$LANGTYPE -omnicc=$COMPILER`
  else
    COMPILER_TYPE=`$OMNIDRIVER -omniQueryCompilerType -omnilang=$LANGTYPE`
  fi
  if [ "x$COMPILER_TYPE" = "x" ] ; then
    echo "$PROGNAME: unknown backend compiler selected."
    exit 1
  fi
else
  echo "$PROGNAME: omni dirver is not installed($OMNIDRIVER)."
  exit 1
fi

if [ -x $INSTALL_ROOT/lib/openmp/$COMPILER_TYPE/bin/$PROGNAME ]; then
  exec $INSTALL_ROOT/lib/openmp/$COMPILER_TYPE/bin/$PROGNAME $savearg
else
  echo "$PROGNAME: omni runtime library for $COMPILER_TYPE compiler is not installed." 2>&1
  exit 1
fi
