* man/mhbuild.man: wrapped one appearance of "Content-Disposition"
[mmh] / configure.in
index 9d3d226..59d9207 100644 (file)
@@ -4,47 +4,67 @@ dnl
 dnl $Id$
 dnl
 
-AC_INIT(h/nmh.h)
+dnl 2.13 definitely chokes; 2.53 is the earliest version I've tested.
+dnl 2.58 needed for help string macro but that only affects help output
+dnl 2.50 is the major breakpoint between the old autoconf and the new,
+dnl so require that. If there are bug reports about 2.50-2.52 not working
+dnl we can always move this up a little.
+AC_PREREQ(2.50)
+
+AC_INIT(nmh, m4_normalize(m4_include([VERSION])))
+AC_CONFIG_SRCDIR(h/nmh.h)
 AC_CONFIG_HEADER(config.h)
 
-AC_CANONICAL_SYSTEM
+AC_CANONICAL_TARGET
 
 dnl ---------------------
 dnl define a macro or two
 dnl ---------------------
 
 AC_DEFUN(NMH_PROG_GNU_LIBTOOL, [
+if test -n "$LIBTOOL" ; then
   tmptest=`$LIBTOOL --version 2>&1 | grep GNU`
   if test x"$tmptest" != x  ; then
     GNU_LIBTOOL=1
     AC_SUBST(GNU_LIBTOOL)dnl
   fi
+fi
 ] )
   
+echo "configuring for AC_PACKAGE_NAME-AC_PACKAGE_VERSION"
+AC_SUBST(VERSION,AC_PACKAGE_VERSION)dnl
 
-dnl What version of nmh are we building?
-VERSION=`sed -e 's/nmh-//' ${srcdir}/VERSION`
-echo "configuring for nmh-$VERSION"
-AC_SUBST(VERSION)dnl
+dnl What date of nmh are we building?
+DATE=`cat ${srcdir}/DATE`
+echo "configuring for nmh dated $DATE"
+AC_SUBST(DATE)dnl
 
 dnl --------------------------
 dnl CHECK COMMAND LINE OPTIONS
 dnl --------------------------
 
+dnl Do you want client-side support for apop?
+AC_ARG_ENABLE(apop, AS_HELP_STRING([--enable-apop],
+  [enable client-side support for POP3 and APOP]))
+if test x"$enable_apop" = x"yes"; then
+  AC_DEFINE(APOP)dnl
+  APOPLIB=md5.o
+  enable_pop=yes
+fi
+AC_SUBST(APOPLIB)dnl
+
 dnl Do you want to debug nmh?
-undefine([debug])dnl
 AC_ARG_ENABLE(debug,
-[  --enable-debug          enable nmh code debugging])
+  AS_HELP_STRING([--enable-debug],[enable nmh code debugging]))
 dnl The old redundant --enable-nmh-debug is deprecated and undocumented.
 if test x"$enable_nmh_debug" = x"yes"; then
   enable_debug=yes
 fi
 
 dnl Allow users to send email from addresses other than their default?
