dnl Process this file with Autoconf to create configure
dnl (c) COPYRIGHT MIT 1995.
dnl Please first read the full copyright statement in the file COPYRIGH.
dnl @(#) $Id: configure.in,v 1.89 2000/12/14 11:49:06 kahan Exp $

AC_REVISION([$Id: configure.in,v 1.89 2000/12/14 11:49:06 kahan Exp $])
AC_PREREQ(2.13)
AC_INIT(Library)

AC_CONFIG_AUX_DIR(config)

AC_CANONICAL_SYSTEM
AC_ARG_PROGRAM

dnl Initialize Automake.
PACKAGE=w3c-libwww
AC_SUBST(PACKAGE)
AC_DEFINE_UNQUOTED(W3C_PACKAGE, "$PACKAGE")
 
VERSION=5.3.2
AC_SUBST(VERSION)
AC_DEFINE_UNQUOTED(W3C_VERSION, "$VERSION")

#dnl for CVS to be able to make a release diff
PREVIOUS_VERSION=5.3.1
AC_SUBST(PREVIOUS_VERSION)

AM_INIT_AUTOMAKE($PACKAGE, $VERSION) 

AM_CONFIG_HEADER(wwwconf.h)

dnl Regular configure...
AC_PROG_CC
AC_ISC_POSIX
dnl AC_PROG_CXX		Caused problems and is not needed...
AC_CYGWIN 	dnl   You should probably
AC_MINGW32  	dnl   use all three of these
AC_EXEEXT   	dnl   for maximum portability
AM_PROG_LIBTOOL
AC_PROG_MAKE_SET
AC_PROG_INSTALL

dnl Remove next line and you get an error -- autoconf
dnl should deal with this automatically.
AC_PATH_X
dnl AC_PATH_XTRA 	Causes problems...

dnl Default location of icons
icondir=$datadir/$PACKAGE
AC_SUBST(icondir)

dnl Location for purify cache
PURIFY_CACHE=/tmp/purify.cache
AC_SUBST(PURIFY_CACHE)

dnl Various compiler directives
AC_MSG_CHECKING(whether to define additional compiler specific flags)
case "$target" in
    alpha-dec*)
	if test "$CC" = "cc"; then
	  CFLAGS="$CFLAGS -std1"
	  AC_MSG_RESULT(Digital Unix's cc)
	fi
	;;
    hp*)
	if test "$CC" = "cc"; then
	  CFLAGS="$CFLAGS -Aa -D_HPUX_SOURCE"
	  AC_MSG_RESULT(HT-UX's cc)
	fi
	;;
    i386-next-nextstep*)
	  CFLAGS="$CFLAGS -D_POSIX_SOURCE"
	  AC_MSG_RESULT(NextStep and OpenStep require _POSIX_SOURCE defined. This may cause some compilation warnings about pre-compiled headers but that should be OK)
	;;
    *)
	AC_MSG_RESULT(no)
	;;
esac

dnl Checks for programs.
AC_CHECK_PROGS(have_telnet, telnet)
if test -n "$have_telnet" ; then
  AC_DEFINE_UNQUOTED(TELNET_PROGRAM, "$have_telnet")
fi
AC_CHECK_PROGS(have_rlogin, rlogin)
if test -n "$have_rlogin" ; then
  AC_DEFINE_UNQUOTED(RLOGIN_PROGRAM, "$have_rlogin")
fi
AC_CHECK_PROGS(have_tn3270, tn3270 x3270)
if test -n "$have_tn3270" ; then
  AC_DEFINE_UNQUOTED(TN3270_PROGRAM, "$have_tn3270")
fi
AC_CHECK_PROGS(have_perl, perl)
if test ! -n "$have_perl" ; then
   AC_MSG_ERROR("Perl needs to be installed in order to compile libwww")
fi

AC_PATH_PROG(RM, rm, rm)
AC_PATH_PROG(AR, ar, ar)
AC_PATH_PROG(MKDIR, mkdir, mkdir)
AC_PATH_PROG(CHMOD, chmod, chmod)
AC_PATH_PROG(CP, cp, cp)
AC_PATH_PROG(TAR, tar, tar)
AC_PATH_PROG(CVS, cvs, cvs)
AC_PATH_PROG(SED, sed, sed)
AC_PATH_PROGS(COMPRESS, gzip compress, compress)
dnl JK 26/July/2000: desactivated the use of the www tool, as it's faster to
dnl use perl
dnl AC_PATH_PROGS(WWW, www, [""])
AC_PROG_LN_S

dnl Checks for misc files
dnl Resolv.conf
AC_PATH_PROG(have_resolv_conf, resolv.conf, , /etc, /usr/etc)
if test -n "$have_resolv_conf" ; then
  AC_DEFINE_UNQUOTED(RESOLV_CONF, "$have_resolv_conf")
fi

