#!/bin/sh
#/****************************************************************************
#**  SIONLIB     http://www.fz-juelich.de/jsc/sionlib                       **
#*****************************************************************************
#**  Copyright (c) 2008-2009                                                **
#**  Forschungszentrum Juelich, Juelich Supercomputing Centre               **
#**                                                                         **
#**  See the file COPYRIGHT in the package base directory for details       **
#****************************************************************************/

USAGE1="usage: sionconfig [--be] [--fe] [--32|--64] [--gcc] [--for] [--ser|--mpi]"
USAGE2="                  (--cflags|--libs|--path)"

if [ $# -eq 0 ]
then
  echo "${USAGE1}"
  echo "${USAGE2}"
  exit 1
fi

INSTDIR=@INSTDIR@
ARCH=@ARCH@

# Initialization
PREC=""
USESMPI=yes
FLIB=""
TASK="dontknow"
SER=""
GCC=""
MPICFLAGS=""
PRECFL=""
FE=""


# Process command line
for arg in "$@"
do
  case ${arg} in
  -*64)                  PREC=64
	                 PRECFL="_64"
                         ;;
  -*32)                  PREC=32
	                 PRECFL="_32"
	                 ;;
  -gcc|--gcc)            USEGCC=yes
	                 GCC="gcc"
                         ;;
  -fe|--fe)              USEFE=yes
	                 FE="fe"
                         ;;
  -be|--be)              USEBE=yes
	                 FE=""
                         ;;
  -f|--for|--fortran)    FLIB="@FMPILIB@"
                         ;;
  -s|--ser|--sequential) USESMPI=no
	                 SER="ser"
                         ;;
  -m|--mpi)              USESMPI=yes
                         SER=""
                         ;;
  --cflags)              TASK=cflags
                         ;;
  --fflags)              TASK=fflags
                         ;;
  --libs)                TASK=libs
                         ;;
  --path)                TASK=path
                         ;;
  *)                     ;;
  esac
done


LIBS="-L${INSTDIR}/lib"
CFLAGS="-I${INSTDIR}/include -D${ARCH}"
FFLAGS="-I${INSTDIR}/include"

case ${ARCH} in
    _XT) SIONARCH="-D_SION_XT"
	;;
    _LINUX) SIONARCH="-D_SION_LINUX"
	FE=""
	PREC=""
	PRECFL=""
	GCC=""
	;;
    _AIXPWR6) SIONARCH="-D_SION_AIX"
	FE=""
	GCC=""
	;;
    _BGL) SIONARCH="-D_SION_BGL"
	PREC=""
	PRECFL=""
	;;
    _BGP) SIONARCH="-D_SION_BGP"
	PREC=""
	PRECFL=""
	;;
esac

# Determine linking flags
  if [ ${USESMPI} = "yes" ]
  then
      MPICFLAGS="-DSION_MPI"
  else
      MPICFLAGS=""
  fi

# Output
case ${TASK} in
path)      echo "${INSTDIR}"
           ;;
cflags)    echo "${CFLAGS} ${MPICFLAGS} ${SIONARCH}"
           ;;
fflags)    echo "${FFLAGS}"
           ;;
libs)      echo "${LIBS} -lsion${SER}${FE}${GCC}${PRECFL}"
           ;;
*)         echo "${USAGE1}"
           echo "${USAGE2}"
           exit 1
           ;;
esac
exit 0