-undefine([masquerade])dnl
 AC_ARG_ENABLE(masquerade,
-  [  --enable-masquerade[='draft_from[ mmailid[ username_extension]]']
-                          enable 3 types of email address masquerading [none]],
+  AS_HELP_STRING([--enable-masquerade='draft_from mmailid username_extension'],
+    [enable up to 3 types of address masquerading]),
   [if test x"$enable_masquerade" = x"yes"; then
     masquerade="draft_from mmailid username_extension"
   else
@@ -53,9 +73,8 @@ AC_ARG_ENABLE(masquerade,
 AC_SUBST(masquerade)dnl
 
 dnl Do you want mhe support?
-undefine([mhe])dnl
 AC_ARG_ENABLE(mhe,
-[  --enable-mhe            enable mhe support (DEFAULT)])
+  AS_HELP_STRING([--disable-mhe],[disable mhe support]))
 
 dnl mhe support is on by default, so define it unless --disable-mhe or the
 dnl deprecated, undocumented --disable-nmh-mhe are specified.
@@ -63,41 +82,60 @@ if test x"$enable_mhe" != x"no" -a x"$enable_nmh_mhe" != x"no"; then
   AC_DEFINE(MHE)dnl
 fi
 
-dnl Do you want client-side support for apop?
-dnl Note that this appears before pop so that we can enforce enable-pop
-AC_ARG_ENABLE(apop,
-[  --enable-apop            enable client-side support for apop])
-if test x"$enable_apop" = x"yes"; then
-  AC_DEFINE(APOP)dnl
-  APOPLIB=md5.o
+dnl Do you want client-side support for pop?
+AC_ARG_ENABLE(pop,
+  AS_HELP_STRING([--enable-pop], [enable client-side support for plain POP3]))
+dnl The old redundant --enable-nmh-pop is deprecated and undocumented.
+if test x"$enable_nmh_pop" = x"yes"; then
   enable_pop=yes
 fi
-AC_SUBST(APOPLIB)dnl
+
+dnl Do you want client-side support for using SASL for authentication?
+dnl Note that this code will be enabled for both POP and SMTP
+AC_ARG_WITH(cyrus-sasl, AS_HELP_STRING([--with-cyrus-sasl=DIR],
+  [specify location of Cyrus SASL library]))
+if test x"$with_cyrus_sasl" != x -a x"$with_cyrus_sasl" != x"no"; then
+  AC_DEFINE(CYRUS_SASL)dnl
+  sasl_support=yes
+else
+  sasl_support=no
+fi
+
+dnl What should be the default editor?
+AC_ARG_WITH(editor,
+  AS_HELP_STRING([--with-editor=EDITOR],[specify the default editor]))
+
+if test -n "$with_editor"; then
+  editorpath="$with_editor"
+fi
+
+dnl Set the backup prefix
+AC_ARG_WITH([hash-backup],
+  AS_HELP_STRING([--with-hash-backup],[use # as the backup prefix (default: ,)]))
+if test x"$with_hash_backup" != x -a x"$with_hash_backup" != x"no"; then
+  backup_prefix="#"
+else
+  backup_prefix=","
+fi
+AC_DEFINE_UNQUOTED(BACKUP_PREFIX, "$backup_prefix")dnl
 
 dnl Do you want support for hesiod
 AC_ARG_WITH(hesiod,
-[  --with-hesiod=PREFIX    specify location of Hesiod])
+  AS_HELP_STRING([--with-hesiod=DIR],[specify location of Hesiod]))
 if test x"$with_hesiod" != x -a x"$with_hesiod" != x"no"; then
   AC_DEFINE(HESIOD)dnl
 fi
 
 dnl Do you want client-side support for kpop
-AC_ARG_WITH(krb4,
-[  --with-krb4=PREFIX      specify location of Kerberos V4 for kpop support])
+AC_ARG_WITH(krb4, AS_HELP_STRING([--with-krb4=DIR],
+  [specify location of Kerberos V4 for KPOP support]))
 if test x"$with_krb4" != x -a x"$with_krb4" != x"no"; then
   enable_pop=yes
   AC_DEFINE(KPOP)dnl
   AC_DEFINE(KPOP_PRINCIPAL, "pop")dnl
 fi
 
-dnl Do you want client-side support for pop?
-undefine([pop])dnl
-AC_ARG_ENABLE(pop,
-[  --enable-pop            enable client-side support for pop])
-dnl The old redundant --enable-nmh-pop is deprecated and undocumented.
-if test x"$enable_nmh_pop" = x"yes"; then
-  enable_pop=yes
-fi
+dnl After we know if we're including apop and kpop support, do pop stuff
 if test x"$enable_pop" = x"yes"; then
   AC_DEFINE(POP)dnl
   POPLIB=popsbr.o
@@ -108,51 +146,57 @@ fi
 AC_SUBST(POPLIB)dnl
 AC_SUBST(POPSED)dnl
 
-dnl What should be the default editor?
-undefine([editor])dnl
-AC_ARG_WITH(editor,
-[  --with-editor=EDITOR    specify the default editor])
-
-if test -n "$with_editor"; then
-  editorpath="$with_editor"
+dnl What method of locking to use?
+AC_ARG_WITH(locking,
+  AS_HELP_STRING([--with-locking=@<:@dot|fcntl|flock|lockf@:>@],
+  [specify the file locking method]))
+
+if test x"$with_locking" = x"dot"; then
+  LOCKTYPE="dot"
+  AC_DEFINE(DOT_LOCKING)dnl
+elif test x"$with_locking" = x"flock"; then
+  LOCKTYPE="flock"
+  AC_DEFINE(FLOCK_LOCKING)dnl
+elif test x"$with_locking" = x"lockf"; then
+  LOCKTYPE="lockf"
+  AC_DEFINE(LOCKF_LOCKING)dnl
+elif test x"$with_locking" = x"fcntl"; then
+  LOCKTYPE="fcntl"
+  AC_DEFINE(FCNTL_LOCKING)dnl
+else
+  LOCKTYPE="dot"
+  AC_DEFINE(DOT_LOCKING)dnl
 fi
 
 dnl What method of posting should post use?
-undefine([mts])dnl
 AC_ARG_WITH(mts,
-[  --with-mts=MTS          specify the mail transport agent])
+  AS_HELP_STRING([--with-mts=@<:@smtp|sendmail@:>@],
+  [specify the default mail transport agent/service]))
 
 if test x"$with_mts" = x"smtp"; then
   MTS="smtp"
-  MTSLIB="mts/smtp/libsmtp.a"
-  AC_DEFINE(SMTPMTS)dnl
 elif test x"$with_mts" = x"sendmail"; then
   MTS="sendmail"
-  MTSLIB="mts/sendmail/libsend.a"
-  AC_DEFINE(SENDMTS)dnl
 else
   MTS="smtp"
-  MTSLIB="mts/smtp/libsmtp.a"
-  AC_DEFINE(SMTPMTS)dnl
 fi
-
 AC_SUBST(MTS)dnl
-AC_SUBST(MTSLIB)dnl
+
+dnl Both the smtp and sendmail mail transport services use the smtp code
+AC_DEFINE(SMTPMTS)dnl
 
 dnl What should be the default pager?
-undefine([pager])dnl
 AC_ARG_WITH(pager,
-[  --with-pager=PAGER      specify the default pager])
+  AS_HELP_STRING([--with-pager=PAGER],[specify the default pager]))
 
 if test -n "$with_pager"; then
   pagerpath="$with_pager"
 fi
 
 dnl What should be the default mail server(s)?
-undefine([smtpservers])dnl
 AC_ARG_WITH(smtpservers,
-[  --with-smtpservers='SMTPSERVER1[ SMTPSERVER2...]'
-                          specify the default smtp server(s) [localhost]])
+  AS_HELP_STRING([--with-smtpservers='SMTPSERVER1@<:@ SMTPSERVER2...@:>@'],
+  [specify the default SMTP server(s) @<:@localhost@:>@]))
 if test -n "$with_smtpservers"; then
   smtpservers="$with_smtpservers"
 else
@@ -189,9 +233,18 @@ if test -n "$auto_cflags"; then
       test -z "$CFLAGS" && CFLAGS=-g || CFLAGS="$CFLAGS -g"
     fi
   else
-    test -z "$LDFLAGS" && LDFLAGS=-s
+    if test -z "$LDFLAGS"; then
+      case "$build_os" in
+       darwin*)
+         LDFLAGS=
+          ;;
+       *)
+         LDFLAGS=-s
+         ;;
+      esac
+    fi
     if test -n "$GCC"; then
