#! /bin/sh
#
# default configuration options and compiler flags for different hosts
#
#
CONFPATH=`echo $0 | cut -c 1-6`
if [ "$CONFPATH" != "../../" ] ; then
  CONFPATH='./'
fi
#
COMP=""
HOSTNAME=`hostname`
#
while test $# != 0
do
  case $1 in
      CC=?*)
          COMP=`expr "X$1" : 'X[^=]*=\(.*\)'`
          ;;
      *)
          HOSTNAME=$1
          ;;
  esac
  shift
done
#
set -x
#
case "${HOSTNAME}" in
# i386-apple-darwin10
    bailung*|d133*|d134*)
        CDOLIBS="--enable-nearpt3 \
                 --with-fftw3 \
                 --with-grib_api=$HOME/local/grib_api-1.13.1 \
                 --with-netcdf=$HOME/local/netcdf-c-4.3.3.1-threadsafe \
                 --with-hdf5=$HOME/local/hdf5-1.8.15-threadsafe \
                 --with-udunits2=/opt/local \
                 --with-curl=/opt/local \
                 --with-proj=/opt/local \
                 --with-szlib=$HOME/local"

        if  test "$COMP" = icc ; then
	  ${CONFPATH}configure  \
                    $CDOLIBS \
	            CC=icc CFLAGS="-g -Wall -Wwrite-strings -O2 -qopt-report=5 -march=native" CXX=icpc
        elif  test "$COMP" = icpc ; then
	  ${CONFPATH}configure  \
                    $CDOLIBS \
	            CC=icpc CFLAGS="-g -std=c++11 -Wall -O2 -qopt-report=5 -march=native"
        elif  test "$COMP" = clang++ ; then
	  ${CONFPATH}configure  \
                    $CDOLIBS \
	            CC=clang++ CFLAGS="-g -Wall -O3"
        elif  test "$COMP" = clang ; then
	  ${CONFPATH}configure  \
                    $CDOLIBS \
	            CC=clang CFLAGS="-g -Wall -Wwrite-strings -O3"
        elif  test "$COMP" = g++ ; then
	  ${CONFPATH}configure  \
                    $CDOLIBS \
	            CC=g++ CFLAGS="-g -std=c++14 -Wall -W -Wfloat-equal -pedantic -O3 -march=native"
        else
	  ${CONFPATH}configure --prefix=$HOME/local \
                    --enable-maintainer-mode \
                    $CDOLIBS \
	            CC=gcc CFLAGS="-g -pipe -Wall -W -Wfloat-equal -Wwrite-strings -pedantic -O3 -march=native -fstack-protector"
#                    --with-libxml2=/usr 
#                    --with-magics=/Users/m214003/local/magics-2.14.9
        fi
	;;
    hama*)
#        CDOLIBS="--with-fftw3 \
#                 --with-netcdf=/opt/local \
#                 --with-hdf5=/opt/local \
#                 --with-szlib=$HOME/local \
#                 --with-proj=/opt/local \
#                 --with-cmor=/Users/m214003/work/CMOR \
#                 --with-curl=/opt/local"
        CDOLIBS="--enable-nearpt3 \
                 --with-fftw3 \
                 --with-grib_api=$HOME/local/gribapi-1.13.0 \
                 --with-netcdf=$HOME/local \
                 --with-hdf5=$HOME/local \
                 --with-proj=/opt/local"

        if  test "$COMP" = icc ; then
	  ${CONFPATH}configure --prefix=$HOME/local \
                    $CDOLIBS \
	            CC=icc CFLAGS="-g -Wall -Wwrite-strings -O2 -qopt-report=5 -march=native" CXX=icpc
        elif  test "$COMP" = icpc ; then
	  ${CONFPATH}configure  \
                    $CDOLIBS \
	            CC=icpc CFLAGS="-g -std=c++11 -Wall -O2 -qopt-report=5 -march=native"
        elif  test "$COMP" = clang++ ; then
	  ${CONFPATH}configure  \
                    $CDOLIBS \
	            CC=clang++ CFLAGS="-g -Wall -O3"
        elif  test "$COMP" = clang ; then
	  ${CONFPATH}configure  \
                    $CDOLIBS \
	            CC=clang CFLAGS="-g -Wall -Wwrite-strings -Ofast -march=native"
        elif  test "$COMP" = g++ ; then
	  ${CONFPATH}configure  \
                    $CDOLIBS \
	            CC=g++ CFLAGS="-g -std=c++14 -Wall -W -Wfloat-equal -pedantic -O3"
        else
	  ${CONFPATH}configure --prefix=$HOME/local \
                    --enable-maintainer-mode \
                    $CDOLIBS \
	            CC=gcc CFLAGS="-g -std=c11 -pipe -Wall -Wwrite-strings -W -Wfloat-equal -pedantic -O3 -march=native -fstack-protector -Wa,-q"
