#!/bin/bash
# $Id: sofa_configure_pgf15_linux 5714 2019-02-13 15:51:08Z idculv $
#
# SOFA shell script for a local 'configure' for ROPP
# USERS SHOULD MODIFY THIS SCRIPT AS REQUIRED FOR LOCAL INSTALL
#
# Compiler: pgf15 / Linux
#
PREFIX=${1-$ROPP_ROOT/pgf15}
echo
echo "Platform:"
uname -a
echo
echo "Fortran compiler:"
pgf15 --version
echo
echo "Installation target:"
echo "$PREFIX"
echo
#
FC=pgf15
FCFLAGS="-O0 -tp penryn-64 -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 makefile to this compiler/platform.  Must 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