dnl This is the standard UNIX value
AC_DEFINE(CACHE_FILE_PREFIX, "/usr/wsrc/")

dnl Checks for libraries:
dnl AC_CHECK_LIB(ICE, IceConnectionNumber)
AC_CHECK_LIB(socket, socket)
AC_CHECK_LIB(inet, connect)
AC_CHECK_LIB(nsl, t_accept)
AC_CHECK_LIB(dl, dlopen)

dnl Checks for header files:
AC_CHECK_HEADERS(appkit/appkit.h appkit.h)
AC_CHECK_HEADERS(arpa/inet.h inet.h)
AC_CHECK_HEADERS(net/errno.h sys/errno.h errno.h)
AC_CHECK_HEADERS(netinet/in.h in.h)
AC_CHECK_HEADERS(netinet/tcp.h tcp.h)
AC_CHECK_HEADERS(sys/fcntl.h fcntl.h)
AC_CHECK_HEADERS(sys/file.h)
AC_CHECK_HEADERS(sys/ioctl.h)
AC_CHECK_HEADERS(sys/ipc.h)
AC_CHECK_HEADERS(sys/limits.h limits.h)
AC_CHECK_HEADERS(sys/machine.h)
AC_CHECK_HEADERS(sys/resource.h resource.h)
AC_CHECK_HEADERS(sys/select.h select.h)
AC_CHECK_HEADERS(sys/socket.h socket.h)
AC_CHECK_HEADERS(sys/stat.h stat.h)
AC_CHECK_HEADERS(sys/syslog syslog.h)
AC_CHECK_HEADERS(sys/systeminfo.h)
AC_CHECK_HEADERS(sys/time.h time.h)
AC_CHECK_HEADERS(sys/types.h types.h)
AC_CHECK_HEADERS(sys/unistd.h unistd.h)
AC_CHECK_HEADERS(wais/wais.h wais.h)
AC_CHECK_HEADERS(bsdtime.h)
AC_CHECK_HEADERS(bsdtypes.h)
AC_CHECK_HEADERS(ctype.h)
AC_CHECK_HEADERS(cursesX.h curses.h)
AC_CHECK_HEADERS(dn.h)
AC_CHECK_HEADERS(dnetdb.h)
AC_CHECK_HEADERS(grp.h)
AC_CHECK_HEADERS(libc.h)
AC_CHECK_HEADERS(malloc.h)
AC_CHECK_HEADERS(manifest.h)
AC_CHECK_HEADERS(memory.h)
AC_CHECK_HEADERS(netdb.h)
AC_CHECK_HEADERS(pwd.h)
AC_CHECK_HEADERS(rxposix.h regex.h)
AC_CHECK_HEADERS(stdefs.h)
AC_CHECK_HEADERS(stdio.h)
AC_CHECK_HEADERS(stdlib.h)
AC_CHECK_HEADERS(string.h strings.h)
AC_CHECK_HEADERS(termios.h)
AC_CHECK_HEADERS(unixlib.h)
AC_HEADER_DIRENT
AC_CHECK_HEADERS(dir.h direct.h) dnl AC_HEADER_DIRENT only checks for some..
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_HEADER_TIME
AC_HEADER_STAT

dnl Checks for typedefs, structures, and compiler characteristics:
AC_TYPE_UID_T
AC_TYPE_PID_T
AC_TYPE_GETGROUPS
AC_TYPE_MODE_T
AC_TYPE_SIZE_T
AC_TYPE_SIGNAL

AC_CHECK_TYPE(BOOLEAN, char)
AC_CHECK_TYPE(u_char, unsigned char)
AC_CHECK_TYPE(u_short, unsigned short)
AC_CHECK_TYPE(u_long, unsigned long)

AC_CHECK_SIZEOF(char)
AC_CHECK_SIZEOF(char *)
AC_CHECK_SIZEOF(int,4)
AC_CHECK_SIZEOF(long,4)
AC_CHECK_SIZEOF_TIME_T
AC_CHECK_SIZEOF_SIZE_T

AC_C_CONST
AC_C_BIGENDIAN
AC_C_CHAR_UNSIGNED
AC_C_LONG_DOUBLE 

AC_STRUCT_TM
AC_STRUCT_GMTOFF
AC_STRUCT_TIMEZONE
AC_STRUCT_WINSIZE

dnl Checks for library functions:
AC_FUNC_VPRINTF
AC_FUNC_STRFTIME
AC_CHECK_FUNCS(getcwd gethostname getdomainname getwd  \
		select socket strerror strtol opendir getpid strchr memcpy \
		getlogin getpass fcntl readdir sysinfo ioctl chdir tempnam \
		getsockopt setsockopt \
		gettimeofday mktime timegm tzset)
AC_CHECK_FUNC(unlink, , AC_CHECK_FUNC(remove, AC_DEFINE(unlink, remove)))

