add autoconf magic to support old systems that don't support multibyte charsets
[mmh] / configure.in
1 dnl
2 dnl configure.in -- autoconf template for nmh
3 dnl
4 dnl $Id$
5 dnl
6
7 dnl 2.13 definitely chokes; 2.53 is the earliest version I've tested. 
8 dnl 2.50 is the major breakpoint between the old autoconf and the new,
9 dnl so require that. If there are bug reports about 2.50-2.52 not working
10 dnl we can always move this up a little.
11 AC_PREREQ(2.50)
12
13 AC_INIT(nmh, m4_normalize(m4_include([VERSION])))
14 AC_CONFIG_SRCDIR(h/nmh.h)
15 AC_CONFIG_HEADER(config.h)
16
17 AC_CANONICAL_TARGET
18
19 dnl ---------------------
20 dnl define a macro or two
21 dnl ---------------------
22
23 AC_DEFUN(NMH_PROG_GNU_LIBTOOL, [
24 if test -n "$LIBTOOL" ; then
25   tmptest=`$LIBTOOL --version 2>&1 | grep GNU`
26   if test x"$tmptest" != x  ; then
27     GNU_LIBTOOL=1
28     AC_SUBST(GNU_LIBTOOL)dnl
29   fi
30 fi
31 ] )
32   
33 echo "configuring for AC_PACKAGE_NAME-AC_PACKAGE_VERSION"
34 AC_SUBST(VERSION,AC_PACKAGE_VERSION)dnl
35
36 dnl What date of nmh are we building?
37 DATE=`cat ${srcdir}/DATE`
38 echo "configuring for nmh dated $DATE"
39 AC_SUBST(DATE)dnl
40
41 dnl --------------------------
42 dnl CHECK COMMAND LINE OPTIONS
43 dnl --------------------------
44
45 dnl Do you want client-side support for apop?
46 AC_ARG_ENABLE(apop,
47 [  --enable-apop           enable client-side support for POP3 and APOP])
48 if test x"$enable_apop" = x"yes"; then
49   AC_DEFINE(APOP)dnl
50   APOPLIB=md5.o
51   enable_pop=yes
52 fi
53 AC_SUBST(APOPLIB)dnl
54
55 dnl Do you want to debug nmh?
56 AC_ARG_ENABLE(debug,
57 [  --enable-debug          enable nmh code debugging])
58 dnl The old redundant --enable-nmh-debug is deprecated and undocumented.
59 if test x"$enable_nmh_debug" = x"yes"; then
60   enable_debug=yes
61 fi
62
63 dnl Allow users to send email from addresses other than their default?
64 AC_ARG_ENABLE(masquerade,
65   [  --enable-masquerade[='draft_from mmailid username_extension']
66                           enable up to 3 types of address masquerading [none]],
67   [if test x"$enable_masquerade" = x"yes"; then
68     masquerade="draft_from mmailid username_extension"
69   else
70     masquerade="$enable_masquerade"
71   fi])
72 AC_SUBST(masquerade)dnl
73
74 dnl Do you want mhe support?
75 AC_ARG_ENABLE(mhe,
76 [  --enable-mhe            enable mhe support (DEFAULT)])
77
78 dnl mhe support is on by default, so define it unless --disable-mhe or the
79 dnl deprecated, undocumented --disable-nmh-mhe are specified.
80 if test x"$enable_mhe" != x"no" -a x"$enable_nmh_mhe" != x"no"; then
81   AC_DEFINE(MHE)dnl
82 fi
83
84 dnl Do you want client-side support for pop?
85 AC_ARG_ENABLE(pop,
86 [  --enable-pop            enable client-side support for plain POP3])
87 dnl The old redundant --enable-nmh-pop is deprecated and undocumented.
88 if test x"$enable_nmh_pop" = x"yes"; then
89   enable_pop=yes
90 fi
91
92 dnl Do you want client-side support for using SASL for authentication?
93 dnl Note that this code will be enabled for both POP and SMTP
94 AC_ARG_WITH(cyrus-sasl,
95 [  --with-cyrus-sasl=<dir> Specify location of Cyrus SASL library for auth])
96 if test x"$with_cyrus_sasl" != x -a x"$with_cyrus_sasl" != x"no"; then
97   AC_DEFINE(CYRUS_SASL)dnl
98   sasl_support=yes
99 else
100   sasl_support=no
101 fi
102
103 dnl What should be the default editor?
104 AC_ARG_WITH(editor,
105 [  --with-editor=EDITOR    specify the default editor])
106
107 if test -n "$with_editor"; then
108   editorpath="$with_editor"
109 fi
110
111 dnl Set the backup prefix
112 AC_ARG_WITH([hash-backup],
113   [  --with-hash-backup      use # as the backup prefix (default: ,)])
114 if test x"$with_hash_backup" != x -a x"$with_hash_backup" != x"no"; then
115   backup_prefix="#"
116 else
117   backup_prefix=","
118 fi
119 AC_DEFINE_UNQUOTED(BACKUP_PREFIX, "$backup_prefix")dnl
120
121 dnl Do you want support for hesiod
122 AC_ARG_WITH(hesiod,
123 [  --with-hesiod=PREFIX    specify location of Hesiod])
124 if test x"$with_hesiod" != x -a x"$with_hesiod" != x"no"; then
125   AC_DEFINE(HESIOD)dnl
126 fi
127
128 dnl Do you want client-side support for kpop
129 AC_ARG_WITH(krb4,
130 [  --with-krb4=PREFIX      specify location of Kerberos V4 for KPOP support])
131 if test x"$with_krb4" != x -a x"$with_krb4" != x"no"; then
132   enable_pop=yes
133   AC_DEFINE(KPOP)dnl
134   AC_DEFINE(KPOP_PRINCIPAL, "pop")dnl
135 fi
136
137 dnl After we know if we're including apop and kpop support, do pop stuff
138 if test x"$enable_pop" = x"yes"; then
139   AC_DEFINE(POP)dnl
140   POPLIB=popsbr.o
141   POPSED='/^%nmhbeginpop%/d;/^%nmhendpop%/d'
142 else
143   POPSED='/^%nmhbeginpop%/,/^%nmhendpop%/d'
144 fi
145 AC_SUBST(POPLIB)dnl
146 AC_SUBST(POPSED)dnl
147
148 dnl What method of locking to use?
149 AC_ARG_WITH(locking,
150 [  --with-locking=LOCKTYPE specify the file locking method
151                           (one of dot, fcntl, flock, lockf)])
152
153 if test x"$with_locking" = x"dot"; then
154   LOCKTYPE="dot"
155   AC_DEFINE(DOT_LOCKING)dnl
156 elif test x"$with_locking" = x"flock"; then
157   LOCKTYPE="flock"
158   AC_DEFINE(FLOCK_LOCKING)dnl
159 elif test x"$with_locking" = x"lockf"; then
160   LOCKTYPE="lockf"
161   AC_DEFINE(LOCKF_LOCKING)dnl
162 elif test x"$with_locking" = x"fcntl"; then
163   LOCKTYPE="fcntl"
164   AC_DEFINE(FCNTL_LOCKING)dnl
165 else
166   LOCKTYPE="dot"
167   AC_DEFINE(DOT_LOCKING)dnl
168 fi
169
170 dnl What method of posting should post use?
171 AC_ARG_WITH(mts,
172 [  --with-mts=MTS          specify the default mail transport agent/service])
173
174 if test x"$with_mts" = x"smtp"; then
175   MTS="smtp"
176 elif test x"$with_mts" = x"sendmail"; then
177   MTS="sendmail"
178 else
179   MTS="smtp"
180 fi
181 AC_SUBST(MTS)dnl
182
183 dnl Both the smtp and sendmail mail transport services use the smtp code
184 AC_DEFINE(SMTPMTS)dnl
185
186 dnl What should be the default pager?
187 AC_ARG_WITH(pager,
188 [  --with-pager=PAGER      specify the default pager])
189
190 if test -n "$with_pager"; then
191   pagerpath="$with_pager"
192 fi
193
194 dnl What should be the default mail server(s)?
195 AC_ARG_WITH(smtpservers,
196 [  --with-smtpservers='SMTPSERVER1[ SMTPSERVER2...]'
197                           specify the default SMTP server(s) [localhost]])
198 if test -n "$with_smtpservers"; then
199   smtpservers="$with_smtpservers"
200 else
201   smtpservers="localhost"
202 fi
203 AC_SUBST(smtpservers)dnl
204
205 dnl ----------------------------------------------------
206 dnl Default location is /usr/local/nmh/{bin,etc,lib,man}
207 dnl ----------------------------------------------------
208 AC_PREFIX_DEFAULT(/usr/local/nmh)
209
210 dnl ------------------
211 dnl CHECK THE COMPILER
212 dnl ------------------
213 dnl We want these before the checks,
214 dnl so the checks can modify their values.
215 test -z "$CFLAGS" && CFLAGS= auto_cflags=1
216 if test x"$enable_debug" = x"yes"; then
217   test -z "$LDFLAGS" && LDFLAGS=-g
218 fi
219
220 AC_PROG_CC
221
222 dnl if the user hasn't specified CFLAGS, then
223 dnl   if compiler is gcc, then
224 dnl     use -O2 and some warning flags
225 dnl   else use -O
226 if test -n "$auto_cflags"; then
227   if test x"$enable_debug" = x"yes"; then
228     if test -n "$GCC"; then
229       test -z "$CFLAGS" && CFLAGS="-Wall -g" || CFLAGS="$CFLAGS -Wall -g"
230     else
231       test -z "$CFLAGS" && CFLAGS=-g || CFLAGS="$CFLAGS -g"
232     fi
233   else
234     if test -z "$LDFLAGS"; then
235       case "$build_os" in
236         darwin*)
237           LDFLAGS=
238           ;;
239         *)
240           LDFLAGS=-s
241           ;;
242       esac
243     fi
244     if test -n "$GCC"; then
245       test -z "$CFLAGS" && CFLAGS="-Wall -O2" || CFLAGS="$CFLAGS -Wall -O2"
246     else
247       test -z "$CFLAGS" && CFLAGS=-O  || CFLAGS="$CFLAGS -O"
248     fi
249   fi
250 fi
251
252 AC_C_CONST              dnl Does compiler support `const'.
253
254 dnl ------------------
255 dnl CHECK FOR PROGRAMS
256 dnl ------------------
257 AC_PROG_MAKE_SET        dnl Does make define $MAKE
258 AC_PROG_INSTALL         dnl Check for BSD compatible `install'
259 AC_PROG_RANLIB          dnl Check for `ranlib'
260 AC_PROG_AWK             dnl Check for mawk,gawk,nawk, then awk
261 AC_PROG_LEX             dnl Check for lex/flex
262
263 dnl Look for `cut'
264 pathtmp=/usr/bin:/bin:/usr/local/bin:/usr/xpg4/bin:/usr/ucb
265 AC_PATH_PROG(cutpath, cut, no, [$pathtmp])
266
267 dnl ----------------------------------------------
268 dnl check for lclint, and lint if it doesn't exist
269 dnl ----------------------------------------------
270 AC_CHECK_PROG(linttmp1, lclint, lclint, no)dnl
271 if test x$ac_cv_prog_linttmp1 != xno ; then
272   LINT=$ac_cv_prog_linttmp1
273   LINTFLAGS="-weak +posixlib -macrovarprefixexclude"
274 else
275   AC_CHECK_PROG(linttmp2, lint, lint, no)dnl
276   if test x$ac_cv_prog_linttmp2 != xno ; then
277     LINT=$ac_cv_prog_linttmp2
278     LINTFLAGS=""
279   else
280     LINT="echo 'No lint program found'"
281     LINTFLAGS=""
282   fi
283 fi
284 AC_SUBST(LINT)dnl
285 AC_SUBST(LINTFLAGS)dnl
286
287 dnl try to figure out which one we've got
288 AC_CHECK_PROG(LIBTOOL, libtool, libtool, , [$pathtmp])
289 NMH_PROG_GNU_LIBTOOL
290
291 dnl Check for lorder and tsort commands
292 AC_CHECK_PROG(LORDER, lorder, lorder, no)dnl
293 AC_CHECK_PROG(TSORT, tsort, tsort, no)dnl
294
295 dnl If either doesn't exist, replace them with echo and cat
296 if test x$ac_cv_prog_LORDER != xlorder -o x$ac_cv_prog_TSORT != xtsort; then
297   LORDER=echo
298   TSORT=cat
299   AC_SUBST(LORDER)dnl
300   AC_SUBST(TSORT)dnl
301 dnl Mac OS X has lorder, but sh is too broken for it to work
302 dnl elif test -z "`lorder config/config.c 2>&1 | grep config/config.c`" ; then
303 dnl   LORDER=echo
304 dnl   TSORT=cat
305 dnl   AC_SUBST(LORDER)dnl
306 dnl   AC_SUBST(TSORT)dnl
307 fi
308
309 dnl Check whether tsort can deal with loops
310 AC_CACHE_CHECK(whether tsort can deal with loops, nmh_cv_tsort_loop,
311   [if test -z "`echo a b b a | tsort 2>/dev/null | grep a`" ; then
312     nmh_cv_tsort_loop=no
313   else
314     nmh_cv_tsort_loop=yes
315   fi])
316 if test x$nmh_cv_tsort_loop = xno ; then
317   LORDER=echo
318   TSORT=cat
319   AC_SUBST(LORDER)dnl
320   AC_SUBST(TSORT)dnl
321 fi
322
323 dnl Look for `ls'
324 pathtmp=/usr/bin:/bin:/usr/local/bin:/usr/xpg4/bin:/usr/ucb
325 AC_PATH_PROG(lspath, ls, no, [$pathtmp])
326
327 dnl See how we get ls to display the owner and the group
328 if test "$lspath" != "no"; then
329   AC_CACHE_CHECK(how to get ls to show us the group ownership of a file, 
330                  nmh_cv_ls_grpopt,
331   [if test x"`$lspath -dl / | $AWK '{print $9}'`" = x"/"; then
332     dnl There were 9 parameters, so unless this is a really bizarre, nonstandard
333     dnl ls, it would seem -l gave us both the user and group.  On this type of
334     dnl ls, -g makes _only_ the group be displayed (and not the user).
335     nmh_cv_ls_grpopt="-l"
336   else
337     dnl Looks like -l only gave us the user, so we need -g to get the group too.
338     nmh_cv_ls_grpopt="-lg"
339   fi])
340 fi
341
342 dnl Look for `more'
343 pathtmp=/usr/bin:/bin:/usr/ucb:/usr/local/bin
344 AC_PATH_PROG(morepath, more, no, [$pathtmp])
345
346 dnl If pager is not specified yet,
347 dnl then use `more' as the default.
348 if test -z "$pagerpath"; then
349   pagerpath="$morepath"
350 fi
351 AC_SUBST(pagerpath)dnl
352
353 dnl Look for `sendmail'
354 pathtmp=/usr/lib:/usr/sbin:/usr/etc:/usr/ucblib:/usr/bin:/bin
355 AC_PATH_PROG(sendmailpath, sendmail, /usr/sbin/sendmail, [$pathtmp])
356
357 dnl Look for `vi'
358 pathtmp=/usr/bin:/bin:/usr/ucb:/usr/local/bin
359 AC_PATH_PROG(vipath, vi, /bin/vi, [$pathtmp])
360
361 dnl If editor is not specified yet,
362 dnl then use `vi' as the default.
363 if test -z "$editorpath"; then
364   editorpath="$vipath"
365 fi
366 AC_SUBST(editorpath)dnl
367
368 dnl Check for broken vi
369 AC_CACHE_CHECK(for broken vi, nmh_cv_attvibug,
370 [if echo 'r /nonexist-file
371 q' | ex > /dev/null
372 then
373         nmh_cv_attvibug=no
374 else
375         nmh_cv_attvibug=yes
376 fi])
377  
378 if test "$nmh_cv_attvibug" = yes; then
379   AC_DEFINE(ATTVIBUG)dnl
380 fi
381
382 dnl ----------------------------------------------------------
383 dnl FIND MAIL SPOOL AND SEE IF WE NEED TO MAKE inc SETGID MAIL
384 dnl ----------------------------------------------------------
385 AC_CACHE_CHECK(where mail spool is located, nmh_cv_mailspool,
386 [for mailspool in /var/mail        dnl
387                   /var/spool/mail  dnl
388                   /usr/spool/mail  dnl
389                   /dev/null;       dnl Just in case we fall through
390 do
391   test -d $mailspool && break
392 done
393 nmh_cv_mailspool=$mailspool
394 ])
395 mailspool=$nmh_cv_mailspool
396 AC_SUBST(mailspool)dnl
397
398 dnl See whether the mail spool directory is world-writable.
399 if test "$lspath" != "no" -a "$cutpath" != "no"; then
400   AC_CACHE_CHECK(whether the mail spool is world-writable, 
401                  nmh_cv_mailspool_world_writable,
402   [if test "`$lspath -dlL $mailspool | $cutpath -c9`" = "-"; then
403     nmh_cv_mailspool_world_writable=no
404   else
405     nmh_cv_mailspool_world_writable=yes
406   fi])
407 fi
408
409 dnl Also, check for liblockfile (as found on Debian systems)
410 AC_CHECK_HEADER(lockfile.h, AC_CHECK_LIB(lockfile, lockfile_create) )
411
412 dnl and whether its companion program dotlockfile is setgid
413 AC_PATH_PROG(dotlockfilepath, dotlockfile, no)
414 if test "$ac_cv_lib_lockfile_lockfile_create" != "no" ; then
415   if test "$ac_cv_path_dotlockfilepath" != "no" ; then
416     AC_CACHE_CHECK(whether dotlockfile is setgid, nmh_cv_dotlockfile_setgid,
417     [ if test -g "$ac_cv_path_dotlockfilepath" ; then
418         nmh_cv_dotlockfile_setgid=yes
419       else
420         nmh_cv_dotlockfile_setgid=no
421       fi])
422   fi
423 fi
424
425 dnl If mailspool is not world-writable and dotlockfile is not setgid,
426 dnl we need to #define MAILGROUP to 1 and make inc setgid.
427 if test x"$nmh_cv_mailspool_world_writable" = x"no" -a x"$nmh_cv_dotlockfile_setgid" != x"yes" ; then
428   dnl do we really need both of these?
429   AC_DEFINE(MAILGROUP)dnl
430   SETGID_MAIL=1
431 fi
432 AC_SUBST(SETGID_MAIL)dnl
433
434 dnl Use ls to see which group owns the mail spool directory.
435 AC_CACHE_CHECK(what group owns the mail spool, nmh_cv_ls_mail_grp,
436 [nmh_cv_ls_mail_grp=`$lspath -dL $nmh_cv_ls_grpopt $mailspool|$AWK '{print $4}'`
437 ])
438 MAIL_SPOOL_GRP=$nmh_cv_ls_mail_grp
439 AC_SUBST(MAIL_SPOOL_GRP)dnl
440
441 dnl ------------------
442 dnl CHECK HEADER FILES
443 dnl ------------------
444 AC_HEADER_DIRENT
445 AC_HEADER_STDC
446 AC_HEADER_TIME
447 AC_HEADER_SYS_WAIT
448 AC_HEADER_STAT
449 AC_CHECK_HEADERS(string.h memory.h stdlib.h unistd.h errno.h fcntl.h \
450                  limits.h crypt.h termcap.h termio.h termios.h locale.h \
451                  langinfo.h wchar.h wctype.h iconv.h netdb.h \
452                  sys/param.h sys/time.h sys/utsname.h sys/stream.h \
453                  arpa/inet.h arpa/ftp.h)
454
455 AC_CACHE_CHECK(POSIX termios, nmh_cv_sys_posix_termios,
456 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
457 #include <unistd.h>
458 #include <termios.h>]],
459 [[/* SunOS 4.0.3 has termios.h but not the library calls.  */
460 tcgetattr(0, 0);]])],
461 nmh_cv_sys_posix_termios=yes, nmh_cv_sys_posix_termios=no)])
462  
463 if test $nmh_cv_sys_posix_termios = yes; then
464   AC_CACHE_CHECK(TIOCGWINSZ in termios.h,
465   nmh_cv_header_termios_h_tiocgwinsz,
466   [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
467 #include <termios.h>]],
468   [[int x = TIOCGWINSZ;]])],
469   nmh_cv_header_termios_h_tiocgwinsz=yes,nmh_cv_header_termios_h_tiocgwinsz=no)])
470 else
471   nmh_cv_header_termios_h_tiocgwinsz=no
472 fi
473  
474 if test $nmh_cv_header_termios_h_tiocgwinsz = no; then
475   AC_CACHE_CHECK(TIOCGWINSZ in sys/ioctl.h,
476   nmh_cv_header_sys_ioctl_h_tiocgwinsz,
477   [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
478 #include <sys/ioctl.h>]],
479   [[int x = TIOCGWINSZ;]])],
480   nmh_cv_header_sys_ioctl_h_tiocgwinsz=yes,nmh_cv_header_sys_ioctl_h_tiocgwinsz=no)])
481   if test $nmh_cv_header_sys_ioctl_h_tiocgwinsz = yes; then
482     AC_DEFINE(GWINSZ_IN_SYS_IOCTL)dnl
483   fi
484 fi
485  
486 dnl
487 dnl Checks for _IO_write_ptr. A Linuxism used by nmh on linux. We
488 dnl really use a whole set of them, but this check should be
489 dnl sufficient.
490 dnl
491 AC_CHECK_HEADER(libio.h, [
492   AC_EGREP_HEADER(_IO_write_ptr, libio.h, [
493     AC_DEFINE(LINUX_STDIO) ]) ]) 
494
495 AC_CHECK_HEADER([sys/ptem.h], AC_DEFINE(WINSIZE_IN_PTEM),,
496 [[#if HAVE_SYS_STREAM_H
497 #  include <sys/stream.h>
498 #endif
499 ]])
500
501 dnl ---------------
502 dnl CHECK FUNCTIONS
503 dnl ---------------
504 AC_FUNC_VFORK
505 AC_CHECK_LIB(mkstemp,mkstemp)
506 AC_CHECK_FUNCS(waitpid wait3 sigaction sigprocmask sigblock sigsetmask \
507                sighold sigrelse writev lstat uname tzset killpg mkstemp \
508                sethostent getutent nl_langinfo mbtowc wcwidth)
509
510 dnl solaris screws this up
511 AC_CHECK_FUNC(gethostbyname, [AC_DEFINE(HAVE_GETHOSTBYNAME)],
512   AC_CHECK_LIB(nsl, gethostbyname, [AC_DEFINE(HAVE_GETHOSTBYNAME)] ) )
513
514 dnl sigsetjmp may be a macro
515 AC_MSG_CHECKING(for sigsetjmp)
516 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <setjmp.h>]],
517   [[sigsetjmp((void *)0, 0);]])],[AC_DEFINE(HAVE_SIGSETJMP) AC_MSG_RESULT(yes)],
518   [AC_MSG_RESULT(no)])
519
520 AC_REPLACE_FUNCS(snprintf strdup)
521
522 dnl Look for the initgroups() declaration.  On AIX 4.[13], Solaris 4.1.3, and
523 dnl ULTRIX 4.2A the function is defined in libc but there's no declaration in
524 dnl any system header.  
525 dnl
526 dnl On Solaris 2.[456], the declaration is in <grp.h>.  On HP-UX 9-11 and
527 dnl (reportedly) FreeBSD 3.[23], it's in <unistd.h>.  Any other locations we
528 dnl need to check? 
529 AC_EGREP_HEADER(initgroups, grp.h, AC_DEFINE(INITGROUPS_HEADER, <grp.h>),
530                 AC_EGREP_HEADER(initgroups, unistd.h, 
531                                 AC_DEFINE(INITGROUPS_HEADER, <unistd.h>)))
532
533 dnl On AIX 4.1, snprintf() is defined in libc.a but there's no prototype in
534 dnl <stdio.h> or elsewhere.  Apparently it's not officially supported (though it
535 dnl seems to work perfectly and IBM apparently uses it in internal code).
536 dnl Anyhow, if we omit our own snprintf() and vsnprintf() prototypes when we
537 dnl HAVE_SNPRINTF, we get a billion warnings at compile time.  Use the C
538 dnl preprocessor to preprocess stdio.h and make sure that there's actually a 
539 dnl prototype. 
540 AC_EGREP_HEADER(snprintf, stdio.h, AC_DEFINE(HAVE_SNPRINTF_PROTOTYPE))
541
542 dnl Check for multibyte character set support
543 if test "x$ac_cv_header_wchar_h" = "xyes" -a "x$ac_cv_header_wctype_h" = "xyes" \
544     -a "x$ac_cv_func_wcwidth" = "xyes" -a "x$ac_cv_func_mbtowc" = "xyes"; then
545   AC_DEFINE(MULTIBYTE_SUPPORT, 1,
546     [Define to enable support for multibyte character sets])
547 fi
548
549 dnl -------------------
550 dnl CHECK FOR LIBRARIES
551 dnl -------------------
552 dnl Check location of modf
553 AC_CHECK_FUNC(modf, , AC_CHECK_LIB(m, modf))
554
555 dnl Checks for network libraries (nsl, socket)
556 AC_CHECK_NETLIBS
557
558 termcap_curses_order="termcap curses ncurses"
559 for lib in $termcap_curses_order; do
560   AC_CHECK_LIB(${lib}, tgetent, [TERMLIB="-l$lib"; break])
561 done
562 AC_SUBST(TERMLIB)dnl
563
564 dnl ---------------
565 dnl CHECK FOR ICONV
566 dnl ---------------
567
568 dnl Find iconv. It may be in libiconv and may be iconv() or libiconv()
569 if test "x$ac_cv_header_iconv_h" = "xyes"; then
570   AC_CHECK_FUNC(iconv, ac_found_iconv=yes, ac_found_iconv=no)
571   if test "x$ac_found_iconv" = "xno"; then
572     AC_CHECK_LIB(iconv, iconv, ac_found_iconv=yes)
573     if test "x$ac_found_iconv" = "xno"; then
574       AC_CHECK_LIB(iconv, libiconv, ac_found_iconv=yes)
575     fi
576     if test "x$ac_found_iconv" != "xno"; then
577       LIBS="-liconv $LIBS"
578     fi
579   else
580     dnl Handle case where there is a native iconv but iconv.h is from libiconv
581     AC_CHECK_DECL(_libiconv_version,
582       [ AC_CHECK_LIB(iconv, libiconv, LIBS="-liconv $LIBS") ],,
583       [ #include <iconv.h> ])
584   fi
585 fi
586 if test "x$ac_found_iconv" = xyes; then
587   AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
588 fi
589
590 dnl Check if iconv uses const in prototype declaration
591 if test "x$ac_found_iconv" = "xyes"; then
592   AC_CACHE_CHECK(for iconv declaration, ac_cv_iconv_const,
593     [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdlib.h>
594         #include <iconv.h>]],
595         [[#ifdef __cplusplus
596           "C"
597           #endif
598           #if defined(__STDC__) || defined(__cplusplus)
599           size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
600           #else
601           size_t iconv();
602           #endif]])],
603       [ac_cv_iconv_const=],
604       [ac_cv_iconv_const=const])])
605   AC_DEFINE_UNQUOTED([ICONV_CONST], $ac_cv_iconv_const,
606     [Define as const if the declaration of iconv() needs const.])
607 fi
608
609 dnl --------------
610 dnl CHECK FOR NDBM
611 dnl --------------
612
613 AC_ARG_WITH([ndbm],AS_HELP_STRING([--with-ndbm=ARG],[use -lARG to link with ndbm]),
614             [nmh_ndbm=$withval],[nmh_ndbm=autodetect])
615 AC_ARG_WITH([ndbmheader],AS_HELP_STRING([--with-ndbmheader=ARG],[#include <ARG> to use ndbm]),
616             [nmh_ndbmheader=$withval],[nmh_ndbmheader=autodetect])
617
618 if test "$nmh_ndbm" = "autodetect"; then
619   if test "$nmh_ndbmheader" != "autodetect"; then
620     AC_MSG_ERROR([must specify both --with-ndbm and --with-ndbmheader or neither])
621   else
622
623     dnl There are at least four implementations of ndbm, and
624     dnl several of those can be in different places at the whim
625     dnl of the system integrator. A good summary of this mess
626     dnl can be found at http://www.unixpapa.com/incnote/dbm.html
627
628     dnl Classic ndbm with no library required (eg NetBSD): try this
629     dnl first so we don't accidentally link in a pointless but harmless
630     dnl library in one of the later ndbm.h+libfoo tests:
631     NMH_CHECK_NDBM(ndbm.h,,,
632     dnl Berkeley DBv2 emulating ndbm: header in db.h:
633       NMH_CHECK_NDBM(db.h,db,,
634     dnl Berkeley DBv1 emulating ndbm:
635         NMH_CHECK_NDBM(ndbm.h,db,,
636           NMH_CHECK_NDBM(ndbm.h,db1,,
637     dnl Classic ndbm:
638             NMH_CHECK_NDBM(ndbm.h,ndbm,,
639     dnl glibc2.1 systems put db1 in a subdir:
640               NMH_CHECK_NDBM(db1/ndbm.h,db1,,
641     dnl GNU gdbm emulating ndbm, with header possibly in gdbm/
642     dnl and possibly needing gbdm_compat library:
643                 NMH_CHECK_NDBM(gdbm/ndbm.h,gdbm,,
644                   NMH_CHECK_NDBM(gdbm/ndbm.h,gdbm_compat -lgdbm,,
645                     NMH_CHECK_NDBM(ndbm.h,gdbm,,
646                       NMH_CHECK_NDBM(ndbm.h,gdbm_compat -lgdbm))))))))))
647
648   fi
649 else
650   dnl We don't really need to check that the user-specified values work,
651   dnl but it is a convenience to the user to bomb out early rather than
652   dnl after configure and half the compile process.
653   NMH_CHECK_NDBM([$nmh_ndbmheader],[$nmh_ndbm])
654 fi
655
656 if test "$nmh_ndbm_found" = "no"; then
657   AC_MSG_ERROR([could not find a working ndbm library/header combination])
658 else
659   dnl Now export the lib/header to our makefile/config.h:
660   if test x"$nmh_ndbmheader" != x; then
661     AC_DEFINE_UNQUOTED(NDBM_HEADER, <$nmh_ndbmheader>)
662   fi
663   if test x"$nmh_ndbm" != x; then
664     NDBM_LIBS="-l$nmh_ndbm"
665   else
666     NDBM_LIBS=
667   fi
668   AC_SUBST(NDBM_LIBS)
669 fi
670
671
672 dnl ----------------
673 dnl CHECK FOR HESIOD
674 dnl ----------------
675 if test x"$with_hesiod" != x -a x"$with_hesiod" != x"no"; then
676   if test x"$with_hesiod" != x"yes"; then
677     HESIOD_INCLUDES="-I$with_hesiod/include"
678     HESIOD_LIBS="-L$with_hesiod/lib"
679   fi
680   AC_CHECK_FUNC(res_send,
681         [AC_CHECK_LIB(hesiod, hes_resolve,
682                 [HESIOD_LIBS="$HESIOD_LIBS -lhesiod"],
683                 [AC_MSG_ERROR(Hesiod library not found)],
684                 $HESIOD_LIBS)],
685         [AC_CHECK_LIB(hesiod, hes_resolve,
686                 [HESIOD_LIBS="$HESIOD_LIBS -lhesiod -lresolv"],
687                 [AC_MSG_ERROR(Hesiod library not found)],
688                 $HESIOD_LIBS -lresolv)])
689
690 fi
691 AC_SUBST(HESIOD_INCLUDES)dnl
692 AC_SUBST(HESIOD_LIBS)dnl
693
694 dnl ----------------------------------
695 dnl CHECK FOR KRB4 (Kerberos4 support)
696 dnl ----------------------------------
697 if test x"$with_krb4" != x -a x"$with_krb4" != x"no"; then
698   if test x"$with_krb4" != x"yes"; then
699     KRB4_INCLUDES="-I$with_krb4/include"
700     if test -d "$with_krb4/include/kerberosIV"; then
701       KRB4_INCLUDES="$KRB4_INCLUDES -I$with_krb4/include/kerberosIV"
702     fi
703     KRB4_LIBS="-L$with_krb4/lib"
704   elif test -d /usr/include/kerberosIV; then
705     KRB4_INCLUDES="-I/usr/include/kerberosIV"
706   fi
707 dnl First, check if we have -lk5crypto, since that means we have a recent krb5
708
709   AC_CHECK_LIB(k5crypto, krb5_encrypt,
710         [AC_CHECK_LIB(krb4, krb_rd_req,
711                 [KRB4_LIBS="$KRB4_LIBS -lkrb4 -ldes425 -lkrb5 -lk5crypto -lcom_err"],
712                 [AC_MSG_ERROR(Kerberos 4 compatibility libraries not found)],
713                 $KRB4_LIBS -ldes425 -lkrb5 -lk5crypto -lcom_err)],
714
715         [AC_CHECK_LIB(krb4, krb_rd_req,
716             [KRB4_LIBS="$KRB4_LIBS -lkrb4 -ldes425 -lkrb5 -lcrypto -lcom_err"],
717             [AC_CHECK_LIB(krb, krb_rd_req,
718               [KRB4_LIBS="$KRB4_LIBS -lkrb -ldes"],
719               [AC_MSG_ERROR(Kerberos 4 libraries not found)],
720               $KRB4_LIBS -ldes)],
721             $KRB4_LIBS -ldes425 -lkrb5 -lcrypto -lcom_err)],
722         $KRB4_LIBS)
723
724 fi
725 AC_SUBST(KRB4_INCLUDES)dnl
726 AC_SUBST(KRB4_LIBS)dnl
727
728 dnl --------------------
729 dnl CHECK FOR CYRUS SASL
730 dnl --------------------
731 if test x"$with_cyrus_sasl" != x -a x"$with_cyrus_sasl" != x"no"; then
732   if test x"$with_cyrus_sasl" != x"yes"; then
733     SASL_INCLUDES="-I$with_cyrus_sasl/include"
734     SASL_LIBS="-L$with_cyrus_sasl/lib"
735
736     dnl Do OS-specific hardcoding of SASL shared library path into executables,
737     dnl so user isn't forced to set environment variables like Solaris'
738     dnl LD_LIBRARY_PATH.
739     case "$target_os" in
740       solaris*)
741         SASL_LIBS="$SASL_LIBS -R$with_cyrus_sasl/lib"
742         ;;
743     esac
744   fi
745   save_LDFLAGS="$LDFLAGS"
746   LDFLAGS="$LDFLAGS $SASL_LIBS"
747   AC_CHECK_LIB(sasl2, sasl_client_new,
748     [SASL_LIBS="$SASL_LIBS -lsasl2"],
749     [AC_MSG_ERROR(Cyrus SASL library not found)])
750   LDFLAGS="$save_LDFLAGS"
751 fi
752 AC_SUBST(SASL_INCLUDES)dnl
753 AC_SUBST(SASL_LIBS)dnl
754
755 dnl ---------------------
756 dnl CHECK TERMCAP LIBRARY
757 dnl ---------------------
758
759 dnl Add the termcap library, so that the following configure
760 dnl tests will find it when it tries to link test programs.
761 nmh_save_LIBS="$LIBS"
762 LIBS="$TERMLIB $LIBS"
763
764 dnl Checks for external variable ospeed in the termcap library.
765 AC_CACHE_CHECK(if an include file defines ospeed,
766 nmh_cv_decl_ospeed_include_defines,
767 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
768 #if HAVE_TERMIOS_H
769 #include <termios.h>
770 #endif
771 #if HAVE_TERMCAP_H
772 #include <termcap.h>
773 #endif]], [[ospeed = 0;]])],
774 nmh_cv_decl_ospeed_include_defines=yes,nmh_cv_decl_ospeed_include_defines=no)])
775  
776 if test $nmh_cv_decl_ospeed_include_defines = no; then
777   AC_CACHE_CHECK(if you must define ospeed,
778   nmh_cv_decl_ospeed_must_define,
779   [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
780   [[extern short ospeed; ospeed = 0;]])],
781   nmh_cv_decl_ospeed_must_define=yes,nmh_cv_decl_ospeed_must_define=no)])
782 fi
783  
784 if test $nmh_cv_decl_ospeed_include_defines = yes; then
785   AC_DEFINE(HAVE_OSPEED)dnl
786 elif test $nmh_cv_decl_ospeed_must_define = yes; then
787   AC_DEFINE(HAVE_OSPEED)
788   AC_DEFINE(MUST_DEFINE_OSPEED)
789 fi
790
791 dnl dnl Checks if tgetent accepts NULL and will
792 dnl dnl allocate its own termcap buffer.
793 dnl AC_CACHE_CHECK(if tgetent accepts NULL,
794 dnl nmh_cv_func_tgetent_accepts_null,
795 dnl [AC_TRY_RUN([main(){int i = tgetent((char*)0,"vt100");exit(!i || i == -1);}],
796 dnl   nmh_cv_func_tgetent_accepts_null=yes,
797 dnl   nmh_cv_func_tgetent_accepts_null=no,
798 dnl   nmh_cv_func_tgetent_accepts_null=no)])
799 dnl if test $nmh_cv_func_tgetent_accepts_null = yes; then
800 dnl   AC_DEFINE(TGETENT_ACCEPTS_NULL)
801 dnl fi
802
803 dnl Now put the libraries back to what it was before we
804 dnl starting checking the termcap library.
805 LIBS="$nmh_save_LIBS"
806
807 dnl --------------
808 dnl CHECK TYPEDEFS
809 dnl --------------
810 AC_TYPE_SIGNAL
811 AC_TYPE_PID_T
812 AC_TYPE_OFF_T
813 AC_TYPE_UID_T
814 AC_TYPE_MODE_T
815 AC_TYPE_SIZE_T
816
817 dnl Check for sigset_t.  Currently I'm looking in
818 dnl <sys/types.h> and <signal.h>.  Others might need
819 dnl to be added.
820 AC_CACHE_CHECK(for sigset_t, nmh_cv_type_sigset_t,
821 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
822 #include <signal.h>]], [[sigset_t tempsigset;]])],
823 nmh_cv_type_sigset_t=yes,nmh_cv_type_sigset_t=no)])
824 if test $nmh_cv_type_sigset_t = no; then
825   AC_DEFINE(sigset_t, unsigned int)
826 fi
827
828 dnl ----------------
829 dnl CHECK STRUCTURES
830 dnl ----------------
831 AC_CHECK_MEMBERS(struct stat.st_blksize)
832
833 AC_CACHE_CHECK(for tm_gmtoff in struct tm, nmh_cv_struct_tm_gmtoff,
834 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#ifdef TIME_WITH_SYS_TIME
835 # include <sys/time.h>
836 # include <time.h>
837 #else
838 # ifdef TM_IN_SYS_TIME
839 #  include <sys/time.h>
840 # else
841 #  include <time.h>
842 # endif
843 #endif]], [[struct tm temptm; temptm.tm_gmtoff = 0;]])],
844 nmh_cv_struct_tm_gmtoff=yes,nmh_cv_struct_tm_gmtoff=no)])
845 if test $nmh_cv_struct_tm_gmtoff = yes; then
846   AC_DEFINE(HAVE_TM_GMTOFF)
847 fi
848
849 AC_CACHE_CHECK(for ut_type in struct utmp, nmh_cv_struct_utmp_ut_type,
850 [AC_TRY_COMPILE(
851 [#include <utmp.h>],
852 [struct utmp temputmp; temputmp.ut_type = 0;],
853   nmh_cv_struct_utmp_ut_type=yes, nmh_cv_struct_utmp_ut_type=no)])
854 if test $nmh_cv_struct_utmp_ut_type = yes; then
855   AC_DEFINE(HAVE_UTMP_UT_TYPE)
856 fi
857
858 dnl -------------
859 dnl CHECK SIGNALS
860 dnl -------------
861 dnl What style of signal do you have (POSIX, BSD, or SYSV)?
862 AC_MSG_CHECKING(what style of signals to use)
863 if test $ac_cv_func_sigaction = yes -a $ac_cv_func_sigprocmask = yes; then
864   signals_style=POSIX_SIGNALS
865   AC_DEFINE(POSIX_SIGNALS)
866   AC_DEFINE(RELIABLE_SIGNALS)
867 elif test $ac_cv_func_sigblock = yes -a $ac_cv_func_sigsetmask = yes; then
868   signals_style=BSD_SIGNALS
869   AC_DEFINE(BSD_SIGNALS)
870   AC_DEFINE(RELIABLE_SIGNALS)
871 elif test $ac_cv_func_sighold = yes -a $ac_cv_func_sigrelse = yes; then
872   signals_style=SYSV_SIGNALS
873   AC_DEFINE(SYSV_SIGNALS)
874 else
875   signals_style=NO_SIGNAL_BLOCKING
876   AC_DEFINE(NO_SIGNAL_BLOCKING)
877 fi
878
879 AC_MSG_RESULT($signals_style)
880
881 dnl Where is <signal.h> located?  Needed as input for signames.awk
882 AC_CACHE_CHECK(where signal.h is located, nmh_cv_path_signal_h,
883 [for SIGNAL_H in /usr/include/bsd/sys/signal.h  dnl Next
884                  /usr/include/asm/signal.h      dnl Linux 1.3.0 and above
885                  /usr/include/asm/signum.h      dnl some versions of Linux/Alpha
886                  /usr/include/linux/signal.h    dnl Linux up to 1.2.11
887                  /usr/include/sys/signal.h      dnl Almost everybody else
888                  /dev/null;                     dnl Just in case we fall through
889 do
890   test -f $SIGNAL_H && \
891   grep '#[      ]*define[       ][      ]*SIG[0-9A-Z]*[         ]*[0-9][0-9]*' $SIGNAL_H > /dev/null && \
892   break
893 done
894 nmh_cv_path_signal_h=$SIGNAL_H
895 ])
896 SIGNAL_H=$nmh_cv_path_signal_h
897 AC_SUBST(SIGNAL_H)dnl
898
899 dnl ----------------
900 dnl OS SPECIFIC DEFINES
901 dnl ----------------
902 case "$target_os" in
903
904   solaris2*)
905     AC_DEFINE(SYS5)
906     AC_DEFINE(SVR4)
907     ;;
908   irix*)
909     AC_DEFINE(SYS5)
910     AC_DEFINE(SVR4)
911     ;;
912   osf*)
913     AC_DEFINE(SYS5)
914     AC_DEFINE(SVR4)
915     ;;
916   aix*)
917     AC_DEFINE(SYS5)
918     AC_DEFINE(SVR4)
919     ;;
920   sunos4*)
921     AC_DEFINE(BSD42)
922     ;;
923   freebsd*)  
924     AC_DEFINE(BSD42)
925     AC_DEFINE(BSD44)
926     ;;
927   netbsd*)
928     AC_DEFINE(BSD42)
929     AC_DEFINE(BSD44)
930     ;;
931   openbsd*)
932     AC_DEFINE(BSD42)
933     AC_DEFINE(BSD44)
934     ;;
935   bsd/os*)
936     AC_DEFINE(BSD42)
937     AC_DEFINE(BSD44)
938     ;;
939   sco5*)
940     AC_DEFINE(SYS5)
941     AC_DEFINE(SCO_5_STDIO)
942     ;;
943 esac
944
945
946 dnl ----------------
947 dnl OUTPUT MAKEFILES
948 dnl ----------------
949 AC_CONFIG_FILES(Makefile config/Makefile h/Makefile sbr/Makefile uip/Makefile \
950                 mts/Makefile mts/smtp/Makefile \
951                 etc/Makefile docs/Makefile man/Makefile)
952 AC_CONFIG_COMMANDS([stamp],[test -z "$CONFIG_HEADERS" || echo > stamp-h])
953 AC_OUTPUT
954
955 dnl Umm, what's the point of these assignments??  -- <dan-nmh@dilvish.speed.net>
956 eval "nmhbin=${bindir}";         eval "nmhbin2=${nmhbin}"
957 eval "nmhsysconf=${sysconfdir}"; eval "nmhsysconf2=${nmhsysconf}"
958 eval "nmhlib=${libdir}";         eval "nmhlib2=${nmhlib}"
959 eval "nmhman=${mandir}"
960
961 pop_kinds=no
962 if test x"$enable_pop" = x"yes"; then
963   pop_kinds="yes ("
964
965   if test x"$enable_apop" = x"yes"; then
966     pop_kinds="${pop_kinds}APOP "
967   fi
968
969   if test x"$with_krb4" != x -a x"$with_krb4" != x"no"; then
970     pop_kinds="${pop_kinds}KPOP "
971   fi
972
973   pop_kinds="${pop_kinds}POP3)"
974 fi
975
976 echo "
977 nmh configuration
978 -----------------
979 nmh version                : AC_PACKAGE_VERSION
980 target os                  : ${target}
981 compiler                   : ${CC}
982 compiler flags             : ${CFLAGS}
983 linker flags               : ${LDFLAGS}
984 source code location       : ${srcdir}
985 binary install path        : ${nmhbin2}
986 libary install path        : ${nmhlib2}
987 config files install path  : ${nmhsysconf2}
988 man page install path      : ${nmhman}
989 backup prefix              : ${backup_prefix}
990 transport system           : ${MTS}
991 file locking type          : ${LOCKTYPE}
992 default smtp servers       : ${smtpservers}
993 default editor             : ${editorpath}
994 default pager              : ${pagerpath}
995 email address masquerading : ${masquerade}
996 pop is enabled             : ${pop_kinds}
997 SASL support               : ${sasl_support}"
998 echo ""