# configure.in for ircii
dnl
dnl Copyright (c) 1993-2024 Matthew R. Green.
dnl All rights reserved.
dnl
dnl Redistribution and use in source and binary forms, with or without
dnl modification, are permitted provided that the following conditions
dnl are met:
dnl 1. Redistributions of source code must retain the above copyright
dnl    notice, this list of conditions and the following disclaimer.
dnl 2. Redistributions in binary form must reproduce the above copyright
dnl    notice, this list of conditions and the following disclaimer in the
dnl    documentation and/or other materials provided with the distribution.
dnl 3. The name of the author may not be used to endorse or promote products
dnl    derived from this software without specific prior written permission.
dnl
dnl THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
dnl IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
dnl OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
dnl IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
dnl INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
dnl BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
dnl LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
dnl AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
dnl OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
dnl OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
dnl SUCH DAMAGE.
dnl
dnl certain portions have other attributions, see below.
dnl
dnl thanks to the screen 3.3 configure.in for giving me examples to
dnl work from and steal ;)
dnl
dnl @(#)$eterna: configure.in,v 1.232 2024/08/03 06:41:43 mrg Exp $

AC_PREREQ([2.71])
AC_REVISION($Revision: 1.232 $)dnl
AC_INIT
AC_CONFIG_SRCDIR([${srcdir}/source/irc.c])
AC_CONFIG_HEADERS([defs.h:include/defs.h.in])

dnl
dnl grok the version number - from source/irc.c
dnl

VERSION=`sed -n -e 's/"[[^"]]*$//' -e '/#define[ 	]*IRCII_VERSION[ 	]*"/s///p' -e '/#define IRCII_VERSION/q' < ${srcdir}/source/irc.c` 
echo this is ircii version $VERSION
echo
AC_SUBST(VERSION)

CATEGORIES='build change-request doc pending runtime'
AC_SUBST(CATEGORIES)

dnl so that the generated configure has an id.
echo '$eterna: configure.in,v 1.232 2024/08/03 06:41:43 mrg Exp $' > /dev/null

dnl So many systems seem to need this that it is better do it here automatically.
AC_MSG_CHECKING(for prefix paths)
AC_ARG_WITH(prefix_paths,
[  --with-prefix-paths                  Add include and library directories from prefix],
[ case "$withval" in
  no)
    AC_MSG_RESULT(no)
    ;;		
  *)
    AC_MSG_RESULT(yes)
    if test "x$prefix" != xNONE; then
      if test -d "$prefix/lib"; then
        LIBS="-L${prefix}/lib $LIBS"
      fi
      if test -d "$prefix/include"; then
        CFLAGS="-I${prefix}/include $CFLAGS"
      fi
    else
      if test -d "$ac_default_prefix/lib"; then
        LIBS="-L${ac_default_prefix}/lib $LIBS"
      fi
      if test -d "$ac_default_prefix/include"; then
        CFLAGS="-I${ac_default_prefix}/include $CFLAGS"
      fi
    fi
    ;;
  esac ]
  AC_MSG_RESULT(no)
)

dnl
dnl initial stuff
dnl

AC_PROG_CC
AC_PROG_CPP

dnl
dnl setup variables
dnl
srcdir=`(cd $srcdir; pwd)`
AC_SUBST(srcdir)
objdir=`pwd`
AC_SUBST(objdir)

AC_USE_SYSTEM_EXTENSIONS

AC_PROG_GCC_TRADITIONAL
if test $ac_cv_c_compiler_gnu = yes; then
  CFLAGS="-pipe $CFLAGS"
fi

AC_MSG_CHECKING(for qnx)
case "`uname -s`" in
dnl bleck - wish i could ditch this qnx test, but we need to bump the stack
  QNX*)
    AC_MSG_RESULT(yes)
    if test -z "$GCC"; then
      LDFLAGS="-N256k -M"
      CFLAGS="-w4 -Otax -zc -Wc,-fr= -Wc,-wcd=121"
    fi
    ;;
  *)
    AC_MSG_RESULT(no)
