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.65 1998/11/11 18:31:47 frystyk Exp $

AC_REVISION([$Id: configure.in,v 1.65 1998/11/11 18:31:47 frystyk Exp $])
AC_PREREQ(2.2)
AC_INIT(HTAABrow.c)

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.2.1
AC_SUBST(VERSION)
AC_DEFINE_UNQUOTED(W3C_VERSION, "$VERSION")

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

AM_INIT_AUTOMAKE($PACKAGE, $VERSION) 

AC_ISC_POSIX

dnl Regular configure...
AM_CYGWIN32
AC_PROG_CC
AM_PROG_LIBTOOL
AC_PROG_MAKE_SET
AC_PROG_INSTALL

sinclude(../../texk/kpathsea/common.ac)
sinclude(../zlib/withenable.ac)
sinclude(../zlib/zlib.ac)

dnl AM_CONFIG_HEADER(wwwconf.h)
AM_CONFIG_HEADER(wwwconf.h:wwwconf.h.in)

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_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_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 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)
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 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 THINGS TO CONSIDER
dnl ******************
AC_DEFINE(TTY_IS_SELECTABLE)

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

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=""
    CVS2SQL=""
    ;;
  *)
    AC_MSG_RESULT(yes)
    if test "x$withval" = "xyes"; then
      AC_ADDLIB("/usr/local/lib/mysql/libmysqlclient.a")
    else
      AC_ADDLIB($withval)
    fi
    AC_DEFINE(HT_MYSQL)
    HTSQL="HTSQL.lo"
    HTSQLLOG="HTSQLLog.lo"
    CVS2SQL="cvs2sql"
    ;;
  esac ],
  AC_MSG_RESULT(no)
  HTSQL=""
  HTSQLLOG=""
  CVS2SQL=""
)
AC_SUBST(HTSQL)
AC_SUBST(HTSQLLOG)
AC_SUBST(CVS2SQL)

AC_MSG_CHECKING(whether to link libwww as shared library)
AC_ARG_ENABLE(shared, [],
[ case "${enableval}" in
  no)
    AC_MSG_RESULT(no)
    ;;
  *) 
    AC_MSG_RESULT(yes)
    AC_DEFINE(LIBWWW_SHARED)
    ;;
  esac ],
[
  AC_MSG_RESULT(yes)
  AC_DEFINE(LIBWWW_SHARED)
]
)

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 Create output files
AC_OUTPUT([Makefile
], date>stamp-h)
