#! /bin/sh
#
# This forms the basis for the ccr-config utility, which provides
# the configuration of the CCR installation. This code was modified
# from the netCDF nc-config software originally by Arlindo DaSilva,
# Ed Hartnett, Ward Fisher, and Dennis Heimbigner
# Author: Charlie Zender

prefix=/mnt/beegfs/paulo.kubota/lib/lib_gnu/ccr
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

cc="gcc -I/mnt/beegfs/paulo.kubota/lib/lib_gnu//udunits/udunits-2.2.28/include"
cflags="-I${includedir} -I/mnt/beegfs/paulo.kubota/lib/lib_gnu/hdf5/hdf5-1.12.1/hdf5/include -I/mnt/beegfs/paulo.kubota/lib/lib_gnu/netcdf/include"
libs="-L${libdir} -lccr"
libsprivate="-ldl -lhdf5_hl -lhdf5 -lnetcdf -lm "

has_bzip2="yes"
has_lz4="no"
version="ccr 1.3.0"
has_par="no"
has_multifilters="yes"

has_fortran="no"

if test "x$has_fortran" = xyes; then
  fc="gfortran"
  fflags="-I${includedir} "
  flibs="-L${libdir} -lccrf -lccr"
  has_f90="no"
  has_f03="no"
fi

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

Available values for OPTION include:

  --all           display all options
  --cc            C compiler
  --cflags        pre-processor and compiler flags
  --has-bzip2     whether Bzip2 filter is installed
  --has-fortran   whether Fortran API is installed
  --has-lz4       whether LZ4 filter is installed
  --has-par       whether Parallel I/O is enabled
  --has-multifilters  whether Multifilters are enabled
  --help          display this help message and exit
  --includedir    Include directory
  --libdir        Library directory
  --libs          library linking information for CCR
  --prefix        Install prefix
  --version       Library version

EOF
if test "x$has_fortran" = xyes; then
    cat <<EOF
  --fc            Fortran compiler
  --fflags        flags needed to compile a Fortran program
  --flibs         libraries needed to link a Fortran program
  --has-f90       whether Fortran 90 API is installed
  --has-f03       whether Fortran 03 API is installed (implies F90).
EOF
fi
    exit $1
}

all()
{
        echo
        echo "This $version has been built with the following features: "
        echo
        echo "  --cc            -> $cc"
        echo "  --cflags        -> $cflags"
        echo "  --libs          -> $libs"
        echo

        echo "  --has-fortran   -> $has_fortran"
if test "x$has_fortran" = xyes; then
        echo "  --fc            -> $fc"
        echo "  --fflags        -> $fflags"
        echo "  --flibs         -> $flibs"
        echo "  --has-f90       -> $has_f90"
        echo "  --has-f03       -> $has_f03"
        echo
fi
        echo "  --has-bzip2     -> $has_bzip2"
        echo "  --has-lz4       -> $has_lz4"
        echo "  --has-par       -> $has_par"
        echo "  --has-multifilters      -> $has_multifilters"
        echo
        echo "  --prefix        -> $prefix"
        echo "  --includedir    -> $includedir"
        echo "  --libdir        -> $libdir"
        echo "  --version       -> $version"
        echo
}

if test $# -eq 0; then
    usage 1
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
        ;;

    --cflags)
        echo $cflags
        ;;

    --has-bzip2)
        echo $has_bzip2
        ;;

    --has-lz4)
        echo $has_lz4
        ;;

    --has-par)
        echo $has_par
        ;;

    --has-multifilters)
        echo $has_multifilters
        ;;

    --libs)
        echo $libs
        ;;

    --prefix)
        echo "${prefix}"
        ;;

    --includedir)
        echo "${includedir}"
        ;;

    --libdir)
        echo "${libdir}"
        ;;

    --version)
        echo $version
        ;;

    --has-fortran)
        echo $has_fortran
        ;;

    --fc)
        echo $fc
        ;;

    --fflags)
        echo $fflags
        ;;

    --flibs)
        echo $flibs
        ;;

    --has-f90)
        echo $has_f90
        ;;

    --has-f03)
        echo $has_f03
        ;;

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

exit 0