-      test -z "$CFLAGS" && CFLAGS=-O2 || CFLAGS="$CFLAGS -O2"
+      test -z "$CFLAGS" && CFLAGS="-Wall -O2" || CFLAGS="$CFLAGS -Wall -O2"
     else
       test -z "$CFLAGS" && CFLAGS=-O  || CFLAGS="$CFLAGS -O"
     fi
@@ -213,6 +266,25 @@ dnl Look for `cut'
 pathtmp=/usr/bin:/bin:/usr/local/bin:/usr/xpg4/bin:/usr/ucb
 AC_PATH_PROG(cutpath, cut, no, [$pathtmp])
 
+dnl ----------------------------------------------
+dnl check for lclint, and lint if it doesn't exist
+dnl ----------------------------------------------
+AC_CHECK_PROG(linttmp1, lclint, lclint, no)dnl
+if test x$ac_cv_prog_linttmp1 != xno ; then
+  LINT=$ac_cv_prog_linttmp1
+  LINTFLAGS="-weak +posixlib -macrovarprefixexclude"
+else
+  AC_CHECK_PROG(linttmp2, lint, lint, no)dnl
+  if test x$ac_cv_prog_linttmp2 != xno ; then
+    LINT=$ac_cv_prog_linttmp2
+    LINTFLAGS=""
+  else
+    LINT="echo 'No lint program found'"
+    LINTFLAGS=""
+  fi
+fi
+AC_SUBST(LINT)dnl
+AC_SUBST(LINTFLAGS)dnl
 
 dnl try to figure out which one we've got
 AC_CHECK_PROG(LIBTOOL, libtool, libtool, , [$pathtmp])
@@ -236,6 +308,20 @@ dnl   AC_SUBST(LORDER)dnl
 dnl   AC_SUBST(TSORT)dnl
 fi
 
+dnl Check whether tsort can deal with loops
+AC_CACHE_CHECK(whether tsort can deal with loops, nmh_cv_tsort_loop,
+  [if test -z "`echo a b b a | tsort 2>/dev/null | grep a`" ; then
+    nmh_cv_tsort_loop=no
+  else
+    nmh_cv_tsort_loop=yes
+  fi])
+if test x$nmh_cv_tsort_loop = xno ; then
+  LORDER=echo
+  TSORT=cat
+  AC_SUBST(LORDER)dnl
+  AC_SUBST(TSORT)dnl
+fi
+
 dnl Look for `ls'
 pathtmp=/usr/bin:/bin:/usr/local/bin:/usr/xpg4/bin:/usr/ucb
 AC_PATH_PROG(lspath, ls, no, [$pathtmp])
@@ -268,11 +354,11 @@ AC_SUBST(pagerpath)dnl
 
 dnl Look for `sendmail'
 pathtmp=/usr/lib:/usr/sbin:/usr/etc:/usr/ucblib:/usr/bin:/bin
-AC_PATH_PROG(sendmailpath, sendmail, no, [$pathtmp])
+AC_PATH_PROG(sendmailpath, sendmail, /usr/sbin/sendmail, [$pathtmp])
 
 dnl Look for `vi'
 pathtmp=/usr/bin:/bin:/usr/ucb:/usr/local/bin