#                    --with-libxml2=/usr \
#                    --with-magics=/Users/m214003/local/Magics-2.18.14nio \
        fi
	;;
    daint*)
        if  test "$COMP" = icc ; then
          CDOLIBS="--with-netcdf=/opt/cray/netcdf/4.3.3.1/INTEL/14.0"
	  ${CONFPATH}configure --prefix=$HOME/local \
                    $CDOLIBS \
	            CC=icc CFLAGS="-g -Wall -O2 -qopt-report=5 -march=native -openmp"
        elif  test "$COMP" = pgcc ; then
          CDOLIBS="--with-netcdf=/opt/cray/netcdf/4.3.3.1/PGI/15.3"
	  ${CONFPATH}configure --disable-openmp \
                    $CDOLIBS \
	            CC=pgcc CFLAGS="-g -O2"
        elif  test "$COMP" = cray ; then
          CDOLIBS="--with-netcdf=/opt/cray/netcdf/4.3.3.1/CRAY/8.3"
	  ${CONFPATH}configure --disable-openmp \
                    $CDOLIBS \
	            CC=cc CFLAGS="-g -O2 -h noomp"
        else
          CDOLIBS="--with-netcdf=/opt/cray/netcdf/4.3.3.1/GNU/4.9"
	  ${CONFPATH}configure --prefix=$HOME/local \
                    $CDOLIBS \
	            CC=gcc CFLAGS="-g -pipe -Wall -W -Wfloat-equal -pedantic -O3 -march=native -fstack-protector -Wa,-q"
        fi
	;;
# x86_64-squeeze-x64-linux
    thunder*)
        CDOLIBS="--with-grib_api=/sw/squeeze-x64/grib_api-1.13.0-static-gccsys \
                 --with-netcdf=/sw/squeeze-x64/netcdf-4.2-static \
                 --with-hdf5=/sw/squeeze-x64/hdf5-1.8.8-static \
                 --with-szlib=/sw/squeeze-x64/szip-2.1 \
                 --with-udunits2=/sw/squeeze-x64/udunits-2.1.19 \
                 --with-proj=/sw/squeeze-x64/proj-4.7.0"

        if  test "$COMP" = icc ; then
          ${CONFPATH}configure --prefix=$HOME/local --exec_prefix=$HOME/local/thunder \
                    --with-fftw3 \
                    $CDOLIBS \
	            CC=icc CFLAGS="-g -Wall -O2 -qopt-report=5 -march=native"
        elif  test "$COMP" = pgcc ; then
          ${CONFPATH}configure --prefix=$HOME/local --exec_prefix=$HOME/local/thunder \
                    $CDOLIBS \
	            CC=pgcc CFLAGS="-g -fast"
	else
          ${CONFPATH}configure --prefix=$HOME/local --exec_prefix=$HOME/local/thunder \
                    --with-fftw3 \
                    $CDOLIBS \
                    CC=gcc CFLAGS='-g -Wall -O3'
	fi
	;;
# mistral
    mlogin*)
        CDOLIBS="--with-grib_api=/sw/rhel6-x64/grib_api/grib_api-1.13.0-gcc48 \
                 --with-netcdf=/sw/rhel6-x64/netcdf/netcdf_c-4.3.2-gcc48 \
                 --with-hdf5=/sw/rhel6-x64/hdf5/hdf5-1.8.14-threadsafe-gcc48 \
                 --with-szlib=/sw/rhel6-x64/sys/szip-2.1-gcc48 \
                 --with-udunits2=/sw/rhel6-x64/util/udunits-2.2.17-gcc48 \
                 --with-proj=/sw/rhel6-x64/graphics/proj4-4.9.1-gcc48"

        if  test "$COMP" = icc ; then
          ${CONFPATH}configure --prefix=$HOME/local \
                    --with-fftw3 \
                    $CDOLIBS \
	            CC=icc CFLAGS="-g -Wall -O2 -qopt-report=5 -march=native"
        elif  test "$COMP" = pgcc ; then
          ${CONFPATH}configure --disable-openmp \
                    $CDOLIBS \
	            CC=pgcc CFLAGS="-g -fast"
	else
          ${CONFPATH}configure --prefix=$HOME/local \
                    --with-fftw3 \
                    $CDOLIBS \
                    CC=gcc CFLAGS='-g -Wall -O3 -march=native'
	fi
	;;
