#!/bin/bash
#
CC=icc
FC=ifort
LD=ifort

DEFINES='-DWORDLENGTH=4'
CPP='cpp -traditional -P'
#MAKEDEPEND=/usr/X11R6/bin/makedepend
EXTENDED_SRC_FLAG='-132'

NOOPTFLAGS='-O0 -g'
NOOPTFILES=''

if test "x$DEVEL" != x ; then
    FFLAGS="$FFLAGS -w95 -u -warn all -WB -convert big_endian -assume byterecl -ftrapuv -g -traceback -gen-interfaces"
else
    FFLAGS="$FFLAGS -w95 -W0 -WB -convert big_endian -assume byterecl"
fi
#- might want to use '-r8' for fizhi pkg:
#FFLAGS="$FFLAGS -r8"

if test "x$IEEE" = x ; then
    #  No need for IEEE-754
    FFLAGS="-assume buffered_io $FFLAGS"
    FOPTIM='-O3 -align -mp'
    NOOPTFLAGS='-O1'
    NOOPTFILES='phy_radiat.F fizhi_lsm.F fizhi_clockstuff.F'
else
    #  Try to follow IEEE-754
    FFLAGS="$FFLAGS"
    FOPTIM='-O0 -noalign -mp' # '-O3 -align' also seems to work fine
fi

F90FLAGS=$FFLAGS
F90OPTIM=$FOPTIM
CFLAGS='-O3'
FC_NAMEMANGLE="#define FC_NAMEMANGLE(X)  X ## _"

if [ "x$NETCDF_ROOT" != x ] ; then
    INCLUDEDIR="${NETCDF_ROOT}/include"
    INCLUDES="-I${NETCDF_ROOT}/include"
    LIBDIR="${NETCDF_ROOT}/lib"
    LIBS="-L${NETCDF_ROOT}/lib"
elif [ "x$NETCDF_HOME" != x ]; then
    INCLUDEDIR="${NETCDF_HOME}/include"
    INCLUDES="-I${NETCDF_HOME}/include"
    LIBDIR="${NETCDF_HOME}/lib"
    LIBS="-L${NETCDF_HOME}/lib"
elif [ "x$NETCDF_INC" != x -a "x$NETCDF_LIB" != x ]; then
    NETCDF_INC=`echo $NETCDF_INC | sed 's/-I//g'`
    NETCDF_LIB=`echo $NETCDF_LIB | sed 's/-L//g'`
    INCLUDEDIR="${NETCDF_INC}"
    INCLUDES="-I${NETCDF_INC}"
    LIBDIR="${NETCDF_LIB}"
    LIBS="-L${NETCDF_LIB}"
elif [ "x$NETCDF_INCDIR" != x -a "x$NETCDF_LIBDIR" != x ]; then
    INCLUDEDIR="${NETCDF_INCDIR}"
    INCLUDES="-I${NETCDF_INCDIR}"
    LIBDIR="${NETCDF_LIBDIR}"
    LIBS="-L${NETCDF_LIBDIR}"
elif test -d /usr/include/netcdf-3 ; then
    INCLUDES='-I/usr/include/netcdf-3'
    LIBS='-L/usr/lib/netcdf-3 -lnetcdf_g77'
elif test -d /usr/include/netcdf ; then
    INCLUDES='-I/usr/include/netcdf'
elif test -d /usr/local/netcdf ; then
    INCLUDES='-I/usr/local/netcdf/include'
    LIBS='-L/usr/local/netcdf/lib'
elif test -d /usr/local/include/netcdf.inc ; then
    INCLUDES='-I/usr/local/include'
    LIBS='-L/usr/local/lib'
fi

if test ! "x$MPI" = x ; then
    LIBS="$LIBS -lmpi"
   #MPI_HEADER_FILES='mpif.h mpiof.h mpif_parameters.h'
    DEFINES="-DALLOW_USE_MPI $DEFINES"
fi