dnl Checks for configuration arguments
AC_MSG_CHECKING(whether to support direct WAIS access.)
AC_ARG_WITH(wais,
[  --with-wais[=PATH]      Compile with support for direct WAIS access.],
[ case "$withval" in
  no)
    AC_MSG_RESULT(no)
    HTWAIS=""
    WWWWAIS=""
    LWWWWAIS=""
    LIBWWWWAIS=""
    ;;
  *)
    AC_MSG_RESULT(yes)
    if test "x$withval" = "xyes"; then
      withval="/usr/local/lib/wais/wais.a /usr/local/lib/wais/client.a"
    fi
    LIBS="$withval -lm $LIBS"
    AC_DEFINE(HT_DIRECT_WAIS)
    AC_TRY_LINK([],
                [ makeDocID(); ],
		[],
		[ AC_MSG_ERROR(Could not find one or more of the $withval libraries.  You must first install WAIS.) ])
    HTWAIS="HTWAIS.lo"
    WWWWAIS="libwwwwais.la"
    LWWWWAIS="-lwwwwais.la"
    LIBWWWWAIS='${top_builddir}/Library/src/libwwwwais.la'
    ;;
  esac ],
  AC_MSG_RESULT(no)
  HTWAIS=""
  WWWWAIS=""
  LWWWWAIS=""
  LIBWWWWAIS=""
)
AC_SUBST(HTWAIS)
AC_SUBST(WWWWAIS)
AC_SUBST(LWWWWAIS)
AC_SUBST(LIBWWWWAIS)

AC_MSG_CHECKING(whether to support zlib compress/decompress)
AC_ARG_WITH(zlib,
[  --with-zlib[=PATH]      Compile with zlib compress/decompress support.],
[ case "$withval" in
  no)
    AC_MSG_RESULT(no)
    HTZLIB=""
    WWWZIP=""
    LWWWZIP=""
    LIBWWWZIP=""
    ;;
  *)
    AC_MSG_RESULT(yes)
    if test "x$withval" = "xyes"; then
      withval="-lz"
      LIBS="$LIBS $withval"
    else
      AC_ADDLIB($withval)
    fi
    AC_DEFINE(HT_ZLIB)
    AC_TRY_LINK([],
                [ zlibVersion(); ],
		[],
		[ AC_MSG_ERROR(Could not find the $withval library.  You must first install zlib.) ])
    HTZLIB="HTZip.lo"
    WWWZIP="libwwwzip.la"
    LWWWZIP="-lwwwzip"
    LIBWWWZIP='${top_builddir}/Library/src/libwwwzip.la'
    ;;
  esac ],
  AC_MSG_RESULT(no)
  HTZLIB=""
  WWWZIP=""
  LWWWZIP=""
  LIBWWWZIP=""
)
AC_SUBST(HTZLIB)
AC_SUBST(WWWZIP)
AC_SUBST(LWWWZIP)
AC_SUBST(LIBWWWZIP)

AC_MSG_CHECKING(whether to support POSIX regex)
AC_ARG_WITH(regex,
[  --with-regex[=PATH]     Compile with POSIC regex library support.],
[ case "$withval" in
  no)
    AC_MSG_RESULT(no)
    ;;
  *)
    AC_MSG_RESULT(yes)
    AC_DEFINE(HT_POSIX_REGEX)
    if test "x$withval" = "xyes"; then
      AC_CHECK_LIB(rx, regexec, [ LIBS="-lrx $LIBS" ] )
    else
      AC_ADDLIB($withval)
      AC_TRY_LINK([],
	          [ regexec(); ],
		  [],
		  [ AC_MSG_ERROR(Could not find the $withval library.  You must first install regex.) ] )
    fi
    ;;
  esac ],
  AC_MSG_RESULT(no)
)

# borrowed from SSH - thanks!
AC_MSG_CHECKING(whether to support SOCKS)
AC_ARG_WITH(socks,
[  --with-socks            Compile with SOCKS firewall traversal support.],
[ case "$withval" in
  no)
    AC_MSG_RESULT(no)
    ;;
  yes)
    AC_MSG_RESULT(yes)
    AC_CHECK_LIB(socks5, SOCKSconnect, [
	    socks=5
	    LIBS="-lsocks5 $LIBS"], [
	AC_CHECK_LIB(socks, Rconnect, [
	    socks=4
	    LIBS="-lsocks $LIBS"], [
		AC_MSG_ERROR(Could not find socks library.  You must first install socks.) ] ) ] )
    ;;
  esac ],
  AC_MSG_RESULT(no)
)