# x86_64-unknown-linux-gnu
    btc*)
        if  test "$COMP" = icc ; then
          ${CONFPATH}configure --prefix=$HOME/local \
                    --with-grib_api=/lustre/sw/rhel6-x64/grib_api/grib_api-1.13.0-intel15 \
	            --with-netcdf=/lustre/sw/rhel6-x64/netcdf/netcdf_c-4.3.2-intel15 \
                    --with-hdf5=/lustre/sw/rhel6-x64/hdf5/hdf5-1.8.14-threadsafe-intel15 \
                    --with-fftw3 \
	            CC=icc CFLAGS="-g -Wall -O2 -qopt-report=5 -xCORE-AVX2"
	else
          ${CONFPATH}configure --prefix=$HOME/local \
                    --with-grib_api=/lustre/sw/rhel6-x64/grib_api/grib_api-1.13.0-gcc48 \
	            --with-netcdf=/lustre/sw/rhel6-x64/netcdf/netcdf_c-4.3.2-gcc48 \
                    --with-hdf5=/lustre/sw/rhel6-x64/hdf5/hdf5-1.8.14-threadsafe-gcc48 \
                    --with-fftw3 \
                    CC=gcc CFLAGS='-g -Wall -O3 -march=native'
	fi
	;;
# ia64-xxx-linux
    ds*)
	${CONFPATH}configure --prefix=$HOME/local \
                    --with-netcdf=/pool/ia64/netcdf/netcdf-3.6.0-p1 \
                    --with-szlib=$HOME/local \
                    CC=icc CFLAGS="-g -O2 -Wall -fno-alias -DMIN_BUF_SIZE=4194304"
	;;
    wasser*)
	${CONFPATH}configure --prefix=$HOME/local \
                    --with-netcdf=/home/dkrz/m214089/local/ia64 \
                    CC=icc CFLAGS="-g -O2 -Wall -fno-alias"
	;;
# x86_64-archlinux
    luthien*)
 	${CONFPATH}configure --prefix=$HOME/local \
                    --program-suffix=-dev \
                    --enable-maintainer-mode \
	            --with-netcdf \
	              --with-hdf5 \
                     --with-szlib \
                  --with-grib_api \
                  --with-udunits2 \
                  --with-proj \
                      --with-pic \
                      CC=gcc CFLAGS="-g -Wall -O2 -DWITH_DATA" LIBS=-lopenjpeg
	;;
# standard workstations at MPI-M x86_64-lenny
    mpipc* )
	${CONFPATH}configure \
               --prefix=`pwd`/build \
               --enable-maintainer-mode \
               --with-netcdf='/sw/lenny-x64/netcdf-latest-gccsys' \
               --with-hdf5='/sw/lenny-x64/hdf5-latest' \
               --with-szlib='/sw/lenny-x64/szip-latest' \
               --with-proj='/sw/lenny-x64/proj-latest' \
               --enable-ruby --enable-swig --enable-python \
	           CC=gcc CFLAGS="-g -Wall -W -Wfloat-equal -pedantic -O2"
        ;;
# dap enabled
    egmont | columbine)
 	  ${CONFPATH}configure --prefix=$HOME/local --exec_prefix=$HOME/local/etch-ia32 \
	            --with-netcdf=/sw/etch-ia32/netcdf-4.1.1-gcc \
	            --with-hdf5=/sw/etch-ia32/hdf5-1.8.4-threadsafe \
                    --with-zlib=/sw/etch-ia32/zlib-1.2.3 \
                    --with-szlib=/sw/etch-ia32/szip-2.1 \
                    --withroj=/sw/etch-ia32/proj-4.6.0 \
	            --enable-all-static CC=icc CFLAGS="-g -fast -openmp" AR=xiar LD=xild
#	            CC=gcc CFLAGS="-g -Wall -W -Wfloat-equal -pedantic -O2"
    ;;
