# Configuration for ht://Dig 3.x
# Copyright (c) 1995-1999 The ht://Dig Group
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

AC_INIT(htcommon/DocumentDB.cc)
VERSION=`cat ${srcdir}/.version`
AM_INIT_AUTOMAKE([htdig], $VERSION)
AC_PREREQ(2.13)

AC_CONFIG_HEADER(include/htconfig.h)
AC_PREFIX_DEFAULT(/opt/www/htdig)
HTDIG_TOP=`pwd`
AC_SUBST(HTDIG_TOP)

dnl Get any --with or --disable flags now
dnl This looks a little messy, but it's word-wrapping problems :-(
AC_ARG_ENABLE(zlib,[  --disable-zlib          do not compile with zlib support],
	WITH_ZLIB=$enableval, WITH_ZLIB="yes")
AC_ARG_WITH(cgi-bin-dir, [  --with-cgi-bin-dir=DIR  where your cgi-bin directory is],
	CGIBIN_DIR="$withval", CGIBIN_DIR="/opt/www/cgi-bin")
AC_SUBST(CGIBIN_DIR)
AC_ARG_WITH(image-dir, [  --with-image-dir=DIR    where the ht://Dig images are installed],
	IMAGE_DIR="$withval", IMAGE_DIR="/opt/www/htdocs/htdig")
AC_SUBST(IMAGE_DIR)
AC_ARG_WITH(search-dir, [  --with-search-dir=DIR   where the sample search form should be installed],
	SEARCH_DIR="$withval", SEARCH_DIR="/opt/www/htdocs/htdig")
AC_SUBST(SEARCH_DIR)

dnl While we're at it, let's work out the program transformations
AC_ARG_PROGRAM

echo configuring ht://Dig version $VERSION

dnl Checks for programs.
AC_PROG_CC
AC_PROG_CXX
AC_PROG_RANLIB
AC_PATH_PROG(AR, ar, ar)
AC_PATH_PROG(SHELL, sh, /bin/sh)
AC_PATH_PROG(SED, sed, /bin/sed)
AC_PATH_PROG(SORT, sort, /bin/sort)
AC_PATH_PROG(FIND, find, /bin/find)
AC_PATH_PROG(GUNZIP, gunzip, /bin/gunzip)
AC_CHECK_PROGS(TAR, tar gtar gnutar, tar)
AC_PATH_PROG(PDF_PARSER, acroread, /usr/local/bin/acroread)
AC_PATH_PROG(SENDMAIL, sendmail, /usr/lib/sendmail, 
   $PATH:/usr/libexec:/usr/sbin:/usr/lib:/usr/etc:etc)

dnl Check for AIX problems
AC_AIX

dnl Checks for libraries.
AC_CHECK_LIB(socket, socket)
AC_CHECK_LIB(nsl, t_accept)
if test $WITH_ZLIB = yes; then
AC_CHECK_LIB(z, deflate)
fi

AC_SUBST(CXXFLAGS)dnl
AC_SUBST(LDFLAGS)dnl

dnl Checks for header files.
AC_HEADER_STDC
AC_HEADER_TIME

dnl More header checks--here use C++
AC_LANG_CPLUSPLUS
AC_CHECK_HEADERS(fcntl.h limits.h malloc.h sys/file.h sys/ioctl.h sys/time.h unistd.h getopt.h strings.h zlib.h alloca.h sys/select.h)
AC_CHECK_HEADER(fstream.h,nofstream=0,nofstream=1)
if test "x$nofstream" = "x1" ; then
AC_MSG_ERROR([To compile ht://Dig, you will need a C++ library. Try installing libstdc++.])
fi

dnl Checks for typedefs, structures, and compiler characteristics.
AC_LANG_C
AC_C_CONST
AC_STRUCT_TM
dnl AC_CHECK_SIZEOF(int *) => SIZEOF_INT_P

dnl Checks for library functions.
AC_CHECK_FUNCS(strdup strerror strstr)
AC_CHECK_FUNCS(localtime_r)
dnl Check for timegm
AC_CHECK_FUNCS(timegm)

dnl These tests need to be run through the c++ compiler
AC_LANG_CPLUSPLUS
AC_MSG_CHECKING(whether we need gethostname() prototype?)
AC_TRY_COMPILE([#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/ioctl.h>
#include <sys/uio.h>
#include <sys/file.h>
#include <fcntl.h>
#include <netdb.h>
#include <stdlib.h>
extern "C" int gethostname(char *, int);],
  [gethostname("sdsu.edu", (int) 8);],
  [AC_MSG_RESULT(yes);AC_DEFINE(NEED_PROTO_GETHOSTNAME)],
  [AC_MSG_RESULT(no)])

AC_LANG_C
AC_MSG_CHECKING(how to call getpeername?)
for sock_t in 'struct sockaddr' 'void'; do
for getpeername_length_t in 'size_t' 'int' 'unsigned int' 'long unsigned int' 'socklen_t'; do
AC_TRY_COMPILE([#include <sys/types.h>
#include <sys/socket.h>],
[extern getpeername(int, $sock_t *, $getpeername_length_t *)],
[ac_found=yes ; break 2],ac_found=no)
done
done
  if test "$ac_found" = no; then
    AC_MSG_WARN([can't determine argument type using int])
    AC_DEFINE_UNQUOTED(GETPEERNAME_LENGTH_T, int)
  else
  AC_MSG_RESULT($getpeername_length_t)
  AC_DEFINE_UNQUOTED(GETPEERNAME_LENGTH_T, $getpeername_length_t)
  fi

dnl Any final tests probably want the C compiler
AC_LANG_C

if test ! -d "./db"; then
  mkdir db
fi
AC_CONFIG_SUBDIRS(db/dist)

AC_OUTPUT(CONFIG Makefile Makefile.config htcommon/Makefile htlib/Makefile htdig/Makefile htmerge/Makefile htnotify/Makefile htfuzzy/Makefile htsearch/Makefile makedp, chmod +x makedp, echo timestamp > stamp-h)

echo ""
echo ""
echo "Now you must run 'make' followed by 'make install'"
echo ""