esac
AC_MSG_CHECKING(for solaris)
if /bin/sun 2> /dev/null
then
  uname=`uname -r`
  case "$uname" in
    5.*)
      AC_MSG_RESULT(yes)
      svr4=1
      ;;
  esac
else
  AC_MSG_RESULT(no)
  AC_MSG_CHECKING(for SVR4)
  AC_EGREP_CPP(yes,
[#if defined(SVR4) || defined(__svr4__) || defined(__SVR4)
  yes
#endif
],AC_MSG_RESULT(yes)
  svr4=1)
fi

if test -n "$svr4"
then
  LIBS="-L/usr/ccs/lib -lnsl -lsocket $LIBS"
else
  AC_MSG_RESULT(no)
fi

dnl
dnl linux ncurses
dnl
case "`uname -s`" in
  Linux*)
    if test -d /usr/include/ncurses; then
      CFLAGS="-I/usr/include/ncurses $CFLAGS"
    fi
    ;;
esac

AC_CHECK_HEADERS(sys/un.h sys/select.h sys/fcntl.h sys/ioctl.h sys/file.h sys/time.h sys/uio.h)dnl sys/ ones
AC_CHECK_HEADERS(fcntl.h memory.h netdb.h crypt.h)dnl non sys/ ones
AC_CHECK_HEADERS(process.h termcap.h iconv.h)dnl others

AC_CHECK_FUNC(fchmod,, AC_DEFINE([NEED_FCHMOD], 1, [define this if you need fchmod()]))

AC_CHECK_FUNCS(\
	getpgid getsid memmove scandir setsid strftime writev \
	snprintf vsnprintf fputc fwrite setenv unsetenv \
	tzset waitpid iconv_open)

dnl
dnl look for get*info in libmedia
dnl

AC_CHECK_LIB(media, getaddrinfo, LIBS="$LIBS -lmedia")

AC_TYPE_MODE_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_TYPE_UID_T
AC_CHECK_TYPES([ssize_t], [AC_DEFINE([HAVE_SSIZE_T], 1, [define this if you have ssize_t type])])

AC_MSG_TRY_COMPILE(for sockaddr_in.sin_len, ircii_cv_HAVE_SOCKADDR_SA_LEN, [
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h> ],
  [ struct sockaddr_in sin;
    int X = sin.sin_len ],
  [AC_DEFINE([HAVE_SOCKADDR_SA_LEN], 1, [define this if your struct sockaddr has a sa_len member])])

