#!/bin/bash
# 
# 
# tested on greenplanet.ps.uci.edu
# Linux greenplanet.ps.uci.edu 2.6.18-128.el5 #1 SMP Wed Jan 21 10:41:14 EST 2009 x86_64 x86_64 x86_64 GNU/Linux
# GNU Fortran (GCC) 4.1.2 20080704 (Red Hat 4.1.2-44)
# Copyright (C) 2007 Free Software Foundation, Inc.

FC=gfortran
F90C=gfortran
CC=gcc
DEFINES='-DWORDLENGTH=4 -DNML_TERMINATOR'
CPP='cpp  -traditional -P'
NOOPTFLAGS='-O0'
EXTENDED_SRC_FLAG='-ffixed-line-length-132'
OMPFLAG='-fopenmp'

if test "x$DEVEL" != x ; then
    FFLAGS='-g -Wall -W -ffpe-trap=invalid,zero,overflow -fbounds-check'
else
    FFLAGS=''
fi

# Requires gfortran from 2006 onwards for -fconvert=big-endian
FFLAGS="$FFLAGS -fconvert=big-endian -fimplicit-none"

if test "x$IEEE" = x ; then
    #  No need for IEEE-754
    FOPTIM='-O3 -funroll-loops'
else
    #  Try to follow IEEE-754
    # these may also be useful, but require specific gfortran versions:
    # -Wnonstd-intrinsics  for gfortran <= 4.3
    # -Wintrinsics-std     for gfortran >= 4.4
    # -Wno-tabs            for gfortran >= 4.3 
    FFLAGS="$FFLAGS -Waliasing -Wampersand -Wsurprising -Wline-truncation"
#   to get plenty of warnings :
#   FFLAGS="$FFLAGS -Wconversion -Wimplicit-interface -Wunused-labels"
    FOPTIM='-O0'
#   for automatic testing with testreport (but no relation with IEEE arithmetic):
    FOPTIM="$FOPTIM -g -ffpe-trap=invalid,zero,overflow -fbounds-check"
fi
F90FLAGS=$FFLAGS
F90OPTIM=$FOPTIM
CFLAGS=$FOPTIM

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 /sopt/netcdf/netcdf3-gcc-serial; then
    INCLUDES='-I/sopt/netcdf/netcdf3-gcc-serial/include'
    LIBS='-L/sopt/netcdf/netcdf3-gcc-serial/lib'
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/lib64'
fi
