#!/bin/sh
# Stolen from rep-config and adapted for use with xmlrpc-c.
# Other bits stolen from gnome-config & automake output.

prefix=/usr
exec_prefix=${prefix}

bindir=${exec_prefix}/bin
sbindir=${exec_prefix}/sbin
libexecdir=${exec_prefix}/libexec
datadir=${prefix}/share
sysconfdir=${prefix}/etc
sharedstatedir=${prefix}/com
localstatedir=${prefix}/var
libdir=${exec_prefix}/lib
infodir=${prefix}/share/info
mandir=${prefix}/share/man
includedir=${prefix}/include

pkgdatadir=$datadir/xmlrpc-c
pkglibdir=$libdir/xmlrpc-c
pkgincludedir=$includedir/xmlrpc-c

usage="Usage: xmlrpc-c-config <module>... <flag>

You may optionally specify one or more modules:
  c++            C++ wrapper code
  libwww-client  libwww-based client
  cgi-server     CGI-based server
  abyss-server   ABYSS-based server

Available flags include:
  --version      The version number of the package
  --modules      List all modules currently installed
  --cflags       C compiler flags to use when '#include'ing package headers
  --libs         Libraries and flags to use when linking programs normally
  --ldadd        Libraries to use with automake
  --ldflags      Flags to use with automake & libtool
  --prefix       The prefix under which the package was installed
  --exec-prefix  The executable prefix under which the package was installed
  --*dir         The various directories under which the package was installed"

if test $# -eq 0; then
      echo "${usage}" 1>&2
      exit 1
fi

the_libdirs="-L${exec_prefix}/lib"
the_libs="-lxmlrpc -lxmlrpc_xmlparse -lxmlrpc_xmltok"
the_rpath=
the_wl_rpath=
cpp_libs=

while test $# -gt 0; do
  case $1 in
    c++)
      cpp_libs="-lxmlrpc_cpp "
      ;;
    cgi-server)
      the_libs="-lxmlrpc_cgi $the_libs"
      ;;
    abyss-server)
      the_libs="-lxmlrpc_abyss_server -lxmlrpc_abyss $the_libs"
      ;;
    libwww-client)
      the_libdirs="-L/usr/lib $the_libdirs"
      the_libs="-lxmlrpc_client -L/usr/lib -lwwwzip -lwwwinit -lwwwapp -lwwwhtml -lwwwtelnet -lwwwnews -lwwwhttp -lwwwmime -lwwwgopher -lwwwftp -lwwwfile -lwwwdir -lwwwcache -lwwwstream -lwwwmux -lwwwtrans -lwwwcore -lwwwutils -lmd5 -ldl -lz $the_libs"
      the_rpath="-rpath /usr/lib $the_rpath"
      the_wl_rpath="-Wl,--rpath -Wl,/usr/lib $the_wl_rpath"
      ;;
    --version)
      echo "0.9.9"
      exit 0
      ;;
    --modules)
      echo "c++ cgi-server abyss-server libwww-client "
      exit 0
      ;;
    --cflags)
      echo "-I${prefix}/include"
      exit 0
      ;;
    --libs)
      echo "$the_libdirs $cpp_libs$the_libs $the_wl_rpath"
      exit 0
      ;;
    --ldadd)
      echo "$the_libdirs $cpp_libs$the_libs"
      exit 0
      ;;
    --ldflags)
      echo "$the_rpath"
      exit 0
      ;;
    --prefix)
      echo "/usr"
      exit 0
      ;;
    --exec-prefix)
      echo "${prefix}"
      exit 0
      ;;
    --*dir)
      # Swiped from gnome-config.
      dirname=\$`echo $1 | sed -e 's,^--,,'`
      dirname=`eval echo $dirname`
      test -z "$dirname" && exit 1
      echo $dirname
      exit 0
      ;;
    --help)
      echo "${usage}" 1>&2
      exit 0
      ;;
    *)
      echo "${usage}" 1>&2
      exit 1
      ;;
  esac
  shift
done

echo "${usage}" 1>&2
exit 1