if test "x$socks" = "x"; then
	AC_MSG_CHECKING(whether to support SOCKS5)
	AC_ARG_WITH(socks5,
	[  --with-socks5[=PATH]    Compile with SOCKS5 firewall traversal support.],
	[ case "$withval" in
	  no)
	    AC_MSG_RESULT(no)
	    ;;
	  *)
	    AC_MSG_RESULT(yes)
	    socks=5
	    if test "x$withval" = "xyes"; then
	      withval="-lsocks5"
	      LIBS="$withval $LIBS"
	    else
      	      AC_ADDLIB($withval)
	    fi
	    AC_TRY_LINK([],
	                [ SOCKSconnect(); ],
			[],
			[ AC_MSG_ERROR(Could not find the $withval library.  You must first install socks5.) ])
	    ;;
	  esac ],
	  AC_MSG_RESULT(no)
	)
fi

if test "x$socks" = "x"; then
	AC_MSG_CHECKING(whether to support SOCKS4)
	AC_ARG_WITH(socks4,
	[  --with-socks4[=PATH]    Compile with SOCKS4 firewall traversal support.],
	[ case "$withval" in
	  no)
	    AC_MSG_RESULT(no)
	    ;;
	  *)
	    AC_MSG_RESULT(yes)
	    socks=4
	    if test "x$withval" = "xyes"; then
	      withval="-lsocks"
	      LIBS="$withval $LIBS"
            else
      	      AC_ADDLIB($withval)
	    fi
	    AC_TRY_LINK([],
	                [ Rconnect(); ],
			[],
			[ AC_MSG_ERROR(Could not find the $withval library.  You must first install socks.) ])
	    ;;
	  esac ],
	  AC_MSG_RESULT(no)
	)
fi

if test "x$socks" = "x4"; then
    AC_DEFINE(SOCKS)
    AC_DEFINE(SOCKS4)
fi

if test "x$socks" = "x5"; then
    AC_DEFINE(SOCKS)
    AC_DEFINE(SOCKS5)
fi

AC_MSG_CHECKING(whether to support mysql access.)
AC_ARG_WITH(mysql,
[  --with-mysql[=PATH]      Compile with support for mysql access.],
[ case "$withval" in
  no)
    AC_MSG_RESULT(no)
    HTSQL=""
    HTSQLLOG=""
    WWWSQL=""
    LWWWSQL=""
    LIBWWWSQL=""
    CVS2SQL=""
    ;;
  *)
    AC_MSG_RESULT(yes)
    if test "x$withval" = "xyes"; then
      if test -f '/usr/local/lib/mysql/libmysqlclient.a'; then
         AC_ADDLIB("/usr/local/lib/mysql/libmysqlclient.a")
      elif test -f '/usr/lib/mysql/libmysqlclient.a'; then
         AC_ADDLIB("/usr/lib/mysql/libmysqlclient.a")
      else
         AC_MSG_ERROR(Could not find the mysql client library.)
      fi
    else
      AC_ADDLIB($withval)
    fi
    AC_DEFINE(HT_MYSQL)
    HTSQL="HTSQL.lo"
    HTSQLLOG="HTSQLLog.lo"
    WWWSQL="libwwwsql.la"
    LWWWSQL="-lwwwsql"
    LIBWWWSQL='${top_builddir}/Library/src/libwwwsql.la'
    CVS2SQL="cvs2sql"
    ;;
  esac ],
  AC_MSG_RESULT(no)
  HTSQL=""
  HTSQLLOG=""
  WWWSQL=""
  LWWWSQL=""
  LIBWWWSQL=""
  CVS2SQL=""
)
AC_SUBST(HTSQL)
AC_SUBST(HTSQLLOG)
AC_SUBST(WWWSQL)
AC_SUBST(LWWWSQL)
AC_SUBST(LIBWWWSQL)
AC_SUBST(CVS2SQL)

AC_MSG_CHECKING(whether we include the Expat XML parser.)
AC_ARG_WITH(expat,
[  --with-expat[=PATH]      Compile with support for expat.],
[ case "$withval" in
  no)
    AC_MSG_RESULT(no)
    HTXML=""
    HTLIBXML=""
    XMLTOK=""
    XMLPARSE=""
    WWWXML=""
    LWWWXML=""
    LIBWWWXML=""
    SHOWXML=""
    ;;
  *)
    AC_MSG_RESULT(yes)
    AC_DEFINE(HT_EXPAT)
    HTXML="HTXML.lo"
    HTLIBXML='${top_builddir}/modules/expat/xmlparse/libxmlparse.la ${top_builddir}/modules/expat/xmltok/libxmltok.la'
    XMLTOK="libxmltok.la"
    XMLPARSE="libxmlparse.la"
    WWWXML="libwwwxml.la"
    LWWWXML="-lwwwxml -lxmltok -lxmlparse"
    LIBWWWXML='${top_builddir}/Library/src/libwwwxml.la ${top_builddir}/modules/expat/xmlparse/libxmlparse.la ${top_builddir}/modules/expat/xmltok/libxmltok.la'
    SHOWXML="showxml ptri stri rdf_parse_file rdf_parse_buffer"
    ;;
  esac ],
  AC_MSG_RESULT(yes)
  AC_DEFINE(HT_EXPAT)
  HTXML="HTXML.lo"
  HTLIBXML='${top_builddir}/modules/expat/xmlparse/libxmlparse.la ${top_builddir}/modules/expat/xmltok/libxmltok.la'
  XMLTOK="libxmltok.la"
  XMLPARSE="libxmlparse.la"
  WWWXML="libwwwxml.la"
  LWWWXML="-lwwwxml -lxmltok -lxmlparse"
  LIBWWWXML='${top_builddir}/Library/src/libwwwxml.la ${top_builddir}/modules/expat/xmlparse/libxmlparse.la ${top_builddir}/modules/expat/xmltok/libxmltok.la'
  SHOWXML="showxml ptri stri rdf_parse_file rdf_parse_buffer"
)
AC_SUBST(HTXML)		# for old style big library
AC_SUBST(HTLIBXML)	# for old style big library
AC_SUBST(XMLTOK)
AC_SUBST(XMLPARSE)
AC_SUBST(WWWXML)
AC_SUBST(LWWWXML)
AC_SUBST(LIBWWWXML)
AC_SUBST(SHOWXML)

