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.51 1998/03/22 21:39:29 frystyk Exp $

AC_REVISION([$Id: configure.in,v 1.51 1998/03/22 21:39:29 frystyk Exp $])
AC_PREREQ(2.2)
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.1l
AC_SUBST(VERSION)
AC_DEFINE_UNQUOTED(W3C_VERSION, "$VERSION")

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

AM_INIT_AUTOMAKE($PACKAGE, $VERSION) 

AM_CONFIG_HEADER(config.h)

dnl Regular configure...
AC_PROG_CC
AC_PROG_RANLIB
AC_PROG_MAKE_SET

dnl Remove next line and you get an error -- autoconf
dnl should deal with this automatically.
AC_ISC_POSIX
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
	;;
    *)
	AC_MSG_RESULT(no)
	;;
esac

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=""
    ;;
  *)
    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.o"
    ;;
  esac ],
  AC_MSG_RESULT(no)
  HTWAIS=""
)
AC_SUBST(HTWAIS)

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=""
    ;;
  *)
    AC_MSG_RESULT(yes)
    if test "x$withval" = "xyes"; then
      withval="-lz"
    fi
    LIBS="$withval $LIBS"
    AC_DEFINE(HT_ZLIB)
    AC_TRY_LINK([],
                [ zlibVersion(); ],
		[],
		[ AC_MSG_ERROR(Could not find the $withval library.  You must first install zlib.) ])
    HTZLIB="HTZip.o"
    ;;
  esac ],
  AC_MSG_RESULT(no)
  HTZLIB=""
)
AC_SUBST(HTZLIB)

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" ],
	    [ AC_CHECK_LIB(c, regexec,
	    [],
	    [ AC_MSG_ERROR(Could not find a POSIX regex library.  You must first install regex.) ] ) ] )
    else
        LIBS="$withval $LIBS"
	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"
	    fi
	    LIBS="$withval $LIBS"
	    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"
	    fi
	    LIBS="$withval $LIBS"
	    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 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_MSG_RESULT(yes)
    AC_DEFINE(HT_REENTRANT) [CFLAGS="$CFLAGS -D_REENTRANT"]
    ;;
  esac ],
  AC_MSG_RESULT(no)
)

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 Checks for programs.
AC_PROG_INSTALL
AC_PROG_RANLIB

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_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)
AC_PROG_LN_S

dnl One remaining platform-specific difference in the library is the
dnl default postscript and image viewers: On the NeXT they are "open,"
dnl on other platforms they are ghostview or xv.  We should decide
dnl how to handle these things; perhaps the following lines would be
dnl useful:
dnl AC_PATH_PROGS(postscript_viewer, open ghostview, ghostview)
dnl AC_DEFINE_UNQUOTED(PRESENT_POSTSCRIPT, "$postscript_viewer %s")
dnl AC_PATH_PROGS(image_viewer, open xv, xv)
dnl AC_DEFINE_UNQUOTED(PRESENT_IMAGE, "$image_viewer %s")

dnl Checks for misc files
dnl AC_FILE_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 Checks for libraries:
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(stdio.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/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/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(string.h strings.h)
AC_CHECK_HEADERS(syslog.h)
AC_CHECK_HEADERS(appkit/appkit.h appkit.h)
AC_CHECK_HEADERS(net/errno.h sys/errno.h errno.h)
AC_CHECK_HEADERS(netinet/tcp.h tcp.h)
AC_CHECK_HEADERS(netinet/in.h in.h)
AC_CHECK_HEADERS(dn.h)
AC_CHECK_HEADERS(termios.h)
AC_CHECK_HEADERS(pwd.h)
AC_CHECK_HEADERS(grp.h)
AC_CHECK_HEADERS(arpa/inet.h inet.h)
AC_CHECK_HEADERS(netdb.h)
AC_CHECK_HEADERS(manifest.h)
AC_CHECK_HEADERS(bsdtypes.h)
AC_CHECK_HEADERS(stdefs.h)
AC_CHECK_HEADERS(bsdtime.h)
AC_CHECK_HEADERS(dnetdb.h)
AC_CHECK_HEADERS(libc.h)
AC_CHECK_HEADERS(stdlib.h)
AC_CHECK_HEADERS(malloc.h)
AC_CHECK_HEADERS(memory.h)
AC_CHECK_HEADERS(unixlib.h)
AC_CHECK_HEADERS(ctype.h)
AC_CHECK_HEADERS(cursesX.h curses.h)
AC_CHECK_HEADERS(rxposix.h regex.h)
AC_CHECK_HEADERS(wais/wais.h wais.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)
AC_CHECK_SIZEOF(long)
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 Other types that aren't checked for, but maybe should be:
dnl AC_TYPE_OFF_T AC_STRUCT_ST_RDEV 

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)
AC_CHECK_FUNC(unlink, , AC_CHECK_FUNC(remove, AC_DEFINE(unlink, remove)))

dnl Checks for external globals.
dnl AC_CHECK_EXTERNS(socket_errno sys_errlist sys_nerr)

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

dnl THINGS TO CONSIDER
dnl ******************
AC_DEFINE(TTY_IS_SELECTABLE)

dnl Create output files
AC_OUTPUT([Makefile
config/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/Examples/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/src/windows/Makefile
ComLine/Makefile ComLine/User/Makefile ComLine/src/Makefile ComLine/src/windows/Makefile
MiniServ/Makefile MiniServ/User/Makefile MiniServ/src/Makefile
Listen/Makefile Listen/User/Makefile Listen/src/Makefile
Icons/Makefile Icons/WWW/Makefile Icons/32x32/Makefile Icons/internal/Makefile
], date>stamp-h)
