dnl Process this file with autoconf to produce a configure script.
dnl ====NOTE: When the user has PREFIX defined, use that one.
dnl ----------------------------------------------------------------

AC_INIT(sesame.c)
version=4.77 #`gawk '/^.VERSION/{v=$2}END{print v}' sesame.c`
AC_SUBST(version)

dnl The default PREFIX:
test "$USER" = "" && USER=`basename $HOME`
AC_PREFIX_DEFAULT(`test X$USER = Xcds && echo $HOME || echo /usr/local`)

dnl Checks for programs.
AC_PROG_MAKE_SET
AC_PROG_AWK
AC_PROG_CC

dnl Decide the daemon directories
AC_MSG_CHECKING(run-time log directories)
if test $USER = cds ; then
    LOGDIR=$HOME/log
    RUNDIR=$HOME/run
    CGIDIR=$HOME/httpd/cgi
    LOGDIR=$HOME/httpd/logs
    RUNln=1
else
    LOGDIR=/var/log
    CGIDIR=/usr/httpd/cgi
    RUNDIR=/var/tmp
    LOGDIR=/var/log/sesame
    RUNln=
fi
AC_MSG_RESULT($LOGDIR)
AC_SUBST(LOGDIR)
AC_SUBST(RUNDIR)
AC_SUBST(CGIDIR)
AC_SUBST(RUNln)

dnl Checks for libraries.
AC_PROG_RANLIB
AC_MSG_CHECKING(options from computer)
CC=cc
case `uname -m` in 
    alpha) a="alpha";   LIBSYS="-ldnet_stub" ;;
    sun4*) a="solaris"; LIBSYS="-lnsl -lsocket" ;
	test -x /opt/SUNWspro/bin/cc && CC=/opt/SUNWspro/bin/cc;
	$CC  -flags | grep '^-Xs' > /dev/null && cc_opt="-Xs" ;;
    i??6)  a="linux";   LIBSYS=""; cc_opt="-Wall" ;;
    x86*)  a="linux";   LIBSYS=""; cc_opt="-Wall" ;;
    *)     a="unknown"; LIBSYS="" ;;
esac
AC_MSG_RESULT($a)
AC_SUBST(cc_opt)
AC_SUBST(LIBSYS)
AC_SUBST(CC)

dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(fcntl.h termio.h dirent.h)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_SIZE_T
AC_STRUCT_TM
AC_SUBST(CC)

dnl Checks for library functions.
AC_TYPE_SIGNAL
AC_CHECK_FUNCS(gethostname socket strerror)

dnl ---- Verify the STRIP utility is not corrupted !
AC_MSG_CHECKING(strip utility)
echo '
#include <stdio.h>
int main()
{
  char buffer[[BUFSIZ]];
    while(fgets(buffer, sizeof(buffer), stdin))
        printf(">%s\\n", buffer);
}
' > ttest.c
$CC ttest.c
a=`strip a.out 2>&1| wc -w`
rm -f ttest.* a.out
if test $a -lt 1; then
    a=" ok "
    STRIP=strip
else
    a=" ***bad strip***"
    STRIP=echo
fi
AC_MSG_RESULT($a)
AC_SUBST(STRIP)

dnl Checks for as4 library
AC_MSG_CHECKING(as4 library)
HAS_AS4="-DHAS_AS4=0"
a="position not interpred, no libas4 in"
for d in /usr/local $HOME; do
    if test -r $d/lib/libas4.a ; then
	HAS_AS4="-DHAS_AS4=1"
        a="yes ($d/lib/libas4.a)"
    fi
    a="$a $d"
done
AC_MSG_RESULT($a)
AC_SUBST(HAS_AS4)

AC_OUTPUT(Makefile)

dnl --- Indicate the Default Directory Installation ---
echo "----the prefix for installation directories is:   $prefix"
echo "    If this choice is not convenient, re-execute this configure"
echo "    with the option       --prefix=(your_choice)"
