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

print_help() {
cat <<EOF
yoda-config: configuration tool for the YODA data analysis library

Usage: $( basename $0 ) [--help|-h] |
           [--{prefix,datadir,libdir,includedir}] |
           [--{cxxflags,ldflags,libs}] |
           [--version]
Options:
  --help | -h   : show this help message

  --prefix              : show the installation prefix (cf. autoconf)
  --datadir             : show the path to the directory containing the YODA data
  --includedir          : show the path to the directory containing the YODA headers
  --libdir              : show the path to the directory containing the YODA libraries
  --pythonpath|--pydir  : show the path(s) to the directory containing YODA's Python package

  --guess-prefix: try to use the runtime prefix, rather than that set at install-time

  --cxx                   : returns a compiler string matching that used to build YODA
  --cxxflags              : returns a string matching the compiler flags used to build YODA
  --cflags|--cppflags     : returns a '-I' string for insertion into CPPFLAGS
  --libs                  : returns a '-L/-l' string for insertion into LDFLAGS/LDLIBS
  --ldflags|--libs-only-L : returns a '-L' string for insertion into LDFLAGS
  --ldlibs|--libs-only-l  : returns a '-l' string for insertion into LDLIBS

  --version     : returns the YODA release version number
EOF
}

## Check that arguments are valid
use_guess=0
show_prefix=0
show_datdir=0
show_incdir=0
show_libdir=0
show_pypath=0
show_cxxexe=0
show_cflags=0
show_iflags=0
show_Lflags=0
show_lflags=0
# Loop over arguments
for opt in "$@"; do
  case "$opt" in
    --help)         print_help && exit 0 ;;
    --h)            print_help && exit 0 ;;
    --version)      echo "2.1.2" && exit 0 ;;
    --guess-prefix) use_guess=1 ;;
    --prefix)       show_prefix=1 ;;
    --datadir)      show_datdir=1 ;;
    --includedir)   show_incdir=1 ;;
    --libdir)       show_libdir=1 ;;
    --pythonpath)   show_pypath=1 ;;
    --pydir)        show_pypath=1 ;;
    --cxx)          show_cxxexe=1 ;;
    --cxxflags)     show_cflags=1 ;;
    --cflags)       show_iflags=1 ;;
    --cppflags)     show_iflags=1 ;;
    --ldflags)      show_Lflags=1 ;;
    --libs-only-L)  show_Lflags=1 ;;
    --ldlibs)       show_lflags=1 ;;
    --libs-only-l)  show_lflags=1 ;;
    --libs)         show_Lflags=1; show_lflags=1 ;;
    *)              print_help
                    echo "Error: Unknown option '$opt'" >&2
                    exit 1 ;;
  esac
done

# Exit early if no valid options were given
if [ "$show_prefix" -eq 0 ] && [ "$show_datdir" -eq 0 ] &&
   [ "$show_incdir" -eq 0 ] && [ "$show_libdir" -eq 0 ] &&
   [ "$show_pypath" -eq 0 ] && [ "$show_cxxexe" -eq 0 ] &&
   [ "$show_cflags" -eq 0 ] && [ "$show_iflags" -eq 0 ] &&
   [ "$show_lflags" -eq 0 ] && [ "$show_Lflags" -eq 0 ]; then
  print_help
  echo "Error: No valid options provided." >&2
  exit 1
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 /
if [ "$use_guess" -eq 1 ]; 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

OUT=""

## "Atomic" build info
[ "$show_cxxexe" -eq 1 ] && OUT="$OUT g++"
[ "$show_prefix" -eq 1 ] && OUT="$OUT /Users/chrisg/software/yoda/local"
[ "$show_datdir" -eq 1 ] && OUT="$OUT ${prefix}/share/YODA"
[ "$show_incdir" -eq 1 ] && OUT="$OUT ${prefix}/include"
[ "$show_libdir" -eq 1 ] && OUT="$OUT ${exec_prefix}/lib"
[ "$show_pypath" -eq 1 ] && OUT="$OUT /Users/chrisg/software/yoda/local/lib/python3.13/site-packages"

## "Pre-rolled" build info
[ "$show_cflags" -eq 1 ] && OUT="$OUT -std=c++17 -O3"
if [ "$show_iflags" -eq 1 ]; 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
if [ "$show_Lflags" -eq 1 ]; then
  lyoda="${exec_prefix}/lib"
  test -n "$lyoda" && OUT="$OUT -L${lyoda}"
  lh5=" -L/opt/homebrew/lib"
  test -n "$lh5" && OUT="$OUT ${lh5}"
  lyaml=""
  test -n "$lyaml" && OUT="$OUT ${lyaml}"
fi
[ "$show_lflags" -eq 1 ] && OUT="$OUT -lYODA  -lhdf5 -lhdf5_hl "

echo $OUT