AC_MSG_TRY_COMPILE(for socklen_t, ircii_cv_HAVE_SOCKLEN_T, [
#include <sys/types.h>
#include <sys/socket.h> ], [ socklen_t X ], [AC_DEFINE([HAVE_SOCKLEN_T], 1, [define this if you have socklen_t])])

dnl
dnl checking for select()
dnl

olibs="$LIBS"
AC_CHECK_FUNC(select, ,
  AC_CHECK_LIB(socket, select, LIBS="$LIBS -lsocket",
    AC_CHECK_LIB(nsl, select, LIBS="$LIBS -lnsl",
      AC_CHECK_LIB(inet, select, LIBS="$LIBS -linet",
        AC_CHECK_LIB(cposix, select, LIBS="$LIBS -lcposix",
          AC_CHECK_LIB(net, select, LIBS="$LIBS -lnet",
            AC_MSG_WARN(i can not find select.  you might need to help me)))))))

dnl
dnl termcap or curses
dnl if termcap, check for tputs declaration
dnl
if test x$aix = x1
then
  LIBS="$LIBS -lcurses"
  include_curses_h=1
else
  olibs="$LIBS"
  AC_CHECK_LIB(termcap, tgetent, LIBS="-ltermcap $olibs",
    AC_CHECK_LIB(tinfo, tgetent, LIBS="-ltinfo $olibs",
      AC_CHECK_LIB(termlib, tgetent, LIBS="$olibs -ltermlib",
        AC_CHECK_LIB(curses, tgetent, LIBS="$olibs -lcurses",
          AC_CHECK_LIB(xtermcap, tgetent, LIBS="$olibs -lxtermcap",
            AC_CHECK_LIB(ncurses, tgetent, LIBS="$olibs -lncurses",
              AC_MSG_WARN(i can not find tgetent.  you might need to help me)))))))
  AC_MSG_CHECKING(for tputs in curses.h)
  AC_EGREP_CPP([tputs( |	|\()],[#include <curses.h>
], include_curses_h=1
   AC_MSG_RESULT(yes), AC_MSG_RESULT(no))
fi

if test -n "$include_curses_h"
then
  AC_DEFINE([INCLUDE_CURSES_H], 1, [define this if you have usable curses.h])
fi


dnl
dnl check the type of iconv(3)'s 2nd argument
dnl

AC_MSG_CHECKING(for const iconv 2nd argument)
AC_EGREP_HEADER([\\<iconv\\>.*\\(.*const], iconv.h,
  AC_MSG_RESULT(yes)
  AC_DEFINE([ICONV_CONST_ARG2], 1,
    [define this if your iconv(3)'s 2nd argument is const]),
  AC_MSG_RESULT(no))


dnl
dnl check the type of scandir(3)'s comparison function
dnl actually, we check alphasort since that is almost certainly
dnl on the same line. ugh.
dnl

AC_MSG_CHECKING(for scandir void * comparison function)
AC_EGREP_HEADER([\\<alphasort\\>.*\\(.*void], dirent.h,
  AC_MSG_RESULT(yes)
  AC_DEFINE([ALPHASORT_VOID_ARG], 1,
    [define this if your scandir(3)'s comparison takes void * or dirent *]),
  AC_MSG_RESULT(no))


dnl
dnl libraries
dnl

dnl work out UNIX mail dir..

AC_MSG_CHECKING(for unix mail directory)

for foo in /var/spool/mail /usr/spool/mail /var/mail /usr/mail
do
  if test -d $foo; then
    mdir=$foo
    break
  fi
done

if test -n "$mdir"; then
  UNIX_MAIL=\"$mdir\"
  AC_MSG_RESULT($mdir)
  AC_DEFINE_UNQUOTED([UNIX_MAIL], ["$mdir"], [define this to the location of normal unix mail])
else
  AC_MSG_RESULT(none)
fi

if test -z "$CFLAGS"; then CFLAGS=-O ; fi
if test -z "$LDFLAGS"; then LDFLAGS= ; fi
RM="rm -f"
LN="ln -s"

if test ! -n "$bindir";
then
	bindir=\${exec_prefix}/bin
fi
AC_SUBST(bindir)

if test ! -n "$IRCLIB";
then
	IRCLIB=\${datarootdir}/irc
fi
AC_SUBST(IRCLIB)

if test "x$libexecdir" = "x"; then
  if test "x$exec_prefix" = "xNONE"; then
    if test "x$prefix" = "xNONE"; then
      libexecdir="$ac_default_prefix/libexec"
    else
      libexecdir="$prefix/libexec"
    fi
  else
    libexecdir="$exec_prefix/libexec"
  fi
fi
AC_SUBST(libexecdir)

AC_MSG_CHECKING(for ElectricFence library)
AC_ARG_WITH(efence,
[changequote(, )  --with-efence[=PATH]                 Compile with the ElectricFence debugging library.changequote([, ])],
[ case "$withval" in
  no)
    AC_MSG_RESULT(no)
    ;;		
  *)
    AC_MSG_RESULT(yes)
    if test "x$withval" = xyes; then
      withval="-lefence"
    else
      if test -d "$withval"; then
        if test -d "$withval/lib"; then
	  withval="-L$withval/lib -R$withval/lib -lefence"
	else
	  withval="-L$withval -lefence"
	fi
      fi
    fi
    LIBS="$withval $LIBS"
    ;;
  esac
], [
  AC_MSG_RESULT(no)
])

AC_MSG_CHECKING(for OpenSSL library)
checkopenssl=no
ssl_path=
AC_ARG_WITH(openssl,
[changequote(, )  --with-openssl[=PATH]                Compile with OpenSSL.changequote([, ])],
[ case "$withval" in
  no)
    ;;		
  *)
    if test "x$withval" != "xyes"; then
      ssl_path="$withval"
    fi
    checkopenssl=yes
    ;;
  esac
], [
  checkopenssl=maybe
])

ssl_libs=""
ssl_cflags=""
if test "x$checkopenssl" != xno; then
  if test "x$ssl_path" = x; then
    ssl_libs="-lssl -lcrypto"
  else
    if test -d "$ssl_path"; then
      if test -d "$ssl_path/lib"; then
        ssl_libs="-L$ssl_path/lib -lssl -lcrypto"
	ssl_cflags="-I$ssl_path/include"
      else
        ssl_libs="-L$ssl_path -lssl -lcrypto"
	ssl_cflags="-I$ssl_path/../include"
      fi
    fi
  fi
fi

if test "x$ssl_libs" != x; then
  AC_MSG_RESULT(yes)
  LIBS="$LIBS $ssl_libs"
  CFLAGS="$CFLAGS $ssl_cflags"
  AC_DEFINE([USE_OPENSSL], 1, [define this if you want to use OpenSSL])
else
  AC_MSG_RESULT(no)
fi

AC_MSG_CHECKING(for default SSL level)
DEFAULT_SSL_LEVEL=SSL_OFF
AC_ARG_WITH(default-ssl,
[changequote(, )  --with-default-ssl=LEVEL             Default SSL level (OFF,SSL,SSLNOCHECK).changequote([, ])],
[ case "$withval" in
  NONE|OFF)
    AC_MSG_RESULT(OFF)
    ;;		
  ON|SSLNOCHECK)
    AC_MSG_RESULT(SSLNOCHECK)
    DEFAULT_SSL_LEVEL=SSL_ON
    ;;		
  VERIFY|SSL)
    AC_MSG_RESULT(SSL)
    DEFAULT_SSL_LEVEL=SSL_VERIFY
    ;;
  *)
    AC_MSG_ERROR("Must be OFF, SSL, or SSLNOCHECK.")
    ;;
  esac ],
  AC_MSG_RESULT(NONE)
)
AC_SUBST(DEFAULT_SSL_LEVEL)
AC_DEFINE_UNQUOTED([DEFAULT_SSL_LEVEL], [$DEFAULT_SSL_LEVEL], [define to the default SSL level])

AC_MSG_CHECKING(for debug flags)
AC_ARG_WITH(debugging,
[changequote(, )  --with-debugging[=flags]             Build with debugging support.changequote([, ])],
[ case "$withval" in
  no)
    AC_MSG_RESULT(no)
    DEBUGFLAGS=
    ;;		
  *)
    AC_MSG_RESULT(yes)
    if test "x$withval" = xyes; then
      withval=-g
    fi
    DEBUGFLAGS="$withval"
    for flag in $CFLAGS; do
      case "$CFLAGS" in
        -DDEBUG|-DDEBUG=*)
	  found=1
	  break
	  ;;
        *)
          found=0
	  ;;
      esac
    done
    if test $found -eq 0; then
      CFLAGS="$CFLAGS -DDEBUG"
    fi
    ;;
  esac ],
  AC_MSG_RESULT(no)
)
AC_SUBST(DEBUGFLAGS)