AC_MSG_CHECKING(whether we include MD5 support for HTTP Digest Authentication.)
AC_ARG_WITH(md5,
[  --with-md5[=PATH]      Compile with support for md5.],
[ case "$withval" in
  no)
    AC_MSG_RESULT(no)
    WWWMD5=""
    LWWWMD5=""
    LIBWWWMD5=""
    ;;
  *)
    AC_MSG_RESULT(yes)
    AC_DEFINE(HT_MD5)
    WWWMD5="libmd5.la"
    LWWWMD5="-lmd5"
    LIBWWWMD5='${top_builddir}/modules/md5/libmd5.la'
    ;;
  esac ],
  AC_MSG_RESULT(yes)
  AC_DEFINE(HT_MD5)
  WWWMD5="libmd5.la"
  LWWWMD5="-lmd5"
  LIBWWWMD5='${top_builddir}/modules/md5/libmd5.la'
)
AC_SUBST(WWWMD5)
AC_SUBST(LWWWMD5)
AC_SUBST(LIBWWWMD5)

dnl Checks for libwww and OpenSSL:
AC_MSG_CHECKING(whether we can find OpenSSL)
dnl find the ssl library dir (empirical)
if test -d '/usr/local/ssl/lib'; then
  ssllib="-L/usr/local/ssl/lib -lssl -lcrypto"
else
  ssllib="-L/usr/lib -lssl -lcrypto"
fi
dnl find the ssl include dir (empirical)
if test -d '/usr/local/ssl/include'; then
  sslinc="-I/usr/local/ssl/include"
elif test -d '/usr/local/openssl/include'; then
  sslinc="-I/usr/local/openssl/include"
elif test -d '/usr/local/include/openssl'; then
  sslinc="-I/usr/local/include/openssl"
elif test -d '/usr/include/ssl'; then
  sslinc="-I/usr/include/ssl"
elif test -d '/usr/include/openssl'; then
  sslinc="-I/usr/include/openssl"
else
  sslinc=""
fi
WWWSSL=""
SSLINC=""
LIBSSL=""
LWWWSSL=""
LIBWWWSSL=""
WWWSSLEX=""
AC_ARG_WITH(ssl,
[  --with-ssl[=PATH]       Link with OpenSSL.],
[ case "$withval" in
  no)
    AC_MSG_RESULT(no)
    ;;
  *)
    if test "x$withval" = "xyes"; then
      withval=$ssllib
      SSLINC=$sslinc
    fi
    LIBS="$LIBS $withval"
    AC_TRY_LINK([],
		[ SSL_library_init(); ],
		[],
		[ AC_MSG_ERROR(Could not find the $withval libraries.  You must first install openSSL.) ])
    AC_MSG_RESULT(yes)
    WWWSSL="libwwwssl.la"
    LWWWSSL="-lwwwssl" 
    LIBWWWSSL='${top_builddir}/Library/src/SSL/libwwwssl.la'
    WWWSSLEX="wwwssl"
    ;;
  esac ],
[ AC_MSG_RESULT(no) ])
AC_SUBST(WWWSSL)
AC_SUBST(SSLINC)
AC_SUBST(LWWWSSL)
AC_SUBST(LIBWWWSSL)
AC_SUBST(WWWSSLEX)

AC_MSG_CHECKING(whether to use internal signal handlers)
AC_ARG_ENABLE(signals, [  --enable-signals        use internal libwww signal handler.],
[ case "${enableval}" in
  no)
    AC_MSG_RESULT(no)
    ;;
  *)
    AC_MSG_RESULT(yes)
    AC_DEFINE(WWWLIB_SIG)
    ;;
  esac ],
  AC_MSG_RESULT(no)
)

