#!/bin/bash


LOCAL=$(pwd)
DST=$( echo ${LOCAL}/../.. )

export -p &> env-pre-cmor.env

module purge

#module load gcc/5.3.0 openmpi/1.10.2
module load intel/2016 openmpi/1.10.2

module load szip/2.1
module load hdf5/1.8.16
module load netcdf-fortran/4.4.3
#module load uuid/1.6.2
module load udunits/2.2.20

DIR_UUID=$DST
DIR_UDUNITS=/opt/cesga/udunits/2.2.20/intel/2016
DIR_NETCDF=/opt/cesga/netcdf-fortran/4.4.3/gcc/intel/2016/
DIR_HDF5=/opt/cesga/hdf5/1.8.16/intel/2016

#export CC=gcc
#export CFLAGS='-fpic -O3 -ip -no-prec-div -static'

#export CPP='gcc -E'
#export CPPFLAGS='-DpgiFortran'
#export CXXCPP='icpc -E'

#export F77=gfortran
#export FC=gfortran
#export FFLAGS='-ffree-line-length-none' #'-fpic -O3 -ip -no-prec-div -static'

export CC=icc
export CFLAGS='-fpic -O3 -ip -no-prec-div -static'

export CPP='icc -E'
export CPPFLAGS='-DpgiFortran'
export CXXCPP='icpc -E'

export F77=ifort
export FC=ifort
export FFLAGS='-fpic -O3 -ip -no-prec-div -static'


set -ev

./configure --prefix=$DST --with-uuid=$DIR_UUID #--with-netcdf=$DIR_NETCDF --with-hdf5=$DIR_HDF5 --with-udunits2=$DIR_UDUNITS --with-uuid=$DIR_UUID

#cat Makefile | tr ' ' '\t' > Makefile

make
make install

export -p &> env-cmor.env
source env-pre-cmor.env

date

