]> Pileus Git - ~andy/fetchmail/blob - configure.ac
Fix CPPFLAGS for GSSAPI compiles.
[~andy/fetchmail] / configure.ac
1 dnl Autoconfigure input file for fetchmail
2 #
3 # Fetchmail automatic configuration support
4 #
5 # Eric S. Raymond <esr@thyrsus.com>
6 # 2004 - 2009 Matthias Andree <matthias.andree@gmx.de>
7 #
8 dnl Process this file with autoconf to produce a configure script.
9 dnl
10
11 dnl XXX - if bumping version here, check fetchmail.man, too!
12 AC_INIT([fetchmail],[6.3.13],[fetchmail-users@lists.berlios.de])
13 AC_CONFIG_SRCDIR([fetchmail.h])
14 AC_CONFIG_HEADERS([config.h])
15 AC_CONFIG_LIBOBJ_DIR([.])
16
17 AC_CANONICAL_HOST
18
19 dnl automake options are in Makefile.am
20 AC_PREREQ(2.60)
21 dnl 2.60 required for AC_USE_SYSTEM_EXTENSIONS
22 AM_INIT_AUTOMAKE
23
24 dnl python is optional
25 #
26 # you can pass PYTHON=: in environment or on the command line
27 # to disable python detection and continue without building/installing
28 # fetchmail.conf -- be sure to check README.packaging, too!
29 #
30 AM_PATH_PYTHON(2.0,,AC_MSG_WARN([Disabling fetchmailconf: python 2.0 or greater not found]))
31 AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != :])
32
33 AC_PROG_AWK
34 AC_PROG_CC
35 AC_PROG_INSTALL
36 AC_PROG_CPP                     dnl Later checks need this.
37 AC_PROG_RANLIB
38 AM_PROG_CC_C_O
39 AC_USE_SYSTEM_EXTENSIONS
40
41 AC_ISC_POSIX
42 dnl AC_ISC_POSIX: - XXX FIXME: remove in fetchmail 6.4.
43 dnl This macro adds `-lcposix' to output variable `LIBS' if necessary
44 dnl for Posix facilities.  Sun dropped support for the obsolete
45 dnl INTERACTIVE Systems Corporation Unix on 2006-07-23.  New programs
46 dnl need not use this macro.  It is implemented as
47 dnl `AC_SEARCH_LIBS([strerror], [cposix])'
48
49 dnl check for b0rked Solaris (and other shells) and find one that works
50 AC_MSG_CHECKING(for a working shell...)
51 for i in /usr/xpg6/bin/sh /usr/xpg4/bin/sh /usr/ccs/bin/sh /bin/sh /usr/bin/sh /bin/ksh /bin/bash /usr/local/bin/bash ; do
52     $i -c 'if ! false ; then echo $(echo ok) ; fi' >config.$$ 2>/dev/null
53     j=`cat config.$$`
54     rm -f config.$$
55     if test "x$j" = "xok" ; then
56         SHELL=$i
57         AC_SUBST(SHELL)
58         break
59     fi
60 done
61 AC_MSG_RESULT($SHELL)
62 if test "x$SHELL" = "x" ; then
63     AC_MSG_ERROR(no SUS compliant shell found - on Solaris, install SUNWxcu4)
64 fi
65
66
67 AC_HEADER_STDC
68 AC_HEADER_TIME
69 AC_TYPE_SIZE_T
70 AC_TYPE_PID_T
71 AC_TYPE_SIGNAL
72 AC_CHECK_HEADERS([unistd.h termios.h termio.h sgtty.h stdarg.h \
73         sys/itimer.h fcntl.h sys/fcntl.h memory.h sys/wait.h \
74         arpa/inet.h arpa/nameser.h netinet/in.h net/socket.h netdb.h \
75         sys/select.h sys/socket.h sys/time.h langinfo.h])
76 if test _$ac_cv_header_stdarg_h != _yes ; then
77 AC_MSG_WARN([stdarg.h is not defined. Unsupported configuration, proceed at your own risk.])
78 fi
79 AC_CHECK_TYPE(u_int32_t,,
80         AC_DEFINE(u_int32_t,unsigned int,
81                 [Define to unsigned int if <sys/types.h> does not define.]),
82         [AC_INCLUDES_DEFAULT
83 #ifdef HAVE_ARPA_NAMESER_H
84 #include <arpa/nameser.h>
85 #endif])
86 AC_CHECK_HEADERS([resolv.h],,,[
87 #include <sys/types.h>
88 #ifdef HAVE_NETINET_IN_H
89 #include <netinet/in.h>
90 #endif
91 #ifdef HAVE_ARPA_NAMESER_H
92 #include <arpa/nameser.h>
93 #endif
94 ])
95
96 AC_C_CONST                      dnl getopt needs this.
97
98 AM_PROG_LEX
99 AC_PROG_MAKE_SET
100 AC_PROG_YACC
101
102 # Check for OS special cases
103 case $host_os in
104 darwin*)
105     AC_MSG_NOTICE(found Darwin - Adding -DBIND_8_COMPAT to CFLAGS)
106     CPPFLAGS="$CPPFLAGS -DBIND_8_COMPAT"
107     ;;
108 # Check for FreeBSD special case: more libs needed
109 freebsd*)
110     AC_MSG_NOTICE(found FreeBSD - Adding -lmd -lkvm -lcom_err to standard libraries)
111     LIBS="$LIBS -lmd -lkvm -lcom_err"
112     ;;
113 # Check for LynxOS special case: -lbsd needed (at least on 2.3.0) and -s
114 # not working.
115 lynxos*)
116     AC_MSG_NOTICE(found LynxOS - Adding -lbsd to standard libraries)
117     LIBS="$LIBS -lbsd"
118     LDFLAGS=`echo $LDFLAGS | sed "s/-s //"`
119     AC_MSG_NOTICE(found LynxOS - Prepending standard include path to gcc flags)
120     CPPFLAGS="$CPPFLAGS -I/usr/include"
121     ;;
122 # Check for Rhapsody special case: it doesn't like -s
123 rhapsody*)
124     AC_MSG_NOTICE(found Rhapsody - Removing -s load flag)
125     LDFLAGS=`echo $LDFLAGS | sed "s/-s //"`
126     ;;
127 esac
128
129 AC_CACHE_SAVE
130
131 dnl i18n
132 AM_GNU_GETTEXT([external], [need-ngettext])
133 AM_GNU_GETTEXT_VERSION([0.14.6])
134 dnl end i18n
135
136 # Under sysV68, socket and friends are provided by the C library.
137 # -linet does not provide socket, but causes multiple definition
138 # errors at link-time.  It is thus better to only use the C library.
139 # So don't add -linet to the link list unless it's necessary
140 AC_CHECK_FUNC(socket,
141     AC_MSG_RESULT(using libc's socket),
142     AC_CHECK_LIB(socket,socket)
143     AC_CHECK_LIB(inet,socket))
144
145 # The condition in this test copes with the presence of inet_addr in libc6.
146 AC_CHECK_FUNC(inet_addr,
147     AC_MSG_RESULT(using libc's inet_addr),
148     AC_CHECK_LIB(nsl,inet_addr))
149
150 dnl Port hack for Interactive UNIX System V/386 Release 3.2
151 AC_CHECK_LIB(cposix, strchr,
152                 [DEFS="$DEFS -D_SYSV3"
153                 LIBS="$LIBS -lcposix"])
154
155 dnl Port hack for Sparc/NetBSD-1.5
156 dnl
157 dnl NB: this has been disabled as it causes the unconditional
158 dnl addition of libintl to the build, which is both undesired
159 dnl and breaks on Solaris/Blastwave.org machines.
160 dnl
161 dnl AC_CHECK_LIB(intl, gettext,
162 dnl             [LIBS="$LIBS -lintl"])
163
164 AC_REPLACE_FUNCS([strstr strcasecmp memmove stpcpy strlcpy strlcat])
165
166 AC_CHECK_FUNC(MD5Init, [],
167               [AC_LIBSOURCE(md5c.c)
168                EXTRAOBJ="$EXTRAOBJ md5c.\$(OBJEXT)"])
169
170 AC_CHECK_FUNC(getopt_long, [],
171               [AC_LIBSOURCES([getopt.c, getopt1.c])
172                EXTRAOBJ="$EXTRAOBJ getopt.\$(OBJEXT) getopt1.\$(OBJEXT)"])
173
174 AC_FUNC_VPRINTF
175
176 AC_SUBST(EXTRAOBJ)
177
178 AC_CHECK_FUNCS(tcsetattr stty setsid geteuid seteuid dnl
179   strerror syslog snprintf vprintf vsnprintf vsyslog dnl
180   atexit inet_aton strftime setrlimit socketpair dnl
181   sigaction strdup setlocale)
182
183 AC_CHECK_DECLS(strerror)
184 dnl INET6 is used by KAME/getnameinfo
185 AC_CACHE_CHECK(for AF_INET6/PF_INET6,ac_cv_inet6,
186 AC_COMPILE_IFELSE([
187   AC_LANG_PROGRAM([[
188     #ifdef HAVE_SYS_TYPES_H
189     #include <sys/types.h>
190     #endif
191     #ifdef HAVE_SYS_SOCKET_H
192     #include <sys/socket.h>
193     #endif
194   ]],[[
195     int foo = AF_INET6;
196     int bar = PF_INET6;
197   ]])],
198   ac_cv_inet6=yes , ac_cv_inet6=no
199 ))
200 if test "x$ac_cv_inet6" = xyes
201 then
202     AC_DEFINE(INET6,1,Define to 1 if your system defines AF_INET6 and PF_INET6.)
203 fi
204
205 # Under Red Hat 4.0 (and many other Linuxes) -lresolv is seriously flaky
206 # and breaks gethostbyname(2).  It's better to use the bind stuff in the C
207 # library.  So don't add -lresolv to the link list unless it's necessary
208 # (It will be necessary when using GNU libc6).
209 old_LIBS="$LIBS"
210 for lib in '' -lresolv; do
211     if test -z "$lib"; then
212        AC_MSG_CHECKING([for res_search in libc])
213     else
214        AC_MSG_CHECKING([for res_search in $lib])
215     fi
216     LIBS="$old_LIBS $lib"
217     AC_LINK_IFELSE([AC_LANG_PROGRAM([[
218 #include <sys/types.h>
219 #ifdef HAVE_NETINET_IN_H
220 #include <netinet/in.h>
221 #endif
222 #ifdef HAVE_ARPA_NAMESER_H
223 #include <arpa/nameser.h>
224 #endif
225 #ifdef HAVE_RESOLV_H
226 #include <resolv.h>
227 #endif
228 extern int res_search();
229 ]], [[res_search(0, 0, 0, 0, 0); dn_skipname(0,0);]])],
230     [AC_MSG_RESULT([found])
231      AC_DEFINE(HAVE_RES_SEARCH, [1],
232                [Define to 1 if you have the 'res_search' and 'dn_skipname' functions.])
233      break], [AC_MSG_RESULT([not found])])
234      LIBS=$old_LIBS
235 done
236
237 dnl Check for libcrypt -- it may live in libc or libcrypt, as on IRIX
238 AC_CHECK_FUNC(crypt, , AC_CHECK_LIB(crypt,crypt))
239
240 dnl Check for RSA refersence library in case we're using SSL
241 AC_CHECK_LIB(rsaref, RSAPublicDecrypt)
242
243 dnl AC_FUNC_SETVBUF_REVERSED
244
245 dnl Check for usable void pointer type
246 AC_MSG_CHECKING(use of void pointer type)
247 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[char *p;
248     void *xmalloc();
249     p = (char *) xmalloc(1);
250    ]])],[AC_DEFINE(HAVE_VOIDPOINTER,1,[Define if your C compiler allows void * as a function result]) AC_MSG_RESULT(yes)],[AC_MSG_RESULT(no)])
251
252 dnl Check for ANSI volatile
253 AC_C_VOLATILE
254
255 dnl Check out the wait reality.  We have to assume sys/wait.h is present.
256 AC_CHECK_FUNCS(waitpid wait3)
257 AC_MSG_CHECKING(for union wait);
258 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
259 #include <sys/wait.h>]], [[union wait status; int pid; pid = wait (&status);
260 #ifdef WEXITSTATUS
261 /* Some POSIXoid systems have both the new-style macros and the old
262    union wait type, and they do not work together.  If union wait
263    conflicts with WEXITSTATUS et al, we don't want to use it at all.  */
264 if (WEXITSTATUS (status) != 0) pid = -1;
265 #endif
266 #ifdef HAVE_WAITPID
267 /* Make sure union wait works with waitpid.  */
268 pid = waitpid (-1, &status, 0);
269 #endif
270 ]])],[AC_DEFINE(HAVE_UNION_WAIT,1,Define if 'union wait' is the type of the first arg to wait functions.) AC_MSG_RESULT(yes)],[AC_MSG_RESULT(no)])
271
272 AC_MSG_CHECKING(sys_siglist declaration in signal.h or unistd.h)
273 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <signal.h>
274 /* NetBSD declares sys_siglist in <unistd.h>.  */
275 #ifdef HAVE_UNISTD_H
276 #include <unistd.h>
277 #endif]], [[char *msg = *(sys_siglist + 1);]])],[AC_DEFINE(SYS_SIGLIST_DECLARED,1,[Define if 'sys_siglist' is declared by <signal.h>.]) AC_MSG_RESULT(yes)],[AC_MSG_RESULT(no)])
278
279 # Find the right directory to put the root-mode PID file in
280 for dir in "/var/run" "/etc"
281 do
282         if test -d $dir 
283         then
284                 break;
285         fi
286 done
287 AC_MSG_RESULT(root-mode pid file will go in $dir)
288 AC_DEFINE_UNQUOTED(PID_DIR, "$dir", directory for PID lock files)
289
290 # We may have a fallback MDA available in case the socket open to the 
291 # local SMTP listener fails.  Best to use procmail for this, as we know
292 # it won't try delivering through local SMTP and cause a mail loop.
293 # Sendmail without the -t option to use the message headers will work too,
294 # not just for sendmail itself but for workalikes like exim.
295 #
296 # Note1: A disadvantage of using procmail is that local alias expansion
297 # according to /etc/aliases won't get done if we fall back.  This doesn't
298 # matter in single-drop mode.
299 #
300 # Note2: it would be a very bad idea to use any MDA that doesn't return
301 # a refuse-to-deliver status on disk- or process-table-full
302 # conditions; mail could get lost that way.  Sendmail and all of the MDAs
303 # like exim that might be lurking under a sendmail alias) do the right 
304 # thing in this circumstance.  Matthias Andree warns that procmail does
305 # not.  
306 #
307 # Note3: Defalt value of fallback is now off.  Matthias writes:
308 #
309 # 1. there is no way to predict when the fallback is used. With some MTAs
310 #    (such as those limiting load average), outer circumstances can cause
311 #    the fallback to kick in.
312
313 # 2. the fallback changes fetchmail behaviour in unpredictable ways. It's
314 #    not only about alias expansion, .forwards to special filters won't
315 #    work, mail may end up in a different place (users claim "mail loss"
316 #    for that).
317
318 # 3. The claim procmail did the right thing with its exit codes is plain
319 #    wrong. I've seen procmail exit with code 1 when it should have exited
320 #    with code 75, like, configuration errors. Procmail is a dangerous
321 #    beast and is best replaced by maildrop.
322
323 # 4. if multiple choices exist (like procmail and maildrop), fetchmail
324 #    cannot tell which one it should choose. Say, your MTA is configured
325 #    to use maildrop to deliver to user's mailboxes, if fetchmail then
326 #    chooses procmail, this is plain wrong.
327 #
328
329 AC_PATH_PROG(procmail, procmail, "", $PATH:/usr/sbin)
330 AC_PATH_PROG(sendmail, sendmail, "", $PATH:/usr/sbin:/usr/lib)
331 AC_PATH_PROG(maildrop, maildrop, "", $PATH:/usr/local/bin)
332
333 ###     use option --disable-fallback to disable fallback MDA
334 ###     use option --enable-fallback=procmail or 
335 ###                --enable-fallback=sendmail to select
336 AC_ARG_ENABLE(fallback,
337         [  --enable-fallback=procmail    enable procmail as fallback
338   --enable-fallback=sendmail    enable /usr/sbin/sendmail as fallback
339   --enable-fallback=maildrop    enable maildrop as fallback
340   --enable-fallback=no          disable fallback],,[enable_fallback=no])
341
342 case "$enable_fallback" in
343         sendmail)       if test -z "$sendmail" ; then 
344                                 AC_MSG_ERROR([Sendmail selected as fallback, but not found])
345                                 #not reached
346                         fi
347                         AC_DEFINE_UNQUOTED(FALLBACK_MDA, "$sendmail -i %T", Fallback MTA to use if defined)
348                         AC_MSG_NOTICE(Will use $sendmail as fallback MDA.)
349                         ;;
350         procmail)       if test -z "$procmail" ; then
351                                 AC_MSG_ERROR([procmail selected as fallback, but not found])
352                                 #not reached
353                         fi
354                         AC_DEFINE_UNQUOTED(FALLBACK_MDA, "$procmail -d %T")
355                         AC_MSG_NOTICE(Will use $procmail as fallback MDA.)
356                         ;;
357         maildrop)       if test -z "$maildrop" ; then
358                                 AC_MSG_ERROR([maildrop selected as fallback, but not found])
359                                 #not reached
360                         fi
361                         AC_DEFINE_UNQUOTED(FALLBACK_MDA, "$maildrop -d %T")
362                         AC_MSG_NOTICE(Will use $maildrop as fallback MDA.)
363                         ;;
364         no|unset)       AC_MSG_NOTICE(Will not use a fallback MDA.)
365                         ;;
366         auto|yes|set)   if test -n "$sendmail" ; then
367                                 AC_DEFINE_UNQUOTED(FALLBACK_MDA,"$sendmail -i %T")
368                                 AC_MSG_NOTICE(Will use $sendmail as fallback MDA.)
369                         else
370                                 AC_MSG_WARN(No fallback MDA available.  procmail and maildrop are not eligible)
371                                 AC_MSG_WARN(for automatic fallback MDA configuration for reliability reasons.)
372                         fi
373                         ;;
374         *)              AC_MSG_ERROR([unkown value for --enable-fallback given: $enable_fallback])
375                         #notreached
376                         ;;
377 esac
378
379 AC_CHECK_SIZEOF(short)
380 AC_CHECK_SIZEOF(int)
381 AC_CHECK_SIZEOF(long)
382
383 ###     use option --enable-POP2 to compile in the POP2 support
384 AC_ARG_ENABLE(POP2,
385         [  --enable-POP2           compile in POP2 protocol support (obsolete)],
386         [with_POP2=$enableval],
387         [with_POP2=no])
388 test "$with_POP2" = "yes" && AC_DEFINE(POP2_ENABLE,1,Define if you want POP2 support compiled in)
389 AM_CONDITIONAL(POP2_ENABLE, test "$with_POP2" = yes)
390
391 ###     use option --disable-POP3 to omit the POP3 support
392 AC_ARG_ENABLE(POP3,
393         [  --disable-POP3          don't compile in POP3 protocol support],
394         [with_POP3=$enableval],
395         [with_POP3=yes])
396 test "$with_POP3" = "yes" && AC_DEFINE(POP3_ENABLE,1,Define if you want POP3 support compiled in)
397 AM_CONDITIONAL(POP3_ENABLE, test "$with_POP3" = yes)
398
399 ###     use option --disable-IMAP to omit the IMAP support
400 AC_ARG_ENABLE(IMAP,
401         [  --disable-IMAP          don't compile in IMAP protocol support],
402         [with_IMAP=$enableval],
403         [with_IMAP=yes])
404 test "$with_IMAP" = "yes" && AC_DEFINE(IMAP_ENABLE,1,Define if you want IMAP support compiled in)
405 AM_CONDITIONAL(IMAP_ENABLE, test "$with_IMAP" = yes)
406
407 ###     use option --disable-ETRN to omit the ETRN support
408 AC_ARG_ENABLE(ETRN,
409         [  --disable-ETRN          don't compile in ETRN protocol support],
410         [with_ETRN=$enableval],
411         [with_ETRN=yes])
412 test "$with_ETRN" = "yes" && AC_DEFINE(ETRN_ENABLE,1,Define if you want ETRN support compiled in.)
413 AM_CONDITIONAL(ETRN_ENABLE, test "$with_ETRN" = yes)
414
415 ###     use option --disable-ODMR to omit the ODMR support
416 AC_ARG_ENABLE(ODMR,
417         [  --disable-ODMR          don't compile in ODMR protocol support],
418         [with_ODMR=$enableval],
419         [with_ODMR=yes])
420 test "$with_ODMR" = "yes" && AC_DEFINE(ODMR_ENABLE,1,Define if you want ODMR support compiled in)
421 AM_CONDITIONAL(ODMR_ENABLE, test "$with_ODMR" = yes)
422
423 ###     use option --enable-RPA to compile in the RPA support
424 AC_ARG_ENABLE(RPA,
425         [  --enable-RPA            compile in RPA protocol support],
426         [with_RPA=$enableval],
427         [with_RPA=no])
428 test "$with_RPA" = "yes" && AC_DEFINE(RPA_ENABLE,1,Define if you want RPA support compiled in)
429 AM_CONDITIONAL(RPA_ENABLE, test "$with_RPA" = yes)
430
431 ###     use option --enable-NTLM to compile in the NTLM support
432 AC_ARG_ENABLE(NTLM,
433         [  --enable-NTLM           compile in NTLM authentication support],
434         [with_NTLM=$enableval],
435         [with_NTLM=no])
436 test "$with_NTLM" = "yes" && AC_DEFINE(NTLM_ENABLE,1,Define if you want NTLM authentication)
437
438 ###     use option --enable-SDPS to compile in the SDPS support
439 AC_ARG_ENABLE(SDPS,
440         [  --enable-SDPS           compile in SDPS protocol support],
441         [with_SDPS=$enableval],
442         [with_SDPS=no])
443 if test "$with_SDPS" = yes ; then
444    if test "$with_POP3" != yes ; then
445        AC_MSG_WARN([SDPS cannot be enabled with POP3 disabled. Disabling SDPS.])
446        with_SDPS=no
447    else
448        AC_DEFINE(SDPS_ENABLE,1,Define if you want SDPS support compiled in)
449    fi
450 fi
451 if test "$with_POP3" != yes && test "$with_POP2" != yes \
452     && test "$with_IMAP"  != yes ; then
453     AC_MSG_ERROR([You must enable at least one of POP2, POP3 and IMAP.])
454 fi
455
456 AC_CACHE_SAVE
457
458 ###     use option --enable-opie to compile in the OPIE support
459 AC_ARG_ENABLE(opie,
460         [  --enable-opie           support OTP through the OPIE library],
461         [ AC_CHECK_HEADER(opie.h,, [AC_MSG_ERROR(cannot find <opie.h>, which is required for OPIE support.)])
462           AC_CHECK_LIB(opie,opiegenerator,, [AC_MSG_ERROR(cannot find libopie, which is required for OPIE support.)])
463           with_opie=$enableval],
464         [with_opie=no])
465 test "$with_opie" = "yes" && AC_DEFINE(OPIE_ENABLE,1,Define if you want OPIE support compiled in)
466
467 dnl Mostly stolen from gnulib's getaddrinfo.m4
468 AC_SEARCH_LIBS(getaddrinfo, [nsl socket])
469 AC_CACHE_CHECK([for getaddrinfo],[fm_cv_getaddrinfo],[
470   AC_TRY_LINK([
471 #include <sys/types.h>
472 #ifdef HAVE_SYS_SOCKET_H
473 #include <sys/socket.h>
474 #endif
475 #ifdef HAVE_NETDB_H
476 #include <netdb.h>
477 #endif
478   ], [getaddrinfo(0, 0, 0, 0);],
479     [ fm_cv_getaddrinfo=yes],
480     [ fm_cv_getaddrinfo=no ])
481 ])
482
483 if test x"$fm_cv_getaddrinfo" = "xyes"; then  
484      AC_DEFINE(HAVE_GETADDRINFO, 1,
485       [Define to 1 if you have the getaddrinfo function.])
486 fi
487
488 AC_CACHE_CHECK([for getnameinfo],[fm_cv_getnameinfo],[
489   AC_TRY_LINK([
490 #include <sys/types.h>
491 #ifdef HAVE_SYS_SOCKET_H
492 #include <sys/socket.h>
493 #endif
494 #ifdef HAVE_NETDB_H
495 #include <netdb.h>
496 #endif
497 #ifndef NULL
498 #define NULL ((void *)0)
499 #endif
500   ], [getnameinfo(NULL,0, NULL,0, NULL, 0, 0);],
501     [ fm_cv_getnameinfo=yes],
502     [ fm_cv_getnameinfo=no ])
503 ])
504 if test $fm_cv_getnameinfo = yes ; then
505     AC_DEFINE(HAVE_GETNAMEINFO,1,[Define to 1 if your system has getnameinfo()])
506 fi
507
508 AM_CONDITIONAL(NEED_GETADDRINFO, test "$fm_cv_getaddrinfo" != yes)
509 AM_CONDITIONAL(NEED_GETNAMEINFO, test "$fm_cv_getnameinfo"   != yes)
510
511 AC_CHECK_FUNCS(inet_ntop)
512 dnl Check if getaddrinfo is async-signal-safe - most implementations aren't
513 if test "$fm_cv_getaddrinfo" = yes ; then
514     AC_MSG_CHECKING(if your getaddrinfo is async-signal-safe)
515     gai_ts=no
516     dnl we have getaddrinfo() - check if the OS is known to have a async-signal-safe implementation
517     case $host_os in
518         darwin9*)                               gai_ts=yes ;;
519         linux*)                                 gai_ts=yes ;;
520         freebsd5.5|freebsd6*|freebsd7*)         gai_ts=yes ;;
521         solaris2.8|solaris2.9|solaris2.10)      gai_ts=yes ;;
522     esac
523     AC_MSG_RESULT($gai_ts)
524     if test $gai_ts = yes ; then
525         AC_DEFINE(GETADDRINFO_ASYNCSAFE, 1, [define to 1 if you know your getaddrinfo function is async-signal-safe])
526     fi
527 fi
528
529 # This version of the Kerberos 4 and 5 options addresses the follwing issues:
530
531 # * Build correctly under Heimdal kerberos if it is compiled with db2 and
532 #   OpenSSL support (Debian's is)
533 # * Build the kerberos.c stuff (KPOP) only for kerberosIV, to avoid breakage.
534 #   I don't know if this is 100% correct, but now at least IMAP and POP3
535 #   behave the same way regarding kerberosV.
536 # * Build without any fuss for both kerberosIV and V at the same time.
537 # * Move all the kerberos header mess to kerberos.h, and #include that
538 #   in driver.c and kerberos.c.
539
540 # Tested using the Heimdal Kerberos V libs, Kungliga Tekniska Högskolan (the
541 # Royal Institute of Technology in Stockholm, Sweden)'s kerberos IV libs, and
542 # the MIT reference implementation of KerberosV (all as packaged in Debian).
543
544 ###    use option --with-kerberos5=DIR to point at a Kerberos 5 directory
545 ### make sure --with-ssl is run before --with-kerberos* !
546 AC_ARG_WITH(kerberos5,
547        [  --with-kerberos5=DIR    point fetchmail compilation at a Kerberos 5 directory],
548 [
549 if test "$with_kerberos5" != "no"
550 then
551 # Check for a OpenBSD special case
552 if test "$with_kerberos5" = "yes" && ( test `uname` = "OpenBSD" )
553 then
554   AS_MESSAGE(checking kerberosV for OpenBSD...)
555   AC_DEFINE(HEIMDAL,1,Define if you have HEIMDAL kerberos 5)
556   AC_DEFINE(KERBEROS_V5,1,Define if you have Kerberos V5)
557   CFLAGS="$CFLAGS -I/usr/include/kerberosV"
558   LIBS="$LIBS -lasn1 -lkrb5 -lcom_err -lkafs"
559 elif krb5-config 2> /dev/null >/dev/null ; then
560   krb5_prefix=`krb5-config --prefix krb5`
561   AC_MSG_RESULT([krb5-config points to kerberosV under $krb5_prefix])
562   if test -f ${krb5_prefix}/include/et/com_err.h && \
563    ! test -f ${krb5_prefix}/include/com_err.h  ; then
564     CFLAGS="$CFLAGS -I${krb5_prefix}/include/et"
565   fi
566   unset krb5_prefix
567   CFLAGS="$CFLAGS `krb5-config --cflags krb5`"
568   LIBS="$LIBS `krb5-config --libs krb5`"
569   AC_DEFINE(KERBEROS_V5)
570 else
571   if test "$with_kerberos5" != "yes" 
572   then
573       LDFLAGS="$LDFLAGS -L${with_kerberos5}/lib"
574       searchdirs="$with_kerberos5"
575   else
576       searchdirs="/usr/kerberos /usr/local/krb5 /usr/athena /usr"
577   fi
578   with_kerberos5=
579   for dir in $searchdirs
580   do AC_MSG_CHECKING([for Kerberos V in $dir])
581      if test -f "$dir/include/krb5.h" || test -f "$dir/include/krb5/krb5.h"
582      then
583         if test -d "$dir/include/krb5" ; then CPPFLAGS="$CPPFLAGS -I$dir/include/krb5" ; fi
584         ac_krblibs=
585         if test -f "$dir/include/roken.h" || test -f "$dir/include/krb5/roken.h"
586         then
587            ac_krblibs="-lasn1 -lroken -lcom_err"
588            AC_MSG_RESULT([Heimdal found])
589           dnl Attempt to detect if we need to -ldb2 to link Heimdal
590           dnl we assume we do if it is available
591            AC_CHECK_LIB(db2, db_open, ac_krblibs="$ac_krblibs -ldb2", [],
592                 ${LDFLAGS})
593            AC_CHECK_LIB(des, des_string_to_key, libk5crypto=-ldes,
594               AC_CHECK_LIB(crypto, MD5_Init, [],
595                 AC_MSG_ERROR([DES libraries not found. Try adding --with-ssl to enable OpenSSL support]),
596                 ${LDFLAGS} ${ac_krblibs}),
597            ${LDFLAGS} ${ac_krblibs})
598            AC_DEFINE(HEIMDAL)
599         else
600           AC_MSG_RESULT([found])
601           ac_krblibs="-lcom_err"
602            AC_CHECK_LIB(crypto,
603              krb5_des_string_to_key,
604              libk5crypto=-lcrypto,
605                 AC_CHECK_LIB(k5crypto,
606                    krb5_des_string_to_key,
607                    libk5crypto=-lk5crypto,
608                       AC_MSG_ERROR([Kerberos 5 DES libraries not found]),
609                    ${LDFLAGS} ${ac_krblibs}),
610                  ${LDFLAGS} ${ac_krblibs})
611         fi
612         AC_CHECK_LIB(krb5, krb5_init_context,[],
613            continue,
614            ${LDFLAGS} ${ac_krblibs})
615         AC_DEFINE(KERBEROS_V5)
616         test "$dir" != "/usr" && CFLAGS="$CFLAGS -I$dir/include"
617         LDFLAGS="$LDFLAGS -L$dir/lib"
618        LIBS="$LIBS $ac_krblibs $libk5crypto"
619         with_kerberos5=$dir
620         break
621      else
622         AC_MSG_RESULT([not found])
623      fi
624   done
625   if test -z "$with_kerberos5" ; then
626      AC_MSG_ERROR([Kerberos 5 libraries not found])
627   fi
628 fi
629 fi
630 ]) dnl --with-kerberos5=DIR
631
632 ###    use option --with-kerberos=DIR to point at a Kerberos 4 directory
633 KERBEROS_V4=0
634 AC_ARG_WITH(kerberos,
635        [  --with-kerberos=DIR     point fetchmail compilation at a Kerberos 4 directory],
636 [
637 if test "$with_kerberos" != "no"
638 then
639     AC_MSG_WARN([Kerberos IV support is obsolete. Use --with-kerberos5 if possible.])
640 # Check for a NetBSD/OpenBSD special case
641 if test "$with_kerberos" = "yes" && ( test `uname` = "NetBSD" || test `uname` = "OpenBSD" )
642 then
643   AS_MESSAGE(checking kerberosIV for `uname`...)
644   KERBEROS_V4=1
645   CFLAGS="$CFLAGS -I/usr/include/kerberosIV"
646   case `uname` in
647       NetBSD)  LIBS="$LIBS -lkrb -ldes -lroken -lcom_err" ;;
648       OpenBSD) LIBS="$LIBS -lkrb -ldes" ;;
649   esac
650 elif krb4-config 2> /dev/null >/dev/null ; then
651   krb4_prefix=`krb4-config --prefix`
652   AC_MSG_RESULT([krb4-config points to kerberosIV under $krb4_prefix])
653   unset krb4_prefix
654   CFLAGS="$CFLAGS `krb4-config --cflags`"
655   LIBS="$LIBS `krb4-config --libs`"
656   KERBEROS_V4=1
657 elif krb5-config 2> /dev/null >/dev/null ; then
658   krb4_prefix=`krb5-config --prefix krb4`
659   AC_MSG_RESULT([krb5-config points to kerberosIV under $krb4_prefix])
660   if test -f ${krb4_prefix}/include/kerberosIV/krb.h ; then
661     AC_DEFINE(KERBEROS_V4_V5,1,Define if you have Kerberos V4 headers under a kerberosIV directory)
662   fi
663   unset krb4_prefix
664   CFLAGS="$CFLAGS `krb5-config --cflags krb4`"
665   LIBS="$LIBS `krb5-config --libs krb4`"
666   KERBEROS_V4=1
667 else
668   #we need to detect when we're building under a kerberosV compatibility
669   #layer, btw...
670   if test "$with_kerberos" != "yes" ; then
671      searchdirs="$with_kerberos"
672   else
673      searchdirs="$with_kerberos5 /usr/kerberos /usr/kerberosIV /usr/athena /usr"
674   fi
675   with_kerberos=
676   ac_saveLDFLAGS="$LDFLAGS"
677   for dir in $searchdirs
678   do
679      AC_MSG_CHECKING([for Kerberos IV in $dir])
680      if test -f "$dir/include/krb.h" || test -f "$dir/include/krb4.h" \
681             || test -f "$dir/include/kerberosIV/krb.h"
682      then
683         AC_MSG_RESULT([found])
684      else
685         AC_MSG_RESULT([not found])
686        continue
687      fi
688      #Find libs
689      if test -f "$with_kerberos5/roken.h" ; then
690        AC_CHECK_LIB(45, krb_mk_req)
691      fi
692      LDFLAGS="-L$dir/lib $ac_saveLDFLAGS"
693      if test `uname` = "FreeBSD"; then
694         AC_SEARCH_LIBS(_ossl_old_des_string_to_key, [des425 des crypto], [], continue)
695      else
696         AC_SEARCH_LIBS(des_string_to_key, [crypto], [], continue)
697      fi
698      AC_SEARCH_LIBS(krb_realmofhost, [krb4 krb], [], continue)
699      with_kerberos="$dir"
700      if test -f "$dir/include/kerberosIV/krb.h" ; then
701         dir="$dir/include/kerberosIV"
702      else
703        dir="$dir/include"
704      fi
705      KERBEROS_V4=1
706      test -f "$with_kerberos5/roken.h" && AC_DEFINE(HEIMDAL)
707      test "$dir" != "/usr/include" && CFLAGS="$CFLAGS -I$dir"
708      LDFLAGS="$LDFLAGS -L$with_kerberos/lib"
709      break
710   done
711   if test -z "$with_kerberos" ; then
712      AC_MSG_ERROR([Kerberos 4 libraries not found])
713   fi
714   LDFLAGS="$ac_saveLDFLAGS"
715 fi
716 fi
717 ]) dnl --with-kerberos=DIR
718 if test "$KERBEROS_V4" = 1 ; then
719     AC_DEFINE(KERBEROS_V4,1,Define if you have Kerberos V4)
720 fi
721 AM_CONDITIONAL(KERBEROS_V4_ENABLE, test "$KERBEROS_V4" = 1)
722
723 ###     use option --with-ssl to compile in the SSL support
724 AC_ARG_WITH(ssl,
725         [  --with-ssl=[DIR]        enable SSL support using libraries in DIR],
726         [with_ssl=$withval],
727         [with_ssl=no])
728 test "$with_ssl" != "no" && AC_DEFINE(SSL_ENABLE,1,Define if you want SSL support compiled in)
729
730 if test "$with_ssl" = "yes"
731 then
732     #   User didn't specify an SSL location.  Let's look at some common
733     #   directories where SSL has been found in the past and try and auto
734     #   configure for SSL.  OpenSSL determination will be made later.
735     #   This will screw up if an OpenSSL install is located in a later
736     #   directory than an older SSLeay install, but the user should fix that
737     #   anyways and he can override on the configure line.
738     #   Just testing for directories is not sufficient, /usr exists on
739     #   all systems!
740     for ac_dir in \
741       /usr/local/ssl \
742       /usr/local \
743       /usr/ssl \
744       /usr \
745       /local/ssl \
746       /opt/ssl \
747       /opt/csw \
748       ; \
749     do
750         if test -r "$ac_dir/include/openssl/ssl.h" ; then
751             with_ssl=$ac_dir
752             break;
753         fi
754     done
755 fi
756
757 if test -n "$with_ssl" -a "$with_ssl" != "no"
758 then
759   # With the autoconfigure above, the only time this is going to be
760   # true is going to be when we could not find the headers.  If they
761   # are not in system standard locations, we are going to be broken.
762   if test "$with_ssl" = "yes"
763   then
764     # Let's just define the standard location for the SSLeay root
765     with_ssl="/usr/local/ssl"
766   fi
767   if test -r $with_ssl/include/openssl/ssl.h
768   then
769     ### ssl.h found under openssl.  Use openssl configuration preferentially,
770     AC_MSG_NOTICE(Enabling OpenSSL support in $with_ssl.)
771     test "$with_ssl" != "/usr" && CFLAGS="$CFLAGS -I$with_ssl/include"
772     ### In Red Hat 9, this file includes a reference to <krb5.h>, so we
773     ### force the Kerberos direcory onto the include path so it will build.
774     CFLAGS="$CFLAGS -I/usr/kerberos/include"
775     ### OpenBSD comes with ssl headers
776   else
777     AC_MSG_ERROR([SSL support enabled, but OpenSSL not found])
778   fi
779   LDFLAGS="$LDFLAGS -L$with_ssl/lib"
780   LIBS="$LIBS -lssl -lcrypto"
781   dnl check if -ldl is needed
782   AC_MSG_CHECKING([for additional library dependencies of SSL])
783   found=0
784   save_LIBS="$LIBS"
785   for i in "" "-ldl" ; do
786       LIBS="$LDFLAGS $save_LIBS $i"
787       AC_LINK_IFELSE([AC_LANG_PROGRAM(,[SSL_library_init()])],[found=1; break])
788   done
789   if test $found = 0 ; then
790       AC_MSG_RESULT([error])
791       AC_MSG_ERROR([cannot link with SSL - check config.log])
792   fi
793   LIBS="$save_LIBS $i"
794   if test "$i" = "" ; then i="(none)" ; fi
795   AC_MSG_RESULT($i)
796   dnl XXX FIXME: use pkg-config if available!
797   AC_DEFINE(SSL_ENABLE)
798 else
799   AC_MSG_NOTICE(Disabling SSL support.)
800 fi
801
802 ###     use option --with-socks=DIR to point at SOCKS library
803 AC_ARG_WITH(socks,
804         [  --with-socks[=DIR]      add built-in SOCKS firewall access],
805 [
806 if test "$with_socks" != no
807 then
808     if test "$with_socks" != yes
809     then
810         LDFLAGS="$LDFLAGS -L$with_socks"
811     else
812         AC_CHECK_LIB(socks, Rconnect,,
813                AC_MSG_ERROR([could not find libsocks which is needed for built-in SOCKS support]))
814     fi
815     AC_DEFINE(HAVE_SOCKS,1,Define if you want built-in SOCKS support)
816     CFLAGS="$CFLAGS -Dconnect=Rconnect -Dgetsockname=Rgetsockname -Dbind=Rbind -Daccept=Raccept -Dlisten=Rlisten -Dselect=Rselect"
817     LIBS="-lsocks $LIBS"
818 fi])
819
820 ###     use option --with-socks5=DIR to point at SOCKS library
821 AC_ARG_WITH(socks5,
822         [  --with-socks5[=DIR]     add built-in SOCKS5 firewall access],
823 [
824 if test "$with_socks5" != no
825 then
826   if test "$with_socks5" != yes
827   then
828     LDFLAGS="$LDFLAGS -L$with_socks5"
829   fi
830   ac_savedLDFLAGS="$LDFLAGS"
831   LDFLAGS="$LDFLAGS $LDFLAGS"
832   AC_CHECK_LIB(socks5, SOCKSconnect,,
833         AC_MSG_ERROR([could not find libsocks5 which is needed for built-in SOCKS5 support]))
834   AC_DEFINE(HAVE_SOCKS)
835   CFLAGS="$CFLAGS -Dconnect=SOCKSconnect -Dgetsockname=SOCKSgetsockname -Dbind=SOCKSbind -Daccept=SOCKSaccept -Dlisten=SOCKSlisten -Dselect=SOCKSselect -Drecvfrom=SOCKSrecvfrom -Dsendto=SOCKSsendto -Drecv=SOCKSrecv -Dsend=SOCKSsend -Dread=SOCKSread -Dwrite=SOCKSwrite -Drresvport=SOCKSrresvport -Dshutdown=SOCKSshutdown -Dlisten=SOCKSlisten -Dclose=SOCKSclose -Ddup=SOCKSdup -Ddup2=SOCKSdup2 -Dgethostbyname=SOCKSgethostbyname"
836   AC_CHECK_FUNC(SOCKSfclose, [CFLAGS="$CFLAGS -Dfclose=SOCKSfclose"])
837   LDFLAGS="$ac_savedLDFLAGS"
838 fi])
839
840 ACX_WHICH_GETHOSTBYNAME_R
841
842 ###     use option --with-hesiod=DIR to point at a HESIOD directory
843 AC_ma_SEARCH_PACKAGE(hesiod, hesiod_getmailhost, /usr/athena /usr /usr/local,hesiod, hesiod.h)
844
845 ###     use option --with-gssapi=DIR to compile in GSSAPI support
846 AC_ARG_WITH(gssapi,
847         [  --with-gssapi[=DIR]     compile in GSSAPI support using libraries in DIR],
848 [
849 if test "$with_gssapi" != "no"
850 then
851   if test "$with_gssapi" = "yes" -a -n "$with_kerberos5"
852   then
853     with_gssapi=$with_kerberos5
854   fi
855
856   if test "$with_gssapi" != "yes" -a -n "$with_gssapi"
857   then
858     CFLAGS="$CFLAGS -I$with_gssapi/include"
859     LDFLAGS="$LDFLAGS -L$with_gssapi/lib"
860   fi
861
862   dnl obtain gssapi default libs
863   if krb5-config --libs gssapi 2>/dev/null >/dev/null ; then
864       LIBS="$LIBS `krb5-config --libs gssapi`"
865   else
866     AC_CHECK_LIB(gss, gss_check_version, LIBS="$LIBS -lgss", nogss=t)
867     if test -n "$nogss"
868     then
869       # -lgss not found
870       if test "$with_gssapi" = yes ; then
871           with_gssapi=/usr
872       fi
873       if test -f "$with_gssapi/include/roken.h" -o -f "$with_gssapi/include/krb5/roken.h"
874       then
875          # have roken.h, assume Heimdal
876          case `uname` in
877              NetBSD) LIBS="$LIBS -lkrb5" ;;
878              *)      LIBS="$LIBS -lkrb5 -lasn1 -ldes -lroken -ldb -ldl" ;;
879          esac
880          AC_CHECK_LIB(gssapi, gss_init_sec_context,LIBS="$LIBS -lgssapi",
881                       AC_MSG_ERROR([could not find libgssapi which is needed for GSSAPI support]), )
882          AC_DEFINE(HEIMDAL)
883       else
884          # no roken.h, assume MIT
885          AC_CHECK_LIB(gssapi_krb5, gss_init_sec_context,LIBS="$LIBS -lgssapi_krb5",
886                       AC_MSG_ERROR([could not find libgssapi_krb5 which is needed for GSSAPI support]), -lkrb5)
887       fi
888     fi
889   fi
890   AC_DEFINE(GSSAPI,1,Define if you want GSSAPI authentication)
891   if test "$with_gssapi" != yes ; then
892     CPPFLAGS="$CPPFLAGS -I$with_gssapi/include"
893   fi
894   AC_CHECK_HEADERS(gss.h gssapi.h gssapi/gssapi.h gssapi/gssapi_generic.h)
895   if test "$ac_cv_header_gssapi_h" = "yes"; then
896     AC_EGREP_HEADER(GSS_C_NT_HOSTBASED_SERVICE, gssapi.h, AC_DEFINE(HAVE_GSS_C_NT_HOSTBASED_SERVICE,1,Define if you have MIT kerberos))
897   else
898     AC_EGREP_HEADER(GSS_C_NT_HOSTBASED_SERVICE, gssapi/gssapi.h, AC_DEFINE(HAVE_GSS_C_NT_HOSTBASED_SERVICE))
899   fi
900 fi])
901
902 dnl ,------------------------------------------------------------------
903 dnl Check if we need TRIO
904 needtrio=0
905 if test "$FORCE_TRIO" = "yes" ; then
906     needtrio=1
907     ac_cv_func_vsnprintf=no
908     ac_cv_func_snprintf=no
909 fi
910 if test "x$ac_cv_func_snprintf" != "xyes" ; then
911     AC_DEFINE(snprintf, trio_snprintf,
912               [Define to trio_snprintf if your system lacks snprintf])
913     needtrio=1
914 fi
915 if test "x$ac_cv_func_vsnprintf" != "xyes" ; then
916     AC_DEFINE(vsnprintf, trio_vsnprintf,
917               [Define to trio_vsnprintf if your system lacks vsnprintf])
918     needtrio=1
919 fi
920 AM_CONDITIONAL(NEED_TRIO, test "$needtrio" = 1)
921
922 dnl TRIO IEEE compiler option for Alpha
923 dnl
924 if test "$needtrio" = 1 ; then
925     AC_MSG_CHECKING(for IEEE compilation options)
926     AC_CACHE_VAL(ac_cv_ieee_option, [
927     AC_TRY_COMPILE(,[
928     #if !(defined(__alpha) && (defined(__DECC) || defined(__DECCXX) || (defined(__osf__) && defined(__LANGUAGE_C__))) && (defined(VMS) || defined(__VMS)))
929     # error "Option needed"
930     #endif
931     ],ac_cv_ieee_option="/IEEE_MODE=UNDERFLOW_TO_ZERO/FLOAT=IEEE",
932     AC_TRY_COMPILE(,[
933     #if !(defined(__alpha) && (defined(__DECC) || defined(__DECCXX) || (defined(__osf__) && defined(__LANGUAGE_C__))) && !(defined(VMS) || defined(__VMS)) && !defined(_CFE))
934     # error "Option needed"
935     #endif
936     ],ac_cv_ieee_option="-ieee",
937     AC_TRY_COMPILE(,[
938     #if !(defined(__alpha) && (defined(__GNUC__) && (defined(__osf__) || defined(__linux__))))
939     # error "Option needed"
940     #endif
941     ],ac_cv_ieee_option="-mieee",
942     ac_cv_ieee_option="none"
943     )
944     )
945     )
946     ])
947     AC_MSG_RESULT($ac_cv_ieee_option)
948     if test $ac_cv_ieee_option != none; then
949       CFLAGS="${CFLAGS} ${ac_cv_ieee_option}"
950     fi
951 fi
952 dnl ----------------------------------------------------------------'
953
954 AC_CONFIG_FILES([Makefile po/Makefile.in genlsm.sh])
955 AC_OUTPUT
956
957 dnl Local Variables:
958 dnl comment-start: "dnl "
959 dnl comment-end: ""
960 dnl comment-start-skip: "\\bdnl\\b\\s *"
961 dnl compile-command: "make configure config.h.in"
962 dnl End: