#! /usr/bin/env bash
#Adopted from
#https://yoda.hepforge.org/trac/browser/bin/yoda-config.in
#Docs from https://cmake.org/cmake/help/v3.2/command/configure_file.html
## 
#The line below assures at least some relocation.
prefix=$(dirname $(dirname $(readlink -f  $0)))

tmp=$(echo $* | egrep -- '--\<help\>|-\<h\>')
if test $# -eq 0 || test -n "$tmp"; then
    echo "HepMC-config: configuration tool for the HepMC library"
    echo
    echo "Usage: $( basename $0 ) [--help|-h] | "
    echo "           [--{prefix,libdir,includedir}] | "
    echo "           [--{cxxflags,ldflags,libs}] | "
    echo "           [--version]"
    echo "Options:"
    echo "  --help | -h   : show this help message"
    echo
    echo "  --prefix      : show the installation prefix"
    echo "  --includedir  : show the path to the directory containing the HepMC headers"
    echo "  --libdir      : show the path to the directory containing the HepMC libraries"
    echo
    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 "  --static            : returns a string for insertion into LIBS or LIBADD"
    echo "  --rootIO            : returns a '-L/-l' string for insertion into LIBS or LIBADD with rootIO support"
    echo
    echo "  --version           : returns the HepMC release version number"
    exit 0
fi

OUT=""

tmp=$( echo "$*" | egrep -- '--\<prefix\>')
test -n "$tmp" && OUT="$OUT $prefix"

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

tmp=$( echo "$*" | egrep -- '--\<libdir\>')
test -n "$tmp" && OUT="$OUT $prefix//usr/lib64"

tmp=$( echo "$*" | egrep -- '--\<cflags|cppflags|cxxflags\>')
test -n "$tmp" && OUT="$OUT -I$prefix/include"

tmp=$( echo "$*" | egrep -- '--\<ldflags|libs\>')
test -n "$tmp" && OUT="$OUT -L$prefix//usr/lib64 -lHepMC"

tmp=$( echo "$*" | egrep -- '--\<static\>')
test -n "$tmp" && OUT="$OUT $prefix//usr/lib64/libHepMC.a -lHepMC"

tmp=$( echo "$*" | egrep -- '--\<rootIO\>')
test -n "$tmp" && OUT="$OUT -L$prefix//usr/lib64  "

tmp=$( echo "$*" | egrep -- '--\<version\>')
test -n "$tmp" && echo 3&& exit 0

echo $OUT
