#!/bin/sh
# $Id$
# Copyright (C) 2004-2007 Alexander Chernov <cher@ejudge.ru>

prefix="/usr"
exec_prefix="/usr"
bindir="/usr/bin"
datarootdir="${prefix}/share"
datadir="/usr/share"
includedir="/usr/include"
libdir="/usr/lib64"
libexecdir="/usr/lib"
cgibindir="/usr/lib/ejudge/cgi-bin"

static_flag=""
no_rpath_flag="1"

# This variable is updated on each build
build_version="3.5.1 #1"

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

General options:
  --help               print this message
  --version            print the version of ejudge associated with this script
  --cflags             print C the compilation flags for libchecker
  --ldflags            print C the linking flags for libchecker
  --libs               print C the libraries for libchecker
EOF
  exit 0
}

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

while [ $# -ne 0 ]
do
  case "$1" in
      --help) usage;;
      --version)
          echo "${build_version}"
          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=""

if [ x"${need_cflags}" = x1 ]
then
  eval fullincldir="${includedir}"/ejudge
  [ x"${output}" != x ] && output="${output} "
  output="${output}-I${fullincldir}"
fi

if [ x"${need_ldflags}" = x1 ]
then
  eval fulllibdir="${libdir}"
  [ 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}-lchecker -lm"
fi

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

exit 0

