#!/usr/bin/sh

# This script returns information on BOUT++ configuration
#
# Borrowed idea and some code from NetCDF nc-config
#
#
# Configure sets these variables to the paths as they are
# at that time. If "make install" is used then the values
# are replaced with the install paths


BOUT_LIB_PATH=/usr/lib64/openmpi/lib
BOUT_INCLUDE_PATH=/usr/include/openmpi-ppc64le/bout++
MPARK_VARIANT_INCLUDE_PATH=
BOUT_CONFIG_FILE=/usr/share/bout++/make.config

cc="mpic++"
cxx="mpic++"
ld="mpic++"
checks="2"
cflags="-I$BOUT_INCLUDE_PATH -I/usr/include -I/usr/include -I/usr/include/openmpi-ppc64le/petsc -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mcpu=power8 -mtune=power8 -fasynchronous-unwind-tables -fstack-clash-protection -DHAS_PRETTY_FUNCTION -Wextra -Wnull-dereference -Wno-cast-function-type -DCHECK=2 -DSIGHANDLE -DLOGCOLOR -DBOUT_VERSION_STRING="4.4.2" -DBOUT_VERSION_DOUBLE=4.42 -DBACKTRACE -fPIC -DBOUT_HAS_FFTW -DNCDF4 -DHDF5 -DBOUT_HAS_PETSC -DBOUT_HAS_IDA -DBOUT_HAS_CVODE -DBOUT_HAS_ARKODE -DBOUT_HAS_PVODE -DBOUT_HAS_GETTEXT -DBOUT_LOCALE_PATH=/usr/share/locale -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mcpu=power8 -mtune=power8 -fasynchronous-unwind-tables -fstack-clash-protection -DHAS_PRETTY_FUNCTION -Wextra -Wnull-dereference -Wno-cast-function-type -DCHECK=2 -DSIGHANDLE -DLOGCOLOR -DBOUT_VERSION_STRING="4.4.2" -DBOUT_VERSION_DOUBLE=4.42 -DBACKTRACE -fPIC -DBOUT_HAS_FFTW -DNCDF4 -DHDF5 -DBOUT_HAS_PETSC -DBOUT_HAS_IDA -DBOUT_HAS_CVODE -DBOUT_HAS_ARKODE -DBOUT_HAS_PVODE -DBOUT_HAS_GETTEXT -DBOUT_LOCALE_PATH=/usr/share/locale -DBOUT_FLAGS_STRING=-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64 -mcpu=power8 -mtune=power8 -fasynchronous-unwind-tables -fstack-clash-protection -DHAS_PRETTY_FUNCTION -Wextra -Wnull-dereference -Wno-cast-function-type -DCHECK=2 -DSIGHANDLE -DLOGCOLOR -DBOUT_VERSION_STRING="4.4.2" -DBOUT_VERSION_DOUBLE=4.42  -DBACKTRACE -fPIC -DBOUT_HAS_FFTW -DNCDF4 -DHDF5 -DBOUT_HAS_PETSC -DBOUT_HAS_IDA -DBOUT_HAS_CVODE -DBOUT_HAS_ARKODE -DBOUT_HAS_PVODE -DBOUT_HAS_GETTEXT -DBOUT_LOCALE_PATH=/usr/share/locale -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64 -mcpu=power8 -mtune=power8 -fasynchronous-unwind-tables -fstack-clash-protection -DHAS_PRETTY_FUNCTION -Wextra -Wnull-dereference -Wno-cast-function-type -DCHECK=2 -DSIGHANDLE -DLOGCOLOR -DBOUT_VERSION_STRING="4.4.2" -DBOUT_VERSION_DOUBLE=4.42  -DBACKTRACE -fPIC -DBOUT_HAS_FFTW -DNCDF4 -DHDF5 -DBOUT_HAS_PETSC -DBOUT_HAS_IDA -DBOUT_HAS_CVODE -DBOUT_HAS_ARKODE -DBOUT_HAS_PVODE -DBOUT_HAS_GETTEXT -DBOUT_LOCALE_PATH=/usr/share/locale   "
libs="-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=sha1 -Wl,-dT,/builddir/build/BUILD/BOUT++-v4.4.2/.package_note-bout++-4.4.2-5.fc37.ppc64le.ld -lm -L$BOUT_LIB_PATH -lbout++ -lm -lfftw3 -L/usr/lib64 -lnetcdf_c++4 -lnetcdf -L/usr/lib64 -lhdf5_hl -lhdf5 -lhdf5_hl -lsz -lz -ldl -lm -L/usr/lib64/openmpi/lib -lpetsc -lhdf5 -lsundials_ida -lsundials_nvecparallel -lsundials_cvode -lsundials_nvecparallel -lsundials_arkode -lsundials_nvecparallel -L$BOUT_LIB_PATH -lpvode -lpvpre"

version="4.4.2"
git=""
idlpath=/usr/share/bout++/idllib/
pythonpath=/usr/share/bout++/pylib/