AC_MSG_CHECKING(for warning flags)
AC_ARG_WITH(warnings,
[changequote(, )  --with-warnings[=flags]              Build with GCC warnings.changequote([, ])],
[ case "$withval" in
  no)
    AC_MSG_RESULT(no)
    WARNINGFLAGS=
    ;;		
  *)
    AC_MSG_RESULT(yes)
    if test "x$withval" = xyes; then
      withval='-Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wmissing-declarations -Wnested-externs -Wpointer-arith -Wformat -Wformat-security'
    fi
    WARNINGFLAGS="$withval"
    ;;
  esac ],
  AC_MSG_RESULT(no)
)
AC_SUBST(WARNINGFLAGS)

AC_MSG_CHECKING(for warnings as errors)
AC_ARG_WITH(warning-errors,
[changequote(, )  --with-warning-errors[=flags]        Turn warnings into errors.changequote([, ])],
[ case "$withval" in
  no)
    AC_MSG_RESULT(no)
    ERRORFLAGS=
    ;;		
  *)
    AC_MSG_RESULT(yes)
    if test "x$withval" = xyes; then
      withval='-Werror'
    fi
    ERRORFLAGS="$withval"
    ;;
  esac ],
  AC_MSG_RESULT(no)
)
AC_SUBST(ERRORFLAGS)