AC_MSG_CHECKING(whether to disable Nagle's algorithm)
AC_ARG_ENABLE(nagle,
[  --disable-nagle         Turning off Nagle's algorithm.],
[ case "${enableval}" in
  no)
    AC_MSG_RESULT(yes)
    AC_DEFINE(HT_NO_NAGLE)
    ;;
  *) 
    AC_MSG_RESULT(no)
    ;;
  esac ],
  AC_MSG_RESULT(yes)
  AC_DEFINE(HT_NO_NAGLE)
)

AC_MSG_CHECKING(whether to accept new rule files without asking an end user.)
AC_ARG_ENABLE(autorules,
[  --enable-autorules      Enabling acceptance of rule files without user interaction.],
[ case "${enableval}" in
  yes)
    AC_MSG_RESULT(yes)
    AC_DEFINE(HT_AUTOMATIC_RULES)
    ;;
  *) 
    AC_MSG_RESULT(no)
    ;;
  esac ],
  AC_MSG_RESULT(no)
)

AC_MSG_CHECKING(whether to disable HTTP/1.1 pipelining)
AC_ARG_ENABLE(pipelining,
[  --disable-pipelining    Turning off HTTP/1.1 Pipelining.],
[ case "${enableval}" in
  no)
    AC_MSG_RESULT(yes)
    AC_DEFINE(HT_NO_PIPELINING)
    ;;
  *) 
    AC_MSG_RESULT(no)
    ;;
  esac ],
  AC_MSG_RESULT(no)
)


AC_MSG_CHECKING(whether to use MUX as transport for HTTP.)
AC_ARG_ENABLE(mux,
[  --enable-mux            Enabling MUX as transport for HTTP.],
[ case "${enableval}" in
  yes)
    AC_MSG_RESULT(yes)
    AC_DEFINE(HT_MUX)
    ;;
  *) 
    AC_MSG_RESULT(no)
    ;;
  esac ],
  AC_MSG_RESULT(no)
)

AC_MSG_CHECKING(whether to define _REENTRANT)
AC_ARG_ENABLE(reentrant, [  --enable-reentrant      define _REENTRANT to enable reentrant system calls],
[ case "${enableval}" in
  no)
    AC_MSG_RESULT(no)
    ac_cv_reentrant=no
    ;;
  *) 
    AC_MSG_RESULT(yes)
    AC_DEFINE(HT_REENTRANT) [CFLAGS="$CFLAGS -D_REENTRANT"]
    ac_cv_reentrant=yes
    ;;
  esac ],
  AC_MSG_RESULT(no)
)