# i386-pc-solaris2.10
    grim | mil* )
	${CONFPATH}configure --prefix=$HOME/local --exec_prefix=$HOME/local/solaris10-x86 \
                    --with-netcdf=/client \
                    --with-szlib=$HOME/local/solaris10-x86 \
                    CC=cc CFLAGS="-g -mt -fast"
	;;
# sx6-nec-superux12.2
    cs*)
	${CONFPATH}configure --prefix=$HOME/local \
         	    --with-netcdf=/pool/netcdf/netcdf-3.6.0-p1 \
		    CC=cc \
                    CFLAGS="-O -Onooverlap,restrict=all -pvctl,fullmsg,noassume,loopcnt=1000000"
	;;
    sx6)
	${CONFPATH}configure --host=sx6 --prefix=$HOME/local \
                    --with-netcdf=/pool/SX-6/netcdf/netcdf-3.6.0-p1 \
		    CC=sxcc AR=sxar \
                    CFLAGS="-O -Onooverlap,restrict=all -pvctl,fullmsg,noassume,loopcnt=1000000"
	;;
    es)
	${CONFPATH}configure --host=sx6 --prefix=$HOME/local/ES \
                    --with-netcdf=/S/n010/home010/c0148/local/SX \
		    CC=escc AR=esar \
                    CFLAGS="-O -Onooverlap,restrict=all -pvctl,fullmsg,noassume,loopcnt=1000000"
	;;
# x86_64-unknown-linux-gnu (rhel55)
    wizard*)
        LDFLAGS="-lpng"
        export LDFLAGS
	${CONFPATH}configure --prefix=$HOME/local/centos58-x64 \
                    --with-proj=/sw/centos58-x64/proj-4.7.0 \
                    --with-hdf5=/sw/centos58-x64/hdf5-1.8.10-patch1 \
                    --with-udunits2=/sw/centos58-x64/udunits-2.1.19 \
                    --with-grib_api=/sw/centos58-x64/grib_api-1.12.3 \
                    --with-netcdf=/sw/centos58-x64/netcdf-4.2.1.1 \
                    --with-szlib=/sw/centos58-x64/szip-2.1 \
                    --with-zlib=/usr \
	            CC=gcc CFLAGS="-g -Wall -O3"
	;;
# powerpc-ibm-aix5.3.0.0
    blizzard*)
	${CONFPATH}configure --prefix=$HOME/local \
                    --with-netcdf=/sw/aix61/netcdf-4.2-threadsafe \
                    --with-hdf5=/sw/aix61/hdf5-1.8.8-threadsafe \
                    --with-szlib=/sw/aix61/szip-2.1-threadsafe \
                    --with-udunits2=/sw/aix61/udunits-2.1.14 \
                    --with-proj=/sw/aix53/proj-4.6.1 \
                    --with-curl=/sw/aix61/curl-7.21.3 \
                    AR="ar -X 64"  LDFLAGS="-brtl -R/sw/aix61/openssl-1.0.0d/lib:/sw/aix61/zlib-1.2.6/lib" \
 	            CC=xlc_r CFLAGS="-g -O3 -q64 -qhot -qstrict -qarch=auto -qtune=auto -qsmp=omp -DHAVE_MMAP -qthreaded"
	;;
# powerpc-ibm-aix6.0.0.0
    c1a*)
	${CONFPATH}configure --prefix=$HOME/local \
                    --with-netcdf=/usr/local/apps/netcdf/3.6.3/LP64 \
                    --with-hdf5=/usr/local/apps/hdf5/1.8.1/LP64 \
                    --with-szlib=/usr/local/apps/szip/2.1/LP64 \
                    AR="ar -X 64"  LDFLAGS="-brtl" \
	            CC=xlc_r CFLAGS="-g -O3 -q64 -qhot -qstrict -qarch=auto -qtune=auto -qsmp=omp -DHAVE_MMAP -qthreaded"
	;;
    *)
	echo "configuration for hostname $HOSTNAME not found!"
	;;
# x86_64-unknown-linux-gnu (cray)
    brisi*)
        ${CONFPATH}configure  \
                    --with-netcdf=/opt/cray/netcdf/4.3.2/INTEL/140 \
                    --with-hdf5=/opt/cray/hdf5/1.8.13/INTEL/140 \
                    --with-fftw3 \
                    CC=gcc CFLAGS='-g -Wall -O3'
	;;
esac