AC_MSG_CHECKING(for sanitizers)
AC_ARG_WITH(sanitizer,
[changequote(, )  --with-sanitizer[=<list>]            Use sanitizers, default ASAN.changequote([, ])],
[ case "$withval" in
  no)
    AC_MSG_RESULT(no)
    LIBSANI=
    ;;		
  *)
    if test "x$withval" = xyes; then
      withval='address'
    fi
    have_asan=0
    have_lsan=0
    have_ubsan=0
    for val in `echo "$withval" | sed "s/,/ /"`
    do
      LIBSANI=
      case "$val" in
      asan|address)
        FSANI=address
        LIBSANI=asan
        have_asan=1
        ;;
      lsan|leak)
        FSANI=leak
        LIBSANI=lsan
        have_lsan=1
        ;;
      ubsan|undefined)
        FSANI=undefined
        LIBSANI=ubsan
        have_ubsan=1
        ;;
      *)
        AC_MSG_ERROR(Sanitizer support for address, leak, and undefined behaviour only.)
        ;;
      esac
    done
    if test "$have_asan" -eq 1 -a "$have_lsan" -eq 1; then
      AC_MSG_ERROR(Do not combine address and leak sanitizers.)
    fi
    list=""
    sep=""
    if test "$have_asan" -eq 1; then
      CFLAGS="$CFLAGS -fsanitize=address"
      LIBS="$LIBS -lasan"
      list="$list$sep"address
      sep=" "
    fi
    if test "$have_lsan" -eq 1; then
      CFLAGS="$CFLAGS -fsanitize=leak"
      LIBS="$LIBS -llsan"
      list="$list$sep"leak
      sep=" "
    fi
    if test "$have_ubsan" -eq 1; then
      CFLAGS="$CFLAGS -fsanitize=undefined"
      LIBS="$LIBS -lubsan"
      list="$list$sep"undefined
      sep=" "
    fi
    AC_MSG_RESULT($list)
    ;;
  esac ],
  AC_MSG_RESULT(no)
)

AC_MSG_CHECKING(for emacs meta keys)
AC_ARG_WITH(emacs-meta-keys,
[changequote(, )  --with-emacs-meta-keys               Enable Emacs meta key support.changequote([, ])],
[ case "$withval" in
  no)
    AC_MSG_RESULT(no)
    ;;		
  *)
    AC_MSG_RESULT(yes)
    AC_DEFINE([WITH_EMACS_META_KEYS], 1, [define this if you want Emacs metakey support])
    ;;
  esac ],
  AC_MSG_RESULT(no)
)

AC_MSG_CHECKING(paranoia status)
AC_ARG_WITH(paranoid,
[changequote(, )  --with-paranoid                      Sets the compile-time paranoid flag.changequote([, ])],
[ AC_MSG_RESULT(yes)
  AC_DEFINE_UNQUOTED([PARANOID], 1, [define this if you want to be paranoid]) ],
  AC_MSG_RESULT(none)
)

AC_MSG_CHECKING(link time optimisation)
AC_ARG_WITH(lto,
[changequote(, )  --with-lto                           Enable use of the -flto option.changequote([, ])],
[ AC_MSG_RESULT(yes)
  CFLAGS="$CFLAGS -flto" ],
  AC_MSG_RESULT(none)
)

AC_MSG_CHECKING(for /dev/urandom)
if test -c /dev/urandom; then
  AC_MSG_RESULT(yes)
  have_dev_random=1
  dev_random_path="/dev/urandom"
else
  AC_MSG_RESULT(no)
  AC_MSG_CHECKING(for /dev/random)
  if test -c /dev/random; then
    AC_MSG_RESULT(yes)
    have_dev_random=1
    dev_random_path="/dev/random"
  else
    AC_MSG_RESULT(no)
  fi
