#!/bin/sh 
COMPILER_OPTS=" -D__HONOR_STD -D__ICC=1210 -D__INTEL_COMPILER=1210 -D__PTRDIFF_TYPE__=long -D__WCHAR_TYPE__=int -D__LONG_MAX__=9223372036854775807L -D__QMSPP_ -D__OPTIMIZE__ -D__NO_MATH_INLINES -D__NO_STRING_INLINES -D__NO_INLINE__ -D__GNUC_GNU_INLINE__ -D__GNUG__=4 -D__GNUC__=4 -D__GNUC_MINOR__=4 -D__GNUC_PATCHLEVEL__=6 -D__LP64__ -D_LP64 -D_GNU_SOURCE=1 -D__DEPRECATED=1 -D__GXX_WEAK__=1 -D__GXX_ABI_VERSION=1002 -D__REGISTER_PREFIX__= -D__INTEL_RTTI__ -D__EXCEPTIONS=1 -D__unix__ -D__unix -D__linux__ -D__linux -D__gnu_linux__ -Dunix -Dlinux -D__ELF__ -D__x86_64 -D__x86_64__ -D_MT -D__INTEL_COMPILER_BUILD_DATE=20111011 -D__i686 -D__i686__ -D__pentiumpro -D__pentiumpro__ -D__pentium4 -D__pentium4__ -D__tune_pentium4__ -D__SSE2__ -D__SSE__ -D__MMX__ "

#!/bin/sh 

BINDIR=/usr/local/pdtoolkit/x86_64/intel/bin
PDTDIR=/usr/local/pdtoolkit
FLINTHOME=${PDTDIR}/etc
export FLINTHOME
STDINC=
VERBOSE=off
TMP="/tmp"
PDB=pdtfilenotspecified

PDTOPT=""
if [ $# = 0 ]
then
  echo "Usage: `basename $0` [-v] [-o<file>] [files]" 1>&2
  exit 1
fi

if [ ! -f ${BINDIR}/pdtflint ]
then
  echo "f95parse invoking f90parse ..."
  ${BINDIR}/f90parse $* -v
  exit
fi
# Remove Mutek front-end options from the commandline
MUTEKARGS=0


# default compiler options

# Architecture specific options for KAI headers
# ---------------------------------------------
# local options, if any
LOCOPT=" " 

for arg in "$@"
do
  MUTEKARGS=0
  if [ "y$arg" = "y-ffixed-line-length-132" ] ; then
      NOTHING=1
  elif [ "y$arg" = "y-v" ]
  then
    VERBOSE=on
  else
    for t in -M -F -r -U -u -A -L -q 
    do
      testarg=${arg#$t}
      if [ "y$testarg" != "y$arg" ]
      then 
        MUTEKARGS=1
      fi
    done
# CHECK for  -o<file> option
    testarg=${arg#-o}
    if [ "y$testarg" != "y$arg" ]
    then
      PDB=$testarg
      MUTEKARGS=1
    fi
    if [ "y$MUTEKARGS" != "y1" ]
    then
      mod_arg=`echo "x$arg" | sed -e 's/^x//' -e 's/"/\\\"/g' -e 's/'\''/'\\\'\''/g' -e 's/ /\\\ /g'`
      SPAWNARGS="$SPAWNARGS $mod_arg"
      MUTEKARGS=0
    fi
  fi
done

# What is the name of the first file on the commandline? 
for arg in "$@"
do
  case $arg in 
    *.? | *.?? | *.??? ) INF=$arg
         break
    ;;
  esac

done
#echo "SPAWNARGS=$SPAWNARGS"

#
# if the -o<file> option is not specified, create the pdb file based on the
# the name of the first source file
#

if [ $PDB = pdtfilenotspecified ]
then
  case ${INF} in
    *.f)	PDB=`basename ${INF} .f`.pdb
	;;
    *.F)	PDB=`basename ${INF} .F`.pdb
	;;
    *.F90)	PDB=`basename ${INF} .F90`.pdb
	;;
    *.f90)	PDB=`basename ${INF} .f90`.pdb
	;;
    *.f95)	PDB=`basename ${INF} .f95`.pdb
	;;
    *)	PDB=${INF}.pdb
	;;
  esac
fi

if [ ${PDB} = ".pdb" ]
then
  echo "ERROR: Source file not specified."
  echo "PDT accepts upto three letter suffixes in file names (e.g. foo.f90)"
  exit 1
fi

#
# run the FLINT parser
#
if [ $VERBOSE = on ] 
then
# print the output of the pdtflint command
  echo "	pdtflint ${SPAWNARGS} --> ${PDB}"
  echo "Executing ${BINDIR}/pdtflint ${SPAWNARGS} ${LOCOPT} ${EDGOPT} ${ARCHOPT} -Mpdb=pdtf$$.pdb; mv pdtf$$.pdb $PDB; "
  eval ${BINDIR}/pdtflint ${ARCHOPT} ${SPAWNARGS} ${LOCOPT} ${EDGOPT} -Mpdb=pdtf$$.pdb
else
# disable printing of stdout/stderr unless there is an error
  eval ${BINDIR}/pdtflint ${ARCHOPT} ${SPAWNARGS} ${LOCOPT} ${EDGOPT} -Mpdb=pdtf$$.pdb 1> /dev/null  2>&1
  if [ $? != 0 ] 
  then
    eval ${BINDIR}/pdtflint ${ARCHOPT} ${SPAWNARGS} ${LOCOPT} ${EDGOPT} -Mpdb=pdtf$$.pdb
  fi
fi

# Move the file to the output file
mv pdtf$$.pdb ${PDB}


# EOF
