#!/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//usr/lib64/mpich/lib
BOUT_INCLUDE_PATH=/usr//usr/include/mpich-aarch64/bout++
MPARK_VARIANT_INCLUDE_PATH=/usr/include
FMT_INCLUDE_PATH=/usr/include
BOUT_CONFIG_FILE=/make.config

cc="/usr/lib64/mpich/bin/mpicxx"
cxx="/usr/lib64/mpich/bin/mpicxx"
ld="/usr/lib64/mpich/bin/mpicxx"
checks="2"
cflags=" -I${BOUT_INCLUDE_PATH}  -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -mbranch-protection=standard -fasynchronous-unwind-tables -fstack-clash-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -I/usr/include/mpich-aarch64/petsc"
libs=" -Wl,-rpath,$BOUT_LIB_PATH -L$BOUT_LIB_PATH -lbout++ -lfmt"

version="5.2.0"
git="Unknown"
idlpath=""
pythonpath="/usr//usr/lib64/python3.12/site-packages/mpich"

has_netcdf="ON"
has_legacy_netcdf="OFF"
has_pnetcdf="OFF"
has_pvode="ON"
has_cvode="ON"
has_ida="ON"
has_lapack="TRUE"
has_petsc="ON"
has_hypre="OFF"
has_slepc="OFF"
has_arkode="ON"
has_openmp="OFF"
has_nls="ON"
has_fftw="ON"

petsc_has_sundials=""

metric_type="2D"

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-legacy-netcdf  Legacy NetCDF file support
  --has-pnetcdf Parallel NetCDF 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-hypre   Hypre support
  --has-slepc   SLEPc support
  --has-nls     Natural Language Support

  --petsc-has-sundials 

  --metric-type
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-legacy-netcdf  -> $has_legacy_netcdf"
        echo "  --has-pnetcdf -> $has_pnetcdf"
        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-hypre   -> $has_hypre"
        echo "  --has-slepc   -> $has_slepc"
        echo "  --has-arkode  -> $has_arkode"
        echo "  --has-nls     -> $has_nls"
        echo
        echo "  --petsc-has-sundials -> $petsc_has_sundials"
        echo
        echo "  --metric-type -> $metric_type"        
}

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-legacy-netcdf)
        echo $has_legacy_netcdf
        ;;

    --has-pnetcdf)
        echo $has_pnetcdf
        ;;

    --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-hypre)
        echo $has_hypre
        ;;

    --has-slepc)
        echo $has_slepc
        ;;

    --has-arkode)
	    echo $has_arkode
	    ;;

    --has-openmp)
	    echo $has_openmp
	    ;;

    --has-nls)
	    echo $has_nls
	    ;;

    --metric-type)
	    echo $metric_type
	    ;;
    
    --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