fi

if test -n "$have_dev_random"
then
  AC_DEFINE([HAVE_DEV_RANDOM], 1, [Define this if you have /dev/random])
  AC_DEFINE_UNQUOTED([DEV_RANDOM_PATH], ["$dev_random_path"], [Define this to the random device to use])
fi

AC_MSG_CHECKING(for default server)
AC_ARG_WITH(default-server,
[changequote(, )  --with-default-server=SERVER[:PORT]  Connect to SERVER by default.changequote([, ])],
[ if test "$withval"; then
    AC_MSG_RESULT($withval)
    AC_DEFINE_UNQUOTED([DEFAULT_SERVER], ["$withval"], [define this to be the name<:port> of the default server])
  else
    AC_MSG_RESULT(none)
  fi ],
  AC_MSG_RESULT(none)
)

dnl
dnl transitory option to disable the new window resizer
dnl

AC_MSG_CHECKING(for default window resize method)
defval=1
AC_ARG_WITH(default-resize-method,
[  --with-default-resize-method[=type]    Either "old" or "new"],
[ case "$withval" in
  new|old)
    AC_MSG_RESULT($withval)
    if test "$withval" = old; then
      defval=0;
    fi
    ;;
  *)
    AC_MSG_ERROR(Window resize method must be either "old" or "new".)
    ;;
  esac ],
  AC_MSG_RESULT("new")
)
if test $defval -eq 1; then
  AC_DEFINE_UNQUOTED([DEFAULT_RESIZE_METHOD], [$defval], [Use default window resize method. 0 for old method.])
fi

dnl
dnl check for -lcrypt
dnl

AC_CHECK_LIB(c, crypt,
  [have_crypt=1],
  AC_CHECK_LIB(crypt, crypt,
    [have_crypt=1
     LIBS="$LIBS -lcrypt"],
    AC_CHECK_LIB(des, des,
      [have_crypt=1
       LIBS="$LIBS -ldes"])))

if test -n "$have_crypt"
then
  AC_DEFINE([HAVE_CRYPT], 1, [define this if you have crypt(3)])
fi

dnl
dnl check for SOCKS
dnl

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="$LIBS -lsocks5"], [
	AC_CHECK_LIB(socks, Rconnect, [
	    socks=4
	    LIBS="$LIBS -lsocks"], [
		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,
	[changequote(, )  --with-socks5[=PATH]                 Compile with SOCKS5 firewall traversal support.changequote([, ])],
	[ case "$withval" in
	  no)
	    AC_MSG_RESULT(no)
	    ;;
	  *)
	    AC_MSG_RESULT(yes)
	    socks=5
	    socks5lib=""
	    if test "x$withval" = "xyes"; then
	      socks5lib="-lsocks5"
	    else
	      if test -d "$withval"; then
		if test -d "$withval/include"; then
		  CFLAGS="$CFLAGS -I$withval/include"
		else
		  CFLAGS="$CFLAGS -I$withval"
		fi
	        if test -d "$withval/lib"; then
		  socks5lib="-L$withval/lib -lsocks5"
		else
		  socks5lib="-L$withval -lsocks5"
		fi
	      else
		socks5lib="$withval"
	      fi
	    fi
	    LIBS="$socks5lib $LIBS"
	    # If Socks was compiled with Kerberos support, we will need
	    # to link against kerberos libraries.  Temporarily append
	    # to LIBS.  This is harmless if there is no kerberos support.
	    TMPLIBS="$LIBS"
	    LIBS="$LIBS $KERBEROS_LIBS"
	    AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
					    [[ SOCKSconnect(); ]])],
			   [],
			   [ AC_MSG_ERROR(Could not find the $withval library.  You must first install socks5.) ])
	    LIBS="$TMPLIBS"
	    ;;
	  esac ],
	  AC_MSG_RESULT(no)
	)
fi

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

if test -n "$socks"; then
  AC_DEFINE([SOCKS], 1, [Define this if compiling with SOCKS (the firewall traversal library)])
fi

