#!/bin/bash

# These variables need to exist
prefix=/usr
exec_prefix=/usr

if [[ $# -eq 0 || -n $( echo $* | egrep -- "--help|-h" ) ]]; then
    echo
    echo "apfel-config: configuration tool for APFEL: A PDF Evolution Library"
    echo "              webpage: http://apfel.hepforge.org"
    echo
    echo "Usage: apfel-config [[--help|-h] | [--prefix] | [--ldflags]]"
    echo "Options:"
    echo "  --help | -h    : show this help message"
    echo "  --version      : show the code version"
    echo "  --prefix       : show the installation prefix (cf. autoconf)"
    echo "  --incdir       : show the path to the APFEL header directory (for C++ interface)"
    echo "  --libdir       : show the path to the APFEL library directory"
    echo "  --cppflags     : get compiler flags for use with the C preprocessor stage of C++ compilation"
    echo "  --cxxflags     : get compiler flags for use with the C preprocessor stage of C++ compilation"
    echo "  --ldflags      : get compiler flags for use with the linker stage of any compilation"
    echo "  --ldflagsevol  : get compiler flags for use with the linker stage only evolution"
    echo "  --list-funcs   : list functions available in the current version of APFEL with a short description"
    echo "  --checkapfel   : check apfel internal functions in the current machine"
    echo
    echo "  --version      : returns APFEL release version number"
fi

OUT=""

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

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

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

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

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

tmp=$( echo "$*" | egrep -- '--\<ldflags\>')
test -n "$tmp" && OUT="$OUT -L/usr/lib -lAPFEL"

tmp=$( echo "$*" | egrep -- '--\<ldflagsevol\>')
test -n "$tmp" && OUT="$OUT -L/usr/lib -lAPFELevol"

tmp=$( echo "$*" | egrep -- '--\<list-funcs\>')
test -n "$tmp" && ListFunctions

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

## Version
tmp=$( echo "$*" | egrep -- '--\<version\>')
test -n "$tmp" && OUT="$OUT 3.1.1"

echo $OUT
