#!/bin/bash
# $Id: sofa_configure_nagfor61_linux 6490 2020-09-10 17:36:27Z idculv $
#
# SOFA shell script for a local 'configure' for ROPP
# USERS SHOULD MODIFY THIS SCRIPT AS REQUIRED FOR LOCAL INSTALL
#
# Compiler: nagfor61 / Linux
#
PREFIX=${1-$ROPP_ROOT/nagfor61}
echo
echo "Platform:"
uname -a
echo
echo "Fortran compiler:"
nagfor61 -V
echo
echo "Installation target:"
echo "$PREFIX"
echo
#
FC=nagfor61
FCFLAGS="-O0 -w"

# If ROPP_BUILD_DEPS_PATH set, we want to build outside ROPP_SRC
# (nfs versus local mount).
if test -n "$ROPP_BUILD_DEPS_PATH"; then
    deps_src=$ROPP_BUILD_DEPS_PATH
    test -d $deps_src || { echo "$ROPP_BUILD_DEPS_PATH no such directory"; exit 1; }
else
    deps_src=$ROPP_SRC
fi

mfile=$(find ${deps_src}/sofa -name makefile)
test -f $mfile || { echo "No makefile found in $dep_src"; exit 1; }

if [[ ! -f ${mfile}.original ]] ; then # make one
  cp $mfile ${mfile}.original
else # work on a copy of the original
  cp ${mfile}.original $mfile
fi

# Tailor the modifications to this compiler.  Need to compile without optimisation,
# otherwise the test will detect differences and fail.
sed -i "s:INSTALL_DIR = \$(HOME):INSTALL_DIR = ${PREFIX}:g"  $mfile
sed -i "s:FC = gfortran:FC = ${FC}:g"                        $mfile
sed -i "s:FX = -O -Wall:FX = ${FCFLAGS}:g"                   $mfile

# Also need to suppress CALL EXIT(JESTAT) in t_sofa_f.for, as this is
# apparently no longer supported by nagfor.

tfile=$(find ${deps_src}/sofa -name t_sofa_f.for)
test -f $tfile || { echo "No testfile found in $dep_src"; exit 1; }

if [[ ! -f ${tfile}.original ]] ; then # make one
  cp $tfile ${tfile}.original
else # work on a copy of the original
  cp ${tfile}.original $tfile
fi

# Tailor the code for this compiler.
sed -i "s:      CALL EXIT(JESTAT):*      CALL EXIT(JESTAT):g"  $tfile

