#!/bin/sh
# $Id: reuse-config.v.in 535 2008-12-27 18:46:23Z cher $
# Copyright (C) 2004-2008 Alexander Chernov <cher@ejudge.ru>

prefix="/usr"
exec_prefix="/usr"
bindir="/usr/bin"
datarootdir="${prefix}/share"
datadir="/usr/share"
includedir="/usr/include"
libdir="${exec_prefix}/lib64"
libexecdir="/usr/lib"
build="x86_64-alt-linux-gnu"
libcap_name=""

# This variable is updated on each build
build_version="4.3.8"

usage() {
cat <<EOF
Usage: reuse-config [OPTION]...

General options:
  --help               print this message
  --version            print the version of reuse associated with this script
  --build              print the configuration name
  --prefix             print the installation prefix
  --cflags             print C the compilation flags for reuse
  --ldflags            print C the linking flags for reuse
  --libs               print C the libraries for reuse
EOF
  exit 0
}

if [ $# -eq 0 ]; then
    usage
fi

while [ $# -ne 0 ]
do
  case "$1" in
      --help) usage;;
      --binmode)
          shift
          ;;
      --version)
          echo "${build_version}"
          exit 0;;
      --build)
          echo "${build}"
          exit 0;;
      --prefix)
          echo "${prefix}"
          exit 0;;
      --cflags)
          need_cflags=1
          shift
          ;;
      --ldflags)
          need_ldflags=1
          shift
          ;;
      --libs)
          need_libs=1
          shift
          ;;
      *)
          echo "Invalid option. Type $0 --help for help" >&2
          exit 1;;
  esac
done

output=""

eval fullincldir="${includedir}"
eval fulllibdir="${libdir}"

if [ x"${need_cflags}" = x1 ]
then
  [ x"${output}" != x ] && output="${output} "
  output="${output}-I${fullincldir} -I${libdir}/reuse/include"
fi

if [ x"${need_ldflags}" = x1 ]
then
  [ x"${output}" != x ] && output="${output} "
  output="${output}-L${fulllibdir}"
  if [ x"${no_rpath_flag}" != x1 -a x"${static_flag}" != x1 ]
  then
    output="${output} -Wl,-rpath,${fulllibdir}"
  fi
fi

if [ x"${need_libs}" = x1 ]
then
  [ x"${output}" != x ] && output="${output} "
  output="${output}-lreuse ${libcap_name} -lm"
fi

if [ x"${output}" != x ]
then
  echo "${output}"
fi

exit 0