if test "$ac_cv_reentrant" = "yes"; then

    AC_MSG_CHECKING(for ctime_r)
    if test -z "$ac_cv_ctime_args"; then
        AC_TRY_COMPILE(
        [#include <time.h>],
        [
            time_t clock;
            char buf[26];
            ctime_r(&clock, buf);
        ], ac_cv_ctime_args=2)
    fi
    if test -z "$ac_cv_ctime_args" ; then
        AC_TRY_COMPILE(
        [#include <time.h>],
        [
            time_t clock;
            char buf[26];
            ctime_r(&clock, buf, 26);
        ], ac_cv_ctime_args=3)
    fi
    if test -z "$ac_cv_ctime_args"; then
        AC_MSG_RESULT(no)
        have_missing_r_funcs="$have_missing_r_funcs ctime_r"
    else
        if test "$ac_cv_ctime_args" = 2; then
            AC_DEFINE(HAVE_CTIME_R_2)
        elif test "$ac_cv_ctime_args" = 3; then
            AC_DEFINE(HAVE_CTIME_R_3)
        fi
        AC_MSG_RESULT([yes, and it takes $ac_cv_ctime_args arguments])
    fi

    AC_MSG_CHECKING(for readdir_r)
    if test -z "$ac_cv_readdir_args"; then
        AC_TRY_COMPILE(
	[
#include <sys/types.h>

#if defined(HAVE_DIRENT_H)
#   include <dirent.h>
#   define NAMLEN(dirent) strlen((dirent)->d_name)
#else
#   define dirent direct
#   define NAMLEN(dirent) (dirent)->d_namlen
#   if defined(HAVE_SYS_NDIR_H)
#       include <sys/ndir.h>
#   endif
#   if defined(HAVE_SYS_DIR_H)
#       include <sys/dir.h>
#   endif
#   if defined(HAVE_NDIR_H)
#       include <ndir.h>
#   endif
#endif  ],
        [
        struct dirent dir, *dirp;
        DIR *mydir;
        dirp = readdir_r(mydir, &dir);
	], ac_cv_readdir_args=2)
    fi
    if test -z "$ac_cv_readdir_args"; then
	
        AC_TRY_COMPILE(
        [
#include <sys/types.h>
#if defined(HAVE_DIRENT_H)
#   include <dirent.h>
#   define NAMLEN(dirent) strlen((dirent)->d_name)
#else
#   define dirent direct
#   define NAMLEN(dirent) (dirent)->d_namlen
#   if defined(HAVE_SYS_NDIR_H)
#       include <sys/ndir.h>
#   endif
#   if defined(HAVE_SYS_DIR_H)
#       include <sys/dir.h>
#   endif
#   if defined(HAVE_NDIR_H)
#       include <ndir.h>
#   endif
#endif  ],
        [
        struct dirent dir, *dirp;
        DIR *mydir;
        int rc;
        rc = readdir_r(mydir, &dir, &dirp);
        ], ac_cv_readdir_args=3)
    fi

    if test -z "$ac_cv_readdir_args"; then
        AC_MSG_RESULT(no)
        have_missing_r_funcs="$have_missing_r_funcs readdir_r"
    else
        if test "$ac_cv_readdir_args" = 2; then
            AC_DEFINE(HAVE_READDIR_R_2)
        elif test "$ac_cv_readdir_args" = 3; then
            AC_DEFINE(HAVE_READDIR_R_3)
        fi
        AC_MSG_RESULT([yes, and it takes $ac_cv_readdir_args arguments])
    fi

    AC_MSG_CHECKING(for gethostbyname_r)
    if test -z "$ac_cv_gethostbyname_args"; then
        AC_TRY_COMPILE(
	    [
#include <sys/types.h>
#include <netdb.h>],
	    [
struct hostent *hp;
struct hostent h;
char *name;
char buffer[10];
int  h_errno;
hp = gethostbyname_r(name, &h, buffer, 10, &h_errno);],
            ac_cv_gethostbyname_args=5)
    fi
    if test -z "$ac_cv_gethostbyname_args"; then
        AC_TRY_COMPILE(
	    [
#include <sys/types.h>
#include <netdb.h>],
	    [
struct hostent h;
struct hostent_data hdata;
char *name;
int  rc;
rc = gethostbyname_r(name, &h, &hdata);],
            ac_cv_gethostbyname_args=3)
    fi
    if test -z "$ac_cv_gethostbyname_args"; then
        AC_TRY_COMPILE(
	    [
#include <sys/types.h>
#include <netdb.h>],
	    [
struct hostent h;
struct hostent *hp;
char *name;
char buf[10];
int rc;
int h_errno;

rc = gethostbyname_r(name, &h, buf, 10, &hp, &h_errno);
	    ],
	    ac_cv_gethostbyname_args=6)
    fi
    if test -z "$ac_cv_gethostbyname_args"; then
        AC_MSG_RESULT(no)
        have_missing_r_funcs="$have_missing_r_funcs gethostbyname_r"
    else
        if test "$ac_cv_gethostbyname_args" = 3; then
            AC_DEFINE(HAVE_GETHOSTBYNAME_R_3)
        elif test "$ac_cv_gethostbyname_args" = 5; then
            AC_DEFINE(HAVE_GETHOSTBYNAME_R_5)
        elif test "$ac_cv_gethostbyname_args" = 6; then
            AC_DEFINE(HAVE_GETHOSTBYNAME_R_6)
        fi
        AC_MSG_RESULT([yes, and it takes $ac_cv_gethostbyname_args arguments])
    fi

    AC_MSG_CHECKING(for gethostbyaddr_r)
    if test -z "$ac_cv_gethostbyaddr_args"; then
	AC_TRY_COMPILE(
	    [
#include <sys/types.h>
#include <netdb.h>],
	    [
                char * address;
                int length;
                int type;
                struct hostent h;
                struct hostent_data hdata;
                int rc;
                rc = gethostbyaddr_r(address, length, type, &h, &hdata);
	    ],
	    ac_cv_gethostbyaddr_args=5)
	
    fi
    if test -z "$ac_cv_gethostbyaddr_args"; then
	AC_TRY_COMPILE(
	    [
#include <sys/types.h>
#include <netdb.h>],
	    [
                char * address;
                int length;
                int type;
                struct hostent h;
		char buffer[10];
		int buflen;
		int h_errnop;
		struct hostent * hp;

		hp = gethostbyaddr_r(address, length, type, &h,
				     buffer, buflen, &h_errnop);
	    ],
	    ac_cv_gethostbyaddr_args=7)
    fi

    if test -z "$ac_cv_gethostbyaddr_args"; then
	AC_TRY_COMPILE(
	    [
#include <sys/types.h>
#include <netdb.h>],
	    [
                char * address;
                int length;
                int type;
                struct hostent h;
		char buffer[10];
		int buflen;
		int h_errnop;
		struct hostent * hp;
		int rc;

		rc = gethostbyaddr_r(address, length, type, &h,
				     buffer, buflen, &hp, &h_errnop);
	    ],
	    ac_cv_gethostbyaddr_args=8)
    fi
    if test -z "$ac_cv_gethostbyaddr_args"; then
        AC_MSG_RESULT(no)
        have_missing_r_funcs="$have_missing_r_funcs gethostbyaddr_r"
    else
        if test "$ac_cv_gethostbyaddr_args" = 5; then
            AC_DEFINE(HAVE_GETHOSTBYADDR_R_5)
        elif test "$ac_cv_gethostbyaddr_args" = 7; then
            AC_DEFINE(HAVE_GETHOSTBYADDR_R_7)
        elif test "$ac_cv_gethostbyaddr_args" = 8; then
            AC_DEFINE(HAVE_GETHOSTBYADDR_R_8)
        fi
        AC_MSG_RESULT([yes, and it takes $ac_cv_gethostbyaddr_args arguments])
    fi

    AC_MSG_CHECKING(for getlogin_r)
    if test -z "$ac_cv_getlogin_r_style"; then
	AC_TRY_RUN(
	    [
#include <unistd.h>

int main()
{
    char name[1024];
    int len=1024;
    int rc;
    char *login;

    name[0]='\0';

    rc = getlogin_r(name, len);
    if(rc == 0 && name[0] != '\0')
    {
	return 0; /* returns zero on success */
    }
    else if(rc != 0 && name[0] == '\0')
    {
	return 0; /* returns errno on failure */
    }
    else if(rc == 0 && name[0] == '\0')
    {
	return 0; /* can't tell */
    }
    else if(rc != 0 && name[0] != '\0')
    {
	return 1; /* returns pointer on success */
    }
}
	    ],
	    [
		ac_cv_getlogin_r_style=1
	    ],
	    [
		ac_cv_getlogin_r_style=2
	    ])
    fi
    if test -z "$ac_cv_getlogin_r_style"; then
	AC_MSG_RESULT(no)
        have_missing_r_funcs="$have_missing_r_funcs getlogin_r"
    else
	if test $ac_cv_getlogin_r_style = 1; then
	    AC_DEFINE(GETLOGIN_R_RETURNS_INT)
	    AC_MSG_RESULT([yes, and it returns an int])
	elif test $ac_cv_getlogin_r_style = 2; then
	    AC_DEFINE(GETLOGIN_R_RETURNS_POINTER)
	    AC_MSG_RESULT([yes, and it returns a pointer])
	else
	    AC_MSG_RESULT(no: result is $ac_cv_getlogin_r_style)
            have_missing_r_funcs="$have_missing_r_funcs getlogin_r"
	fi
    fi
    if test -n "$have_missing_r_funcs"; then
        AC_MSG_WARN(missing reentrant functions: $have_missing_r_funcs)
    fi
fi

AC_MSG_CHECKING(whether to define _POSIX_SOURCE)
AC_ARG_ENABLE(posix, [  --enable-posix          define _POSIX_SOURCE],
[ case "${enableval}" in
  no)
    AC_MSG_RESULT(no)
    ;;
  *) 
    AC_MSG_RESULT(yes)
    AC_DEFINE(_POSIX_SOURCE) [CFLAGS="$CFLAGS -D_POSIX_SOURCE"]
    ;;
  esac ],
  AC_MSG_RESULT(no)
)

AC_ARG_ENABLE(cyrillic, [  --enable-cyrillic       include support for Cyrillic in line mode browser],
  AC_DEFINE(CYRILLIC)
  A_STDIO="a_stdio.o", A_STDIO="")
AC_SUBST(A_STDIO)

dnl Create output files
AC_OUTPUT([Makefile libwww-config w3c-libwww.spec
config/Makefile
modules/Makefile
modules/expat/Makefile modules/expat/xmltok/Makefile modules/expat/xmlparse/Makefile
modules/md5/Makefile
Library/Makefile Library/User/Makefile Library/User/Patch/Makefile
Library/User/Architecture/Makefile Library/User/Using/Makefile Library/User/Guide/Makefile
Library/User/Style/Makefile Library/User/Platform/Makefile
Library/Test/Makefile Library/Test/User/Makefile Library/Test/src/Makefile
Library/src/Makefile Library/src/windows/Makefile Library/src/vms/Makefile 
Library/src/SSL/Makefile Library/src/SSL/windows/Makefile
Library/Examples/Makefile
Library/cvs2sql/Makefile
Library/External/Makefile
PICS-client/Makefile PICS-client/User/Makefile PICS-client/src/Makefile PICS-client/src/windows/Makefile
LineMode/Makefile LineMode/User/Makefile
LineMode/src/Makefile LineMode/src/windows/Makefile LineMode/src/vms/Makefile
Robot/Makefile Robot/User/Makefile Robot/src/Makefile Robot/tcl/Makefile Robot/src/windows/Makefile
ComLine/Makefile ComLine/User/Makefile ComLine/src/Makefile ComLine/src/windows/Makefile
WinCom/Makefile WinCom/hlp/Makefile WinCom/res/Makefile
Icons/Makefile Icons/WWW/Makefile Icons/32x32/Makefile Icons/internal/Makefile
], date>stamp-h)
