#!/bin/bash
## -*- sh -*-
## bin/rivet-config.  Generated from rivet-config.in by configure.

print_help() {
cat <<EOF
rivet-config: configuration tool for the Rivet generator validation system
              http://projects.hepforge.org/rivet/

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

  --prefix              : show the installation prefix (cf. autoconf)
  --includedir          : show the path to the directory containing the Rivet headers
  --libdir              : show the path to the directory containing the Rivet libraries
  --datadir             : show the path to the directory containing Rivet data
  --pythonpath|--pydir  : show the path(s) to the directory containing Rivet'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 Rivet
  --cxxflags              : returns a string matching the compiler flags used to build Rivet
  --cflags|--cppflags     : returns a Rivet '-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 LDFLAG
  --ldlibs|--libs-only-l  : returns a '-l' string for insertion into LDLIBS

  --version     : returns Rivet 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 "4.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=/usr
    exec_prefix=/usr
fi

OUT=""

## "Atomic" build info
[ "$show_cxxexe" -eq 1 ] && OUT="$OUT g++"
[ "$show_prefix" -eq 1 ] && OUT="$OUT /usr"
[ "$show_datdir" -eq 1 ] && OUT="$OUT ${prefix}/share/Rivet"
[ "$show_incdir" -eq 1 ] && OUT="$OUT /usr/include"
[ "$show_libdir" -eq 1 ] && OUT="$OUT /usr/lib64"
[ "$show_pypath" -eq 1 ] && OUT="$OUT /usr/lib64/python3.13/site-packages"

## "Pre-rolled" build info
[ "$show_cflags" -eq 1 ] && OUT="$OUT -std=c++17 -O2 -Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -flto=auto -g"
if [ "$show_iflags" -eq 1 ]; then
    irivet="-I/usr/include"
    test -n "$irivet" && OUT="$OUT ${irivet}"
    ihepmc="-I/usr/include"
    test -n "$ihepmc" && OUT="$OUT ${ihepmc}"
    iyoda="-I/usr/include -I/usr/include"
    test -n "$iyoda" && OUT="$OUT ${iyoda}"
    ifastjet="-I/usr/include"
    test -n "$ifastjet" && OUT="$OUT ${ifastjet}"
    ifjcontrib=""
    test -n "$ifjcontrib" && OUT="$OUT ${ifjcontrib}"
    iyamlcpp=""
    test -n "$iyamlcpp" && OUT="$OUT ${iyamlcpp}"
fi
if [ "$show_Lflags" -eq 1 ]; then
    lrivet="/usr/lib64"
    test -n "$lrivet" && OUT="$OUT -L${lrivet}"
    lldflags=" -flto=auto"
    test -n "$lldflags" && OUT="$OUT ${lldflags}"
    lhepmc="-L/usr/lib64"
    test -n "$lhepmc" && OUT="$OUT ${lhepmc}"
    lyoda="-L/usr/lib64"
    test -n "$lyoda" && OUT="$OUT ${lyoda}"
    lyaml=""
    test -n "$lyaml" && OUT="$OUT ${lyaml}"
    lfastjet="-L/usr/lib64"
    test -n "$lfastjet" && OUT="$OUT ${lfastjet}"
fi
if [ "$show_lflags" -eq 1 ]; then
  # remove potential duplicates
  TMP=`echo "-lRivet  -L/usr/lib64 -lYODA -lhdf5 -lhdf5_hl -lHepMC3 -lHepMC3search -lfastjettools -lfastjet -lgmp -lm -lfastjetplugins -lsiscone_spherical -lsiscone  -lfastjetcontribfragile -lfastjettools" | xargs -n1 | sort -u | xargs`
  OUT="$OUT $TMP"
fi

echo $OUT
