#!/bin/sh
VERSION=1.1
PREFIX=/usr/local

while [ -n "$1" ]
do
    case $1 in
    -prefix)
        shift
        PREFIX=$1
        ;;
    esac
    shift
done

(cd dox && qmake dox.pro)
(cd man2html && qmake dox-man2html.pro)
(cd htdig && qmake dox-htdig.pro)
(cd tags2dox && qmake dox-tags2dox.pro)

echo "Configuring for install directory $PREFIX"
echo "  You can change the install prefix by using configure -prefix /path"
echo "VERSION=$VERSION" > config.status
echo "PREFIX=$PREFIX" >> config.status
echo "#define PREFIX \"$PREFIX\"" > config.h

# htdig check

htdig=`which htdig 2>/dev/null`
if test -z "$htdig" ; then
  if test -x "/opt/www/htdig/bin/htdig" ; then
    htdig="/opt/www/htdig/bin/htdig"
  fi
fi
if test -n "$htdig" ; then
  htmerge=`which htmerge 2>/dev/null`
  if test -z "$htmerge" ; then
    if test -x "/opt/www/htdig/bin/htmerge" ; then
      htmerge="/opt/www/htdig/bin/htmerge"
    fi
  fi
fi
if test -n "$htmerge" ; then
  htsearch=`which htsearch 2>/dev/null`
  if test -z "$htsearch" ; then
    if test -x "/opt/www/cgi-bin/htsearch" ; then
      htsearch="/opt/www/cgi-bin/htsearch"
    fi
  fi
fi

if test -n "$htsearch" ; then
  echo "Found htdig as $htdig"
  echo "Found htmerge as $htmerge"
  echo "Found htsearch as $htsearch"
else
  echo "Did not find htdig, htmerge or htsearch."
  echo "  Full text search will not be available."
  echo "  Make sure these binaries are in your \$PATH"
  echo "  and rerun configure if you have htdig installed."
fi  
echo "#define HTDIG \"$htdig\"" >> config.h
echo "#define HTMERGE \"$htmerge\"" >> config.h
echo "#define HTSEARCH \"$htsearch\"" >> config.h

# whatis check

whatisout=`whatis -M /usr/share/man ls 2>/dev/null | grep -e '^ls'`
if test -n "$whatisout" ; then
  echo "Found that whatis supports -M option. Good."
  echo "#define HAVE_SANEWHATIS 1" >> config.h
else
  echo "Found that whatis does not support option -M"
  echo "  Will not be able to provide detailed man page titles"
fi

# KDE check

kdeconfig=`which kde-config 2>/dev/null`
if test -n "$kdeconfig" ; then
  kdehtmlpath=`kde-config --path html`
  echo "Found KDE HTML docs in $kdehtmlpath"
  echo "#define KDEHTMLPATH \"$kdehtmlpath\"" >> config.h
else
  echo "#define KDEHTMLPATH \"\"" >> config.h
fi

# GNUSTEP docs check

if test "${GNUSTEP_SYSTEM_ROOT+set}" = "set" ; then
  gnustepdocdir=$GNUSTEP_SYSTEM_ROOT/Documentation/Developer
fi

if test "${gnustepdocdir+set}" = "set" ; then
  echo "Found GNUStep docs in $gnustepdocdir"
  echo "GNUSTEPDOCDIR=$gnustepdocdir" >> config.status
else
  echo "Did not find GNUStep docs - not installing."
  echo "  Set the environment variable GNUSTEP_SYSTEM_ROOT if you"
  echo "  have GNUStep installed."
fi


echo "Run make now"