-AC_PATH_PROG(vipath, vi, no, [$pathtmp])
+AC_PATH_PROG(vipath, vi, /bin/vi, [$pathtmp])
 
 dnl If editor is not specified yet,
 dnl then use `vi' as the default.
@@ -284,7 +370,7 @@ AC_SUBST(editorpath)dnl
 dnl Check for broken vi
 AC_CACHE_CHECK(for broken vi, nmh_cv_attvibug,
 [if echo 'r /nonexist-file
-q' | ex > /dev/null 2>&1
+q' | ex > /dev/null
 then
         nmh_cv_attvibug=no
 else
@@ -322,8 +408,25 @@ if test "$lspath" != "no" -a "$cutpath" != "no"; then
   fi])
 fi
 
-dnl ...If it's not, we need to #define MAILGROUP to 1 and make inc setgid.
-if test x"$nmh_cv_mailspool_world_writable" = x"no"; then
+dnl Also, check for liblockfile (as found on Debian systems)
+AC_CHECK_HEADER(lockfile.h, AC_CHECK_LIB(lockfile, lockfile_create) )
+
+dnl and whether its companion program dotlockfile is setgid
+AC_PATH_PROG(dotlockfilepath, dotlockfile, no)
+if test "$ac_cv_lib_lockfile_lockfile_create" != "no" ; then
+  if test "$ac_cv_path_dotlockfilepath" != "no" ; then
+    AC_CACHE_CHECK(whether dotlockfile is setgid, nmh_cv_dotlockfile_setgid,
+    [ if test -g "$ac_cv_path_dotlockfilepath" ; then
+        nmh_cv_dotlockfile_setgid=yes
+      else
+        nmh_cv_dotlockfile_setgid=no
+      fi])
+  fi
+fi
+
+dnl If mailspool is not world-writable and dotlockfile is not setgid,
+dnl we need to #define MAILGROUP to 1 and make inc setgid.
+if test x"$nmh_cv_mailspool_world_writable" = x"no" -a x"$nmh_cv_dotlockfile_setgid" != x"yes" ; then
   dnl do we really need both of these?
   AC_DEFINE(MAILGROUP)dnl
   SETGID_MAIL=1
@@ -347,26 +450,25 @@ AC_HEADER_SYS_WAIT
 AC_HEADER_STAT
 AC_CHECK_HEADERS(string.h memory.h stdlib.h unistd.h errno.h fcntl.h \
                  limits.h crypt.h termcap.h termio.h termios.h locale.h \
-                 netdb.h sys/param.h sys/time.h sys/utsname.h arpa/inet.h \
-                 arpa/ftp.h)
-
+                 langinfo.h wchar.h wctype.h iconv.h netdb.h \
+                 sys/param.h sys/time.h sys/utsname.h sys/stream.h \
+                 arpa/inet.h arpa/ftp.h)
 
 AC_CACHE_CHECK(POSIX termios, nmh_cv_sys_posix_termios,
-[AC_TRY_LINK([#include <sys/types.h>
+[AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
 #include <unistd.h>
-#include <termios.h>],
-[/* SunOS 4.0.3 has termios.h but not the library calls.  */
-tcgetattr(0, 0);],
-  nmh_cv_sys_posix_termios=yes, nmh_cv_sys_posix_termios=no)])
+#include <termios.h>]],
+[[/* SunOS 4.0.3 has termios.h but not the library calls.  */
+tcgetattr(0, 0);]])],
+nmh_cv_sys_posix_termios=yes, nmh_cv_sys_posix_termios=no)])
  
 if test $nmh_cv_sys_posix_termios = yes; then
   AC_CACHE_CHECK(TIOCGWINSZ in termios.h,
   nmh_cv_header_termios_h_tiocgwinsz,
-  [AC_TRY_LINK([#include <sys/types.h>
-#include <termios.h>],
-  [int x = TIOCGWINSZ;],
-  nmh_cv_header_termios_h_tiocgwinsz=yes,
-  nmh_cv_header_termios_h_tiocgwinsz=no)])
+  [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
+#include <termios.h>]],
+  [[int x = TIOCGWINSZ;]])],
+  nmh_cv_header_termios_h_tiocgwinsz=yes,nmh_cv_header_termios_h_tiocgwinsz=no)])
 else
   nmh_cv_header_termios_h_tiocgwinsz=no
 fi
@@ -374,13 +476,12 @@ fi
 if test $nmh_cv_header_termios_h_tiocgwinsz = no; then
   AC_CACHE_CHECK(TIOCGWINSZ in sys/ioctl.h,
   nmh_cv_header_sys_ioctl_h_tiocgwinsz,
-  [AC_TRY_LINK([#include <sys/types.h>
-#include <sys/ioctl.h>],
-  [int x = TIOCGWINSZ;],
-  nmh_cv_header_sys_ioctl_h_tiocgwinsz=yes,
-  nmh_cv_header_sys_ioctl_h_tiocgwinsz=no)])
+  [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
+#include <sys/ioctl.h>]],
+  [[int x = TIOCGWINSZ;]])],
+  nmh_cv_header_sys_ioctl_h_tiocgwinsz=yes,nmh_cv_header_sys_ioctl_h_tiocgwinsz=no)])
   if test $nmh_cv_header_sys_ioctl_h_tiocgwinsz = yes; then
-    AC_DEFINE(GWINSZ_IN_SYS_IOCTL)
+    AC_DEFINE(GWINSZ_IN_SYS_IOCTL)dnl
   fi
 fi
  
@@ -393,7 +494,11 @@ AC_CHECK_HEADER(libio.h, [
   AC_EGREP_HEADER(_IO_write_ptr, libio.h, [
     AC_DEFINE(LINUX_STDIO) ]) ]) 
 
-AC_CHECK_HEADER([sys/ptem.h], AC_DEFINE(WINSIZE_IN_PTEM))
+AC_CHECK_HEADER([sys/ptem.h], AC_DEFINE(WINSIZE_IN_PTEM),,
+[[#if HAVE_SYS_STREAM_H
+#  include <sys/stream.h>
+#endif
+]])
 
 dnl ---------------
 dnl CHECK FUNCTIONS
@@ -402,7 +507,7 @@ AC_FUNC_VFORK
 AC_CHECK_LIB(mkstemp,mkstemp)
 AC_CHECK_FUNCS(waitpid wait3 sigaction sigprocmask sigblock sigsetmask \
                sighold sigrelse writev lstat uname tzset killpg mkstemp \
-               sethostent)
+               sethostent getutent nl_langinfo mbtowc wcwidth)
 
 dnl solaris screws this up
 AC_CHECK_FUNC(gethostbyname, [AC_DEFINE(HAVE_GETHOSTBYNAME)],
@@ -410,10 +515,11 @@ AC_CHECK_FUNC(gethostbyname, [AC_DEFINE(HAVE_GETHOSTBYNAME)],
 
 dnl sigsetjmp may be a macro
 AC_MSG_CHECKING(for sigsetjmp)
-AC_TRY_LINK([#include <setjmp.h>], [sigsetjmp((void *)0, 0);],
-        [AC_DEFINE(HAVE_SIGSETJMP) AC_MSG_RESULT(yes)], AC_MSG_RESULT(no))
+AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <setjmp.h>]],
+  [[sigsetjmp((void *)0, 0);]])],[AC_DEFINE(HAVE_SIGSETJMP) AC_MSG_RESULT(yes)],
+  [AC_MSG_RESULT(no)])
 
-AC_REPLACE_FUNCS(snprintf strerror strdup)
+AC_REPLACE_FUNCS(snprintf strdup)
 
 dnl Look for the initgroups() declaration.  On AIX 4.[13], Solaris 4.1.3, and
 dnl ULTRIX 4.2A the function is defined in libc but there's no declaration in
@@ -435,6 +541,13 @@ dnl preprocessor to preprocess stdio.h and make sure that there's actually a
 dnl prototype. 
 AC_EGREP_HEADER(snprintf, stdio.h, AC_DEFINE(HAVE_SNPRINTF_PROTOTYPE))
 
+dnl Check for multibyte character set support
+if test "x$ac_cv_header_wchar_h" = "xyes" -a "x$ac_cv_header_wctype_h" = "xyes" \
+    -a "x$ac_cv_func_wcwidth" = "xyes" -a "x$ac_cv_func_mbtowc" = "xyes"; then
+  AC_DEFINE(MULTIBYTE_SUPPORT, 1,
+    [Define to enable support for multibyte character sets])
+fi
+
 dnl -------------------
 dnl CHECK FOR LIBRARIES
 dnl -------------------
@@ -450,19 +563,113 @@ for lib in $termcap_curses_order; do
 done
 AC_SUBST(TERMLIB)dnl
 
+dnl ---------------
+dnl CHECK FOR ICONV
+dnl ---------------
+
+dnl Find iconv. It may be in libiconv and may be iconv() or libiconv()
+if test "x$ac_cv_header_iconv_h" = "xyes"; then
+  AC_CHECK_FUNC(iconv, ac_found_iconv=yes, ac_found_iconv=no)
+  if test "x$ac_found_iconv" = "xno"; then
+    AC_CHECK_LIB(iconv, iconv, ac_found_iconv=yes)
+    if test "x$ac_found_iconv" = "xno"; then
+      AC_CHECK_LIB(iconv, libiconv, ac_found_iconv=yes)
+    fi
+    if test "x$ac_found_iconv" != "xno"; then
+      LIBS="-liconv $LIBS"
+    fi
+  else
+    dnl Handle case where there is a native iconv but iconv.h is from libiconv
+    AC_CHECK_DECL(_libiconv_version,
+      [ AC_CHECK_LIB(iconv, libiconv, LIBS="-liconv $LIBS") ],,
+      [ #include <iconv.h> ])
+  fi
+fi
+if test "x$ac_found_iconv" = xyes; then
+  AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
+fi
+
+dnl Check if iconv uses const in prototype declaration
+if test "x$ac_found_iconv" = "xyes"; then
+  AC_CACHE_CHECK(for iconv declaration, ac_cv_iconv_const,
+    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdlib.h>
+        #include <iconv.h>]],
+        [[#ifdef __cplusplus
+          "C"
+          #endif
+          #if defined(__STDC__) || defined(__cplusplus)
+          size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
+          #else
+          size_t iconv();
+          #endif]])],
+      [ac_cv_iconv_const=],
+      [ac_cv_iconv_const=const])])
+  AC_DEFINE_UNQUOTED([ICONV_CONST], $ac_cv_iconv_const,
+    [Define as const if the declaration of iconv() needs const.])
+fi
 
 dnl --------------
 dnl CHECK FOR NDBM
 dnl --------------
-dnl Checks for ndbm
-AC_CHECK_FUNC(dbm_open, ,
-  AC_CHECK_LIB(ndbm, dbm_open, ,
-    AC_CHECK_LIB(dbm, dbm_open)))
 
-dnl ----------------
-dnl CHECK FOR NDBM.H
-dnl ----------------
-AC_CHECK_HEADERS(db1/ndbm.h)
+AC_ARG_WITH([ndbm],AS_HELP_STRING([--with-ndbm=ARG],[use -lARG to link with ndbm]),
+            [nmh_ndbm=$withval],[nmh_ndbm=autodetect])
+AC_ARG_WITH([ndbmheader],AS_HELP_STRING([--with-ndbmheader=ARG],[#include <ARG> to use ndbm]),
+            [nmh_ndbmheader=$withval],[nmh_ndbmheader=autodetect])
+
+if test "$nmh_ndbm" = "autodetect"; then
+  if test "$nmh_ndbmheader" != "autodetect"; then
+    AC_MSG_ERROR([must specify both --with-ndbm and --with-ndbmheader or neither])
+  else
+
+    dnl There are at least four implementations of ndbm, and
+    dnl several of those can be in different places at the whim
+    dnl of the system integrator. A good summary of this mess
+    dnl can be found at http://www.unixpapa.com/incnote/dbm.html
+
+    dnl Classic ndbm with no library required (eg NetBSD): try this
+    dnl first so we don't accidentally link in a pointless but harmless
+    dnl library in one of the later ndbm.h+libfoo tests:
+    NMH_CHECK_NDBM(ndbm.h,,,
+    dnl Berkeley DBv2 emulating ndbm: header in db.h:
+      NMH_CHECK_NDBM(db.h,db,,
+    dnl Berkeley DBv1 emulating ndbm:
+        NMH_CHECK_NDBM(ndbm.h,db,,
+          NMH_CHECK_NDBM(ndbm.h,db1,,
+    dnl Classic ndbm:
+            NMH_CHECK_NDBM(ndbm.h,ndbm,,
+    dnl glibc2.1 systems put db1 in a subdir:
+              NMH_CHECK_NDBM(db1/ndbm.h,db1,,
+    dnl GNU gdbm emulating ndbm, with header possibly in gdbm/
+    dnl and possibly needing gbdm_compat library:
+                NMH_CHECK_NDBM(gdbm/ndbm.h,gdbm,,
+                  NMH_CHECK_NDBM(gdbm/ndbm.h,gdbm_compat -lgdbm,,
+                    NMH_CHECK_NDBM(ndbm.h,gdbm,,
+                      NMH_CHECK_NDBM(ndbm.h,gdbm_compat -lgdbm))))))))))
+
+  fi
+else
+  dnl We don't really need to check that the user-specified values work,
+  dnl but it is a convenience to the user to bomb out early rather than
+  dnl after configure and half the compile process.
+  NMH_CHECK_NDBM([$nmh_ndbmheader],[$nmh_ndbm])
+fi
+
+if test "$nmh_ndbm_found" = "no"; then
+  AC_MSG_ERROR([could not find a working ndbm library/header combination])
+else
+  dnl Now export the lib/header to our makefile/config.h:
+  if test x"$nmh_ndbmheader" != x; then
+    AC_DEFINE_UNQUOTED(NDBM_HEADER, <$nmh_ndbmheader>)
+  fi
+  if test x"$nmh_ndbm" != x; then
+    NDBM_LIBS="-l$nmh_ndbm"
+  else
+    NDBM_LIBS=
+  fi
+  AC_SUBST(NDBM_LIBS)
+fi
+
 
 dnl ----------------
 dnl CHECK FOR HESIOD
@@ -472,10 +679,16 @@ if test x"$with_hesiod" != x -a x"$with_hesiod" != x"no"; then
     HESIOD_INCLUDES="-I$with_hesiod/include"
     HESIOD_LIBS="-L$with_hesiod/lib"
   fi
-  AC_CHECK_FUNC(res_send, ,
-    AC_CHECK_LIB(resolv, res_send))
-  AC_CHECK_LIB(hesiod, hes_resolve, [HESIOD_LIBS="$HESIOD_LIBS -lhesiod"],
-    [AC_MSG_ERROR(Hesiod library not found)], $HESIOD_LIBS)
+  AC_CHECK_FUNC(res_send,
+       [AC_CHECK_LIB(hesiod, hes_resolve,
+               [HESIOD_LIBS="$HESIOD_LIBS -lhesiod"],
+               [AC_MSG_ERROR(Hesiod library not found)],
+               $HESIOD_LIBS)],
+       [AC_CHECK_LIB(hesiod, hes_resolve,
+               [HESIOD_LIBS="$HESIOD_LIBS -lhesiod -lresolv"],
+               [AC_MSG_ERROR(Hesiod library not found)],
+               $HESIOD_LIBS -lresolv)])
+
 fi
 AC_SUBST(HESIOD_INCLUDES)dnl
 AC_SUBST(HESIOD_LIBS)dnl
@@ -493,17 +706,54 @@ if test x"$with_krb4" != x -a x"$with_krb4" != x"no"; then
   elif test -d /usr/include/kerberosIV; then
     KRB4_INCLUDES="-I/usr/include/kerberosIV"
   fi
-  AC_CHECK_LIB(krb4, krb_rd_req,
-    [KRB4_LIBS="$KRB4_LIBS -lkrb4 -ldes425 -lkrb5 -lcrypto -lcom_err"],
-    [AC_CHECK_LIB(krb, krb_rd_req,
-      [KRB4_LIBS="$KRB4_LIBS -lkrb -ldes"],
-      [AC_MSG_ERROR(Kerberos 4 libraries not found)],
-      $KRB4_LIBS -ldes)],
-    $KRB4_LIBS -ldes425 -lkrb5 -lcrypto -lcom_err)
+dnl First, check if we have -lk5crypto, since that means we have a recent krb5
+
+  AC_CHECK_LIB(k5crypto, krb5_encrypt,
+       [AC_CHECK_LIB(krb4, krb_rd_req,
+               [KRB4_LIBS="$KRB4_LIBS -lkrb4 -ldes425 -lkrb5 -lk5crypto -lcom_err"],
+               [AC_MSG_ERROR(Kerberos 4 compatibility libraries not found)],
+               $KRB4_LIBS -ldes425 -lkrb5 -lk5crypto -lcom_err)],
+
+       [AC_CHECK_LIB(krb4, krb_rd_req,
+           [KRB4_LIBS="$KRB4_LIBS -lkrb4 -ldes425 -lkrb5 -lcrypto -lcom_err"],
+           [AC_CHECK_LIB(krb, krb_rd_req,
+             [KRB4_LIBS="$KRB4_LIBS -lkrb -ldes"],
+             [AC_MSG_ERROR(Kerberos 4 libraries not found)],
+             $KRB4_LIBS -ldes)],
+           $KRB4_LIBS -ldes425 -lkrb5 -lcrypto -lcom_err)],
+       $KRB4_LIBS)
+
 fi
 AC_SUBST(KRB4_INCLUDES)dnl
 AC_SUBST(KRB4_LIBS)dnl
 
+dnl --------------------
+dnl CHECK FOR CYRUS SASL
+dnl --------------------
+if test x"$with_cyrus_sasl" != x -a x"$with_cyrus_sasl" != x"no"; then
+  if test x"$with_cyrus_sasl" != x"yes"; then
+    SASL_INCLUDES="-I$with_cyrus_sasl/include"
+    SASL_LIBS="-L$with_cyrus_sasl/lib"
+
+    dnl Do OS-specific hardcoding of SASL shared library path into executables,
+    dnl so user isn't forced to set environment variables like Solaris'
+    dnl LD_LIBRARY_PATH.
+    case "$target_os" in
+      solaris*)
+       SASL_LIBS="$SASL_LIBS -R$with_cyrus_sasl/lib"
+       ;;
+    esac
+  fi
+  save_LDFLAGS="$LDFLAGS"
+  LDFLAGS="$LDFLAGS $SASL_LIBS"
+  AC_CHECK_LIB(sasl2, sasl_client_new,
+    [SASL_LIBS="$SASL_LIBS -lsasl2"],
+    [AC_MSG_ERROR(Cyrus SASL library not found)])
+  LDFLAGS="$save_LDFLAGS"
+fi
+AC_SUBST(SASL_INCLUDES)dnl
+AC_SUBST(SASL_LIBS)dnl
+
 dnl ---------------------
 dnl CHECK TERMCAP LIBRARY
 dnl ---------------------
@@ -516,27 +766,25 @@ LIBS="$TERMLIB $LIBS"
 dnl Checks for external variable ospeed in the termcap library.
 AC_CACHE_CHECK(if an include file defines ospeed,
 nmh_cv_decl_ospeed_include_defines,
-[AC_TRY_LINK(
-[#include <sys/types.h>
+[AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
 #if HAVE_TERMIOS_H
 #include <termios.h>
 #endif
 #if HAVE_TERMCAP_H
 #include <termcap.h>
-#endif], [ospeed = 0;],
-nmh_cv_decl_ospeed_include_defines=yes,
-nmh_cv_decl_ospeed_include_defines=no)])
+#endif]], [[ospeed = 0;]])],
+nmh_cv_decl_ospeed_include_defines=yes,nmh_cv_decl_ospeed_include_defines=no)])
  
 if test $nmh_cv_decl_ospeed_include_defines = no; then
   AC_CACHE_CHECK(if you must define ospeed,
   nmh_cv_decl_ospeed_must_define,
-  [AC_TRY_LINK( ,[extern short ospeed; ospeed = 0;],
-  nmh_cv_decl_ospeed_must_define=yes,
-  nmh_cv_decl_ospeed_must_define=no)])
+  [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
+  [[extern short ospeed; ospeed = 0;]])],
+  nmh_cv_decl_ospeed_must_define=yes,nmh_cv_decl_ospeed_must_define=no)])
 fi
  
 if test $nmh_cv_decl_ospeed_include_defines = yes; then
-  AC_DEFINE(HAVE_OSPEED)
+  AC_DEFINE(HAVE_OSPEED)dnl
 elif test $nmh_cv_decl_ospeed_must_define = yes; then
   AC_DEFINE(HAVE_OSPEED)
   AC_DEFINE(MUST_DEFINE_OSPEED)
@@ -572,10 +820,9 @@ dnl Check for sigset_t.  Currently I'm looking in
 dnl <sys/types.h> and <signal.h>.  Others might need
 dnl to be added.
 AC_CACHE_CHECK(for sigset_t, nmh_cv_type_sigset_t,
-[AC_TRY_COMPILE(
-[#include <sys/types.h>
-#include <signal.h>], [sigset_t tempsigset;],
-  nmh_cv_type_sigset_t=yes, nmh_cv_type_sigset_t=no)])
+[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
+#include <signal.h>]], [[sigset_t tempsigset;]])],
+nmh_cv_type_sigset_t=yes,nmh_cv_type_sigset_t=no)])
 if test $nmh_cv_type_sigset_t = no; then
   AC_DEFINE(sigset_t, unsigned int)
 fi
@@ -583,11 +830,10 @@ fi
 dnl ----------------
 dnl CHECK STRUCTURES
 dnl ----------------
-AC_STRUCT_ST_BLKSIZE
+AC_CHECK_MEMBERS(struct stat.st_blksize)
 
 AC_CACHE_CHECK(for tm_gmtoff in struct tm, nmh_cv_struct_tm_gmtoff,
-[AC_TRY_COMPILE(
-[#ifdef TIME_WITH_SYS_TIME
+[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#ifdef TIME_WITH_SYS_TIME
 # include <sys/time.h>
 # include <time.h>
 #else
@@ -596,13 +842,21 @@ AC_CACHE_CHECK(for tm_gmtoff in struct tm, nmh_cv_struct_tm_gmtoff,
 # else
 #  include <time.h>
 # endif
-#endif],
-[struct tm temptm; temptm.tm_gmtoff = 0;],
-  nmh_cv_struct_tm_gmtoff=yes, nmh_cv_struct_tm_gmtoff=no)])
+#endif]], [[struct tm temptm; temptm.tm_gmtoff = 0;]])],
+nmh_cv_struct_tm_gmtoff=yes,nmh_cv_struct_tm_gmtoff=no)])
 if test $nmh_cv_struct_tm_gmtoff = yes; then
   AC_DEFINE(HAVE_TM_GMTOFF)
 fi
 
+AC_CACHE_CHECK(for ut_type in struct utmp, nmh_cv_struct_utmp_ut_type,
+[AC_TRY_COMPILE(
+[#include <utmp.h>],
+[struct utmp temputmp; temputmp.ut_type = 0;],
+  nmh_cv_struct_utmp_ut_type=yes, nmh_cv_struct_utmp_ut_type=no)])
+if test $nmh_cv_struct_utmp_ut_type = yes; then
+  AC_DEFINE(HAVE_UTMP_UT_TYPE)
+fi
+
 dnl -------------
 dnl CHECK SIGNALS
 dnl -------------
@@ -694,12 +948,11 @@ esac
 dnl ----------------
 dnl OUTPUT MAKEFILES
 dnl ----------------
-AC_OUTPUT(Makefile config/Makefile h/Makefile sbr/Makefile uip/Makefile \
-          zotnet/Makefile zotnet/mts/Makefile zotnet/tws/Makefile \
-          zotnet/mf/Makefile zotnet/bboards/Makefile mts/Makefile \
-          mts/smtp/Makefile mts/sendmail/Makefile mts/mmdf/Makefile \
-          etc/Makefile man/Makefile, \
-          [test -z "$CONFIG_HEADERS" || echo > stamp-h])
+AC_CONFIG_FILES(Makefile config/Makefile h/Makefile sbr/Makefile uip/Makefile \
+                mts/Makefile mts/smtp/Makefile \
+               etc/Makefile docs/Makefile man/Makefile)
+AC_CONFIG_COMMANDS([stamp],[test -z "$CONFIG_HEADERS" || echo > stamp-h])
+AC_OUTPUT
 
 dnl Umm, what's the point of these assignments??  -- <dan-nmh@dilvish.speed.net>
 eval "nmhbin=${bindir}";         eval "nmhbin2=${nmhbin}"
@@ -707,26 +960,25 @@ eval "nmhsysconf=${sysconfdir}"; eval "nmhsysconf2=${nmhsysconf}"
 eval "nmhlib=${libdir}";         eval "nmhlib2=${nmhlib}"
 eval "nmhman=${mandir}"
 
-pop_kinds="no"
+pop_kinds=no
 if test x"$enable_pop" = x"yes"; then
-        pop_kinds="yes (pop"
-        if test x"$enable_apop" = x"yes"; then
-                pop_kinds="${pop_kinds} apop"
-        fi
-        if test x"$with_krb4" = x"yes"; then
-                pop_kinds="${pop_kinds} kpop"
-        fi
-        if test "$pop_kinds" = "yes (pop"; then
-                pop_kinds="yes"
-        else
-                pop_kinds="${pop_kinds})"
-        fi
+  pop_kinds="yes ("
+
+  if test x"$enable_apop" = x"yes"; then
+    pop_kinds="${pop_kinds}APOP "
+  fi
+
+  if test x"$with_krb4" != x -a x"$with_krb4" != x"no"; then
+    pop_kinds="${pop_kinds}KPOP "
+  fi
+
+  pop_kinds="${pop_kinds}POP3)"
 fi
 
 echo "
 nmh configuration
 -----------------
-nmh version                : ${VERSION}
+nmh version                : AC_PACKAGE_VERSION
 target os                  : ${target}
 compiler                   : ${CC}
 compiler flags             : ${CFLAGS}
@@ -736,13 +988,13 @@ binary install path        : ${nmhbin2}
 libary install path        : ${nmhlib2}
 config files install path  : ${nmhsysconf2}
 man page install path      : ${nmhman}
+backup prefix              : ${backup_prefix}
 transport system           : ${MTS}
+file locking type          : ${LOCKTYPE}
 default smtp servers       : ${smtpservers}
 default editor             : ${editorpath}
 default pager              : ${pagerpath}
 email address masquerading : ${masquerade}
-pop is enabled             : ${pop_kinds}"
+pop is enabled             : ${pop_kinds}
+SASL support               : ${sasl_support}"
 echo ""
-
-
-