[ci] Reduce log bloat for netbsd job
[xapian.git] / xapian-applications / omega / configure.ac
blob2610289877d093bc9100f0e9238b5b302462de29
1 dnl Process this file with autoconf to produce a configure script.
3 m4_define([project_version], [1.5.0])
4 AC_INIT([xapian-omega], project_version, [https://xapian.org/bugs])
5 AC_PREREQ([2.63])
6 AM_INIT_AUTOMAKE([1.13 -Wportability subdir-objects tar-ustar no-dist-gzip dist-xz])
8 AC_CONFIG_SRCDIR([omega.cc])
10 AC_CONFIG_HEADERS([config.h])
12 AC_CONFIG_MACRO_DIRS([m4])
14 AM_PROG_AR
16 dnl The AM_ICONV macro requires a stack of macros including AC_LIB_PROG_LD,
17 dnl which is just a copy of libtool's LT_PATH_LD with the name changed.
18 dnl We will already have run LT_PATH_LD, so make AC_LIB_PROG_LD a no-op
19 dnl as LT_PATH_LD will already have set the with_gnu_ld variable.
20 AC_DEFUN([AC_LIB_PROG_LD], [])
22 LT_PREREQ([2.2.6])
23 LT_INIT
25 dnl Only pass -no-undefined on platforms where it is required in order to link
26 dnl a shared library at all (Microsoft Windows is the main one) as it can cause
27 dnl problems on other platforms (e.g. Solaris with Sun CC in C++11 mode, though
28 dnl we don't support that compiler now as it lacks C++17 support).
29 NO_UNDEFINED=
30 if test unsupported = "$allow_undefined_flag" ; then
31   NO_UNDEFINED=-no-undefined
33 AC_SUBST(NO_UNDEFINED)
35 dnl disable "maintainer only" rules by default
36 AM_MAINTAINER_MODE
38 dnl Checks for programs.
39 AC_PROG_CXX
41 AC_CANONICAL_HOST
43 # Checked: dragonfly6.4 freebsd8.0 netbsd9.3 openbsd4.6 solaris2.9 solaris2.10
44 case $host_os in
45   linux* | k*bsd*-gnu | dragonfly* | freebsd* | netbsd* | openbsd* | solaris*)
46     dnl Vanilla libtool sets this to "unknown" which it then handles as "yes".
47     link_all_deplibs_CXX=no
48     ;;
49 esac
51 case $host_os in
52   linux*)
53     dnl Extract search path from ldconfig which is more reliable than the way
54     dnl vanilla libtool extracts them from ld.so.conf.
55     d=`/sbin/ldconfig -N -X -v 2>&AS_MESSAGE_LOG_FD|$SED 's,^\(/.*\):\( (.*)\)\?$,\1,p;d'|tr '\n' ' '`
56     test -z "$d" || sys_lib_dlsearch_path_spec=$d
57     ;;
58 esac
60 case $host in
61   *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
62     dnl On these platforms, libtool emits a warning if -no-install is passed,
63     dnl and uses -no-fast-install instead - the least ugly way to avoid that
64     dnl warnings seems to be to duplicate the above list of platforms from
65     dnl libtool and use -no-fast-install on them directly.
66     NO_INSTALL=-no-fast-install ;;
67   *)
68     NO_INSTALL=-no-install ;;
69 esac
70 AC_SUBST([NO_INSTALL])
72 dnl Probe for any options needed to enable C++17 support.
73 AX_CXX_COMPILE_STDCXX([17])
75 dnl Run tests using the C++ compiler.
76 AC_LANG([C++])
78 dnl Enable large file support if possible.
79 AC_SYS_LARGEFILE
81 dnl Test if the compiler works with $1 added to CXXFLAGS; if it does, add $1 to
82 dnl variable $2.  If the test passes, also do $3; if it fails, also do $4.
83 AC_DEFUN([XAPIAN_TEST_CXXFLAGS],
84   [
85   XTC_save_CXXFLAGS=$CXXFLAGS
86   CXXFLAGS="$CXXFLAGS $1"
87   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
88                     [CXXFLAGS=$XTC_save_CXXFLAGS
89                      $2="${$2} $1"
90                      $3],
91                     [CXXFLAGS=$XTC_save_CXXFLAGS
92                      $4])
93   ])
95 dnl Check for xapian-core.
96 XO_LIB_XAPIAN([], [],
97     [xapian-config]regexp(project_version,
98                           [^\([0-9]*\.[0-9]*[13579]\)\..*$], [-\1]))
99 XO_REQUIRE([1.4.0])
101 dnl We want XAPIAN_CXXFLAGS to be used for configure tests.
102 save_CXXFLAGS=$CXXFLAGS
103 CXXFLAGS="$CXXFLAGS $XAPIAN_CXXFLAGS"
105 dnl We need to specify the argument types for builtin functions, or else
106 dnl AC_CHECK_DECLS fails to detect them when the compiler is clang.
107 AC_CHECK_DECLS([__builtin_add_overflow(int, int, int*),
108                 __builtin_sub_overflow(int, int, int*),
109                 __builtin_mul_overflow(int, int, int*)], [], [], [ ])
110 AC_CHECK_DECLS([__builtin_bswap32(uint32_t)], [], [],
111                [#include <stdint.h>])
112 AC_CHECK_DECLS([_byteswap_ulong], [], [],
113                [#include <stdlib.h>])
114 AC_CHECK_DECLS([__builtin_expect(long, long)], [], [], [ ])
115 AC_CHECK_DECLS([_addcarry_u32(unsigned char, unsigned, unsigned, unsigned*),
116                 _addcarry_u64(unsigned char, unsigned __int64, unsigned __int64, unsigned __int64*),
117                 _subborrow_u32(unsigned char, unsigned, unsigned, unsigned*),
118                 _subborrow_u64(unsigned char, unsigned __int64, unsigned __int64, unsigned __int64*)],
119                [], [], [#include <intrin.h>])
121 dnl Check for time functions.
122 AC_FUNC_STRFTIME
123 AC_CHECK_FUNCS([clock_gettime sleep nanosleep gettimeofday ftime])
124 AC_CHECK_FUNCS([gmtime_r timegm])
126 case $host_os in
127   *mingw*)
128     AC_DEFINE([MINGW_HAS_SECURE_API], [1], [Define on mingw to get _s suffixed "secure" functions declared in headers])
129     ;;
130 esac
132 AC_ARG_ENABLE(documentation,
133   [AS_HELP_STRING([--enable-documentation], [enable make rules to rebuild documentation [default=maintainer-mode]])],
134   [case ${enableval} in
135     yes|no) ;;
136     *) AC_MSG_ERROR([bad value ${enableval} for --enable-documentation]) ;;
137   esac])
138 test -z "$enable_documentation" && enable_documentation=$USE_MAINTAINER_MODE
139 AM_CONDITIONAL(DOCUMENTATION_RULES, test x"$enable_documentation" = xyes)
140 AM_CONDITIONAL(MAINTAINER_NO_DOCS, test x"$USE_MAINTAINER_MODE$enable_documentation" = xyesno)
142 vpath_build=no
143 if test "`pwd`" != "`cd $srcdir;pwd`" ; then
144   vpath_build=yes
146 AM_CONDITIONAL([VPATH_BUILD], [test yes = "$vpath_build"])
148 dnl Check for headers.
149 AC_CHECK_HEADERS([strings.h sys/select.h], [], [], [ ])
150 AC_CHECK_HEADERS([sysexits.h sys/time.h]dnl
151                  [sys/resource.h sys/socket.h sys/sysctl.h vm/vm_param.h]dnl
152                  [sys/vmmeter.h sys/sysmp.h sys/sysinfo.h sys/pstat.h],
153                  [], [], [#include <sys/types.h>])
155 dnl Check for zlib.h.
156 AC_CHECK_HEADERS([zlib.h], [], [
157   AC_MSG_ERROR([zlib.h not found])
158   ], [ ])
160 dnl Check for zlibVersion in -lz.
161 SAVE_LIBS=$LIBS
162 LIBS=
163 dnl mingw build needs -lzlib or -lzdll.
164 AC_SEARCH_LIBS([zlibVersion], [z zlib zdll], [], [
165   AC_MSG_ERROR([zlibVersion() not found in -lz, -lzlib, or -lzdll (you  may need to install the zlib1g-dev or zlib-devel package)])
166   ])
167 ZLIB_LIBS=$LIBS
168 AC_SUBST([ZLIB_LIBS])
169 LIBS=$SAVE_LIBS
171 dnl POSIX requires setenv().  The final Unix-like platform without it seems
172 dnl to have been Solaris 9, which is now out of support.
174 dnl Microsoft don't provide setenv() and have marked putenv() as deprecated, so
175 dnl we use _putenv_s() to avoid deprecation warnings with MSVC.  It's also a
176 dnl more similar interface to setenv() so easier to implement a setenv() wrapper
177 dnl around.  We probe for both the function and a declaration since mingw
178 dnl doesn't currently (v3.20) declare it but it is present in the C runtime DLL
179 dnl so we can provide our own declaration to access it.
180 AC_CHECK_FUNCS([setenv _putenv_s])
181 AC_CHECK_DECLS([_putenv_s(const char*, const char*)], [], [],
182 [#include <stdlib.h>])
184 dnl See if we have closefrom(), or some functions that are useful to implement
185 dnl closefrom() on platforms which don't provide it.
186 AC_CHECK_FUNCS([closefrom getdirentries getrlimit])
188 if test $ac_cv_func_ftime = yes ; then
189   dnl See if ftime returns void (as it does on mingw)
190   AC_MSG_CHECKING([return type of ftime])
191   AC_COMPILE_IFELSE(
192     [AC_LANG_PROGRAM([[#include <sys/timeb.h>]],
193                      [[struct timeb tp; int i = ftime(&tp);]])],
194     [AC_MSG_RESULT([int])],
195     [AC_MSG_RESULT([void])
196     AC_DEFINE([FTIME_RETURNS_VOID], [1], [Define if ftime returns void])])
199 dnl mingw (for instance) lacks ssize_t
200 AC_TYPE_SSIZE_T
202 AC_TYPE_PID_T
204 AC_TYPE_MODE_T
206 XAPIAN_TYPE_SOCKLEN_T
208 dnl Used by omegatest to skip some testcases with 32-bit time_t.
209 AC_CHECK_SIZEOF([time_t], [#include <time.h>])
211 dnl Use for Unix permission checks.
212 AC_CHECK_FUNCS([getgrouplist])
214 dnl See if getgrouplist() takes gid_t * (e.g. Linux) or int * (e.g. macOS).
215 if test $ac_cv_func_getgrouplist = yes ; then
216   AC_COMPILE_IFELSE(
217     [AC_LANG_PROGRAM([[#include <grp.h>
218 #include <unistd.h>]],
219                      [[int g[10]; int n = 10; return getgrouplist("root", 1, g, &n) == -1;]])],
220     [AC_DEFINE([GETGROUPLIST_TAKES_INT_P], 1, [Define if getgrouplist takes int *])],
221     [])
224 dnl Check for lstat() (not available under mingw for example).
225 AC_CHECK_FUNCS(lstat)
227 dnl Add in portable replacement for mkdtemp() on platforms which lack it.
228 AC_CHECK_FUNCS(mkdtemp)
229 AM_CONDITIONAL(NEED_MKDTEMP, [test yes != "$ac_cv_func_mkdtemp"])
231 dnl Add in portable replacement for strptime() on platforms which lack it.
232 AC_CHECK_FUNCS(strptime)
233 AM_CONDITIONAL(NEED_STRPTIME, [test yes != "$ac_cv_func_strptime"])
235 AC_CHECK_FUNCS([posix_fadvise])
237 dnl omindex uses fork(), socketpair(), setrlimit() and alarm() to impose resource
238 dnl limits on filter programs and workers.
239 AC_CHECK_FUNCS([mmap fork setrlimit sysmp pstat_getdynamic setpgid sigaction alarm])
240 AC_CHECK_FUNCS([waitpid])
242 dnl -lxnet is needed on Solaris and apparently on HP-UX too.
243 AC_SEARCH_LIBS([socketpair], [xnet],
244   [AC_DEFINE(HAVE_SOCKETPAIR, 1,
245     [Define to 1 if you have the 'socketpair' function])])
247 dnl fnmatch() is used to match ignore pattern.
248 AC_CHECK_FUNCS([fnmatch])
250 OMINDEX_MODULES=""
252 dnl check if poppler is available.
253 PKG_CHECK_MODULES([POPPLER], [poppler-glib >= 0.16], [
254     AC_DEFINE(HAVE_POPPLER, 1, [Define HAVE_POPPLER if the library is available])
255     OMINDEX_MODULES="$OMINDEX_MODULES omindex_poppler"],[ ])
257 dnl check if libe-book is available.
258 PKG_CHECK_MODULES([LIBEBOOK], [libe-book-0.1,librevenge-0.0,librevenge-generators-0.0,librevenge-stream-0.0], [
259     AC_DEFINE(HAVE_LIBEBOOK, 1, [Define HAVE_LIBEBOOK if the library is available])
260     OMINDEX_MODULES="$OMINDEX_MODULES omindex_libebook"],[ ])
262 dnl check if libetonyek is available.
263 PKG_CHECK_MODULES([LIBETONYEK], [libetonyek-0.1,librevenge-0.0,librevenge-generators-0.0,librevenge-stream-0.0], [
264     AC_DEFINE(HAVE_LIBETONYEK, 1, [Define HAVE_LIBETONYEK if the library is available])
265     OMINDEX_MODULES="$OMINDEX_MODULES omindex_libetonyek"],[ ])
267 dnl check if libgepub is available.
268 PKG_CHECK_MODULES([LIBGEPUB], [libgepub-0.7], [
269     AC_DEFINE(HAVE_LIBGEPUB, 1, [Define HAVE_LIBGEPUB if the library is available])
270     OMINDEX_MODULES="$OMINDEX_MODULES omindex_libgepub"],
271     [PKG_CHECK_MODULES([LIBGEPUB], [libgepub-0.6], [
272         AC_DEFINE(HAVE_LIBGEPUB, 1, [Define HAVE_LIBGEPUB if the library is available])
273         OMINDEX_MODULES="$OMINDEX_MODULES omindex_libgepub"],[ ])])
275 dnl check if libtesseract is available.
276 PKG_CHECK_MODULES([TESSERACT], [tesseract, lept], [
277     AC_DEFINE(HAVE_TESSERACT, 1, [Define HAVE_TESSERACT if the library is available])
278     OMINDEX_MODULES="$OMINDEX_MODULES omindex_tesseract"],[ ])
280 dnl Check if gmime is available, using gmime-3.0 in preference.
281 PKG_CHECK_MODULES([GMIME], [gmime-3.0, glib-2.0], [
282     AC_DEFINE(HAVE_GMIME, 1, [Define HAVE_GMIME if the library is available])
283     OMINDEX_MODULES="$OMINDEX_MODULES omindex_gmime"],
284     [PKG_CHECK_MODULES([GMIME], [gmime-2.6, glib-2.0], [
285         AC_DEFINE(HAVE_GMIME, 1, [Define HAVE_GMIME if the library is available])
286         OMINDEX_MODULES="$OMINDEX_MODULES omindex_gmime"],[ ])])
288 dnl check if libarchive is available.
289 PKG_CHECK_MODULES([LIBARCHIVE], [libarchive], [
290     AC_DEFINE(HAVE_LIBARCHIVE, 1, [Define HAVE_LIBARCHIVE if the library is available])
291     OMINDEX_MODULES="$OMINDEX_MODULES omindex_libarchive"],[ ])
293 dnl check if libabw is available.
294 PKG_CHECK_MODULES([LIBABW], [libabw-0.1,librevenge-0.0,librevenge-generators-0.0,librevenge-stream-0.0], [
295     AC_DEFINE(HAVE_LIBABW, 1, [Define HAVE_LIBABW if the library is available])
296     OMINDEX_MODULES="$OMINDEX_MODULES omindex_libabw"],[ ])
298 dnl check if libcdr is available.
299 PKG_CHECK_MODULES([LIBCDR], [libcdr-0.1,librevenge-0.0,librevenge-generators-0.0,librevenge-stream-0.0], [
300     AC_DEFINE(HAVE_LIBCDR, 1, [Define HAVE_LIBCDR if the library is available])
301     OMINDEX_MODULES="$OMINDEX_MODULES omindex_libcdr"],[ ])
303 dnl check if libextractor is available.
304 PKG_CHECK_MODULES([LIBEXTRACTOR], [libextractor], [
305     AC_DEFINE(HAVE_LIBEXTRACTOR, 1, [Define HAVE_LIBEXTRACTOR if the library is available])
306     OMINDEX_MODULES="$OMINDEX_MODULES omindex_libextractor"],[ ])
308 dnl check if libmwaw is available.
309 PKG_CHECK_MODULES([LIBMWAW], [libmwaw-0.3,librevenge-0.0,librevenge-generators-0.0,librevenge-stream-0.0], [
310     AC_DEFINE(HAVE_LIBMWAW, 1, [Define HAVE_LIBMWAW if the library is available])
311     OMINDEX_MODULES="$OMINDEX_MODULES omindex_libmwaw"],[ ])
313 dnl Check if libreofficekit is available.  It's know to be broken on macOS
314 dnl so avoid trying to use it there as it only fails at runtime:
315 dnl https://bugs.documentfoundation.org/show_bug.cgi?id=145127
316 LIBREOFFICEKIT_LIBS=
317 case $host_vendir-$host_os in
318   apple-darwin*) ;;
319   *)
320     AC_CHECK_HEADERS([LibreOfficeKit/LibreOfficeKit.hxx], [
321       if test x"$LO_INCLUDE_PATH" != x ; then
322         LIBREOFFICEKIT_CPPFLAGS="-I'$LO_INCLUDE_PATH'"
323         AC_SUBST([LIBREOFFICEKIT_CPPFLAGS])
324       fi
325       save_LIBS=$LIBS
326       dnl LibreOfficeKit/LibreOfficeKitInit.h has inline code which calls dlopen()
327       dnl (unless _WIN32 or IOS is defined).
328       AC_SEARCH_LIBS([dlopen], [dl], [LIBREOFFICEKIT_LIBS=-ldl])
329       LIBS=$save_LIBS
330       OMINDEX_MODULES="$OMINDEX_MODULES omindex_libreofficekit"
331   ], [], [ ])
332     ;;
333 esac
334 AC_SUBST([LIBREOFFICEKIT_LIBS])
335 dnl Allow easy building against uninstalled LibreOffice.
336 AC_ARG_VAR([LO_INCLUDE_PATH], [Path to directory containing LibreOffice headers])
338 AC_SUBST([OMINDEX_MODULES])
340 AC_CHECK_MEMBERS([struct tm.tm_gmtoff], [], [], [#include <time.h>])
342 AC_ARG_WITH(iconv,
343 [AS_HELP_STRING([--with-iconv], [force use of iconv (error if not found)])
344 AS_HELP_STRING([--without-iconv], [don't use iconv])],
345   [with_iconv=$withval], [with_iconv=auto])
347 if test no != "$with_iconv" ; then
348   dnl AM_ICONV modifies CPPFLAGS if it succeeds which is undesirable (configure
349   dnl shouldn't modify user variables like CPPFLAGS) so save and restore
350   dnl CPPFLAGS around it.  We then add INCICONV where needed instead.
351   save_CPPFLAGS=$CPPFLAGS
352   AM_ICONV
353   CPPFLAGS=$save_CPPFLAGS
354   AC_SUBST([INCICONV])
355   if test yes = "$with_iconv" && test yes != "$am_cv_func_iconv" ; then
356     AC_MSG_ERROR([iconv not found, but --with-iconv specified])
357   fi
360 dnl Check processor endianness.
361 AC_C_BIGENDIAN
363 dnl Check for perl.  Needed for outlookmsg2html script and omegatest.pl.
364 dnl (And in maintainer-mode, also to make man pages from "--help" output, and
365 dnl to make the omegascript vim syntax mode.)
366 AC_PATH_PROG(PERL, perl, [])
367 AC_ARG_VAR([PERL], [Perl interpreter])
368 test -z "$PERL" && AC_MSG_ERROR([perl is required])
370 if test x"$enable_documentation" = xyes; then
371   dnl Check for help2man. (Needed to make man pages from "--help" output).
372   AC_PATH_PROG(HELP2MAN, help2man, [])
373   AC_ARG_VAR([HELP2MAN], [help2man man page generator])
374   test -z "$HELP2MAN" && AC_MSG_ERROR([help2man is required to build documentation])
376   dnl Check for rst2html. (Needed to make HTML from reStructuredText format)
377   dnl Also look for rst2html.py, which archlinux reportedly installs it as.
378   AC_PATH_PROGS(RST2HTML, [rst2html rst2html.py], [])
379   AC_ARG_VAR([RST2HTML], [reST to HTML convertor])
380   test -z "$RST2HTML" && AC_MSG_ERROR([rst2html is required to build documentation])
383 AC_ARG_VAR(PKG_CONFIG, [Location of pkg-config])
384 AC_PATH_TOOL(PKG_CONFIG, [pkg-config], [])
386 dnl libmagic used to detect MIME types for files we don't detect by extension.
387 MAGIC_LIBS=
388 if test -n "$PKG_CONFIG" ; then
389   MAGIC_CFLAGS=`$PKG_CONFIG libmagic --cflags 2>/dev/null`
390   MAGIC_LIBS=`$PKG_CONFIG libmagic --libs 2>/dev/null`
392 if test -z "$MAGIC_LIBS" ; then
393   MAGIC_CFLAGS=
394   AC_CHECK_HEADERS([magic.h])
395   if test $ac_cv_header_magic_h = yes ; then
396     dnl On mingw there are several dependent libraries, so AC_CHECK_LIB would
397     dnl fail - we'd have to use LT_OUTPUT and then perform the test link with
398     dnl libtool, but we've checked for magic.h, so checking the library would
399     dnl not really gain us much - we know it is -lmagic.
400     MAGIC_LIBS=-lmagic
401   fi
403 if test -z "$MAGIC_LIBS" ; then
404   if test -r /etc/debian_version ; then
405     pkg="libmagic-dev"
406   else
407     pkg="file-devel (or maybe libmagic-devel)"
408   fi
409   AC_MSG_ERROR([libmagic required but development files not found.  If you're installing from packages, you probably need to install a package called something like $pkg in order to be able to build $PACKAGE_NAME.])
411 AC_SUBST([MAGIC_CFLAGS])
412 AC_SUBST([MAGIC_LIBS])
414 pcre_runtime_installed() {
415   dnl Simple check to see if the problem is likely to be that we're using a
416   dnl "packaged" pcre but only have the runtime package installed.
417   for sfx in '' 32 64 ; do
418     set /usr/lib$sfx/libpcre2-*.so.*
419     if test "/usr/lib$sfx/libpcre2-*.so.*" != "$1" ; then
420       if test -r /etc/debian_version ; then
421         pkg="libpcre2-dev"
422       else
423         pkg="pcre2-devel"
424       fi
425       AS_SET_STATUS([0])
426     fi
427   done
428   AS_SET_STATUS([1])
431 PCRE2_LIBS_FLAG=--libs8
432 AC_ARG_VAR(PCRE2_CONFIG, [Location of pcre2-config])
433 if test -z "$PCRE2_CONFIG" ; then
434   if test -n "$PKG_CONFIG" ; then
435     pcre_try="$PKG_CONFIG libpcre2-8"
436     if $pcre_try 2>/dev/null ; then
437       PCRE2_CONFIG=$pcre_try
438       PCRE2_LIBS_FLAG=--libs
439     else
440       if pcre_runtime_installed ; then
441         AC_MSG_ERROR(['$pcre_try' failed, but the PCRE2 runtime library seems to be installed.  If you've installed PCRE2 from a package, you probably need to install an extra package called something like $pkg in order to be able to build $PACKAGE_NAME.])
442       else
443         AC_MSG_ERROR(['$pcre_try' failed.  If the PCRE2 library is installed, you need to add PCRE2_CONFIG=/path/to/pcre2-config to your configure command.])
444       fi
445     fi
446   else
447     dnl Fall back to looking for pcre2-config, but that's not installed on PATH
448     dnl with the platform tuple prefixed (at least under MXE), so preferring
449     dnl 'pkg-config libpcre2' works better when cross-compiling.
450     AC_PATH_TOOL(PCRE2_CONFIG, [pcre2-config])
451     if test -z $PCRE2_CONFIG ; then
452       if pcre_runtime_installed ; then
453         AC_MSG_ERROR([Can't find pcre2-config, although the PCRE2 runtime library seems to be installed.  If you've installed PCRE2 from a package, you probably need to install an extra package called something like $pkg in order to be able to build $PACKAGE_NAME.])
454       else
455         AC_MSG_ERROR([Can't find pcre2-config.  If the PCRE2 library is installed, you need to add PCRE2_CONFIG=/path/to/pcre2-config to your configure command.])
456       fi
457     fi
458   fi
460 PCRE2_CFLAGS=`$PCRE2_CONFIG --cflags`
461 PCRE2_LIBS=`$PCRE2_CONFIG $PCRE2_LIBS_FLAG`
462 AC_SUBST(PCRE2_CFLAGS)
463 AC_SUBST(PCRE2_LIBS)
465 dnl If eatmydata is installed, we run the testsuite under it to speed it up.
466 dnl If EATMYDATA is set to an empty value, then skip this check and don't use
467 dnl eatmydata.
468 if test -n "${EATMYDATA-unset}" ; then
469   AC_PATH_PROG([EATMYDATA], [eatmydata], [])
470   AC_ARG_VAR([EATMYDATA], [wrapper to disable fsync (optionally used by test harness)])
473 AC_MSG_CHECKING([for /dev/stdin])
474 if test -c /dev/stdin && (echo hello|$GREP hello /dev/stdin >&AS_MESSAGE_LOG_FD 2>&1); then
475   AC_MSG_RESULT([yes])
476   AC_DEFINE([HAVE_DEV_STDIN], [1], [Define to 1 if you have the '/dev/stdin' special file])
477 else
478   AC_MSG_RESULT([no])
481 dnl ******************************
482 dnl * Set special compiler flags *
483 dnl ******************************
485 AC_ARG_ENABLE([werror],
486   [AS_HELP_STRING([--enable-werror], [enable treating compiler warnings as errors [default=maintainer-mode]])],
487   [case ${enableval} in
488     yes|no) ;;
489   *) AC_MSG_ERROR([bad value ${enableval} for --enable-werror]) ;;
490   esac],
491   [enable_werror=$USE_MAINTAINER_MODE])
493 dnl Put -Werror or equivalent in its own make variable so that it can easily
494 dnl be overridden by `make WERROR=` if needed during development (e.g. if
495 dnl you want to get a full list of compile warnings to fix rather than
496 dnl stopping at the first file with warnings).
497 WERROR=
498 AC_SUBST([WERROR])
500 dnl Set flags to control warnings (enable more, or disable annoying ones).
501 if test yes = "$GXX"; then
502   dnl Intel's C++ compiler and clang both lie and define __GNUC__, so check which
503   dnl we actually have, as neither is really 100% compatible.
504   echo __INTEL_COMPILER __clang__ > conftest.cc
505   case `$CXX -E conftest.cc 2>&AS_MESSAGE_LOG_FD|grep -v '^#'` in
506     *__INTEL_COMPILER*__clang__*)
507       dnl GCC (since neither substituted):
509       dnl The exact format of g++ --version seems to change with almost every
510       dnl minor release so use the preprocessor macros which should be more
511       dnl robust.  Pass -xc++ to avoid warnings about any command-line options
512       dnl included in $CXX which aren't valid for C (such as -std=c++17).
513       AC_MSG_CHECKING([for version of $CXX])
514       gxx_version=`echo __GNUC__.__GNUC_MINOR__.__GNUC_PATCHLEVEL__|$CXX -xc++ -E -|sed '/^#/d;s/ //g'`
515       AC_MSG_RESULT([GCC $gxx_version])
517       dnl -Wundef was supported by g++ 3.0.
518       dnl
519       dnl -Wlogical-op and -Wmissing-declarations (for C++) were added in
520       dnl GCC 4.3.
521       dnl
522       dnl -Wdouble-promotion was added in GCC 4.6.
523       dnl
524       dnl -Wduplicated-cond was added in GCC 6.
525       dnl
526       dnl -Wduplicated-branches was added in GCC 7.
527       dnl
528       dnl All the other options were supported by g++ 2.95.
529       AM_CXXFLAGS="$AM_CXXFLAGS -Wall -W -Wredundant-decls -Wpointer-arith -Wcast-qual -Wcast-align -Wformat-security -fno-gnu-keywords -Wundef -Woverloaded-virtual -Wstrict-null-sentinel -Wshadow -Wstrict-overflow=1 -Wlogical-op -Wmissing-declarations -Wdouble-promotion -Wduplicated-cond -Wduplicated-branches"
531       case $gxx_version in
532       [[0-6]].*)
533         AC_MSG_ERROR([Xapian requires GCC 7.0 or later])
534         ;;
535       esac
537       dnl FIXME:
538       dnl -Wold-style-cast is interesting, but triggers for macros from
539       dnl system headers (e.g. FD_SET).  GCC 4.8 improved this by making
540       dnl -ftrack-macro-expansion=2 the default, but we still see such
541       dnl warnings on some platforms for some reason (e.g. Cygwin with GCC
542       dnl 5.4.0 warns about FD_SET, and on Debian with GCC 4.9.2 we see
543       dnl warnings from zlib.h).
545       WERROR=-Werror
546       ;;
547     *__clang__*)
548       dnl Intel's compiler (since __clang__ not substituted):
549       dnl
550       dnl -w1 stops the avalanche of uninteresting "remark" messages.
551       dnl -wd... disables warnings which don't have good code workarounds.
552       AM_CXXFLAGS="$AM_CXXFLAGS -Wall -w1 -wd177,1572"
554       WERROR=-Werror
555       ;;
556     *__INTEL_COMPILER*)
557       dnl clang (since __INTEL_COMPILER not substituted):
559       dnl These options all work at least as far back as clang++ 3.0:
560       AM_CXXFLAGS="$AM_CXXFLAGS -Wall -W -Wredundant-decls -Wpointer-arith -Wcast-qual -Wcast-align -Wformat-security -fno-gnu-keywords -Wundef -Woverloaded-virtual -Wshadow -Wstrict-overflow=1 -Wmissing-declarations -Winit-self"
562       WERROR=-Werror
563       ;;
564   esac
565   rm -f conftest.cc
566 elif test yes = "$msvc"; then
567   dnl -W1 is command-line default, -W3 IDE default, -W4 highest numbered level.
568   dnl AM_CXXFLAGS="$AM_CXXFLAGS -W4"
570   WERROR=-WX
573 AC_MSG_CHECKING([for option to turn warnings into errors])
574 if test x$enable_werror != xyes; then
575   WERROR=
576   AC_MSG_RESULT([not requested])
577 elif test -z "$WERROR" ; then
578   AC_MSG_RESULT([unknown for $CXX])
579 else
580   AC_MSG_RESULT([$WERROR])
583 if test "$GXX" = yes; then
584   dnl Default to enabling _FORTIFY_SOURCE at level 2.  It shouldn't cause a
585   dnl problem to define it where it's not supported, but we need to check for
586   dnl an issue on mingw-w64 where some versions required linking with -lssp
587   dnl (this was fixed in v11.0.0 released 2023-04-28).  We detect this with a
588   dnl configure-time link test and don't auto-enable _FORTIFY_SOURCE if using
589   dnl an affected version.
590   AC_MSG_CHECKING([if _D_FORTIFY_SOURCE=2 links without extra libraries])
591   save_CPPFLAGS=$CPPFLAGS
592   CPPFLAGS="$CPPFLAGS -D_FORTIFY_SOURCE=2"
593   AC_LINK_IFELSE([AC_LANG_PROGRAM([[
594     #include <string.h>
595     static char a[20], b[10];]], [[
596     strcpy(a, b);
597     ]])],
598     [AC_MSG_RESULT([yes])
599     AC_DEFINE([FORTIFY_SOURCE_OK], [1], [Define to 1 if '-D_FORTIFY_SOURCE=2' link test passes])],
600     [AC_MSG_RESULT([no])])
601   CPPFLAGS=$save_CPPFLAGS
604 AH_BOTTOM(
605 [/* Disable stupid MSVC "performance" warning for converting int to bool. */
606 #ifdef _MSC_VER
607 # pragma warning(disable:4800)
608 #endif
610 /* MSVC defines _WIN32 but not __WIN32__. */
611 #if !defined __WIN32__ && defined _WIN32
612 # define __WIN32__
613 #endif
615 /* MSVC defines _WIN64 but not __WIN64__. */
616 #if !defined __WIN64__ && defined _WIN64
617 # define __WIN64__
618 #endif
620 /* Default to enabling _FORTIFY_SOURCE at level 2 for GCC-like compilers.  It
621  * shouldn't cause a problem to define it where it's not supported.
623  * The FORTIFY_SOURCE_OK check avoids auto-enabling on some mingw-w64 versions
624  * which required linking with -lssp too.  This was addressed in v11.0.0
625  * (released 2023-04-28).
627  * Check if _FORTIFY_SOURCE is already defined to allow the user to override
628  * our choice with "./configure CPPFLAGS=-D_FORTIFY_SOURCE=0" or "...=1" or
629  * "...=3".
630  */
631 #if defined FORTIFY_SOURCE_OK && !defined _FORTIFY_SOURCE
632 # define _FORTIFY_SOURCE 2
633 #endif
635 /* For compilers which support it (such as GCC, clang, Intel's C++ compiler)
636  * we can use __builtin_expect to give the compiler hints about branch
637  * prediction.  See HACKING for how to use these.
638  */
639 #if HAVE_DECL___BUILTIN_EXPECT
640 /* The arguments of __builtin_expect() are both long, so use !! to ensure that
641  * the first argument is always an integer expression, and always 0 or 1, but
642  * still has the same truth value for the if or while it is used in.
643  */
644 # define rare(COND) __builtin_expect(!!(COND), 0)
645 # define usual(COND) __builtin_expect(!!(COND), 1)
646 #else
647 # define rare(COND) (COND)
648 # define usual(COND) (COND)
649 #endif
651 /* This macro can be used around expressions which intentionally make use of
652  * unsigned integer overflow (which is defined behaviour, unlike signed integer
653  * overflow) so that we can use UBSan's optional unsigned-integer-overflow
654  * check to find potential bugs where we unintentionally overflow an unsigned
655  * integer.
656  */
657 #ifdef __clang__
658 #define UNSIGNED_OVERFLOW_OK(X) \
659     ([&]() __attribute__((no_sanitize("unsigned-integer-overflow"))) {\
660         return (X);\
661     }())
662 #else
663 # define UNSIGNED_OVERFLOW_OK(X) (X)
664 #endif
667 AC_SUBST([AM_CXXFLAGS])
669 dnl Restore CXXFLAGS to those the user specified or autoconf defaulted to.
670 CXXFLAGS=$save_CXXFLAGS
672 dnl Required for auto regeneration to work in a combined maintainer-mode tree.
673 : ${AUTOM4TE=autom4te}
674 AC_SUBST([AUTOM4TE])
676 dnl **************************
677 dnl * Build the output files *
678 dnl **************************
680 AC_CONFIG_FILES([
681  Makefile
682  docs/Makefile
683  ])
684 dnl Allow AC_CONFIG_FILES with chmod +x without having to repeat the filename.
685 AC_DEFUN([SCRIPT_TEMPLATE], [AC_CONFIG_FILES([$1], [chmod +x "$1"])])
686 SCRIPT_TEMPLATE([makemanpage])
687 SCRIPT_TEMPLATE([mhtml2html])
688 SCRIPT_TEMPLATE([outlookmsg2html])
689 SCRIPT_TEMPLATE([rfc822tohtml])
690 SCRIPT_TEMPLATE([vcard2text])
691 AC_OUTPUT