Added -ansi -pedantic with gcc.
[mmh] / configure.ac
1 dnl
2 dnl configure.ac -- autoconf template for nmh
3 dnl
4
5 dnl Move this up a bit
6 AC_PREREQ([2.61])
7
8 AC_INIT([nmh], m4_normalize(m4_include([VERSION])), [nmh-workers@nongnu.org])
9 AC_CONFIG_SRCDIR([h/nmh.h])
10 AC_CONFIG_HEADER([config.h])
11 AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects])
12
13 AC_CANONICAL_HOST
14
15 AC_MSG_NOTICE([configuring for AC_PACKAGE_NAME-AC_PACKAGE_VERSION])
16 AC_SUBST(VERSION,AC_PACKAGE_VERSION)dnl
17
18 dnl What date of nmh are we building?
19 DATE=`cat ${srcdir}/DATE`
20 AC_MSG_NOTICE([configuring for nmh dated $DATE])
21 AC_SUBST([DATE])dnl
22
23 dnl --------------------------
24 dnl CHECK COMMAND LINE OPTIONS
25 dnl --------------------------
26
27 dnl Do you want to debug nmh?
28 AC_ARG_ENABLE([debug],
29   AS_HELP_STRING([--enable-debug],[enable nmh code debugging]))
30 dnl The old redundant --enable-nmh-debug is deprecated and undocumented.
31 AS_IF([test x"$enable_nmh_debug" = x"yes"], [enable_debug=yes])
32
33 dnl Do you want to disable use of locale functions
34 AH_TEMPLATE([LOCALE],
35 [Undefine if you don't want locale features.  By default this is defined.])
36 AC_ARG_ENABLE([locale],
37   [AS_HELP_STRING([--disable-locale], [turn off locale features])],
38   [AS_IF([test x$enableval = xyes], [AC_DEFINE(LOCALE)])],
39   [AC_DEFINE(LOCALE)])
40
41 dnl Do you want client-side support for using SASL for authentication?
42 dnl Note that this code will be enabled for both POP and SMTP
43 AC_ARG_WITH([cyrus-sasl], AS_HELP_STRING([--with-cyrus-sasl],
44   [Enable SASL support via the Cyrus SASL library]))
45 AS_IF([test x"$with_cyrus_sasl" != x -a x"$with_cyrus_sasl" != x"no"],[
46       AC_DEFINE([CYRUS_SASL], [1],
47                 [Define to use the Cyrus SASL library for authentication of POP and SMTP.])dnl
48       AS_IF([test x"$with_cyrus_sasl" != xyes],[
49             AC_MSG_WARN([Arguments to --with-cyrus-sasl now ignored])
50             AC_MSG_WARN([Please pass the appropriate arguments to CPPFLAGS/LDFLAGS])])
51       sasl_support=yes], [sasl_support=no])
52
53 dnl Do you want client-side support for encryption with TLS?
54 AC_ARG_WITH([tls], AS_HELP_STRING([--with-tls], [Enable TLS support]))
55 AS_IF([test x"$with_tls" != x -a x"$with_tls" != x"no"],[
56       AC_DEFINE([TLS_SUPPORT], [1], [Support TLS for session encryption.])dnl
57       tls_support=yes],[tls_support=no])
58
59 dnl What should be the default editor?
60 AC_ARG_WITH([editor],
61   AS_HELP_STRING([--with-editor=EDITOR],[specify the default editor]))
62
63 AS_IF([test -n "$with_editor"], [editorpath="$with_editor"])
64
65 dnl Set the backup prefix
66 AC_ARG_WITH([hash-backup],
67   AS_HELP_STRING([--with-hash-backup],[use # as the backup prefix (default: ,)]))
68 AS_IF([test x"$with_hash_backup" != x -a x"$with_hash_backup" != x"no"],
69       [backup_prefix="#"], [backup_prefix=","])
70 AC_DEFINE_UNQUOTED([BACKUP_PREFIX], "$backup_prefix",
71     [The prefix that is prepended to the name of message files when they are "removed" by rmm. This should typically be `,' or `#'.])dnl
72
73 dnl What method of locking to use?
74 AS_CASE(["$host_os"],
75   [aix*|cygwin*|linux*],
76     [default_locktype="fcntl"; default_locking=FCNTL_LOCKING],
77   [freebsd*], [default_locktype="flock"; default_locking=FLOCK_LOCKING],
78   [default_locktype="dot"; default_locking=DOT_LOCKING])
79
80 AC_ARG_WITH(locking,
81   AS_HELP_STRING([--with-locking=@<:@dot|fcntl|flock|lockf@:>@],
82   [specify the file locking method]))
83
84 if test x"$with_locking" = x"dot"; then
85   LOCKTYPE="dot"
86   AC_DEFINE(DOT_LOCKING, 1, [Define to use dot based file locking.])dnl
87 elif test x"$with_locking" = x"flock"; then
88   LOCKTYPE="flock"
89   AC_DEFINE(FLOCK_LOCKING, 1, [Define to use flock() based locking.])dnl
90 elif test x"$with_locking" = x"lockf"; then
91   LOCKTYPE="lockf"
92   AC_DEFINE(LOCKF_LOCKING, 1, [Define to use lockf() based locking.])dnl
93 elif test x"$with_locking" = x"fcntl"; then
94   LOCKTYPE="fcntl"
95   AC_DEFINE(FCNTL_LOCKING, 1, [Define to use fnctl() based locking.])dnl
96 else
97   LOCKTYPE="$default_locktype"
98   AC_DEFINE_UNQUOTED($default_locking, 1)dnl
99 fi
100
101 dnl Should we use a locking directory?
102 AC_ARG_ENABLE([lockdir],
103   [AS_HELP_STRING([--enable-lockdir=dir], [Store dot-lock files in "dir"])], [
104   AS_IF([test "x$enableval" = xyes],[
105     AC_MSG_ERROR([--enable-lockdir requires an argument])])
106   AS_IF([test "x$LOCKTYPE" != xdot],[
107     AC_MSG_ERROR([Can only use --enable-lockdir with dot locking])])
108   AC_DEFINE_UNQUOTED([LOCKDIR], ["$enableval"],
109                      [Directory to store dot-locking lock files])
110 ])
111
112 dnl What method of posting should post use?
113 AC_ARG_WITH([mts],
114   AS_HELP_STRING([--with-mts=@<:@smtp|sendmail@:>@],
115   [specify the default mail transport agent/service]))
116
117 AS_IF([test x"$with_mts" = x"smtp"], [MTS="smtp"],
118       [test x"$with_mts" = x"sendmail"], [MTS="sendmail"],
119       [MTS="smtp"])
120 AC_SUBST([MTS])dnl
121
122 dnl What should be the default pager?
123 AC_ARG_WITH([pager],
124   AS_HELP_STRING([--with-pager=PAGER],[specify the default pager]))
125
126 AS_IF([test -n "$with_pager"], [pagerpath="$with_pager"])
127
128 dnl If a pager is not explicitly specified, then look for one.
129 dnl Fall back to `cat', to avoid catastrophic failure of
130 dnl `mhshow', et al., if pagerpath is set to `no'.
131 if test -z "$pagerpath"; then
132   pathtmp=/usr/bin:/bin:/usr/ucb:/usr/local/bin
133   AC_PATH_PROGS([pagerpath], [more less most cat], [no], [$pathtmp])
134 fi
135 AC_SUBST(pagerpath)dnl
136
137 dnl What should be the default mail server(s)?
138 AC_ARG_WITH(smtpservers,
139   AS_HELP_STRING([--with-smtpservers='SMTPSERVER1@<:@ SMTPSERVER2...@:>@'],
140   [specify the default SMTP server(s) @<:@localhost@:>@]))
141 AS_IF([test -n "$with_smtpservers"], [smtpservers="$with_smtpservers"],
142       [smtpservers="localhost"])
143 AC_SUBST([smtpservers])dnl
144
145 dnl ----------------------------------------------------
146 dnl Default location is /usr/local/nmh/{bin,etc,lib,man}
147 dnl ----------------------------------------------------
148 AC_PREFIX_DEFAULT([/usr/local/nmh])
149
150 dnl ------------------
151 dnl CHECK THE COMPILER
152 dnl ------------------
153 dnl We want these before the checks,
154 dnl so the checks can modify their values.
155 test -z "$CFLAGS" && CFLAGS= auto_cflags=1
156 if test x"$enable_debug" = x"yes"; then
157   test -z "$LDFLAGS" && LDFLAGS=-g
158 fi
159
160 AC_PROG_CC
161 AM_PROG_CC_C_O
162
163 AC_CACHE_CHECK([whether preprocessor supports -Wunused-macros],
164   [nmh_cv_has_unusedmacros],
165   [nmh_saved_cppflags="$CPPFLAGS"
166    CPPFLAGS="$CPPFLAGS -Wunused-macros -Wno-unused-macros"
167    AC_TRY_COMPILE([],[],nmh_cv_has_unusedmacros=yes,nmh_cv_has_unusedmacros=no)
168    CPPFLAGS="$nmh_saved_cppflags"])
169
170 if test "$nmh_cv_has_unusedmacros" = 'yes'; then
171   test -z "$CPPFLAGS"  &&  CPPFLAGS=-Wunused-macros \
172                       ||  CPPFLAGS="$CPPFLAGS -Wunused-macros"
173   DISABLE_UNUSED_MACROS_WARNING=-Wno-unused-macros
174 fi
175 AC_SUBST(DISABLE_UNUSED_MACROS_WARNING)dnl
176
177 AC_CACHE_CHECK([whether compiler supports -Wno-sign-compare],
178   [nmh_cv_has_nosigncompare],
179   [nmh_saved_cppflags="$CPPFLAGS"
180    CPPFLAGS="$CPPFLAGS -Wno-sign-compare"
181    AC_TRY_COMPILE([],[],nmh_cv_has_nosigncompare=yes,
182                   nmh_cv_has_nosigncompare=no)
183    CPPFLAGS="$nmh_saved_cppflags"])
184
185 if test "$nmh_cv_has_nosigncompare" = 'yes'; then
186   DISABLE_SIGN_COMPARE_WARNING=-Wno-sign-compare
187 fi
188 AC_SUBST(DISABLE_SIGN_COMPARE_WARNING)dnl
189
190 AC_CACHE_CHECK([whether compiler supports -Wextra], [nmh_cv_has_wextra],
191 [nmh_saved_cflags="$CFLAGS"
192  CFLAGS="$CFLAGS -Wextra -Wno-clobbered"
193  AC_TRY_COMPILE([],[],nmh_cv_has_wextra=yes,nmh_cv_has_wextra=no)
194  CFLAGS="$nmh_saved_cflags"])
195
196 AC_CACHE_CHECK([whether compiler supports -Wno-pointer-sign], [nmh_cv_has_noptrsign],
197 [nmh_saved_cflags="$CFLAGS"
198  CFLAGS="$CFLAGS -Wno-pointer-sign"
199  AC_TRY_COMPILE([],[],nmh_cv_has_noptrsign=yes,nmh_cv_has_noptrsign=no)
200  CFLAGS="$nmh_saved_cflags"])
201
202 dnl if the user hasn't specified CFLAGS, then
203 dnl   if compiler is gcc, then
204 dnl    use -O2 and some warning flags
205 dnl   else use -O
206 dnl We use -Wall and -Wextra if supported.  If the compiler supports it we
207 dnl also use -Wno-pointer-sign, because gcc 4 now produces a lot of new
208 dnl warnings which are probably mostly spurious and which in any case we
209 dnl don't want to deal with now.
210 if test "$nmh_cv_has_noptrsign" = "yes"; then
211     nmh_gcc_common_flags="-ansi -pedantic -Wall"
212     if test "$nmh_cv_has_wextra" = "yes"; then
213         nmh_gcc_warnflags="${nmh_gcc_common_flags} -Wextra -Wno-clobbered "\
214 "-Wno-pointer-sign"
215     else
216         nmh_gcc_warnflags="${nmh_gcc_common_flags} -Wno-pointer-sign"
217     fi
218 else
219     if test "$nmh_cv_has_wextra" = "yes"; then
220         nmh_gcc_warnflags="${nmh_gcc_common_flags} -Wextra -Wno-clobbered"
221     else
222         nmh_gcc_warnflags="${nmh_gcc_common_flags}"
223     fi
224 fi
225
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="$nmh_gcc_warnflags -g" || CFLAGS="$CFLAGS $nmh_gcc_warnflags -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="$nmh_gcc_warnflags -O2" || CFLAGS="$CFLAGS $nmh_gcc_warnflags -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_SED             dnl Check for Posix-compliant sed
262 AC_PROG_LEX             dnl Check for lex/flex
263
264 dnl Look for `cut'
265 pathtmp=/usr/bin:/bin:/usr/local/bin:/usr/xpg4/bin:/usr/ucb
266 AC_PATH_PROG([cutpath], [cut], [no], [$pathtmp])
267
268 dnl
269 dnl Check for MD5 program and formatting command
270 dnl
271 AC_CHECK_PROGS([MD5SUM], [md5sum md5], [missing])
272 AS_CASE(["${MD5SUM}"],
273         [md5sum], [MD5FMT="cat"],
274         [md5], [[MD5FMT="${SED} -e 's/MD5 *(\(.*\)) *= \([0-9a-f]*\)/\2  \1/'"]],
275         [MD5FMT="missing"])
276 AC_SUBST([MD5FMT])
277
278 dnl ----------------------------------------------
279 dnl check for lclint, and lint if it doesn't exist
280 dnl ----------------------------------------------
281 AC_CHECK_PROG(linttmp1, lclint, lclint, no)dnl
282 if test x$ac_cv_prog_linttmp1 != xno ; then
283   LINT=$ac_cv_prog_linttmp1
284   LINTFLAGS="-weak +posixlib -macrovarprefixexclude"
285 else
286   AC_CHECK_PROG(linttmp2, lint, lint, no)dnl
287   if test x$ac_cv_prog_linttmp2 != xno ; then
288     LINT=$ac_cv_prog_linttmp2
289     LINTFLAGS=""
290   else
291     LINT="echo 'No lint program found'"
292     LINTFLAGS=""
293   fi
294 fi
295 AC_SUBST([LINT])dnl
296 AC_SUBST([LINTFLAGS])dnl
297
298 dnl Look for `ls'
299 pathtmp=/usr/bin:/bin:/usr/local/bin:/usr/xpg4/bin:/usr/ucb
300 AC_PATH_PROG([lspath], [ls], [no], [$pathtmp])
301
302 dnl See how we get ls to display the owner and the group
303 if test "$lspath" != "no"; then
304   AC_CACHE_CHECK([how to get ls to show us the group ownership of a file],
305                  [nmh_cv_ls_grpopt],
306   [if test x"`$lspath -dl / | $AWK '{print $9}'`" = x"/"; then
307     dnl There were 9 parameters, so unless this is a really bizarre, nonstandard
308     dnl ls, it would seem -l gave us both the user and group.  On this type of
309     dnl ls, -g makes _only_ the group be displayed (and not the user).
310     nmh_cv_ls_grpopt="-l"
311   else
312     dnl Looks like -l only gave us the user, so we need -g to get the group too.
313     nmh_cv_ls_grpopt="-lg"
314   fi])
315 fi
316
317 dnl Look for `sendmail'
318 pathtmp=/usr/lib:/usr/sbin:/usr/etc:/usr/ucblib:/usr/bin:/bin
319 AC_PATH_PROG([sendmailpath], [sendmail], [/usr/sbin/sendmail], [$pathtmp])
320
321 dnl Look for `vi'
322 pathtmp=/usr/bin:/bin:/usr/ucb:/usr/local/bin
323 AC_PATH_PROG([vipath], [vi], [/bin/vi], [$pathtmp])
324
325 dnl If editor is not specified yet,
326 dnl then use `vi' as the default.
327 AS_IF([test -z "$editorpath"], [editorpath="$vipath"])
328 AC_SUBST([editorpath])dnl
329
330 dnl ----------------------------------------------------------
331 dnl FIND MAIL SPOOL AND SEE IF WE NEED TO MAKE inc SETGID MAIL
332 dnl ----------------------------------------------------------
333 AC_CACHE_CHECK(where mail spool is located, nmh_cv_mailspool,
334 [for mailspool in /var/mail        dnl
335                   /var/spool/mail  dnl
336                   /usr/spool/mail  dnl
337                   /dev/null;       dnl Just in case we fall through
338 do
339   test -d $mailspool && break
340 done
341 nmh_cv_mailspool=$mailspool
342 ])
343 mailspool=$nmh_cv_mailspool
344 AC_SUBST([mailspool])dnl
345
346 dnl See whether the mail spool directory is world-writable.
347 if test "$lspath" != "no" -a "$cutpath" != "no"; then
348   AC_CACHE_CHECK(whether the mail spool is world-writable,
349                  nmh_cv_mailspool_world_writable,
350   [if test "`$lspath -dlL $mailspool | $cutpath -c9`" = "-"; then
351     nmh_cv_mailspool_world_writable=no
352   else
353     nmh_cv_mailspool_world_writable=yes
354   fi])
355 fi
356
357 dnl Also, check for liblockfile (as found on Debian systems)
358 AC_CHECK_HEADER([lockfile.h], [AC_CHECK_LIB(lockfile, lockfile_create)])
359
360 dnl and whether its companion program dotlockfile is setgid
361 AC_PATH_PROG(dotlockfilepath, dotlockfile, no)
362 if test "$ac_cv_lib_lockfile_lockfile_create" != "no" ; then
363   if test "$ac_cv_path_dotlockfilepath" != "no" ; then
364     AC_CACHE_CHECK(whether dotlockfile is setgid, nmh_cv_dotlockfile_setgid,
365     [ if test -g "$ac_cv_path_dotlockfilepath" ; then
366         nmh_cv_dotlockfile_setgid=yes
367       else
368         nmh_cv_dotlockfile_setgid=no
369       fi])
370   fi
371 fi
372
373 dnl Provide a way for distcheck to disable setgid_mail via
374 dnl DISTCHECK_CONFIGURE_FLAGS.
375 if test x"$DISABLE_SETGID_MAIL" != x -a x"$DISABLE_SETGID_MAIL" != x0; then
376   nmh_cv_dotlockfile_setgid=yes
377 fi
378
379 dnl If mailspool is not world-writable and dotlockfile is not setgid,
380 dnl we need to #define MAILGROUP to 1 and make inc setgid.
381 if test x"$LOCKTYPE" = x"dot" -a x"$nmh_cv_mailspool_world_writable" = x"no" -a x"$nmh_cv_dotlockfile_setgid" != x"yes" ; then
382   dnl do we really need both of these?
383   AC_DEFINE(MAILGROUP,1,
384     [Define to 1 if you need to make `inc' set-group-id because your mail spool is not world writable. There are no guarantees as to the safety of doing this, but this #define will add some extra security checks.])dnl
385   SETGID_MAIL=1
386 fi
387 AC_SUBST(SETGID_MAIL)dnl
388
389 dnl Use ls to see which group owns the mail spool directory.
390 AC_CACHE_CHECK(what group owns the mail spool, nmh_cv_ls_mail_grp,
391 [nmh_cv_ls_mail_grp=`$lspath -dL $nmh_cv_ls_grpopt $mailspool|$AWK '{print $4}'`
392 ])
393 MAIL_SPOOL_GRP=$nmh_cv_ls_mail_grp
394 AC_SUBST(MAIL_SPOOL_GRP)dnl
395
396 dnl ------------------
397 dnl CHECK HEADER FILES
398 dnl ------------------
399
400 dnl On glibc we need to define at least the '_XOPEN_SOURCE' level of features,
401 dnl or wchar.h doesn't declare a prototype for wcwidth(). But if we only define
402 dnl that level then db.h won't compile. So we define _GNU_SOURCE which turns
403 dnl on everything. Perhaps other OSes need some feature switch set to get wcwidth()
404 dnl declared; if so they should have an entry added to this case statement.
405 dnl NB that we must define this on the compiler command line, not in config.h,
406 dnl because it must be set before any system header is included and there's no
407 dnl portable way to make sure that files generated by lex include config.h
408 dnl before system header files.
409
410 AS_CASE(["$host_os"],
411         [linux*],
412         [# Like DEFS, but doesn't get stomped on by configure when using config.h:
413           AS_IF([test -z "$CPPFLAGS"],[CPPFLAGS="-D_GNU_SOURCE"],
414                 [CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"])])
415
416 AC_HEADER_STDC
417 AC_HEADER_TIOCGWINSZ
418 AC_CHECK_HEADERS([errno.h fcntl.h crypt.h ncurses/termcap.h termcap.h \
419                   langinfo.h wchar.h wctype.h iconv.h netdb.h \
420                   sys/param.h sys/time.h sys/stream.h])
421
422 dnl
423 dnl Checks for _IO_write_ptr. A Linuxism used by nmh on linux. We
424 dnl really use a whole set of them, but this check should be
425 dnl sufficient.
426 dnl
427 AC_CHECK_HEADER(libio.h, [
428   AC_EGREP_HEADER(_IO_write_ptr, libio.h, [
429     AC_DEFINE(LINUX_STDIO,1,[Use the Linux _IO_*_ptr defines from <libio.h>.]) ]) ])
430
431 AC_CHECK_HEADER([sys/ptem.h], AC_DEFINE(WINSIZE_IN_PTEM,1,
432   [Define to 1 if `struct winsize' requires <sys/ptem.h>.]),,
433 [[#if HAVE_SYS_STREAM_H
434 #  include <sys/stream.h>
435 #endif
436 ]])
437
438 dnl ---------------
439 dnl CHECK FUNCTIONS
440 dnl ---------------
441 AC_CHECK_FUNCS([wcwidth mbtowc writev lstat nl_langinfo getutxent])
442
443 dnl Check for multibyte character set support
444 if test "x$ac_cv_header_wchar_h" = "xyes" -a "x$ac_cv_header_wctype_h" = "xyes" \
445     -a "x$ac_cv_func_wcwidth" = "xyes" -a "x$ac_cv_func_mbtowc" = "xyes"; then
446   AC_DEFINE(MULTIBYTE_SUPPORT, 1,
447     [Define to enable support for multibyte character sets.])
448 fi
449
450 dnl -------------------
451 dnl CHECK FOR LIBRARIES
452 dnl -------------------
453 dnl Check location of modf
454 AC_CHECK_FUNC([modf], , AC_CHECK_LIB([m], [modf]))
455
456 dnl Checks for network libraries (nsl, socket)
457 NMH_CHECK_NETLIBS
458
459 NMH_READLINE
460
461 termcap_curses_order="termcap curses ncurses"
462 for lib in $termcap_curses_order; do
463   AC_CHECK_LIB(${lib}, tgetent, [TERMLIB="-l$lib"; break])
464 done
465 AC_SUBST([TERMLIB])dnl
466 AS_IF([test "x$TERMLIB" = "x"],
467       [AC_MSG_FAILURE([Could not find tgetent in any library.  Is there a curses
468 or ncurses library or package that you can install?])])
469
470
471 dnl ---------------
472 dnl CHECK FOR ICONV
473 dnl ---------------
474
475 dnl Find iconv. It may be in libiconv and may be iconv() or libiconv()
476 if test "x$ac_cv_header_iconv_h" = "xyes"; then
477   AC_CHECK_FUNC(iconv, ac_found_iconv=yes, ac_found_iconv=no)
478   if test "x$ac_found_iconv" = "xno"; then
479     AC_CHECK_LIB(iconv, iconv, ac_found_iconv=yes)
480     if test "x$ac_found_iconv" = "xno"; then
481       AC_CHECK_LIB(iconv, libiconv, ac_found_iconv=yes)
482     fi
483     if test "x$ac_found_iconv" != "xno"; then
484       ICONVLIB="-liconv"
485     fi
486   else
487     dnl Handle case where there is a native iconv but iconv.h is from libiconv
488     AC_CHECK_DECL(_libiconv_version,
489       [ AC_CHECK_LIB(iconv, libiconv, LIBS="-liconv $LIBS") ],,
490       [ #include <iconv.h> ])
491   fi
492 fi
493 if test "x$ac_found_iconv" = xyes; then
494   AC_DEFINE([HAVE_ICONV], [1], [Define if you have the iconv() function.])
495 fi
496 AC_SUBST([ICONVLIB])
497
498 dnl Check if iconv uses const in prototype declaration
499 if test "x$ac_found_iconv" = "xyes"; then
500   AC_CACHE_CHECK(for iconv declaration, ac_cv_iconv_const,
501     [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdlib.h>
502         #include <iconv.h>]],
503         [[#ifdef __cplusplus
504           "C"
505           #endif
506           #if defined(__STDC__) || defined(__cplusplus)
507           size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
508           #else
509           size_t iconv();
510           #endif]])],
511       [ac_cv_iconv_const=],
512       [ac_cv_iconv_const=const])])
513   AC_DEFINE_UNQUOTED([ICONV_CONST], $ac_cv_iconv_const,
514     [Define as const if the declaration of iconv() needs const.])
515 fi
516
517 dnl --------------
518 dnl CHECK FOR NDBM
519 dnl --------------
520
521 AC_ARG_WITH([ndbm],AS_HELP_STRING([--with-ndbm=ARG],[use -lARG to link with ndbm]),
522             [nmh_ndbm=$withval],[nmh_ndbm=autodetect])
523 AC_ARG_WITH([ndbmheader],AS_HELP_STRING([--with-ndbmheader=ARG],[#include <ARG> to use ndbm]),
524             [nmh_ndbmheader=$withval],[nmh_ndbmheader=autodetect])
525
526 if test "$nmh_ndbm" = "autodetect"; then
527   if test "$nmh_ndbmheader" != "autodetect"; then
528     AC_MSG_ERROR([must specify both --with-ndbm and --with-ndbmheader or neither])
529   else
530
531     dnl There are at least four implementations of ndbm, and
532     dnl several of those can be in different places at the whim
533     dnl of the system integrator. A good summary of this mess
534     dnl can be found at http://www.unixpapa.com/incnote/dbm.html
535
536     dnl Classic ndbm with no library required (eg NetBSD): try this
537     dnl first so we don't accidentally link in a pointless but harmless
538     dnl library in one of the later ndbm.h+libfoo tests:
539     NMH_CHECK_NDBM(ndbm.h,,,
540     dnl Berkeley DBv2 emulating ndbm: header in db.h:
541       NMH_CHECK_NDBM(db.h,db,,
542     dnl Berkeley DBv1 emulating ndbm:
543         NMH_CHECK_NDBM(ndbm.h,db,,
544           NMH_CHECK_NDBM(ndbm.h,db1,,
545     dnl Classic ndbm:
546             NMH_CHECK_NDBM(ndbm.h,ndbm,,
547     dnl glibc2.1 systems put db1 in a subdir:
548               NMH_CHECK_NDBM(db1/ndbm.h,db1,,
549     dnl GNU gdbm emulating ndbm, with header possibly in gdbm/
550     dnl and possibly needing gbdm_compat library:
551                 NMH_CHECK_NDBM(gdbm/ndbm.h,gdbm,,
552                   NMH_CHECK_NDBM(gdbm/ndbm.h,gdbm_compat -lgdbm,,
553                     NMH_CHECK_NDBM(ndbm.h,gdbm,,
554                       NMH_CHECK_NDBM(ndbm.h,gdbm_compat -lgdbm))))))))))
555
556   fi
557 else
558   dnl We don't really need to check that the user-specified values work,
559   dnl but it is a convenience to the user to bomb out early rather than
560   dnl after configure and half the compile process.
561   NMH_CHECK_NDBM([$nmh_ndbmheader],[$nmh_ndbm])
562 fi
563
564 if test "$nmh_ndbm_found" = "no"; then
565   AC_MSG_ERROR([could not find a working ndbm library/header combination])
566 else
567   dnl Now export the lib/header to our makefile/config.h:
568   if test x"$nmh_ndbmheader" != x; then
569     AC_DEFINE_UNQUOTED(NDBM_HEADER, <$nmh_ndbmheader>,
570       [Define to the header containing the ndbm API prototypes.])
571   fi
572   if test x"$nmh_ndbm" != x; then
573     NDBM_LIBS="-l$nmh_ndbm"
574   else
575     NDBM_LIBS=
576   fi
577   AC_SUBST([NDBM_LIBS])
578 fi
579
580 dnl ------------------
581 dnl Set RPM build root
582 dnl ------------------
583 dnl nmhrpm is used in the final summary, see below.  The default value is
584 dnl reported there as ./RPM, consistent with the reporting of the default
585 dnl source code location as ., but its absolute path is used in the Makefile.
586 AC_ARG_WITH(rpmdir,
587   AS_HELP_STRING([--with-rpmdir=RPMDIR], [RPM build directory @<:@RPM@:>@]))
588   AS_IF([test x"$with_rpmdir" = x], [rpmdir='$(abs_srcdir)/RPM'; nmhrpm=./RPM],
589           [rpmdir="$with_rpmdir"; eval "nmhrpm=${rpmdir}"])
590 AC_SUBST([rpmdir])
591
592
593 dnl --------------------
594 dnl CHECK FOR CYRUS-SASL
595 dnl --------------------
596
597 AS_IF([test x"$sasl_support" = x"yes"],[
598   AC_CHECK_HEADER([sasl/sasl.h], , [AC_MSG_ERROR([sasl.h not found])])
599   AC_CHECK_LIB([sasl2], [sasl_client_new], [SASLLIB="-lsasl2"],
600     [AC_MSG_ERROR([Cyrus SASL library not found])])],[SASLLIB=""])
601 AC_SUBST([SASLLIB])
602
603 dnl -----------------
604 dnl CHECK FOR OPENSSL
605 dnl -----------------
606
607 AS_IF([test x"$tls_support" = x"yes"],[
608   AC_CHECK_HEADER([openssl/ssl.h], , [AC_MSG_ERROR([openssl/ssl.h not found])])
609   AC_CHECK_LIB([crypto], [BIO_write], ,
610     [AC_MSG_ERROR([OpenSSL crypto library not found])])
611   AC_CHECK_LIB([ssl], [SSL_library_init], ,
612     [AC_MSG_ERROR([OpenSSL library not found])])])
613
614 dnl ---------------------
615 dnl CHECK TERMCAP LIBRARY
616 dnl ---------------------
617
618 dnl Add the termcap library, so that the following configure
619 dnl tests will find it when it tries to link test programs.
620 nmh_save_LIBS="$LIBS"
621 LIBS="$TERMLIB $LIBS"
622
623 dnl Check if tgetent accepts NULL (and will allocate its own termcap buffer)
624 dnl Some termcaps reportedly accept a zero buffer, but then dump core
625 dnl in tgetstr().
626 dnl Under Cygwin test program crashes but exit code is still 0. So,
627 dnl we test for a file that porgram should create
628 AH_TEMPLATE([TGETENT_ACCEPTS_NULL],
629 [Define to 1 if tgetent() accepts NULL as a buffer.])
630 AC_CACHE_CHECK(if tgetent accepts NULL,
631 nmh_cv_func_tgetent_accepts_null,
632 [AC_TRY_RUN([
633 main()
634 {
635     char buf[4096];
636     int r1 = tgetent(buf, "vt100");
637     int r2 = tgetent((char*)0,"vt100");
638     if (r1 >= 0 && r1 == r2) {
639         char tbuf[1024], *u;
640         u = tbuf;
641         tgetstr("cl", &u);
642         creat("conftest.tgetent", 0640);
643     }
644     exit((r1 != r2) || r2 == -1);
645 }
646 ],
647   if test -f conftest.tgetent; then
648     nmh_cv_func_tgetent_accepts_null=yes
649   else
650     nmh_cv_func_tgetent_accepts_null=no
651   fi,
652   nmh_cv_func_tgetent_accepts_null=no,
653   nmh_cv_func_tgetent_accepts_null=no)])
654 if test x$nmh_cv_func_tgetent_accepts_null = xyes; then
655   AC_DEFINE(TGETENT_ACCEPTS_NULL)
656 fi
657 AC_CACHE_CHECK(if tgetent returns 0 on success,
658 nmh_cv_func_tgetent_zero_success,
659 [AC_TRY_RUN([
660 main()
661 {
662     char buf[4096];
663     int r1 = tgetent(buf, "!@#$%^&*");
664     int r2 = tgetent(buf, "vt100");
665     if (r1 < 0 && r2 == 0) {
666         char tbuf[1024], *u;
667         u = tbuf;
668         tgetstr("cl", &u);
669         creat("conftest.tgetent0", 0640);
670     }
671     exit(r1 == r2);
672 }
673 ],
674   if test -f conftest.tgetent0; then
675     nmh_cv_func_tgetent_zero_success=yes
676   else
677     nmh_cv_func_tgetent_zero_success=no
678   fi,
679   nmh_cv_func_tgetent_zero_success=no,
680   nmh_cv_func_tgetent_zero_success=no)])
681 AH_TEMPLATE([TGETENT_SUCCESS],
682 [Define to what tgetent() returns on success (0 on HP-UX X/Open curses).])
683 if test x$nmh_cv_func_tgetent_zero_success = xyes; then
684   AC_DEFINE(TGETENT_SUCCESS, 0)
685 else
686   AC_DEFINE(TGETENT_SUCCESS, 1)
687 fi
688
689 dnl Now put the libraries back to what it was before we
690 dnl starting checking the termcap library.
691 LIBS="$nmh_save_LIBS"
692
693 dnl --------------
694 dnl CHECK TYPEDEFS
695 dnl --------------
696 AC_TYPE_PID_T
697 AC_TYPE_OFF_T
698 AC_TYPE_UID_T
699 AC_TYPE_MODE_T
700 AC_TYPE_SIZE_T
701
702 dnl ----------------
703 dnl CHECK STRUCTURES
704 dnl ----------------
705
706 dnl For platforms such as FreeBSD that have tm_gmtoff in struct tm.
707 dnl (FreeBSD has a timezone() function but not a timezone global
708 dnl variable that is visible).
709 AC_CHECK_MEMBERS([struct tm.tm_gmtoff],,,[#include <time.h>])
710
711 AC_STRUCT_DIRENT_D_TYPE
712
713 dnl Where is <signal.h> located?  Needed as input for signames.awk
714 AC_CACHE_CHECK(where signal.h is located, nmh_cv_path_signal_h,
715 [for SIGNAL_H in /usr/include/bsd/sys/signal.h  dnl Next
716                  /usr/include/asm/signal.h      dnl Linux 1.3.0 and above
717                  /usr/include/asm/signum.h      dnl some versions of Linux/Alpha
718                  /usr/include/linux/signal.h    dnl Linux up to 1.2.11
719                  /usr/include/sys/signal.h      dnl Almost everybody else
720                  /dev/null;                     dnl Just in case we fall through
721 do
722   test -f $SIGNAL_H && \
723   grep '#[      ]*define[       ][      ]*SIG[0-9A-Z]*[         ]*[0-9][0-9]*' $SIGNAL_H > /dev/null && \
724   break
725 done
726 nmh_cv_path_signal_h=$SIGNAL_H
727 ])
728 SIGNAL_H=$nmh_cv_path_signal_h
729 AC_SUBST(SIGNAL_H)dnl
730
731 dnl
732 dnl Sigh, this is required because under the new world order autoconf has
733 dnl nothing to create in a few of the build directories when doing an object
734 dnl tree build.  So make sure we created certain directories if they don't
735 dnl exist.
736 dnl
737
738 AC_CONFIG_COMMANDS([build-directories],
739 [test -d etc || ${MKDIR_P} etc
740 test -d man || ${MKDIR_P} man])
741
742 AC_CONFIG_COMMANDS_POST([
743
744 dnl These odd looking assignments are done to expand out unexpanded
745 dnl variables in bindir et al (for instance mandir is '${datarootdir}/man'),
746 dnl but expanding that gives '${prefix}/share/man', so we need to expand
747 dnl again to get the final answer.
748 dnl We only use the expanded versions to print the install paths in
749 dnl the final summary and should use them nowhere else (see the autoconf
750 dnl docs for the rationale for bindir etc being unexpanded).
751 eval "nmhbin=${bindir}";         eval "nmhbin=${nmhbin}"
752 eval "nmhsysconf=${sysconfdir}"; eval "nmhsysconf=${nmhsysconf}"
753 eval "nmhlib=${libdir}";         eval "nmhlib=${nmhlib}"
754 eval "nmhman=${mandir}";         eval "nmhman=${nmhman}"
755 eval "nmhrpm=${nmhrpm}";
756
757 AC_MSG_NOTICE([
758 nmh configuration
759 -----------------
760 nmh version                : AC_PACKAGE_VERSION
761 host os                    : ${host}
762 compiler                   : ${CC}
763 compiler flags             : ${CFLAGS}
764 linker flags               : ${LDFLAGS}
765 preprocessor flags         : ${CPPFLAGS}
766 source code location       : ${srcdir}
767 binary install path        : ${nmhbin}
768 library install path       : ${nmhlib}
769 config files install path  : ${nmhsysconf}
770 man page install path      : ${nmhman}
771 RPM build root             : ${nmhrpm}
772 backup prefix              : ${backup_prefix}
773 transport system           : ${MTS}
774 file locking type          : ${LOCKTYPE}
775 default smtp servers       : ${smtpservers}
776 default editor             : ${editorpath}
777 default pager              : ${pagerpath}
778 SASL support               : ${sasl_support}
779 TLS support                : ${tls_support}
780 ])])dnl
781
782 dnl ---------------
783 dnl OUTPUT MAKEFILE
784 dnl ---------------
785 AC_CONFIG_FILES([Makefile test/common.sh])
786 AC_OUTPUT