#! /usr/bin/env bash
## bin/yoda-config.  Generated from yoda-config.in by configure.

tmp=$(echo $* | grep -E -- '--\<help\>|-\<h\>')
if test $# -eq 0 || test -n "$tmp"; then
    echo "yoda-config: configuration tool for the YODA data analysis library"
    echo
    echo "Usage: $( basename $0 ) [--help|-h] | "
    echo "           [--{prefix,datadir,libdir,includedir}] | "
    echo "           [--{cxxflags,ldflags,libs}] | "
    echo "           [--version]"
    echo "Options:"
    echo "  --help | -h   : show this help message"
    echo
    echo "  --prefix      : show the installation prefix (cf. autoconf)"
    echo "  --includedir  : show the path to the directory containing the YODA headers"
    echo "  --libdir      : show the path to the directory containing the YODA libraries"
    echo "  --pythonpath  : show the path(s) to the directory containing YODA's Python package"
    echo
    echo "  --guess-prefix: try to use the runtime prefix, rather than that set at install-time"
    echo
    echo "  --cxx               : returns a compiler string matching that used to build YODA"
    echo "  --cflags|--cppflags : returns a '-I' string for insertion into CPPFLAGS or CXXFLAGS"
    echo "  --ldflags|--libs    : returns a '-L/-l' string for insertion into LIBS or LIBADD"
    echo
    echo "  --version     : returns the YODA release version number"
    if [[ $# -eq 0 ]]; then exit 1; else exit 0; fi
fi


## These variables need to exist
## Note no use of $DESTDIR... we ignore it so that destdir can be used
## for temp installs later copied to /
tmp=$( echo "$*" | grep -E -- '--\<guess-prefix\>')
if [[ -n "$tmp" ]]; then
    bindir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
    prefix=$(dirname $bindir)
    exec_prefix=$prefix
else
    prefix=/Users/chrisg/software/yoda/local
    exec_prefix=${prefix}
fi
datarootdir=${prefix}/share


OUT=""

## "Atomic" build info
tmp=$( echo "$*" | grep -E -- '--\<cxx\>')
test -n "$tmp" && OUT="$OUT g++ -std=gnu++11 -std=c++17"

tmp=$( echo "$*" | grep -E -- '--\<prefix\>')
test -n "$tmp" && OUT="$OUT /Users/chrisg/software/yoda/local"

tmp=$( echo "$*" | grep -E -- '--\<includedir\>')
test -n "$tmp" && OUT="$OUT ${prefix}/include"

tmp=$( echo "$*" | grep -E -- '--\<libdir\>')
test -n "$tmp" && OUT="$OUT ${exec_prefix}/lib"

tmp=$( echo "$*" | grep -E -- '--\<pythonpath|pydir\>')
test -n "$tmp" && OUT="$OUT /Users/chrisg/software/yoda/local/lib/python3.13/site-packages"


## "Pre-rolled" build info
tmp=$( echo "$*" | grep -E -- '--\<cflags\>|--\<cxxflags\>')
test -n "$tmp" && OUT="$OUT -O3"

tmp=$( echo "$*" | grep -E -- '--\<cppflags\>')
if test -n "$tmp"; then
  iyoda="${prefix}/include"
  test -n "$iyoda" && OUT="$OUT -I${iyoda}"
  ihdf5="-I/opt/homebrew/Cellar/hdf5-mpi/1.14.6/include -I/opt/homebrew/include"
  test -n "$ihdf5" && OUT="$OUT ${ihdf5}"
  ihighfive=""
  test -n "$ihighfive" && OUT="$OUT ${ihighfive}"
  iyamlcpp=""
  test -n "$iyamlcpp" && OUT="$OUT ${iyamlcpp}"
fi

tmp=$( echo "$*" | grep -E -- '--\<ldflags\>|--\<libs\>')
if test -n "$tmp"; then
  lyoda="${exec_prefix}/lib"
  test -n "$lyoda" && OUT="$OUT -L${lyoda}"
  lh5=" -L/opt/homebrew/lib  -lhdf5 -lhdf5_hl "
  test -n "$lh5" && OUT="$OUT ${lh5}"
  lyaml=""
  test -n "$lyaml" && OUT="$OUT ${lyaml}"
fi

tmp=$( echo "$*" | grep -E -- '--\<libs\>|--\<ldadd\>')
test -n "$tmp" && OUT="$OUT -lYODA"


## Version
tmp=$( echo "$*" | grep -E -- '--\<version\>')
test -n "$tmp" && echo 2.1.0 && exit 0

echo $OUT