has_netcdf="yes"
has_pnetcdf="no"
has_hdf5="yes"
has_pvode="yes"
has_cvode="yes"
has_ida="yes"
has_lapack="no"
has_petsc="yes"
has_slepc="no"
has_mumps="no"
has_arkode="yes"
has_openmp="no"
has_nls="yes"
has_fftw="yes"

petsc_has_sundials="no"

usage()
{
    cat <<EOF
Usage: bout-config [OPTION]

Available values for OPTION include:

  --help      display this help message and exit
  --all       Print all configuration

  --cc        C compiler
  --cxx       C++ compiler
  --ld        Linker
  --cflags    pre-processor and compiler flags
  --libs      library linking flags
  
  --version      BOUT++ version
  --git          Git commit
  --checks       Run-time checking level
  --config-file  Full path to the configuration file
  --idl          IDL path
  --python       Python path

  --has-netcdf  NetCDF file support
  --has-pnetcdf Parallel NetCDF file support
  --has-hdf5    HDF5 file support
  --has-pvode   PVODE solver support
  --has-cvode   SUNDIALS CVODE solver support
  --has-ida     SUNDIALS IDA solver support
  --has-lapack  LAPACK support
  --has-petsc   PETSc support
  --has-slepc   SLEPc support
  --has-mumps   MUMPS support
  --has-nls     Natural Language Support

  --petsc-has-sundials 
EOF

    exit $1
}

all()
{
        echo
        echo "This version of BOUT++ has been built with the following features: "
        echo
        echo "  --cc          -> $cc"
        echo "  --cxx         -> $cxx"
        echo "  --ld          -> $ld"
        echo "  --cflags      -> $cflags"
        echo "  --libs        -> $libs"
        echo
        echo "  --version     -> $version"
        echo "  --git         -> $git"
        echo "  --checks      -> $checks"
        echo "  --config-file -> $BOUT_CONFIG_FILE"
        echo "  --idl         -> $idlpath"
        echo "  --python      -> $pythonpath"
        echo
        echo "  --has-netcdf  -> $has_netcdf"
        echo "  --has-pnetcdf -> $has_pnetcdf"
        echo "  --has-hdf5    -> $has_hdf5"
        echo "  --has-pvode   -> $has_pvode"
        echo "  --has-cvode   -> $has_cvode"
        echo "  --has-ida     -> $has_ida"
        echo "  --has-lapack  -> $has_lapack"
        echo "  --has-petsc   -> $has_petsc"
        echo "  --has-slepc   -> $has_slepc"
        echo "  --has-mumps   -> $has_mumps"
        echo "  --has-arkode  -> $has_arkode"
        echo "  --has-nls     -> $has_nls"
        echo
        echo "  --petsc-has-sundials -> $petsc_has_sundials"
        echo
}

if test $# -eq 0; then
    usage 2
fi

while test $# -gt 0; do
    case "$1" in
    # this deals with options in the style
    # --option=value and extracts the value part
    # [not currently used]
    -*=*) value=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
    *) value= ;;
    esac

    case "$1" in

    --help)
        usage 0
        ;;

    --all)
       all
       ;;

    --cc)
        echo $cc
        ;;

    --cxx)
        echo $cxx
        ;;

    --ld)
	echo $ld
	;;

    --cflags)
        echo $cflags
        ;;

    --libs)
        echo $libs
        ;;

    --version)
        echo $version
        ;;

    --git)
        echo $git
        ;;

    --checks)
        echo $checks
        ;;

    --config-file)
        echo $BOUT_CONFIG_FILE
        ;;

    --idl)
        echo $idlpath
        ;;

    --python)
        echo $pythonpath
        ;;

    --has-netcdf)
        echo $has_netcdf
        ;;

    --has-pnetcdf)
        echo $has_pnetcdf
        ;;

    --has-hdf5)
        echo $has_hdf5
        ;;

    --has-pvode)
        echo $has_pvode
        ;;

    --has-cvode)
        echo $has_cvode
        ;;

    --has-ida)
        echo $has_ida
        ;;

    --has-lapack)
        echo $has_lapack
        ;;

    --has-petsc)
        echo $has_petsc
        ;;

    --has-slepc)
        echo $has_slepc
        ;;

    --has-mumps)
        echo $has_mumps
        ;;

    --has-arkode)
	    echo $has_arkode
	    ;;

    --has-openmp)
	    echo $has_openmp
	    ;;

    --has-nls)
	    echo $has_nls
	    ;;

    
    --petsc-version)
        # TODO: Remove in next release
        # Left in for backwards-compatibility
        ;;

    --petsc-release)
        # TODO: Remove in next release
        # Left in for backwards-compatibility
        ;;

    --petsc-has-sundials)
        echo $petsc_has_sundials
        ;;

    *)
        echo "unknown option: $1"
        usage 2
        ;;
    esac
    shift
done

exit 0
