chiark / gitweb /
wip compile
[inn-innduct.git] / configure.in
1 dnl Process this file with autoconf to produce a configure script.
2 dnl $Id: configure.in 7811 2008-04-30 07:06:58Z iulius $
3 dnl
4 dnl Please try to follow GNU conventions and autoconf manual conventions as
5 dnl much as possible in this file so that any macros we develop can be easily
6 dnl contributed to the macro archive and possibly rolled into future versions
7 dnl of autoconf so that we can stop supporting them.  This means, for example,
8 dnl that code excerpts should probably follow the GNU coding standards rather
9 dnl than INN's.
10 dnl
11 dnl The macro archive is at <http://www.gnu.org/software/ac-archive/>.  Due to
12 dnl the submission format and significant changes to autoconf's internal
13 dnl architecture and building-block macros, I'm waiting until INN is switched
14 dnl to autoconf 2.52 or later and we can convert this file into a bunch of
15 dnl separate files before submitting macros to that archive.
16 dnl
17 dnl If a check is any way non-trivial, please package it up in a macro with
18 dnl AC_DEFUN.  This will allow us to easily break up this (far too long) file
19 dnl into a directory full of .m4 files for particular checks once we switch to
20 dnl autoconf 2.52 or later.  Please also put any long code blocks into a
21 dnl separate macro rather than in-line in the test macro; this will make
22 dnl quoting issues much easier.  See the existing tests for details on how to
23 dnl do this.
24 dnl
25 dnl Try to do as much with AC_DEFINE and as little with AC_SUBST as is
26 dnl reasonable; obviously, makefile things like library paths and so forth and
27 dnl paths to programs have to use AC_SUBST, but any compile-time parameters
28 dnl are easier to handle with AC_DEFINE.  (And AC_SUBST is slower.)
29 dnl
30 dnl And remember:  If you don't have any alternative available if your check
31 dnl for something fails, and there's no purpose served in aborting configure
32 dnl instead of the compile if what you're checking for is missing, don't
33 dnl bother checking for it.  Compile-time errors often produce a lot more
34 dnl useful information for someone debugging a problem than configure-time
35 dnl errors.
36
37 AC_REVISION($Revision: 7811 $)dnl
38 AC_PREREQ(2.13)
39 AC_INIT(Makefile.global.in)
40 AC_CONFIG_AUX_DIR(support)
41 AC_PREFIX_DEFAULT(/usr/local/news)
42
43 dnl Make sure $prefix is set so that we can use it internally.
44 test x"$prefix" = xNONE && prefix="$ac_default_prefix"
45
46 dnl Linking against in-tree libraries need to know the current directory (the
47 dnl top of the build directory, not the source directory).
48 builddir=`pwd`
49 AC_SUBST(builddir)
50
51 dnl Earlier versions of INN used --with-largefiles, which was the wrong flag
52 dnl from the perspective of what --with and --enable are supposed to mean.
53 dnl Catch the old usage and error out.
54 if test x"$with_largefiles" != x ; then
55     AC_MSG_ERROR([Use --enable-largefiles instead of --with-largefiles])
56 fi
57
58 dnl Used to check whether -o can be provided with -c with the chosen
59 dnl compiler.  We need this if we're not using libtool so that object files
60 dnl can be built in subdirectories.  This macro is stolen shamelessly from
61 dnl the libtool macros; there's a better version in Autoconf that we should
62 dnl eventually use that tests twice.
63 AC_DEFUN([INN_PROG_CC_C_O],
64 [AC_REQUIRE([AC_OBJEXT])
65 AC_MSG_CHECKING([if $CC supports -c -o file.$ac_objext])
66 AC_CACHE_VAL([inn_cv_compiler_c_o],
67 [rm -f -r conftest 2>/dev/null
68 mkdir conftest
69 cd conftest
70 echo "int some_variable = 0;" > conftest.$ac_ext
71 mkdir out
72 # According to Tom Tromey, Ian Lance Taylor reported there are C compilers
73 # that will create temporary files in the current directory regardless of
74 # the output directory.  Thus, making CWD read-only will cause this test
75 # to fail, enabling locking or at least warning the user not to do parallel
76 # builds.
77 chmod -w .
78 save_CFLAGS="$CFLAGS"
79 CFLAGS="$CFLAGS -o out/conftest2.$ac_objext"
80 compiler_c_o=no
81 if { (eval $ac_compile) 2> out/conftest.err; } \
82     && test -s out/conftest2.$ac_objext; then
83   # The compiler can only warn and ignore the option if not recognized
84   # So say no if there are warnings
85   if test -s out/conftest.err; then
86     inn_cv_compiler_c_o=no
87   else
88     inn_cv_compiler_c_o=yes
89   fi
90 else
91   # Append any errors to the config.log.
92   cat out/conftest.err 1>&AC_FD_CC
93   inn_cv_compiler_c_o=no
94 fi
95 CFLAGS="$save_CFLAGS"
96 chmod u+w .
97 rm -f conftest* out/*
98 rmdir out
99 cd ..
100 rmdir conftest
101 rm -f -r conftest 2>/dev/null])
102 compiler_c_o=$inn_cv_compiler_c_o
103 AC_MSG_RESULT([$compiler_c_o])])
104
105 dnl A few tests need to happen before any of the libtool tests in order to
106 dnl avoid error messages.  We therefore lift them up to the top of the file.
107 AC_PROG_CC
108 AC_AIX
109 AC_ISC_POSIX
110 INN_PROG_CC_C_O
111
112 dnl Check to see if the user wants to use libtool.  We only invoke the libtool
113 dnl setup macros if they do.  Keep this call together with the libtool setup
114 dnl so that the arguments to configure will be together in configure --help.
115 inn_use_libtool=no
116 AC_ARG_ENABLE(libtool,
117     [  --enable-libtool        Use libtool for lib generation [default=no]],
118     if test "$enableval" = yes ; then
119         inn_use_libtool=yes
120     fi)
121 if test x"$inn_use_libtool" = xyes ; then
122     AC_PROG_LIBTOOL
123     EXTLIB='la'
124     EXTOBJ='lo'
125     LIBTOOL='$(top)/libtool'
126     LIBTOOLCC='$(top)/libtool --mode=compile'
127     LIBTOOLLD='$(top)/libtool --mode=link'
128     CCOUTPUT='-c -o $@ $<'
129 else
130     AC_CANONICAL_HOST
131     EXTLIB='a'
132     EXTOBJ='o'
133     LIBTOOL=''
134     LIBTOOLCC=''
135     LIBTOOLLD=''
136     if test x"$compiler_c_o" = xyes ; then
137         CCOUTPUT='-c -o $@ $<'
138     else
139         CCOUTPUT='-c $< && if test x"$(@F)" != x"$@" ; then mv $(@F) $@ ; fi'
140     fi
141     AC_SUBST(LIBTOOL)
142 fi
143 AC_SUBST(EXTLIB)
144 AC_SUBST(EXTOBJ)
145 AC_SUBST(LIBTOOLCC)
146 AC_SUBST(LIBTOOLLD)
147 AC_SUBST(CCOUTPUT)
148
149 dnl INN has quite a few more configurable paths than autoconf supports by
150 dnl default.  For right now, those additional paths are configured with
151 dnl --with-*-dir options.  This is the generic macro for those arguments; it
152 dnl takes the name of the directory, the path relative to $prefix if none
153 dnl given to configure, the variable to set, and the help string.
154 AC_DEFUN([INN_ARG_DIR],
155 [AC_ARG_WITH([$1-dir], [$4], [$3=$with_$1_dir], [$3=$prefix/$2])
156 AC_SUBST($3)])
157
158 dnl And here are all the paths.
159 dnl
160 dnl FIXME: We should honor bindir, libdir, includedir, and mandir at the
161 dnl least, and we should use libdir over --with-lib-dir.
162 INN_ARG_DIR(control, bin/control, CONTROLDIR,
163     [  --with-control-dir=PATH Path for control programs [PREFIX/bin/control]])
164 INN_ARG_DIR(db, db, DBDIR,
165     [  --with-db-dir=PATH      Path for news database files [PREFIX/db]])
166 INN_ARG_DIR(doc, doc, DOCDIR,
167     [  --with-doc-dir=PATH     Path for news documentation [PREFIX/doc]])
168 INN_ARG_DIR(etc, etc, ETCDIR,
169     [  --with-etc-dir=PATH     Path for news config files [PREFIX/etc]])
170 INN_ARG_DIR(filter, bin/filter, FILTERDIR,
171     [  --with-filter-dir=PATH  Path for embedded filters [PREFIX/bin/filter]])
172 INN_ARG_DIR(lib, lib, LIBDIR,
173     [  --with-lib-dir=PATH     Path for news library files [PREFIX/lib]])
174 INN_ARG_DIR(log, log, LOGDIR,
175     [  --with-log-dir=PATH     Path for news logs [PREFIX/log]])
176 INN_ARG_DIR(run, run, RUNDIR,
177     [  --with-run-dir=PATH     Path for news PID/runtime files [PREFIX/run]])
178 INN_ARG_DIR(spool, spool, SPOOLDIR,
179     [  --with-spool-dir=PATH   Path for news storage [PREFIX/spool]])
180 INN_ARG_DIR(tmp, tmp, tmpdir,
181     [  --with-tmp-dir=PATH     Path for temporary files [PREFIX/tmp]])
182
183 dnl This is actually given to AC_SUBST later on when we check whether the
184 dnl system has the LOG_NEWS facility.
185 AC_ARG_WITH(syslog-facility,
186 [  --with-syslog-facility=LOG_FAC  Syslog facility [LOG_NEWS or LOG_LOCAL1]],
187     SYSLOG_FACILITY=$with_syslog_facility,
188     SYSLOG_FACILITY=none)
189
190 dnl INN allows the user and group INN will run as to be specified, as well as
191 dnl the user to receive nightly reports and the like.  These are all fairly
192 dnl similar, so factor the commonality into this macro.  Takes the name of
193 dnl what we're looking for, the default, the variable to set, the help string,
194 dnl and the comment for config.h.
195 AC_DEFUN([INN_ARG_USER],
196 [AC_ARG_WITH([news-$1], [$4], [$3=$with_news_$1], [$3=$2])
197 AC_SUBST($3)
198 AC_DEFINE_UNQUOTED($3, "$[$3]", [$5])])
199
200 dnl And here they are.
201 INN_ARG_USER(user, news, NEWSUSER,
202     [  --with-news-user=USER   News user name [news]],
203     [The user that INN should run as.])
204 INN_ARG_USER(group, news, NEWSGRP,
205     [  --with-news-group=GROUP News group name [news]],
206     [The group that INN should run as.])
207 INN_ARG_USER(master, usenet, NEWSMASTER,
208     [  --with-news-master=USER News master (address for reports) [usenet]],
209     [The user who gets all INN-related e-mail.])
210
211 dnl INN defaults to a umask of 002 with the corresponding directory and file
212 dnl permissions, mostly for historical reasons.  If the user sets the umask to
213 dnl something else, change all of the permissions.
214 NEWSUMASK=02
215 FILEMODE=0664
216 DIRMODE=0775
217 RUNDIRMODE=0770
218 AC_ARG_WITH(news-umask,
219     [  --with-news-umask=UMASK umask for news files [002]],
220     with_news_umask=`echo "$with_news_umask" | sed 's/^0*//'`
221     if test "x$with_news_umask" = x22 ; then
222         NEWSUMASK=022
223         FILEMODE=0644
224         DIRMODE=0755
225         RUNDIRMODE=0750
226     else
227         if test "x$with_news_umask" != x2 ; then
228             AC_MSG_ERROR(Valid umasks are 02 or 022)
229         fi
230     fi)
231 AC_SUBST(NEWSUMASK)
232 AC_SUBST(FILEMODE)
233 AC_SUBST(DIRMODE)
234 AC_SUBST(RUNDIRMODE)
235 AC_DEFINE_UNQUOTED(ARTFILE_MODE, $FILEMODE,
236     [Mode that incoming articles are created with.])
237 AC_DEFINE_UNQUOTED(BATCHFILE_MODE, $FILEMODE,
238     [Mode that batch files are created with.])
239 AC_DEFINE_UNQUOTED(GROUPDIR_MODE, $DIRMODE,
240     [Mode that directories are created with.])
241 AC_DEFINE_UNQUOTED(NEWSUMASK, $NEWSUMASK,
242     [The umask used by all INN programs.])
243
244 dnl inews used to be installed setgid, but may not be secure.  Only do this if
245 dnl it's explicitly requested at configure time.
246 INEWSMODE=0550
247 AC_ARG_ENABLE(setgid-inews,
248     [  --enable-setgid-inews   Install inews setgid],
249     if test "x$enableval" = xyes ; then
250         INEWSMODE=02555
251     fi)
252 AC_SUBST(INEWSMODE)
253
254 dnl rnews used to be installed setuid root so that it could be run by the uucp
255 dnl user for incoming batches, but this isn't necessary unless you're using
256 dnl UUCP (which most people aren't) and only setuid news is required.  Only do
257 dnl this if it's explicitly requested at configure time.
258 RNEWSGRP=$NEWSGRP
259 RNEWSMODE=0500
260 AC_ARG_ENABLE(uucp-rnews,
261     [  --enable-uucp-rnews     Install rnews setuid, group uucp],
262     if test "x$enableval" = xyes ; then
263         RNEWSGRP=uucp
264         RNEWSMODE=04550
265     fi)
266 AC_SUBST(RNEWSGRP)
267 AC_SUBST(RNEWSMODE)
268
269 dnl Choose the log compression method; the argument should not be a full path,
270 dnl just the name of the compression type.
271 AC_ARG_WITH(log-compress,
272     [  --with-log-compress=METHOD   Log compression method [gzip]],
273     LOG_COMPRESS=$with_log_compress,
274     LOG_COMPRESS=gzip)
275 case "$LOG_COMPRESS" in
276 bzip2) LOG_COMPRESSEXT=".bz2" ;;
277 gzip)  LOG_COMPRESSEXT=".gz"  ;;
278 *)     LOG_COMPRESSEXT=".Z"   ;;
279 esac
280 AC_SUBST(LOG_COMPRESS)
281 AC_SUBST(LOG_COMPRESSEXT)
282
283 dnl inndstart by default only allows ports 119 and 433 below 1024; if the user
284 dnl wants to use some other port as well, they must use this option.
285 AC_ARG_WITH(innd-port,
286     [  --with-innd-port=PORT   Additional low-numbered port for inndstart],
287     AC_DEFINE_UNQUOTED(INND_PORT, $with_innd_port,
288                        [Additional valid low-numbered port for inndstart.]))
289
290 dnl By default, we omit all IPv6 support.  This option enables it.
291 AC_ARG_ENABLE(ipv6,
292     [  --enable-ipv6           Enable IPv6 support],
293     if test "x$enableval" = xyes ; then
294         inn_enable_ipv6_tests=yes
295         AC_DEFINE(HAVE_INET6, 1, [Define to enable IPv6 support.])
296     fi)
297
298 dnl Maximum number of sockets that can be listened on.
299 AC_ARG_WITH(max-sockets,
300     [  --with-max-sockets=N    Maximum number of listening sockets in innd],,
301     [with_max_sockets=15])
302 AC_DEFINE_UNQUOTED(MAX_SOCKETS, $with_max_sockets,
303                [Maximum number of sockets that innd can listen on.])
304
305 dnl This will eventually be a runtime option rather than a compile-time
306 dnl option.
307 AC_ARG_ENABLE(tagged-hash,
308     [  --enable-tagged-hash    Use tagged hash table for history],
309     if test "x$enableval" = xyes ; then
310         DO_DBZ_TAGGED_HASH=DO
311         AC_DEFINE(DO_TAGGED_HASH, 1,
312                   [Define to use tagged hash for the history file.])
313     else
314         DO_DBZ_TAGGED_HASH=DONT
315     fi)
316 AC_SUBST(DO_DBZ_TAGGED_HASH)
317
318 dnl Whether to enable the keyword generation code in innd.  Use of this code
319 dnl requires a regular expression library, which is checked for later on.
320 inn_enable_keywords=0
321 AC_ARG_ENABLE(keywords,
322     [  --enable-keywords       Automatic keyword generation support],
323     if test x"$enableval" = xyes ; then
324         inn_enable_keywords=1
325     fi)
326 AC_DEFINE_UNQUOTED(DO_KEYWORDS, $inn_enable_keywords,
327     [Define to 1 to compile in support for keyword generation code.])
328
329 dnl Whether to use the OS flags to enable large file support.  Ideally this
330 dnl should just always be turned on if possible and the various parts of INN
331 dnl that read off_t's from disk should adjust somehow to the size, but INN
332 dnl isn't there yet.  Currently tagged hash doesn't work with large file
333 dnl support due to assumptions about the size of off_t.
334 AC_ARG_ENABLE(largefiles,
335     [  --enable-largefiles     Support for files larger than 2GB [default=no]],
336     [case "${enableval}" in
337     yes) inn_enable_largefiles=yes
338          if test x"$DO_DBZ_TAGGED_HASH" = xDO ; then
339 AC_MSG_ERROR([--enable-tagged-hash conflicts with --enable-largefiles.])
340          fi ;;
341     no)  inn_enable_largefiles=no ;;
342     *)   AC_MSG_ERROR(invalid argument to --enable-largefiles) ;;
343     esac])
344
345 dnl Override the automatically detected path to sendmail.  Used later on.
346 AC_ARG_WITH(sendmail,
347     [  --with-sendmail=PATH    Path to sendmail],
348     SENDMAIL=$with_sendmail)
349
350 dnl Specify the path to the Kerberos libraries if the user wants to build
351 dnl auth_krb5.  Note that we don't search far and wide for the libraries if
352 dnl the user doesn't specify the path.
353 AC_ARG_WITH(kerberos,
354     [  --with-kerberos=PATH    Path to Kerberos v5 (for auth_krb5)],
355     [if test x"$with_kerberos" != xno ; then
356          KRB5_LDFLAGS="-L$with_kerberos/lib"
357          KRB5_INC="-I$with_kerberos/include"
358      fi])
359
360 dnl Checks for embedded interpretors.
361 dnl
362 dnl FIXME: These should ideally be combined with the later logic to
363 dnl determine the version, determine the compiler and linker flags, etc.
364 AC_ARG_WITH(perl,
365     [  --with-perl             Embedded Perl script support [default=no]],
366     [case "${withval}" in
367     yes) DO_PERL=DO
368          AC_DEFINE(DO_PERL, 1, [Define to compile in Perl script support.])
369          ;;
370     no)  DO_PERL=DONT ;;
371     *)   AC_MSG_ERROR(invalid argument to --with-perl) ;;
372     esac],
373     DO_PERL=DONT)
374
375 AC_ARG_WITH(python,
376     [  --with-python           Embedded Python module support [default=no]],
377     [case "${withval}" in
378     yes) DO_PYTHON=define
379          AC_DEFINE(DO_PYTHON, 1,
380                    [Define to compile in Python module support.])
381          ;;
382     no)  DO_PYTHON=DONT ;;
383     *)   AC_MSG_ERROR(invalid argument to --with-python) ;;
384     esac],
385     DO_PYTHON=DONT)
386
387 dnl Set some configuration file defaults from the machine hostname.
388 HOSTNAME=`hostname 2> /dev/null || uname -n`
389 AC_SUBST(HOSTNAME)
390
391 dnl Checks for programs.
392 AC_PROG_GCC_TRADITIONAL
393 AC_PROG_LEX
394 AC_PROG_MAKE_SET
395 AC_PROG_RANLIB
396 AC_PROG_YACC
397
398 dnl On MacOS X Server, -traditional-cpp is needed for gcc for compiling as
399 dnl well as preprocessing according to Miro Jurisic <meeroh@meeroh.org>.
400 case "$CPP" in
401 *-traditional-cpp*)
402     CFLAGS="-traditional-cpp $CFLAGS"
403     ;;
404 esac
405
406 case "$host" in
407
408 dnl HP-UX's native compiler needs a special flag to turn on ANSI, and needs
409 dnl -g on link as well as compile for debugging to work.
410 *hpux*)
411     if test x"$GCC" != xyes ; then
412         dnl Need flag to turn on ANSI.
413         CFLAGS="$CFLAGS -Ae"
414
415         dnl Need -g on link command for debug to work properly.
416         case "$CFLAGS" in
417         *-g*)
418             LDFLAGS="$LDFLAGS -g"
419             ;;
420         esac
421     fi
422     ;;
423
424 dnl OSX needs '-multiply_defined suppress' 
425 *darwin*)
426     LDFLAGS="$LDFLAGS -multiply_defined suppress"
427     ;;
428
429 dnl From Boyd Gerber <gerberb@zenez.com>, needed in some cases to compile
430 dnl the bison-generated parser for innfeed.conf.
431 *UnixWare*|*unixware*|*-sco3*)
432     if test x"$GCC" != xyes ; then
433         CFLAGS="$CFLAGS -Kalloca"
434     fi
435 esac
436   
437 dnl Checks for pathnames.
438
439 dnl See if we have ctags; if so, set CTAGS to its full path plus the -t -w
440 dnl options.  Otherwise, set CTAGS to echo.
441 AC_PATH_PROG(CTAGS, ctags, echo)
442 if test x"$CTAGS" != xecho ; then
443     CTAGS="$CTAGS -t -w"
444 fi
445
446 dnl Use INN_PATH_PROG if it's an error not to find a program.
447 AC_DEFUN([INN_ENSURE_PATH_PROG],
448 [AC_PATH_PROG($1, $2)
449 if test -z "${$1}" ; then
450     AC_MSG_ERROR($2 was not found in path and is required)
451 fi])
452
453 INN_ENSURE_PATH_PROG(_PATH_AWK,awk)
454 INN_ENSURE_PATH_PROG(_PATH_EGREP,egrep)
455 INN_ENSURE_PATH_PROG(_PATH_PERL,perl)
456 INN_ENSURE_PATH_PROG(_PATH_SH,sh)
457 INN_ENSURE_PATH_PROG(_PATH_SED,sed)
458 INN_ENSURE_PATH_PROG(_PATH_SORT,sort)
459 AC_PATH_PROGS(_PATH_UUX,uux,uux)
460
461 dnl Check for a required version of Perl.  The separate shell variable and
462 dnl the changequotes are necessary for autoconf 2.13; autoconf 2.50 will
463 dnl provide a different interface that will allow this to work correctly.
464 changequote(<<,>>)dnl
465 inn_perl_command='print $]'
466 changequote([,])dnl
467 AC_DEFUN([INN_PERL_VERSION],
468 [AC_CACHE_CHECK(for Perl version, inn_cv_perl_version,
469 [if $_PATH_PERL -e 'require $1;' > /dev/null 2>&1 ; then
470     inn_cv_perl_version=`$_PATH_PERL -e "$inn_perl_command"`
471 else
472     AC_MSG_ERROR(Perl $1 or greater is required)
473 fi])])
474
475 dnl Embedded Perl requires 5.004.  controlchan requires 5.004_03.  Other
476 dnl things may work with 5.003, but make 5.004_03 the minimum level; anyone
477 dnl should really have at least that these days.
478 INN_PERL_VERSION(5.004_03)
479
480 dnl Look for PGP 5.0's pgpv, then pgp, then pgpgpg (not sure why anyone would
481 dnl have pgpgpg and not gpgv, but it doesn't hurt).  Separately look for
482 dnl GnuPG (which we prefer).
483 pgpverify=true
484 AC_PATH_PROGS(PATH_GPGV, gpgv)
485 AC_PATH_PROGS(_PATH_PGP, pgpv pgp pgpgpg)
486 if test -z "$_PATH_PGP" && test -z "$PATH_GPGV" ; then
487     pgpverify=false
488 fi
489 AC_SUBST(pgpverify)
490
491 dnl Look for a program that takes an ftp URL as a command line argument and
492 dnl retrieves the file to the current directory.  Shame we can't also use
493 dnl lynx -source; it only writes to stdout.  ncftp as of version 3 doesn't
494 dnl support this any more (it comes with ncftpget instead), but if someone
495 dnl has ncftp and not ncftpget they have an earlier version.
496 AC_PATH_PROGS(GETFTP, wget ncftpget ncftp, $prefix/bin/simpleftp)
497
498 dnl Look for both compress and gzip, since the UUCP batching scripts require
499 dnl both.  If we're using a log compression method other than compress or
500 dnl gzip, check for it too and make sure whatever log compressor we're using
501 dnl exists.  If we don't find compress or gzip for the UUCP scripts, just
502 dnl use the bare program names in the hope that the path will be better at
503 dnl the time the script runs (or that the script will never run).
504 case "$LOG_COMPRESS" in
505 compress|gzip) ;;
506 *)             INN_ENSURE_PATH_PROG(LOG_COMPRESS, "$LOG_COMPRESS")
507 esac
508 AC_PATH_PROG(COMPRESS, compress, compress)
509 if test x"$LOG_COMPRESS" = xcompress ; then
510     if test x"$COMPRESS" = xcompress ; then
511         AC_MSG_ERROR(compress not found but specified for log compression)
512     fi
513     LOG_COMPRESS="$COMPRESS"
514 fi
515 AC_PATH_PROG(GZIP, gzip, gzip)
516 if test x"$LOG_COMPRESS" = xgzip ; then
517     if test x"$GZIP" = xgzip ; then
518         AC_MSG_ERROR(gzip not found but specified for log compression)
519     fi
520     LOG_COMPRESS="$GZIP"
521 fi
522
523 dnl Figure out what program to use to uncompress .Z files.  On systems that
524 dnl have gzip but don't have compress, we can use gzip for this purpose and
525 dnl should rather than hoping compres will be found at runtime.
526 if test x"$COMPRESS" = xcompress && test x"$GZIP" != xgzip ; then
527     UNCOMPRESS="$GZIP -d"
528 else
529     UNCOMPRESS="$COMPRESS -d"
530 fi
531 AC_SUBST(UNCOMPRESS)
532
533 dnl Search for sendmail, checking the path first and then some common
534 dnl locations.  If --with-sendmail was given, that path overrides.
535 if test "${with_sendmail+set}" = set ; then
536     AC_MSG_CHECKING(for sendmail)
537     AC_MSG_RESULT($SENDMAIL)
538 else
539     AC_PATH_PROG(SENDMAIL, sendmail, , "/usr/sbin:/usr/lib")
540     if test -z "$SENDMAIL" ; then
541         AC_MSG_ERROR(sendmail not found, re-run with --with-sendmail)
542     fi
543 fi
544
545 dnl FIXME: innshellvars* wants to know if we have uustat, send-uucp expects
546 dnl it to be in the old subst DO/DONT format.  Should take a path.
547 AC_CHECK_PROG(HAVE_UUSTAT, uustat, DO, DONT)
548 AC_SUBST(HAVE_UUSTAT)
549
550 dnl If we're compiling with Python support, make sure Python is available.
551 if test x"$DO_PYTHON" = xdefine ; then
552     INN_ENSURE_PATH_PROG(_PATH_PYTHON, python)
553 fi
554
555 dnl Search for a particular library, and if found, add that library to the
556 dnl specified variable (the third argument) and run the commands given in the
557 dnl fourth argument, if any.  This is for libraries we don't want to pollute
558 dnl LIBS with.
559 AC_DEFUN([INN_SEARCH_AUX_LIBS],
560 [inn_save_LIBS=$LIBS
561 LIBS=${$3}
562 AC_SEARCH_LIBS($1, $2,
563                [$3=$LIBS
564                 $4], $5, $6)
565 LIBS=$inn_save_LIBS
566 AC_SUBST($3)])
567
568 dnl Checks for libraries.  Use AC_SEARCH_LIBS where possible to avoid
569 dnl adding libraries when the function is found in libc.  In several
570 dnl cases, we explicitly just add the library to LIBS on success rather
571 dnl than using default actions so as not to clutter config.h with defines
572 dnl we never use.
573
574 dnl Check for setproctitle in libc first, then libutil if not found there.
575 dnl We have a replacement function if we can't find it, and then we also need
576 dnl to check for pstat.
577 AC_SEARCH_LIBS(setproctitle, util,
578     [AC_DEFINE(HAVE_SETPROCTITLE, 1,
579         [Define if you have the setproctitle function.])],
580     [LIBOBJS="$LIBOBJS setproctitle.o"
581      AC_CHECK_FUNCS(pstat)])
582
583 dnl The rat's nest of networking libraries.  The common cases are not to
584 dnl need any extra libraries, or to need -lsocket -lnsl.  We need to avoid
585 dnl linking with libnsl unless we need it, though, since on some OSes where
586 dnl it isn't necessary it will totally break networking.  Unisys also
587 dnl includes gethostbyname in libsocket but needs libnsl for socket().
588 AC_SEARCH_LIBS(gethostbyname, nsl)
589 AC_SEARCH_LIBS(socket, socket, ,
590     [AC_CHECK_LIB(nsl, socket, LIBS="$LIBS -lsocket -lnsl", , -lsocket)])
591
592 dnl Check for inet_aton.  We have our own, but on Solaris the version in
593 dnl libresolv is more lenient in ways that Solaris's internal DNS resolution
594 dnl code requires, so if we use our own *and* link with libresolv (which may
595 dnl be forced by Perl) DNS resolution fails.
596 AC_SEARCH_LIBS(inet_aton, resolv)
597
598 dnl Search for various additional libraries used by portions of INN.
599 INN_SEARCH_AUX_LIBS(crypt, crypt, CRYPT_LIB)
600 INN_SEARCH_AUX_LIBS(getspnam, shadow, SHADOW_LIB)
601
602 dnl IRIX has a PAM library with the right symbols but no header files suitable
603 dnl for use with it, so we have to check the header files first and then only
604 dnl if one is found do we check for the library.
605 inn_check_pam=1
606 AC_CHECK_HEADERS([pam/pam_appl.h], ,
607     [AC_CHECK_HEADER([security/pam_appl.h], , [inn_check_pam=0])])
608 if test x"$inn_check_pam" = x1; then
609     INN_SEARCH_AUX_LIBS([pam_start], [pam], [PAM_LIB],
610         [AC_DEFINE([HAVE_PAM], 1, [Define if you have PAM.])])
611 fi
612
613 dnl If keyword generation support was requested, check for the appropriate
614 dnl libraries.
615 if test x"$inn_enable_keywords" = x1 ; then
616     INN_SEARCH_AUX_LIBS(regexec, regex, REGEX_LIB, ,
617         [AC_MSG_ERROR(no usable regular expression library found)])
618 fi
619
620 dnl Check for whether the user wants to compile with BerkeleyDB, and if so
621 dnl what the path to the various components of it is.
622 AC_DEFUN([INN_LIB_BERKELEYDB],
623 [AC_ARG_WITH(berkeleydb,
624     [  --with-berkeleydb[=PATH]  Enable BerkeleyDB (for ovdb overview method)],
625     BERKELEY_DB_DIR=$with_berkeleydb,
626     BERKELEY_DB_DIR=no)
627 AC_MSG_CHECKING(if BerkeleyDB is desired)
628 if test x"$BERKELEY_DB_DIR" = xno ; then
629     AC_MSG_RESULT(no)
630     BERKELEY_DB_LDFLAGS=
631     BERKELEY_DB_CFLAGS=
632     BERKELEY_DB_LIB=
633 else
634     AC_MSG_RESULT(yes)
635     AC_MSG_CHECKING(for BerkeleyDB location)
636     if test x"$BERKELEY_DB_DIR" = xyes ; then
637         for v in BerkeleyDB BerkeleyDB.3.0 BerkeleyDB.3.1 BerkeleyDB.3.2 \
638                  BerkeleyDB.3.3 BerkeleyDB.4.0 BerkeleyDB.4.1 BerkeleyDB.4.2 \
639                  BerkeleyDB.4.3 BerkeleyDB.4.4 BerkeleyDB.4.5 BerkeleyDB.4.6; do
640             for d in $prefix /usr/local /opt /usr ; do
641                 if test -d "$d/$v" ; then
642                     BERKELEY_DB_DIR="$d/$v"
643                     break
644                 fi
645             done
646         done
647     fi
648     if test x"$BERKELEY_DB_DIR" = xyes ; then
649         for v in db46 db45 db44 db43 db42 db41 db4 db3 db2 ; do
650             if test -d "/usr/local/include/$v" ; then
651                 BERKELEY_DB_LDFLAGS="-L/usr/local/lib"
652                 BERKELEY_DB_CFLAGS="-I/usr/local/include/$v"
653                 BERKELEY_DB_LIB="-l$v"
654                 AC_MSG_RESULT(FreeBSD locations)
655                 break
656             fi
657         done
658         if test x"$BERKELEY_DB_LIB" = x ; then
659             for v in db44 db43 db42 db41 db4 db3 db2 ; do
660                 if test -d "/usr/include/$v" ; then
661                     BERKELEY_DB_CFLAGS="-I/usr/include/$v"
662                     BERKELEY_DB_LIB="-l$v"
663                     AC_MSG_RESULT(Linux locations)
664                     break
665                 fi
666             done
667             if test x"$BERKELEY_DB_LIB" = x ; then        
668                 BERKELEY_DB_LIB=-ldb
669                 AC_MSG_RESULT(trying -ldb)
670             fi
671         fi
672     else
673         BERKELEY_DB_LDFLAGS="-L$BERKELEY_DB_DIR/lib"
674         BERKELEY_DB_CFLAGS="-I$BERKELEY_DB_DIR/include"
675         BERKELEY_DB_LIB="-ldb"
676         AC_MSG_RESULT($BERKELEY_DB_DIR)
677     fi
678     AC_DEFINE(USE_BERKELEY_DB, 1, [Define if BerkeleyDB is available.])
679 fi
680 AC_SUBST(BERKELEY_DB_LDFLAGS)
681 AC_SUBST(BERKELEY_DB_CFLAGS)
682 AC_SUBST(BERKELEY_DB_LIB)])
683 INN_LIB_BERKELEYDB
684
685 dnl The dbm libraries are a special case.  If we're building with BerkeleyDB,
686 dnl just use the ndbm support provided by it.
687 if test x"$BERKELEY_DB_LIB" != x ; then
688     DBM_INC="$BERKELEY_DB_CFLAGS"
689     DBM_LIB="$BERKELEY_DB_LDFLAGS $BERKELEY_DB_LIB"
690     AC_SUBST([DBM_LIB])
691     AC_DEFINE([HAVE_BDB_DBM], 1,
692         [Define if the BerkeleyDB dbm compatibility layer is available.])
693 else
694     INN_SEARCH_AUX_LIBS([dbm_open], [ndbm dbm], [DBM_LIB],
695         [AC_DEFINE([HAVE_DBM], 1, [Define if you have a dbm library.])])
696     DBM_INC=
697 fi
698 AC_SUBST([DBM_INC])
699
700 dnl Check for whether the user wants to compile with OpenSSL, and if so what
701 dnl the path to the various components of it is.
702 AC_DEFUN([INN_LIB_OPENSSL],
703 [AC_ARG_WITH(openssl,
704     [  --with-openssl=PATH     Enable OpenSSL (for NNTP over SSL support)],
705     OPENSSL_DIR=$with_openssl,
706     OPENSSL_DIR=no)
707 AC_MSG_CHECKING(if OpenSSL is desired)
708 if test x"$OPENSSL_DIR" = xno ; then
709     AC_MSG_RESULT(no)
710     SSL_BIN=
711     SSL_INC=
712     SSL_LIB=
713 else
714     AC_MSG_RESULT(yes)
715     AC_MSG_CHECKING(for OpenSSL location)
716     if test x"$OPENSSL_DIR" = xyes ; then
717         for dir in $prefix /usr/local/ssl /usr/lib/ssl /usr/ssl /usr/pkg \
718                    /usr/local /usr ; do
719             if test -f "$dir/include/openssl/ssl.h" ; then
720                 OPENSSL_DIR=$dir
721                 break
722             fi
723         done
724     fi
725     if test x"$OPENSSL_DIR" = xyes ; then
726         AC_MSG_ERROR(Can not find OpenSSL)
727     else
728         AC_MSG_RESULT($OPENSSL_DIR)
729         SSL_BIN="${OPENSSL_DIR}/bin"
730         SSL_INC="-I${OPENSSL_DIR}/include"
731
732         # This is mildly tricky.  In order to satisfy most linkers, libraries
733         # have to be listed in the right order, which means that libraries
734         # with dependencies on other libraries need to be listed first.  But
735         # the -L flag for the OpenSSL library directory needs to go first of
736         # all.  So put the -L flag into LIBS and accumulate actual libraries
737         # into SSL_LIB, and then at the end, restore LIBS and move -L to the
738         # beginning of SSL_LIB.
739         inn_save_LIBS=$LIBS
740         LIBS="$LIBS -L${OPENSSL_DIR}/lib"
741         SSL_LIB=''
742         AC_CHECK_LIB(rsaref, RSAPublicEncrypt,
743             [AC_CHECK_LIB(RSAglue, RSAPublicEncrypt,
744                           [SSL_LIB="-lRSAglue -lrsaref"], , -lrsaref)])
745         AC_CHECK_LIB(crypto, BIO_new,
746                      [AC_CHECK_LIB(dl, DSO_load,
747                                    SSL_LIB="-lcrypto -ldl $SSL_LIB",
748                                    SSL_LIB="-lcrypto $SSL_LIB",
749                                    -lcrypto -ldl $SSL_LIB)],
750                      [AC_MSG_ERROR(Can not find OpenSSL)],
751                      $SSL_LIB)
752         AC_CHECK_LIB(ssl, SSL_library_init,
753                      [SSL_LIB="-lssl $SSL_LIB"],
754                      [AC_MSG_ERROR(Can not find OpenSSL)],
755                      $SSL_LIB)
756         SSL_LIB="-L${OPENSSL_DIR}/lib $SSL_LIB"
757         LIBS=$inn_save_LIBS
758         AC_DEFINE(HAVE_SSL, 1, [Define if OpenSSL is available.])
759     fi
760 fi
761 AC_SUBST(SSL_BIN)
762 AC_SUBST(SSL_INC)
763 AC_SUBST(SSL_LIB)])
764 INN_LIB_OPENSSL
765
766 dnl Check for whether the user wants to compile with SASL, and if so what
767 dnl the path to the various components of it is.
768 AC_DEFUN([INN_LIB_SASL],
769 [AC_ARG_WITH(sasl,
770     [  --with-sasl=PATH        Enable SASL (for imapfeed authentication)],
771     SASL_DIR=$with_sasl,
772     SASL_DIR=no)
773 AC_MSG_CHECKING(if SASL is desired)
774 if test x"$SASL_DIR" = xno ; then
775     AC_MSG_RESULT(no)
776     SASL_INC=
777     SASL_LIB=
778 else
779     AC_MSG_RESULT(yes)
780     AC_MSG_CHECKING(for SASL location)
781     if test x"$SASL_DIR" = xyes ; then
782         for dir in $prefix /usr/local/sasl /usr/sasl /usr/pkg /usr/local ; do
783             if test -f "$dir/include/sasl/sasl.h" ; then
784                 SASL_DIR=$dir
785                 break
786             fi
787         done
788     fi
789     if test x"$SASL_DIR" = xyes ; then
790         if test -f "/usr/include/sasl/sasl.h" ; then
791             SASL_INC=-I/usr/include/sasl
792             SASL_DIR=/usr
793             AC_MSG_RESULT($SASL_DIR)
794             inn_save_LIBS=$LIBS
795             AC_CHECK_LIB(sasl2, sasl_getprop,
796                  [SASL_LIB=-lsasl2], [AC_MSG_ERROR(Can not find SASL)])
797             LIBS=$inn_save_LIBS
798             AC_DEFINE(HAVE_SASL, 1, [Define if SASL is available.])
799         else
800             AC_MSG_ERROR(Can not find SASL)
801         fi
802     else
803         AC_MSG_RESULT($SASL_DIR)
804         SASL_INC="-I${SASL_DIR}/include"
805
806         inn_save_LIBS=$LIBS
807         LIBS="$LIBS -L${SASL_DIR}/lib"
808         AC_CHECK_LIB(sasl2, sasl_getprop,
809                      [SASL_LIB="-L${SASL_DIR}/lib -lsasl2"],
810                      [AC_MSG_ERROR(Can not find SASL)],)
811         LIBS=$inn_save_LIBS
812         AC_DEFINE(HAVE_SASL, 1, [Define if SASL is available.])
813     fi
814 fi
815 AC_SUBST(SASL_INC)
816 AC_SUBST(SASL_LIB)])
817 INN_LIB_SASL
818
819 dnl Check for Kerberos libraries for auth_krb5, and if found define KRB5_AUTH
820 dnl to the relevant object file, which will enable compilation of it.
821 if test x"$KRB5_INC" != x ; then
822     INN_SEARCH_AUX_LIBS(krb5_parse_name, krb5, KRB5_LIB,
823         [KRB5_AUTH="auth_krb5"
824          KRB5_LIB="$KRB5_LDFLAGS $KRB5_LIB -lk5crypto -lcom_err"
825          AC_SUBST(KRB5_AUTH)
826          AC_SUBST(KRB5_INC)
827          AC_CHECK_HEADERS([et/com_err.h])], , [$LIBS -lk5crypto -lcom_err])
828 fi
829
830 dnl Check for necessity of krb5_init_ets
831 dnl OSX does not require this function
832 if test x"$KRB5_INC" != x ; then
833     inn_save_LIBS=$LIBS
834     LIBS=$KRB5_LIB
835     AC_CHECK_FUNCS(krb5_init_ets)
836     LIBS=$inn_save_LIBS
837 fi
838
839 dnl Libraries and flags for embedded Perl.  Some distributions of Linux have
840 dnl Perl linked with gdbm but don't normally have gdbm installed, so on that
841 dnl platform only strip -lgdbm out of the Perl libraries.  Leave it in on
842 dnl other platforms where it may be necessary (it isn't on Linux; Linux
843 dnl shared libraries can manage their own dependencies).  Strip -lc out, which
844 dnl is added on some platforms, is unnecessary, and breaks compiles with
845 dnl -pthread (which may be added by Python).
846 dnl
847 dnl If we aren't compiling with large-file support, strip out the large file
848 dnl flags from inn_perl_core_flags; otherwise, innd/cc.c and lib/qio.c
849 dnl disagree over the size of an off_t.  Since none of our calls into Perl
850 dnl use variables of type off_t, this should be harmless; in any event, it's
851 dnl going to be better than the innd/cc.c breakage.
852 if test x"$DO_PERL" = xDO ; then
853     AC_MSG_CHECKING(for Perl linkage)
854     inn_perl_core_path=`$_PATH_PERL -MConfig -e 'print $Config{archlibexp}'`
855     inn_perl_core_flags=`$_PATH_PERL -MExtUtils::Embed -e ccopts`
856     inn_perl_core_libs=`$_PATH_PERL -MExtUtils::Embed -e ldopts 2>&1 | tail -1`
857     inn_perl_core_libs=" $inn_perl_core_libs "
858     inn_perl_core_libs=`echo "$inn_perl_core_libs" | sed 's/ -lc / /'`
859     for i in $LIBS ; do
860         inn_perl_core_libs=`echo "$inn_perl_core_libs" | sed "s/ $i / /"`
861     done
862     case $host in
863     *-linux*)
864         inn_perl_core_libs=`echo "$inn_perl_core_libs" | sed 's/ -lgdbm / /'`
865         ;;
866     *-cygwin*)
867         inn_perl_libname=`$_PATH_PERL -MConfig -e 'print $Config{libperl}'`
868         inn_perl_libname=`echo "$inn_perl_libname" | sed 's/^lib//; s/\.a$//'`
869         inn_perl_core_libs="${inn_perl_core_libs}-l$inn_perl_libname"
870         ;;
871     esac
872     inn_perl_core_libs=`echo "$inn_perl_core_libs" | sed 's/^  *//'`
873     inn_perl_core_libs=`echo "$inn_perl_core_libs" | sed 's/  *$//'`
874     inn_perl_core_flags=" $inn_perl_core_flags "
875     if test x"$inn_enable_largefiles" != xyes ; then
876         for f in -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES ; do
877             inn_perl_core_flags=`echo "$inn_perl_core_flags" | sed "s/ $f / /"`
878         done
879     fi
880     inn_perl_core_flags=`echo "$inn_perl_core_flags" | sed 's/^  *//'`
881     inn_perl_core_flags=`echo "$inn_perl_core_flags" | sed 's/  *$//'`
882     PERL_INC="$inn_perl_core_flags"
883     PERL_LIB="$inn_perl_core_libs"
884     AC_MSG_RESULT($inn_perl_core_path)
885 else
886     PERL_INC=''
887     PERL_LIB=''
888 fi
889 AC_SUBST(PERL_INC)
890 AC_SUBST(PERL_LIB)
891
892 dnl Libraries and flags for embedded Python.
893 dnl
894 dnl FIXME: I wish there was a less icky way to get this.
895 if test x"$DO_PYTHON" = xdefine ; then
896     AC_MSG_CHECKING(for Python linkage)
897     py_prefix=`$_PATH_PYTHON -c 'import sys; print sys.prefix'`
898     py_ver=`$_PATH_PYTHON -c 'import sys; print sys.version[[:3]]'`
899     py_libdir="${py_prefix}/lib/python${py_ver}"
900     PYTHON_INC="-I${py_prefix}/include/python${py_ver}"
901     py_linkage=""
902     for py_linkpart in LIBS LIBC LIBM LOCALMODLIBS BASEMODLIBS \
903                        LINKFORSHARED LDFLAGS ; do
904         py_linkage="$py_linkage "`grep "^${py_linkpart}=" \
905                                        $py_libdir/config/Makefile \
906                                   | sed -e 's/^.*=//'`
907     done
908     PYTHON_LIB="-L$py_libdir/config -lpython$py_ver $py_linkage"
909     PYTHON_LIB=`echo $PYTHON_LIB | sed -e 's/[ \\t]*/ /g'`
910     AC_MSG_RESULT($py_libdir)
911 else
912     PYTHON_LIB=""
913     PYTHON_INC=""
914 fi
915 AC_SUBST(PYTHON_LIB)
916 AC_SUBST(PYTHON_INC)
917
918 dnl If configuring with large file support, determine the right flags to
919 dnl use based on the platform.  This is the wrong approach; autoconf 2.50
920 dnl comes with a macro that takes the right approach.  But this works well
921 dnl enough until we switch to autoconf 2.50 or later.
922 if test x"$inn_enable_largefiles" = xyes ; then
923     AC_MSG_CHECKING(for largefile linkage)
924     case "$host" in
925     *-aix4.[01]*)
926         AC_MSG_RESULT(no)
927         AC_MSG_ERROR([AIX before 4.2 does not support large files])
928         ;;
929     *-aix4*)
930         AC_MSG_RESULT(ok)
931         LFS_CFLAGS="-D_LARGE_FILES"
932         LFS_LDFLAGS=""
933         LFS_LIBS=""
934         ;;
935     *-hpux*)
936         AC_MSG_RESULT(ok)
937         LFS_CFLAGS="-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
938         LFS_LDFLAGS=""
939         LFS_LIBS=""
940         ;;
941     *-irix*)
942         AC_MSG_RESULT(no)
943         AC_MSG_ERROR([Large files not supported on this platform])
944         ;;
945     *-linux*)
946         AC_MSG_RESULT(maybe)
947         LFS_CFLAGS="-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
948         LFS_LDFLAGS=""
949         LFS_LIBS=""
950         AC_DEFINE([_GNU_SOURCE], 1,
951                   [Some versions of glibc need this defined for pread/pwrite.])
952         ;;
953     *-solaris*)
954         AC_MSG_RESULT(ok)
955         AC_PATH_PROG(GETCONF, getconf)
956         if test -z "$GETCONF" ; then
957             AC_MSG_ERROR([getconf required to configure large file support])
958         fi
959         LFS_CFLAGS=`$GETCONF LFS_CFLAGS`
960         LFS_LDFLAGS=`$GETCONF LFS_LDFLAGS`
961         LFS_LIBS=`$GETCONF LFS_LIBS`
962         ;;
963     *)
964         AC_MSG_RESULT(maybe)
965         LFS_CFLAGS="-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
966         LFS_LDFLAGS=""
967         LFS_LIBS=""
968         ;;
969     esac
970     AC_SUBST(LFS_CFLAGS)
971     AC_SUBST(LFS_LDFLAGS)
972     AC_SUBST(LFS_LIBS)
973 fi
974
975 dnl Start by checking for standard C headers.  AC_HEADER_STDC will set
976 dnl STDC_HEADERS if stdlib.h, stdarg.h, string.h, and float.h all exist, if
977 dnl memchr (and probably the other mem functions) is in string.h, if free (and
978 dnl probably malloc and friends) are in stdlib.h, and if ctype.h will work on
979 dnl high-bit characters.
980 AC_HEADER_STDC
981
982 dnl Only if that wasn't set do we need to go hunting for other headers to
983 dnl include on non-ANSI systems and check for functions that all ANSI C
984 dnl systems should have.
985 if test x"$ac_cv_header_stdc" = xno ; then
986     AC_CHECK_HEADERS(memory.h stdlib.h strings.h)
987     AC_CHECK_FUNCS(memcpy strchr)
988 fi
989
990 dnl Special checks for header files.
991 AC_HEADER_DIRENT
992 AC_HEADER_TIME
993 AC_HEADER_SYS_WAIT
994
995 dnl Generic checks for header files.
996 AC_CHECK_HEADERS(crypt.h inttypes.h limits.h ndbm.h pam/pam_appl.h stdbool.h \
997                  stddef.h stdint.h string.h sys/bitypes.h sys/filio.h \
998                  sys/loadavg.h sys/param.h sys/select.h sys/sysinfo.h \
999                  sys/time.h unistd.h)
1000
1001 dnl Some Linux systems have db1/ndbm.h instead of ndbm.h.  Others have
1002 dnl gdbm-ndbm.h.
1003 if test x"$ac_cv_header_ndbm_h" = xno ; then
1004     AC_CHECK_HEADERS(db1/ndbm.h gdbm-ndbm.h)
1005 fi
1006
1007 dnl Check to see if herrno is declared.
1008 AC_DEFUN([INN_NEED_HERRNO_DECLARATION],
1009 [AC_CACHE_CHECK([whether h_errno must be declared], inn_cv_herrno_need_decl,
1010 [AC_TRY_COMPILE([#include <netdb.h>], [h_errno = 0;],
1011                inn_cv_herrno_need_decl=no,
1012                inn_cv_herrno_need_decl=yes)])
1013 if test "$inn_cv_herrno_need_decl" = yes ; then
1014     AC_DEFINE([NEED_HERRNO_DECLARATION], 1,
1015               [Define if <netdb.h> does not declare h_errno.])
1016 fi])
1017 INN_NEED_HERRNO_DECLARATION
1018
1019 dnl The set of standard includes, used for checking if functions need to be
1020 dnl declared and for tests that need to use standard functions.
1021 define([_INN_HEADER_SOURCE],
1022 [#include <stdio.h>
1023 #include <sys/types.h>
1024 #if STDC_HEADERS
1025 # include <stdlib.h>
1026 # include <stddef.h>
1027 #else
1028 # if HAVE_STDLIB_H
1029 #  include <stdlib.h>
1030 # endif
1031 # if !HAVE_STRCHR
1032 #  define strchr index
1033 #  define strrchr rindex
1034 # endif
1035 #endif
1036 #if HAVE_STRING_H
1037 # if !STDC_HEADERS && HAVE_MEMORY_H
1038 #  include <memory.h>
1039 # endif
1040 # include <string.h>
1041 #else
1042 # if HAVE_STRINGS_H
1043 #  include <strings.h>
1044 # endif
1045 #endif
1046 #if HAVE_UNISTD_H
1047 # include <unistd.h>
1048 #endif])
1049
1050 dnl See if a given function needs a declaration by seeing if we can access a
1051 dnl function pointer for that function.  This is done in a really ugly way
1052 dnl with hacks so that autoheader will pick up the defines properly; it's a
1053 dnl stop-gap solution until switching to autoconf 2.50.
1054 AC_DEFUN([INN_NEED_DECLARATION],
1055 [AC_MSG_CHECKING([whether $1 must be declared])
1056 AC_CACHE_VAL([inn_cv_decl_needed_$1],
1057 [AC_TRY_COMPILE(
1058 _INN_HEADER_SOURCE()
1059 [$3],
1060 [char *(*pfn) = (char *(*)) $1],
1061 [inn_cv_decl_needed_$1=no], [inn_cv_decl_needed_$1=yes])])
1062 if test $inn_cv_decl_needed_$1 = yes ; then
1063     AC_MSG_RESULT(yes)
1064     AC_DEFINE($2, 1, [Define if $1 isn't declared in the system headers.])
1065 else
1066     AC_MSG_RESULT(no)
1067 fi])
1068 INN_NEED_DECLARATION(inet_aton, [NEED_DECLARATION_INET_ATON],
1069 [#include <netinet/in.h>
1070 #include <arpa/inet.h>])
1071 INN_NEED_DECLARATION(inet_ntoa, [NEED_DECLARATION_INET_NTOA],
1072 [#include <netinet/in.h>
1073 #include <arpa/inet.h>])
1074 INN_NEED_DECLARATION(snprintf, [NEED_DECLARATION_SNPRINTF])
1075 INN_NEED_DECLARATION(vsnprintf, [NEED_DECLARATION_VSNPRINTF])
1076
1077 dnl Checks for typedefs, structures, and compiler characteristics.
1078 AC_C_BIGENDIAN
1079 AC_C_CONST
1080 AC_STRUCT_ST_BLKSIZE
1081 AC_STRUCT_TM
1082 AC_TYPE_SIZE_T
1083 AC_TYPE_UID_T
1084 AC_TYPE_OFF_T
1085 AC_TYPE_PID_T
1086 AC_CHECK_TYPE(ptrdiff_t, long)
1087 AC_CHECK_TYPE(ssize_t, int)
1088
1089 dnl Check for ISO C99 variadic macro support in the compiler.
1090 AC_DEFUN([INN_C_C99_VAMACROS],
1091 [AC_CACHE_CHECK(for C99 variadic macros, inn_cv_c_c99_vamacros,
1092 [AC_TRY_COMPILE(
1093 [#include <stdio.h>
1094 #define error(...) fprintf(stderr, __VA_ARGS__)],
1095 [error("foo"); error("foo %d", 0); return 0;],
1096 [inn_cv_c_c99_vamacros=yes], [inn_cv_c_c99_vamacros=no])])
1097 if test $inn_cv_c_c99_vamacros = yes ; then
1098     AC_DEFINE(HAVE_C99_VAMACROS, 1,
1099               [Define if the compiler supports C99 variadic macros.])
1100 fi])
1101 INN_C_C99_VAMACROS
1102
1103 dnl Check for GNU-style variadic macro support in the compiler.
1104 AC_DEFUN([INN_C_GNU_VAMACROS],
1105 [AC_CACHE_CHECK(for GNU-style variadic macros, inn_cv_c_gnu_vamacros,
1106 [AC_TRY_COMPILE(
1107 [#include <stdio.h>
1108 #define error(args...) fprintf(stderr, args)],
1109 [error("foo"); error("foo %d", 0); return 0;],
1110 [inn_cv_c_gnu_vamacros=yes], [inn_cv_c_gnu_vamacros=no])])
1111 if test $inn_cv_c_gnu_vamacros = yes ; then
1112     AC_DEFINE(HAVE_GNU_VAMACROS, 1,
1113               [Define if the compiler supports GNU-style variadic macros.])
1114 fi])
1115 INN_C_GNU_VAMACROS
1116
1117 dnl Check for long long int, and define HAVE_LONG_LONG if the compiler
1118 dnl supports it.
1119 AC_DEFUN([INN_C_LONG_LONG],
1120 [AC_CACHE_CHECK(for long long int, inn_cv_c_long_long,
1121 [AC_TRY_COMPILE(, [long long int i;],
1122                 inn_cv_c_long_long=yes,
1123                 inn_cv_c_long_long=no)])
1124 if test $inn_cv_c_long_long = yes ; then
1125     AC_DEFINE(HAVE_LONG_LONG, 1,
1126               [Define if the compiler supports long long int.])
1127 fi])
1128 INN_C_LONG_LONG
1129
1130 dnl From Paul D. Smith <psmith@baynetworks.com> on the autoconf mailing list,
1131 dnl this is a version of AC_CHECK_TYPE that allows specification of additional
1132 dnl headers.  It's a modified version of the standard autoconf macro.
1133 AC_DEFUN([INN_CHECK_TYPE],
1134 [AC_REQUIRE([AC_HEADER_STDC])
1135 AC_MSG_CHECKING(for $1)
1136 AC_CACHE_VAL(ac_cv_type_$1,
1137 [AC_EGREP_CPP(dnl
1138 changequote(<<, >>)dnl
1139 <<(^|[^a-zA-Z_0-9])$1[^a-zA-Z_0-9]>>dnl
1140 changequote([, ]),
1141 [#include <sys/types.h>
1142 #ifdef STDC_HEADERS
1143 # include <stdlib.h>
1144 # include <stddef.h>
1145 #endif
1146 $3],
1147     ac_cv_type_$1=yes,
1148     ac_cv_type_$1=no
1149 )])
1150 AC_MSG_RESULT($ac_cv_type_$1)
1151 if test x"$ac_cv_type_$1" = xno ; then
1152     AC_DEFINE_UNQUOTED($1, $2)
1153 fi])
1154
1155 INN_CHECK_TYPE(sig_atomic_t, int, [#include <signal.h>])
1156 INN_CHECK_TYPE(socklen_t, int, [#include <sys/socket.h>])
1157
1158 dnl Source used by INN_MACRO_IOV_MAX.
1159 define([_INN_MACRO_IOV_MAX_SOURCE],
1160 [[#include <sys/types.h>
1161 #include <stdio.h>
1162 #include <sys/uio.h>
1163 #include <errno.h>
1164 #include <fcntl.h>
1165 #ifdef HAVE_UNISTD_H
1166 # include <unistd.h>
1167 #endif
1168 #ifdef HAVE_LIMITS_H
1169 # include <limits.h>
1170 #endif
1171
1172 int
1173 main ()
1174 {
1175   int fd, size;
1176   struct iovec array[1024];
1177   char data;
1178
1179   FILE *f = fopen ("conftestval", "w");
1180   if (!f) return 1;
1181 #ifdef IOV_MAX
1182   fprintf (f, "set in limits.h\n");
1183 #else
1184 # ifdef UIO_MAXIOV
1185   fprintf (f, "%d\n", UIO_MAXIOV);
1186 # else
1187   fd = open ("/dev/null", O_WRONLY, 0666);
1188   if (fd < 0) return 1;
1189   for (size = 1; size <= 1024; size++)
1190     {
1191       array[size - 1].iov_base = &data;
1192       array[size - 1].iov_len = sizeof data;
1193       if (writev (fd, array, size) < 0)
1194         {
1195           if (errno != EINVAL) return 1;
1196           fprintf(f, "%d\n", size - 1);
1197           exit (0);
1198         }
1199     }
1200   fprintf (f, "1024\n");
1201 # endif /* UIO_MAXIOV */
1202 #endif /* IOV_MAX */
1203   return 0;
1204 }]])
1205
1206 dnl Check for the number of elements in an iovec (IOV_MAX).  SVr4 systems
1207 dnl appear to use that name for this limit (checked Solaris 2.6, IRIX 6.5, and
1208 dnl HP-UX 11.00).  Linux doesn't have it, but instead has UIO_MAXIOV defined
1209 dnl in <iovec.h> included from <sys/uio.h>.  The platforms that have IOV_MAX
1210 dnl appear to also offer it via sysconf(3), but it should be a constant for a
1211 dnl given implementation.  Set IOV_MAX if it's not defined in <sys/uio.h> or
1212 dnl <limits.h>.
1213 AC_DEFUN([INN_MACRO_IOV_MAX],
1214 [AC_CACHE_CHECK([value of IOV_MAX], [inn_cv_macro_iov_max],
1215 [AC_TRY_RUN(_INN_MACRO_IOV_MAX_SOURCE(),
1216             inn_cv_macro_iov_max=`cat conftestval`,
1217             inn_cv_macro_iov_max=error, 16)
1218 if test x"$inn_cv_macro_iov_max" = xerror ; then
1219     AC_MSG_WARN([probe failure, assuming 16])
1220     inn_cv_macro_iov_max=16
1221 fi])
1222 if test x"$inn_cv_macro_iov_max" != x"set in limits.h" ; then
1223     AC_DEFINE_UNQUOTED(IOV_MAX, $inn_cv_macro_iov_max,
1224                        [Define to the max vectors in an iovec.])
1225 fi])
1226 INN_MACRO_IOV_MAX
1227
1228 dnl Check for SUN_LEN (size of a Unix domain socket struct, macro required
1229 dnl POSIX.1g but not that widespread yet).
1230 AC_DEFUN([INN_MACRO_SUN_LEN],
1231 [AC_CACHE_CHECK(for SUN_LEN, inn_cv_macro_sun_len,
1232 [AC_TRY_LINK(
1233 [#include <sys/types.h>
1234 #include <sys/un.h>],
1235 [struct sockaddr_un sun;
1236 int i;
1237
1238 i = SUN_LEN(&sun);],
1239     inn_cv_macro_sun_len=yes,
1240     inn_cv_macro_sun_len=no)])
1241 if test x"$inn_cv_macro_sun_len" = xyes ; then
1242     AC_DEFINE(HAVE_SUN_LEN, 1,
1243               [Define if <sys/un.h> defines the SUN_LEN macro.])
1244 fi])
1245 INN_MACRO_SUN_LEN
1246
1247 dnl BSD hosts have a tm_gmtoff element in struct tm containing the offset from
1248 dnl GMT/UTC for that time.  This is the strongly preferred way of getting time
1249 dnl zone information.
1250 AC_DEFUN([INN_STRUCT_TM_GMTOFF],
1251 [AC_CACHE_CHECK(for tm_gmtoff in struct tm, inn_cv_struct_tm_gmtoff,
1252 [AC_TRY_LINK([#include <time.h>],
1253              [struct tm t; t.tm_gmtoff = 3600],
1254              inn_cv_struct_tm_gmtoff=yes,
1255              inn_cv_struct_tm_gmtoff=no)])
1256 if test x"$inn_cv_struct_tm_gmtoff" = xyes ; then
1257     AC_DEFINE([HAVE_TM_GMTOFF], 1,
1258               [Define if your struct tm has a tm_gmtoff member.])
1259 fi])
1260 INN_STRUCT_TM_GMTOFF
1261
1262 dnl BSD hosts have the name of the local time zone in struct tm, which is much
1263 dnl nicer to use than the tzname variable (and also potentially handles
1264 dnl renamings of the time zone in the past).
1265 AC_DEFUN([INN_STRUCT_TM_ZONE],
1266 [AC_CACHE_CHECK(for tm_zone in struct tm, inn_cv_struct_tm_zone,
1267 [AC_TRY_LINK([#include <time.h>],
1268              [struct tm t; t.tm_zone = "UTC"],
1269              inn_cv_struct_tm_zone=yes,
1270              inn_cv_struct_tm_zone=no)])
1271 if test x"$inn_cv_struct_tm_zone" = xyes ; then
1272     AC_DEFINE([HAVE_TM_ZONE], 1,
1273               [Define if your struct tm has a tm_zone member.])
1274 fi])
1275 INN_STRUCT_TM_ZONE
1276
1277 dnl Many System V hosts have an external variable timezone containing the
1278 dnl offset of local time from GMT/UTC.  We can use this for the timezone
1279 dnl offset for current time, although it's not usable for anything else.
1280 dnl Unfortunately, some BSD varients have a function named timezone instead.
1281 dnl HP-UX has timezone but doesn't have altzone, which isn't good enough.
1282 AC_DEFUN([INN_VAR_TIMEZONE],
1283 [AC_CACHE_CHECK(for timezone variable, inn_cv_var_timezone,
1284 [AC_TRY_LINK([#include <time.h>], [timezone = 3600; altzone = 7200],
1285              inn_cv_var_timezone=yes,
1286              inn_cv_var_timezone=no)])
1287 if test x"$inn_cv_var_timezone" = xyes ; then
1288     AC_DEFINE([HAVE_VAR_TIMEZONE], 1,
1289               [Define if timezone is an external variable in <time.h>.])
1290 fi])
1291 INN_VAR_TIMEZONE
1292
1293 dnl Many System V hosts and some BSD systems have an external variable tzname
1294 dnl containing the abbreviations of the main and alternate time zone.  We can
1295 dnl use these as a reasonable approximation of the correct time zone names,
1296 dnl although they could be incorrect if the time zone name has changed in the
1297 dnl past.
1298 AC_DEFUN([INN_VAR_TZNAME],
1299 [AC_CACHE_CHECK(for tzname variable, inn_cv_var_tzname,
1300 [AC_TRY_LINK([#include <time.h>], [*tzname = "UTC"],
1301              inn_cv_var_tzname=yes,
1302              inn_cv_var_tzname=no)])
1303 if test x"$inn_cv_var_tzname" = xyes ; then
1304     AC_DEFINE([HAVE_VAR_TZNAME], 1,
1305               [Define if tzname is an external variable in <time.h>.])
1306 fi])
1307 INN_VAR_TZNAME
1308
1309 dnl A modified version of AC_CHECK_SIZEOF that doesn't always AC_DEFINE, but
1310 dnl instead lets you execute shell code based on success or failure.  This is
1311 dnl to avoid config.h clutter.
1312 AC_DEFUN(INN_IF_SIZEOF,
1313 [changequote(<<, >>)dnl
1314 dnl The name to #define.
1315 define(<<AC_TYPE_NAME>>, translit(sizeof_$1, [a-z *], [A-Z_P]))dnl
1316 dnl The cache variable name.
1317 define(<<AC_CV_NAME>>, translit(ac_cv_sizeof_$1, [ *], [_p]))dnl
1318 changequote([, ])dnl
1319 AC_MSG_CHECKING(size of $1)
1320 AC_CACHE_VAL(AC_CV_NAME,
1321 [AC_TRY_RUN([#include <stdio.h>
1322 main()
1323 {
1324     FILE *f = fopen("conftestval", "w");
1325     if (!f) exit(1);
1326     fprintf(f, "%d\n", sizeof($1));
1327     exit(0);
1328 }], AC_CV_NAME=`cat conftestval`, AC_CV_NAME=0,
1329 ifelse([$2], , , AC_CV_NAME=$2))
1330 ])dnl
1331 AC_MSG_RESULT($AC_CV_NAME)
1332 if test x"$AC_CV_NAME" = x"$3" ; then
1333     ifelse([$4], , :, [$4])
1334 else
1335     ifelse([$5], , :, [$5])
1336 fi
1337 undefine([AC_TYPE_NAME])dnl
1338 undefine([AC_CV_NAME])dnl
1339 ])
1340
1341 dnl Find a 32 bit type, by trying likely candidates.  First, check for the C9X
1342 dnl int32_t, then look for something else with a size of four bytes.
1343 INN_IF_SIZEOF(int, 4, 4, INN_INT32=int,
1344     [INN_IF_SIZEOF(long, 4, 4, INN_INT32=long,
1345         [INN_IF_SIZEOF(short, 2, 4, INN_INT32=short)])])
1346 INN_CHECK_TYPE(int32_t, $INN_INT32,
1347 [#ifdef HAVE_STDINT_H
1348 # include <stdint.h>
1349 #endif
1350 #ifdef HAVE_SYS_BITYPES_H
1351 # include <sys/bitypes.h>
1352 #endif
1353 ])
1354
1355 dnl Figure out the unsigned version.
1356 INN_CHECK_TYPE(uint32_t, unsigned $INN_INT32,
1357 [#ifdef HAVE_STDINT_H
1358 # include <stdint.h>
1359 #endif
1360 #ifdef HAVE_SYS_BITYPES_H
1361 # include <sys/bitypes.h>
1362 #endif
1363 ])
1364
1365 dnl Checks for library functions.
1366 AC_FUNC_MEMCMP
1367 AC_TYPE_SIGNAL
1368
1369 dnl Source used by INN_FUNC_INET_NTOA
1370 define([_INN_FUNC_INET_NTOA_SOURCE],
1371 [#include <sys/types.h>
1372 #include <sys/socket.h>
1373 #include <netinet/in.h>
1374 #include <arpa/inet.h>
1375 #if STDC_HEADERS || HAVE_STRING_H
1376 # include <string.h>
1377 #endif
1378
1379 int
1380 main ()
1381 {
1382   struct in_addr in;
1383   in.s_addr = htonl (0x7f000000L);
1384   return (!strcmp (inet_ntoa (in), "127.0.0.0") ? 0 : 1);
1385 }])
1386
1387 dnl Check whether inet_ntoa is present and working.  Since calling inet_ntoa
1388 dnl involves passing small structs on the stack, present and working versions
1389 dnl may still not function with gcc on some platforms (such as IRIX).
1390 AC_DEFUN([INN_FUNC_INET_NTOA],
1391 [AC_CACHE_CHECK(for working inet_ntoa, inn_cv_func_inet_ntoa_works,
1392 [AC_TRY_RUN(_INN_FUNC_INET_NTOA_SOURCE(),
1393             [inn_cv_func_inet_ntoa_works=yes],
1394             [inn_cv_func_inet_ntoa_works=no],
1395             [inn_cv_func_inet_ntoa_works=no])])
1396 if test "$inn_cv_func_inet_ntoa_works" = yes ; then
1397     AC_DEFINE([HAVE_INET_NTOA], 1,
1398               [Define if your system has a working inet_ntoa function.])
1399 else
1400     LIBOBJS="$LIBOBJS inet_ntoa.${ac_objext}"
1401 fi])
1402 INN_FUNC_INET_NTOA
1403
1404 dnl Check whether sockaddr structs have sa_len fields
1405 AC_DEFUN([INN_SOCKADDR_SA_LEN],
1406 [AC_CACHE_CHECK(whether struct sockaddr has sa_len,
1407                 inn_cv_struct_sockaddr_sa_len,
1408                 [AC_TRY_COMPILE(
1409                         [#include <sys/types.h>
1410                         #include <sys/socket.h>
1411                         #include <netinet/in.h>],
1412                         [struct sockaddr sa; int x = sa.sa_len;],
1413                         [inn_cv_struct_sockaddr_sa_len=yes],
1414                         [inn_cv_struct_sockaddr_sa_len=no])])
1415 if test "$inn_cv_struct_sockaddr_sa_len" = yes ; then
1416     AC_DEFINE([HAVE_SOCKADDR_LEN],1,
1417             [Define if your system has a sa_len field in struct sockaddr])
1418 fi])
1419 INN_SOCKADDR_SA_LEN
1420
1421 dnl Check whether we have an SA_LEN macro available to us
1422 AC_DEFUN([INN_SA_LEN_MACRO],
1423 [AC_CACHE_CHECK(for SA_LEN(s) macro, inn_cv_sa_len_macro,
1424                 [AC_TRY_LINK(
1425                         [#include <sys/types.h>
1426                         #include <sys/socket.h>
1427                         #include <netinet/in.h>],
1428                         [struct sockaddr sa; int x = SA_LEN(&sa);],
1429                         [inn_cv_sa_len_macro=yes],
1430                         [inn_cv_sa_len_macro=no])])
1431 if test "$inn_cv_sa_len_macro" = yes ; then
1432     AC_DEFINE([HAVE_SA_LEN_MACRO],1,
1433             [Define if your system has a SA_LEN(s) macro])
1434 fi])
1435 INN_SA_LEN_MACRO
1436
1437 dnl Check to see how struct sockaddr_storage members are named.
1438 dnl  *** Called from INN_SOCKADDR_STORAGE
1439 AC_DEFUN([INN_2553_SS_FAMILY],
1440 [AC_CACHE_CHECK(for RFC 2553 style sockaddr_storage member names,
1441                 inn_cv_2553_ss_family,
1442                 [AC_TRY_COMPILE(
1443                         [#include <sys/types.h>
1444                         #include <sys/socket.h>
1445                         #include <netinet/in.h>],
1446                         [struct sockaddr_storage ss; int x=ss.ss_family;],
1447                         [inn_cv_2553_ss_family=no],
1448                         [inn_cv_2553_ss_family=yes])])
1449 if test "$inn_cv_2553_ss_family" = yes ; then
1450     AC_DEFINE([HAVE_2553_STYLE_SS_FAMILY],1,
1451         [Define if your system has sockaddr_storage.__ss_family])
1452 fi])
1453
1454 dnl Check whether we have struct sockaddr_storage as defined by RFC 2553,
1455 dnl or whether we should define it ourselves.
1456 AC_DEFUN([INN_SOCKADDR_STORAGE],
1457 [AC_CACHE_CHECK(for struct sockaddr_storage, inn_cv_struct_sockaddr_storage,
1458                 [AC_TRY_COMPILE(
1459                         [#include <sys/types.h>
1460                         #include <sys/socket.h>
1461                         #include <netinet/in.h>],
1462                         [struct sockaddr_storage ss;],
1463                         [inn_cv_struct_sockaddr_storage=yes],
1464                         [inn_cv_struct_sockaddr_storage=no])])
1465 if test "$inn_cv_struct_sockaddr_storage" = yes ; then
1466     AC_DEFINE([HAVE_SOCKADDR_STORAGE],1,
1467         [Define if your system has struct sockaddr_storage])
1468     INN_2553_SS_FAMILY
1469 fi])
1470 INN_SOCKADDR_STORAGE
1471
1472 dnl Source used by INN_IN6_EQ_BROKEN
1473 dnl Test borrowed from a bug report by tmoestl@gmx.net for glibc
1474 define([_INN_IN6_EQ_BROKEN_SOURCE],
1475 [#include <sys/types.h>
1476 #include <sys/socket.h>
1477 #include <netinet/in.h>
1478 #include <arpa/inet.h>
1479
1480 int
1481 main ()
1482 {
1483   struct in6_addr a;
1484   struct in6_addr b;
1485
1486   inet_pton(AF_INET6,"fe80::1234:5678:abcd",&a);
1487   inet_pton(AF_INET6,"fe80::1234:5678:abcd",&b);
1488   return IN6_ARE_ADDR_EQUAL(&a,&b) ? 0 : 1;
1489 }])
1490
1491 dnl Checks whether IN6_ARE_ADDR_EQUAL macro is broken (glibc 2.1.3 is)
1492 dnl *** only run if we're building for IPv6 (--enable-ipv6)
1493 AC_DEFUN([INN_IN6_EQ_BROKEN],
1494 [AC_CACHE_CHECK(whether IN6_ARE_ADDR_EQUAL macro is broken,
1495                 inn_cv_in6_are_addr_equal_broken,
1496                 [AC_TRY_RUN(_INN_IN6_EQ_BROKEN_SOURCE,
1497                         inn_cv_in6_are_addr_equal_broken=no,
1498                         inn_cv_in6_are_addr_equal_broken=yes,
1499                         inn_cv_in6_are_addr_equal_broken=no)])
1500 if test "$inn_cv_in6_are_addr_equal_broken" = yes ; then
1501     AC_DEFINE([HAVE_BROKEN_IN6_ARE_ADDR_EQUAL],1,
1502         [Define if your IN6_ARE_ADDR_EQUAL macro is broken])
1503 fi])
1504 if test "$inn_enable_ipv6_tests" = yes ; then
1505     INN_IN6_EQ_BROKEN
1506 fi
1507
1508 dnl Source used by INN_FUNC_SNPRINTF.
1509 define([_INN_FUNC_SNPRINTF_SOURCE],
1510 [[#include <stdio.h>
1511 #include <stdarg.h>
1512
1513 char buf[2];
1514
1515 int
1516 test (char *format, ...)
1517 {
1518   va_list args;
1519   int count;
1520
1521   va_start (args, format);
1522   count = vsnprintf (buf, sizeof buf, format, args);
1523   va_end (args);
1524   return count;
1525 }
1526
1527 int
1528 main ()
1529 {
1530   return ((test ("%s", "abcd") == 4 && buf[0] == 'a' && buf[1] == '\0'
1531            && snprintf(NULL, 0, "%s", "abcd") == 4) ? 0 : 1);
1532 }]])
1533
1534 dnl Check for a working snprintf.  Some systems have snprintf, but it doesn't
1535 dnl null-terminate if the buffer isn't large enough or it returns -1 if the
1536 dnl string doesn't fit instead of returning the number of characters that
1537 dnl would have been formatted.
1538 AC_DEFUN([INN_FUNC_SNPRINTF],
1539 [AC_CACHE_CHECK(for working snprintf, inn_cv_func_snprintf_works,
1540 [AC_TRY_RUN(_INN_FUNC_SNPRINTF_SOURCE(),
1541             [inn_cv_func_snprintf_works=yes],
1542             [inn_cv_func_snprintf_works=no],
1543             [inn_cv_func_snprintf_works=no])])
1544 if test "$inn_cv_func_snprintf_works" = yes ; then
1545     AC_DEFINE([HAVE_SNPRINTF], 1,
1546         [Define if your system has a working snprintf function.])
1547 else
1548     LIBOBJS="$LIBOBJS snprintf.${ac_objext}"
1549 fi])
1550 INN_FUNC_SNPRINTF
1551
1552 dnl Check for various other functions.
1553 AC_CHECK_FUNCS(atexit getloadavg getrlimit getrusage getspnam setbuffer \
1554                sigaction setgroups setrlimit setsid socketpair statvfs \
1555                strncasecmp strtoul symlink sysconf)
1556
1557 dnl Find a way to get the file descriptor limit.
1558 if test x"$ac_cv_func_getrlimit" = xno ; then
1559     AC_CHECK_FUNCS(getdtablesize ulimit, break)
1560 fi
1561
1562 dnl If we don't have statvfs, gather some more information for inndf.
1563 if test x"$ac_cv_func_statvfs" = xno ; then
1564     AC_CHECK_FUNCS(statfs)
1565     AC_CHECK_HEADERS(sys/vfs.h sys/mount.h)
1566 fi
1567
1568 dnl If we can't find any of the following, we have replacements for them.
1569 AC_REPLACE_FUNCS(fseeko ftello getpagesize hstrerror inet_aton mkstemp \
1570                  pread pwrite seteuid strcasecmp strerror strlcat strlcpy \
1571                  strspn setenv)
1572
1573 dnl Source used by INN_TYPE_FPOS_T_LARGE.
1574 define([_INN_TYPE_FPOS_T_LARGE_SOURCE],
1575 [#include <stdio.h>
1576 #include <sys/types.h>
1577
1578 int
1579 main ()
1580 {
1581   fpos_t fpos = 9223372036854775807ULL;
1582   off_t off;
1583   off = fpos;
1584   exit(off == (off_t) 9223372036854775807ULL ? 0 : 1);
1585 }])
1586
1587 dnl Check whether fpos_t is 64 bits and can be assigned to an off_t.  If so,
1588 dnl sets HAVE_LARGE_FPOS_T; this means that a missing fseeko or ftello can be
1589 dnl emulated usint fgetpos and fsetpos.
1590 AC_DEFUN([INN_TYPE_FPOS_T_LARGE],
1591 [AC_CACHE_CHECK(for off_t-compatible fpos_t, inn_cv_type_fpos_t_large,
1592 [AC_TRY_RUN(_INN_TYPE_FPOS_T_LARGE_SOURCE(),
1593             [inn_cv_type_fpos_t_large=yes],
1594             [inn_cv_type_fpos_t_large=no],
1595             [inn_cv_type_fpos_t_large=no])
1596 if test "$inn_cv_type_fpos_t_large" = yes ; then
1597     AC_DEFINE([HAVE_LARGE_FPOS_T], 1,
1598         [Define if fpos_t is at least 64 bits and compatible with off_t.])
1599 fi])])
1600
1601 dnl If replacing fseeko or ftello, see if we can use fsetpos/fgetpos.
1602 if test "$ac_cv_func_fseeko" = no || test "$ac_cv_func_ftello" = no ; then
1603    INN_TYPE_FPOS_T_LARGE
1604 fi
1605
1606 dnl Source used by INN_FUNC_MMAP.
1607 define([_INN_FUNC_MMAP_SOURCE],
1608 [_INN_HEADER_SOURCE()]
1609 [[#include <fcntl.h>
1610 #include <sys/mman.h>
1611
1612 int
1613 main()
1614 {
1615   int *data, *data2;
1616   int i, fd;
1617
1618   /* First, make a file with some known garbage in it.  Use something
1619      larger than one page but still an odd page size. */
1620   data = malloc (20000);
1621   if (!data) return 1;
1622   for (i = 0; i < 20000 / sizeof (int); i++)
1623     data[i] = rand();
1624   umask (0);
1625   fd = creat ("conftestmmaps", 0600);
1626   if (fd < 0) return 1;
1627   if (write (fd, data, 20000) != 20000) return 1;
1628   close (fd);
1629
1630   /* Next, try to mmap the file and make sure we see the same garbage. */
1631   fd = open ("conftestmmaps", O_RDWR);
1632   if (fd < 0) return 1;
1633   data2 = mmap (0, 20000, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
1634   if (data2 == (int *) -1) return 1;
1635   for (i = 0; i < 20000 / sizeof (int); i++)
1636     if (data[i] != data2[i])
1637       return 1;
1638
1639   close (fd);
1640   unlink ("conftestmmaps");
1641   return 0;
1642 }]])
1643
1644
1645 dnl This portion is similar to what AC_FUNC_MMAP does, only it tests shared,
1646 dnl non-fixed mmaps.
1647 AC_DEFUN([INN_FUNC_MMAP],
1648 [AC_CACHE_CHECK(for working mmap, inn_cv_func_mmap,
1649 [AC_TRY_RUN(_INN_FUNC_MMAP_SOURCE(),
1650             inn_cv_func_mmap=yes,
1651             inn_cv_func_mmap=no,
1652             inn_cv_func_mmap=no)])
1653 if test $inn_cv_func_mmap = yes ; then
1654     AC_DEFINE(HAVE_MMAP)
1655 fi])
1656
1657 dnl Source used by INN_FUNC_MMAP_NEEDS_MSYNC.
1658 define([_INN_FUNC_MMAP_NEEDS_MSYNC_SOURCE],
1659 [_INN_HEADER_SOURCE()]
1660 [[#include <sys/types.h>
1661 #include <fcntl.h>
1662 #include <sys/mman.h>
1663
1664 int
1665 main()
1666 {
1667   int *data, *data2;
1668   int i, fd;
1669
1670   /* First, make a file with some known garbage in it.  Use something
1671      larger than one page but still an odd page size. */
1672   data = malloc (20000);
1673   if (!data) return 1;
1674   for (i = 0; i < 20000 / sizeof (int); i++)
1675     data[i] = rand();
1676   umask (0);
1677   fd = creat ("conftestmmaps", 0600);
1678   if (fd < 0) return 1;
1679   if (write (fd, data, 20000) != 20000) return 1;
1680   close (fd);
1681
1682   /* Next, try to mmap the file and make sure we see the same garbage. */
1683   fd = open ("conftestmmaps", O_RDWR);
1684   if (fd < 0) return 1;
1685   data2 = mmap (0, 20000, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
1686   if (data2 == (int *) -1) return 1;
1687
1688   /* Finally, see if changes made to the mmaped region propagate back to
1689      the file as seen by read (meaning that msync isn't needed). */
1690   for (i = 0; i < 20000 / sizeof (int); i++)
1691     data2[i]++;
1692   if (read (fd, data, 20000) != 20000) return 1;
1693   for (i = 0; i < 20000 / sizeof (int); i++)
1694     if (data[i] != data2[i])
1695       return 1;
1696
1697   close (fd);
1698   unlink ("conftestmmapm");
1699   return 0;
1700 }]])
1701
1702 dnl Check whether the data read from an open file sees the changes made to an
1703 dnl mmaped region, or if msync has to be called for other applications to see
1704 dnl those changes.
1705 AC_DEFUN([INN_FUNC_MMAP_NEEDS_MSYNC],
1706 [AC_CACHE_CHECK(whether msync is needed, inn_cv_func_mmap_need_msync,
1707 [AC_TRY_RUN(_INN_FUNC_MMAP_NEEDS_MSYNC_SOURCE(),
1708             inn_cv_func_mmap_need_msync=no,
1709             inn_cv_func_mmap_need_msync=yes,
1710             inn_cv_func_mmap_need_msync=yes)])
1711 if test $inn_cv_func_mmap_need_msync = yes ; then
1712     AC_DEFINE(MMAP_NEEDS_MSYNC, 1,
1713        [Define if you need to call msync for calls to read to see changes.])
1714 fi])
1715
1716 dnl Source used by INN_FUNC_MMAP_SEES_WRITES.
1717 define([_INN_FUNC_MMAP_SEES_WRITES_SOURCE],
1718 [[#include <stdlib.h>
1719 #include <sys/types.h>
1720 #include <sys/stat.h>
1721 #include <fcntl.h>
1722 #if HAVE_UNISTD_H
1723 # include <unistd.h>
1724 #endif
1725 #include <sys/mman.h>
1726
1727 /* Fractional page is probably worst case. */
1728 static char zbuff[1024];
1729 static char fname[] = "conftestw";
1730
1731 int
1732 main ()
1733 {
1734   char *map;
1735   int i, fd;
1736
1737   fd = open (fname, O_RDWR | O_CREAT, 0660);
1738   if (fd < 0) return 1;
1739   unlink (fname);
1740   write (fd, zbuff, sizeof (zbuff));
1741   lseek (fd, 0, SEEK_SET);
1742   map = mmap (0, sizeof (zbuff), PROT_READ, MAP_SHARED, fd, 0);
1743   if (map == (char *) -1) return 2;
1744   for (i = 0; fname[i]; i++)
1745     {
1746       if (write (fd, &fname[i], 1) != 1) return 3;
1747       if (map[i] != fname[i]) return 4;
1748     }
1749   return 0;
1750 }]])
1751
1752 dnl Check if an mmaped region will see writes made to the underlying file
1753 dnl without an intervening msync.
1754 AC_DEFUN([INN_FUNC_MMAP_SEES_WRITES],
1755 [AC_CACHE_CHECK(whether mmap sees writes, inn_cv_func_mmap_sees_writes,
1756 [AC_TRY_RUN(_INN_FUNC_MMAP_SEES_WRITES_SOURCE(),
1757             inn_cv_func_mmap_sees_writes=yes,
1758             inn_cv_func_mmap_sees_writes=no,
1759             inn_cv_func_mmap_sees_writes=no)])
1760 if test $inn_cv_func_mmap_sees_writes = no ; then
1761     AC_DEFINE(MMAP_MISSES_WRITES, 1,
1762               [Define if you need to call msync after writes.])
1763 fi])
1764
1765 dnl Check whether msync takes three arguments.  (It takes three arguments on
1766 dnl Solaris and Linux, two arguments on BSDI.)
1767 AC_DEFUN([INN_FUNC_MSYNC_ARGS],
1768 [AC_CACHE_CHECK(how many arguments msync takes, inn_cv_func_msync_args,
1769 [AC_TRY_COMPILE(
1770 [#include <sys/types.h>
1771 #include <sys/mman.h>],
1772                 [char *p; int psize; msync (p, psize, MS_ASYNC);],
1773                 inn_cv_func_msync_args=3,
1774                 inn_cv_func_msync_args=2)])
1775 if test $inn_cv_func_msync_args = 3 ; then
1776     AC_DEFINE(HAVE_MSYNC_3_ARG, 1,
1777               [Define if your msync function takes three arguments.])
1778 fi])
1779
1780 dnl Now that all the tests are set up, do the work of the mmap tests.
1781 INN_FUNC_MMAP
1782 if test x"$inn_cv_func_mmap" = xyes ; then
1783     AC_CHECK_FUNCS(madvise)
1784     INN_FUNC_MMAP_SEES_WRITES
1785     INN_FUNC_MMAP_NEEDS_MSYNC
1786     INN_FUNC_MSYNC_ARGS
1787 fi
1788
1789 dnl If AF_UNIX is set in <sys/socket.h>, assume we have Unix domain sockets.
1790 AC_DEFUN([INN_SYS_UNIX_SOCKETS],
1791 [AC_CACHE_CHECK([for Unix domain sockets], inn_cv_sys_unix_sockets,
1792 [AC_EGREP_CPP(yes,
1793 [#include <sys/socket.h>
1794 #ifdef AF_UNIX
1795 yes
1796 #endif],
1797               inn_cv_sys_unix_sockets=yes,
1798               inn_cv_sys_unix_sockets=no)])
1799 if test $inn_cv_sys_unix_sockets = yes ; then
1800     AC_DEFINE(HAVE_UNIX_DOMAIN_SOCKETS, 1,
1801               [Define if you have unix domain sockets.])
1802 fi])
1803 INN_SYS_UNIX_SOCKETS
1804
1805 dnl Determine the facility for syslog messages.  Default to LOG_NEWS for
1806 dnl syslog facility if it's available, but if it's not, fall back on
1807 dnl LOG_LOCAL1.  --with-syslog-facility may have already set this.
1808 AC_DEFUN([INN_LOG_FACILITY],
1809 [AC_MSG_CHECKING(log facility for news)
1810 AC_CACHE_VAL(inn_cv_log_facility,
1811 [AC_EGREP_CPP(yes,
1812 [#include <syslog.h>
1813 #ifdef LOG_NEWS
1814 yes
1815 #endif],
1816               inn_cv_log_facility=LOG_NEWS,
1817               inn_cv_log_facility=LOG_LOCAL1)])
1818 if test x"$SYSLOG_FACILITY" = xnone ; then
1819     SYSLOG_FACILITY=$inn_cv_log_facility
1820 fi
1821 AC_MSG_RESULT($SYSLOG_FACILITY)
1822 AC_DEFINE_UNQUOTED(LOG_INN_SERVER, $SYSLOG_FACILITY,
1823                    [Syslog facility to use for innd logs.])
1824 AC_DEFINE_UNQUOTED(LOG_INN_PROG, $SYSLOG_FACILITY,
1825                    [Syslog facility to use for INN program logs.])
1826 AC_SUBST(SYSLOG_FACILITY)])
1827 INN_LOG_FACILITY
1828
1829 dnl Clean up our LIBS, just for grins.
1830 LIBS=`echo "$LIBS" | sed 's/^  *//' | sed 's/   */ /g' | sed 's/  *$//'`
1831
1832 AC_CONFIG_HEADER(include/config.h)
1833 AC_OUTPUT(
1834         Makefile.global
1835         include/paths.h
1836         samples/inn.conf
1837         samples/innreport.conf
1838         samples/newsfeeds
1839         samples/sasl.conf
1840         scripts/inncheck
1841         scripts/innshellvars
1842         scripts/innshellvars.pl
1843         scripts/innshellvars.tcl
1844         scripts/news.daily
1845         support/fixscript
1846         ,
1847         chmod +x support/fixscript
1848 )
1849
1850 dnl Print out some additional information on what to check.
1851 cat <<EOM
1852
1853 Please check the following files before running make, to ensure that 
1854 everything was set correctly.
1855
1856         Makefile.global
1857         include/config.h
1858         include/paths.h
1859         innfeed/innfeed.h
1860
1861 EOM
1862
1863 dnl Finally, double-check the configured temporary directory.  Some people
1864 dnl point this at the system temporary directories or at other world-writeable
1865 dnl directories, which can be a local security hole.
1866 if $_PATH_PERL -e "exit((stat('$tmpdir'))[[2]] & 2)" > /dev/null ; then
1867     :
1868 else
1869     cat <<EOM
1870
1871 WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
1872
1873   The temporary directory you have configured is world-writeable.  It is
1874   currently set to $tmpdir.
1875
1876   This directory is used by INN for temporary files and should only be
1877   writeable by the news user.  INN does not go to great lengths to prevent
1878   symlink attacks and the like because it assumes this directory is not
1879   world-writeable.  By configuring INN in this fashion, you may be
1880   introducing a locally exploitable security hole.
1881
1882   It is STRONGLY recommended that you use a temporary directory reserved for
1883   INN's exclusive use, one which is not world-writeable.  You can do this
1884   either with --with-tmp-dir or by setting --prefix to something other than
1885   /usr or /.
1886
1887 EOM
1888 fi