if test "x$socks" = "x4"; then
    AC_DEFINE([SOCKS4], 1, [Define this if using the SOCKS version 4 library])
fi

if test "x$socks" = "x5"; then
    AC_DEFINE([SOCKS5], 1, [Define this if using the SOCKS version 5 library])
fi

AC_MSG_CHECKING(for non-blocking)
AC_ARG_WITH(non-blocking,
[changequote(, )  --with-non-blocking=[TYPE]           Use TYPE non-blocking, yes or no.changequote([, ])],
[
  case "$withval" in
  no|none)
    AC_MSG_RESULT(no)
    ;;
  *)
    if test -z "$socks"; then
      withval=no
      AC_MSG_RESULT(no, disabled due to SOCKS support)
    else
      AC_MSG_RESULT(yes)
      non_blocking_connects=1
    fi
    ;;
  esac ],
[ 
  AC_MSG_RESULT(yes)
  non_blocking_connects=1
])

if test -n "$non_blocking_connects"
then
  AC_DEFINE([NON_BLOCKING_CONNECTS], 1, [define this to use non-blocking connects. Precluded by SOCKS])
fi

if test -n "$hpux"
then
	# HP-UX's pax is broken
	AC_CHECK_PROGS(COPY_DIRECTORY, tar cpio)
else
	AC_CHECK_PROGS(COPY_DIRECTORY, pax tar cpio)
fi
if test "x$COPY_DIRECTORY" = "xpax";
then
    INSTALL_HELP_CMD='cd $(topdir)/help; pax -r -w -s ";.*/CVS$$;;" -s ";.*/\.CVS$$;;" -s ";.*/CVS/.*;;" -s ";.*/\.CVS/.*;;" . $(HELP_DIR)'
else
    if test "x$COPY_DIRECTORY" = "xtar";
    then
	INSTALL_HELP_CMD='cd $(topdir)/help; tar -cf - . | ( cd $(HELP_DIR); tar -xf - )'
    else
	if test "x$COPY_DIRECTORY" = "xcpio";
	then
	    INSTALL_HELP_CMD='cd $(topdir)/help; find . -print | cpio -pdu $(HELP_DIR)'
	else
	    INSTALL_HELP_CMD="@echo \"I couldn't figure out a way to install the help files.\""
	fi
    fi
fi
AC_SUBST(INSTALL_HELP_CMD)

AC_CHECK_PROGS(ZCAT, gzcat zcat gunzip gzip uncompress uncompress)
case "x$ZCAT" in
  xgzcat)
    ZSUFFIX=".gz"
    ZARGS=
    ;;
  xzcat)
    ZSUFFIX=".Z"
    ZARGS=
    ;;
  xgunzip)
    ZSUFFIX=".gz"
    ZARGS="-c"
    ;;
  xgzip)
    ZSUFFIX=".gz"
    ZARGS="-dc"
    ;;
  xuncompress)
    ZSUFFIX=".Z"
    ZARGS="-c"
    ;;
  xcompress)
    ZSUFFIX=".Z"
    ZARGS="-dc"
    ;;
esac
AC_DEFINE_UNQUOTED([ZCAT],["$ZCAT"], [define this to the ZCAT program of your choice])
AC_DEFINE_UNQUOTED([ZSUFFIX],["$ZSUFFIX"], [define these to the ZCAT suffer of your choice(.gz)])
if test x"$ZARGS" != x; then
  AC_DEFINE_UNQUOTED([ZARGS],["$ZARGS"], [define these to the ZCAT args of your choice])
fi

AC_FIND_PROGRAM(SENDMAIL,sendmail,/usr/sbin:/usr/lib:/usr/ucblib:/usr/local/sbin:/usr/pkg/sbin)

AC_SUBST(RM)
AC_SUBST(LN)
AC_CONFIG_FILES([Makefile ircbug])
AC_OUTPUT

if test ! -f config.h; then
  cp ${srcdir}/include/config.h.dist config.h
fi

echo
echo well there we are, you now might want to look in config.h and 
echo see if there is anything you might want to tune, else you can
echo just run a make here..  good luck!
echo

