#!/bin/sh
#
srcdir=.
prefix=/usr/pkg
exec_prefix=${prefix}
bindir=${exec_prefix}/bin
sbindir=${exec_prefix}/sbin
libdir=${exec_prefix}/lib
datarootdir=${prefix}/share
datadir=${datarootdir}
includedir=${prefix}/include/validator
mandir=/usr/pkg/man

lvc_PREFIX=$prefix
lvc_EXEC_PREFIX=$exec_prefix
lvc_INCLUDEDIR=$includedir
lvc_DEVCFLAGS=""
lvc_CFLAGS="-O2 -I/usr/pkg/include -I/usr/include -Unetbsdelf -Dnetbsdelf=netbsdelf -Unetbsdelf -Dnetbsdelf=netbsdelf -DLIBVAL_CONFIGURED=1"
lvc_CPPFLAGS="-I/usr/pkg/include -I/usr/include"
lvc_LDFLAGS="-L/usr/pkg/lib -Wl,-R/usr/pkg/lib/perl5/5.40.0/earmv4-netbsd-thread-multi/CORE -L/usr/lib -Wl,-R/usr/lib -Wl,-R/usr/pkg/lib"
lvc_LIBS="-lssl -lcrypto  -lpthread"
lvc_LIBDIR="-L${libdir}"
LIBVAL_SUFFIX=-threads

lvc_RESOLV_CONF="/usr/pkg/etc/dnssec-tools/dnssec-tools/resolv.conf"
lvc_ROOT_HINTS="/usr/pkg/etc/dnssec-tools/dnssec-tools/root.hints"
lvc_DNSVAL="/usr/pkg/etc/dnssec-tools/dnsval.conf"

if test "x$1" = "x"; then
  usage="yes"
else
  while test "x$done" = "x" -a "x$1" != "x" -a "x$usage" != "xyes"; do
  case "$1" in
    -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
    *) optarg= ;;
  esac

  case $1 in
    --prefix=*)
      prefix=$optarg
      lvc_PREFIX=${prefix}
      lvc_INCLUDEDIR=${prefix}/include
      lvc_LIBDIR=-L${prefix}/lib
      ;;

    --exec-prefix=*)
      exec_prefix=$optarg
      lvc_EXEC_PREFIX=${exec_prefix}
      lvc_LIBDIR=-L${exec_prefix}/lib
      ;;

    --configure-options|--con*)
      echo " '--disable-option-checking' '--prefix=/usr/pkg' '--with-nsec3' '--with-resolv-conf=/usr/pkg/etc/dnssec-tools/dnssec-tools/resolv.conf' '--with-root-hints=/usr/pkg/etc/dnssec-tools/dnssec-tools/root.hints' '--with-perl-build-args=INSTALLDIRS=vendor' '--with-ipv6' '--without-dlv' 'BIND_DNSSEC_KEYGEN=/usr/sbin/dnssec-keygen' 'BIND_DNSSEC_SIGNZONE=/usr/sbin/dnssec-signzone' 'BIND_DNSSEC_CHECKZONE=/usr/sbin/named-checkzone' '--build=armv4--netbsdelf-eabi' '--host=armv4--netbsdelf-eabi' '--mandir=/usr/pkg/man' '--enable-option-checking=yes' 'build_alias=armv4--netbsdelf-eabi' 'host_alias=armv4--netbsdelf-eabi' 'CC=gcc' 'CFLAGS=-O2 -I/usr/pkg/include -I/usr/include' 'LDFLAGS=-L/usr/pkg/lib -Wl,-R/usr/pkg/lib/perl5/5.40.0/earmv4-netbsd-thread-multi/CORE -L/usr/lib -Wl,-R/usr/lib -Wl,-R/usr/pkg/lib' 'LIBS=' 'CPPFLAGS=-I/usr/pkg/include -I/usr/include' '--cache-file=/dev/null' '--srcdir=.'"
      ;;
    #################################################### compile
    --base-cflags)
      echo ${lvc_CFLAGS} ${lvc_CPPFLAGS} -I${lvc_INCLUDEDIR}
      ;;
    --cflags|--cf*)
      echo ${lvc_CFLAGS} ${lvc_DEVFLAGS} ${lvc_CPPFLAGS} -I. -I${lvc_INCLUDEDIR}
      ;;
    --srcdir)
      echo $lvc_SRCDIR
      ;;
    #################################################### linking
    --libdir|--lib-dir)
      echo $lvc_LIBDIR
      ;;
    --ldflags|--ld*)
      echo $lvc_LDFLAGS
      ;;
    #################################################### client lib
    --libs)
      # use this one == --libval-libs + --external-libs
      echo $lvc_LDFLAGS $lvc_LIBDIR -lsres -lval${LIBVAL_SUFFIX} $lvc_LIBS
      ;;
    --libval-libs)
      echo $lvc_LIBDIR -lsres -lval${LIBVAL_SUFFIX}
      ;;
    --external-libs)
      echo $lvc_LDFLAGS $lvc_LIBS
      ;;
    ####################################################
    --resolver-config|--res*)
        echo $lvc_RESOLV_CONF
        ;;
    --root-hints|--roo*)
        echo $lvc_ROOT_HINTS
        ;;
    --dnsval-config|--dns*)
        echo $lvc_DNSVAL
        ;;
    ####################################################
    --version|--ver*)
      echo 0.3
      ;;
    --help)
      usage="yes"
      ;;
    --prefix|--pre*)
      echo $lvc_PREFIX
      ;;
    --exec-prefix)
      echo $lvc_EXEC_PREFIX
      ;;
    *)
      echo "unknown option $1"
      usage="yes"
      ;;
  esac
  shift
  done
fi

if test "x$usage" = "xyes"; then
  echo ""
  echo "Usage:"
  echo "  libval-config [--cflags] [--agent-libs] [--libs] [--version]"
  echo "                  ... [see below for complete flag list]"
  echo ""
  echo "    --version         displays the libval version number"
  echo ""
  echo "  These options produce the various compilation flags needed when"
  echo "  building external SNMP applications:"
  echo ""
  echo "    --base-cflags     lists additional compilation flags needed"
  echo "    --cflags          lists additional compilation flags needed"
  echo "                      (includes -I. and extra developer warning flags)"
  echo ""
  echo "  These options produce the various link flags needed when"
  echo "  building external SNMP applications:"
  echo ""
  echo "    --libs            lists libraries needed for building applications"
  echo ""
  echo "  These options produce various link flags broken down into parts."
  echo "  (Most of the time the simple options above should be used.)"
  echo ""
  echo "    --libdir              path to libval"
  echo ""
  echo "    --libval-libs         libval (with path)"
  echo ""
  echo "    --ldflags             link flags for external libraries"
  echo "    --external-libs       external libraries needed by libval"
  echo ""
  echo "  Details on how the libval package was compiled:"
  echo ""
  echo "    --configure-options   display original configure arguments"
  echo "    --prefix              display the installation prefix"
  echo ""
  echo "    --resolver-config     display path to resolver configuration"
  echo "    --root-hints          display path to root hints file"
  echo "    --dnsval-config       display path to dnsval configuration"
  exit
fi  
