Get kill_remote() to work in shared Microsoft Windows build
[xapian.git] / xapian-core / configure.ac
blob3ac6a24cbaadd290312f3c2c85a06fad8c470c02
1 dnl Process this file with autoconf to produce a configure script.
3 dnl NB When updating the version for a release, update LIBRARY_VERSION_INFO
4 dnl below too.
5 AC_INIT([xapian-core], [1.5.0], [https://xapian.org/bugs])
6 dnl See HACKING document for details of the reasons for required versions.
7 AC_PREREQ([2.64])
8 dnl Extract from the libtool info manual:
9 dnl
10 dnl Here are a set of rules to help you update your library version information:
11 dnl
12 dnl 1. Start with version information of '0:0:0' for each libtool library.
13 dnl
14 dnl 2. Update the version information only immediately before a public
15 dnl    release of your software.  More frequent updates are unnecessary,
16 dnl    and only guarantee that the current interface number gets larger
17 dnl    faster.
18 dnl
19 dnl 3. If the library source code has changed at all since the last
20 dnl    update, then increment REVISION ('C:R:A' becomes 'C:r+1:A').
21 dnl
22 dnl 4. If any interfaces have been added, removed, or changed since the
23 dnl    last update, increment CURRENT, and set REVISION to 0.
24 dnl
25 dnl 5. If any interfaces have been added since the last public release,
26 dnl    then increment AGE.
27 dnl
28 dnl 6. If any interfaces have been removed since the last public release
29 dnl    then set AGE to 0.
30 dnl
31 dnl LIBRARY_VERSION_INFO for libxapian1.5
32 dnl 0:0:0 1.5.0 Reset as library renamed
33 LIBRARY_VERSION_INFO=0:0:0
34 AC_SUBST([LIBRARY_VERSION_INFO])
36 LIBRARY_VERSION_SUFFIX=
37 dnl Where xapian.h, etc go.
38 incdir=$includedir
39 case $PACKAGE_VERSION in
40   [*.*[13579].*])
41     dnl Development release series:
42     [dev_series=`echo "$PACKAGE_VERSION"|sed 's/\.[^.]*$//'`]
44     dnl Append version installed programs by default.  To specify no suffix,
45     dnl configure with: --program-suffix=
46     test x"$program_suffix" != xNONE || program_suffix=-$dev_series
48     incdir=$incdir/xapian-$dev_series
50     LIBRARY_VERSION_SUFFIX=-$dev_series
51     ;;
52 esac
54 AC_SUBST([LIBRARY_VERSION_SUFFIX])
55 AC_SUBST([incdir])
57 dnl Check the build directory doesn't contain a space, so we die early with
58 dnl a helpful error.
59 case `pwd` in
60 *' '*)
61    AC_MSG_ERROR([You can't build in a directory whose path contains a space])
62    ;;
63 esac
65 dnl Check the source directory doesn't contain a space, so we die early with
66 dnl a helpful error.  FIXME: Unfortunately, configure seems to choke before
67 dnl it gets to us so this code doesn't get a chance to fire.
68 case $0 in
69 *' '*)
70    dnl Note: for in-tree builds, the build directory test above will fire
71    dnl before this can.
72    AC_MSG_ERROR([You can't build with sources in a directory whose path contains a space])
73    ;;
74 esac
76 dnl Check the prefix to install in doesn't contain a space, so we die early with
77 dnl a helpful error.
78 case $prefix in
79 *' '*)
80    AC_MSG_ERROR([You can't install in a directory whose path contains a space])
81    ;;
82 esac
84 dnl Note if the user specified a particular C++ compiler so we can give a more
85 dnl appropriate error message if we can't link a simple C++ program.
86 original_CXX=
87 if test -n "$CXX" ; then
88   original_CXX="CXX=$CXX"
89 elif test -n "$CCC" ; then
90   original_CXX="CCC=$CCC"
93 dnl See HACKING document for details of the reasons for required versions.
94 AM_INIT_AUTOMAKE([1.13 -Wportability tar-ustar no-dist-gzip dist-xz std-options])
95 AC_CONFIG_SRCDIR([matcher/andpostlist.cc])
97 AC_CONFIG_HEADERS([config.h])
99 AC_CONFIG_MACRO_DIRS([m4])
101 AM_PROG_AR
103 dnl Use libtool to manage our libraries.
104 LT_PREREQ([2.2.8])
105 dnl Default to only building shared libraries.
107 dnl Building both shared and static means having to compile the files which
108 dnl make up the library twice on most platforms.  Shared libraries are the
109 dnl better option for most users, and if anyone really wants static libraries,
110 dnl they can configure with --enable-static (or --enable-static=xapian-core if
111 dnl configuring a combined tree with the bindings).
113 dnl We don't export any data items from the library, so it should be safe to
114 dnl enable win32-dll without decorating any declarations specially.
115 LT_INIT([disable-static win32-dll])
117 dnl Only pass -no-undefined on platforms where it is required in order to link
118 dnl a shared library at all (Microsoft Windows is the main one) as it can cause
119 dnl problems on other platforms (e.g. Solaris with Sun CC in C++11 mode, though
120 dnl we don't support that compiler now as it lacks C++17 support).
121 NO_UNDEFINED=
122 if test unsupported = "$allow_undefined_flag" ; then
123   NO_UNDEFINED=-no-undefined
125 AC_SUBST(NO_UNDEFINED)
127 AM_CXXFLAGS=
129 dnl A standard "gotcha" for mingw and cygwin users is to not set up their
130 dnl PATH correctly, so that MSDOS FIND.EXE is found before Unix find.  Help
131 dnl them out by checking for this condition, rather than letting libtool
132 dnl fail in obscure ways.  NB check the *BUILD* OS, not the host one!
133 case $build_os in
134   cygwin* | mingw* | msys* | pw32*)
135     find /dirunlikelytoexist >/dev/null 2>&1
136     if test $? = 2 ; then
137         dnl Unix find will return 1 if the directory didn't exist, or 0 if
138         dnl it did.
139         AC_MSG_ERROR([
140 *** You appear to have an MSDOS-like FIND.EXE in your PATH ahead of any
141 *** UNIX-like find.  This misconfiguration will confuse libtool - you'll need
142 *** to make sure you have a UNIX-like find installed and fix your PATH, then
143 *** rerun configure.  For more information, see:
145 ***   https://www.cygwin.com/faq/faq.html#faq.using.find
147     fi
148   ;;
149 esac
151 dnl Add parameters for aclocal
152 dnl (This must come after AM_INIT_AUTOMAKE, since it modifies ACLOCAL)
153 ACLOCAL="$ACLOCAL $ACLOCAL_FLAGS"
155 dnl disable "maintainer only" rules by default
156 AM_MAINTAINER_MODE
158 dnl Checks for programs.
159 AC_PROG_CXX
161 AC_CANONICAL_HOST
163 # Checked: dragonfly6.4 freebsd8.0 netbsd9.3 openbsd4.6 solaris2.9 solaris2.10
164 case $host_os in
165   linux* | k*bsd*-gnu | dragonfly* | freebsd* | netbsd* | openbsd* | solaris*)
166     dnl Vanilla libtool sets this to "unknown" which it then handles as "yes".
167     link_all_deplibs_CXX=no
168     ;;
169 esac
171 case $host_os in
172   linux*)
173     dnl Extract search path from ldconfig which is more reliable than the way
174     dnl vanilla libtool extracts them from ld.so.conf.
175     d=`/sbin/ldconfig -N -X -v 2>&AS_MESSAGE_LOG_FD|$SED 's,^\(/.*\):\( (.*)\)\?$,\1,p;d'|tr '\n' ' '`
176     test -z "$d" || sys_lib_dlsearch_path_spec=$d
177     ;;
178 esac
180 case $host in
181   *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
182     dnl On these platforms, libtool emits a warning if -no-install is passed,
183     dnl and uses -no-fast-install instead - the least ugly way to avoid that
184     dnl warnings seems to be to duplicate the above list of platforms from
185     dnl libtool and use -no-fast-install on them directly.
186     NO_INSTALL=-no-fast-install ;;
187   *)
188     NO_INSTALL=-no-install ;;
189 esac
190 AC_SUBST([NO_INSTALL])
192 dnl For reasons which are beyond me, if autoconf can't find a C++ compiler
193 dnl it will set CXX to g++ (which obviously won't work) rather than actually
194 dnl telling the user that it couldn't find a C++ compiler and telling them
195 dnl to either install one or set CXX if there's one configure failed to find.
196 dnl It's probably worthwhile checking that the C++ compiler actually works
197 dnl anyway!
198 if test -n "$CXX" ; then
199   AC_LANG([C++])
200   AC_MSG_CHECKING([whether $CXX is a working C++ compiler])
201   AC_CACHE_VAL([xo_cv_cxx_works],
202     [
203     AC_RUN_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
204                   [xo_cv_cxx_works=yes],
205                   [xo_cv_cxx_works=no],
206                   [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
207                                   [xo_cv_cxx_works=yes],
208                                   [xo_cv_cxx_works=no])])
209     ])
210   AC_MSG_RESULT([$xo_cv_cxx_works])
211 else
212   xo_cv_cxx_works=no
214 if test no = "$xo_cv_cxx_works" ; then
215   case $original_CXX in
216   CCC=*)
217     dnl CCC is handled in a slightly odd way - if its value isn't an
218     dnl executable (taking PATH into account) then it is ignored!
219     test "$original_CXX" = "CCC=$CXX" || original_CXX=
220     ;;
221   esac
222   if test -z "$original_CXX" ; then
223   AC_MSG_ERROR([
224 *** You need a working C++ compiler to compile Xapian, but configure failed to
225 *** find one.  If you have a working C++ compiler, you can tell configure where
226 *** to find it by invoking it like so:
228 ***   ./configure CXX=/opt/bin/c++
230   else
231   AC_MSG_ERROR([
232 *** You need a working C++ compiler to compile Xapian, but the compiler you
233 *** specified (with '$original_CXX') doesn't appear to be able to successfully
234 *** compile and link a simple program.
236   fi
239 dnl Probe for C++ standards version selection options.  We need at least C++17
240 dnl support, but enable support for a newer standards version if the compiler
241 dnl supports it since then we can conditionally make use of newer features.
242 AX_CXX_COMPILE_STDCXX([23], [], [optional])
243 if test "$HAVE_CXX23" = 0 ; then
244   AX_CXX_COMPILE_STDCXX([20], [], [optional])
245   if test "$HAVE_CXX20" = 0 ; then
246     AX_CXX_COMPILE_STDCXX([17])
247   fi
250 dnl We don't use a C compiler to compile Xapian's code, but on some platforms
251 dnl (e.g. mingw) libtool uses $LTCC which defaults to $CC, and it's also use to
252 dnl build auxiliary tools like snowball and lemon.
253 AC_PROG_CC
255 dnl Check endianness.
256 AC_C_BIGENDIAN
258 dnl We want a non-cross-compiling C compiler for building lemon with.
259 if test -z "$CC_FOR_BUILD" ; then
260   if test yes = "$cross_compiling"; then
261     CC_FOR_BUILD=cc
262   else
263     CC_FOR_BUILD="$CC"
264   fi
266 AC_ARG_VAR([CC_FOR_BUILD], [C compiler command for native compilation (needed to compile build tools during cross-builds)])
268 dnl Enable large file support if possible.  There's a bug in this macro in
269 dnl autoconf 2.72 where it always tests with the C compiler.  We could just
270 dnl let it, but Xapian is only C++ so the C compiler could be a totally
271 dnl different compiler with different large-file settings, so we temporarily
272 dnl set CC to the C++ compiler in order to actually test the C++ compiler.
273 AC_LANG([C])
274 save_CC=$CC
275 CC=$CXX
276 AC_SYS_LARGEFILE
277 CC=$save_CC
279 dnl Run tests using the C++ compiler.
280 AC_LANG([C++])
282 dnl With xlC on AIX, -D_LARGE_FILES changes the ABI of std::string, so it
283 dnl also needs to be used when compiling user code.
284 abi_affecting_cxxflags=
285 if $GREP '^#define _LARGE_FILES 1$' confdefs.h > /dev/null 2>&1 ; then
286   abi_affecting_cxxflags=-D_LARGE_FILES
288 AC_SUBST([abi_affecting_cxxflags])
290 AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
291 #if defined __WIN32__ || defined _WIN32
292 #error WIN32
293 #endif
294 ]])], [win32=no], [win32=yes])
296 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
297 #ifdef _MSC_VER
298 #error MSVC
299 #endif
300 ]])], [msvc=no], [msvc=yes])
302 XAPIAN_LDFLAGS=
303 XAPIAN_LIBS=
304 AC_SUBST([XAPIAN_LDFLAGS])
305 AC_SUBST([XAPIAN_LIBS])
307 xo_fn_unknown_option_check() {
308   dnl Some compilers don't error out on unknown options which unhelpfully
309   dnl means we would think the option is supported, use it, and end up
310   dnl with a warning or note diagnostic every time we use the option.
311   dnl
312   dnl Check compiler stderr for known strings:
313   dnl * MSVC: Command line warning D9002 : ignoring unknown option '...'
314   dnl * MSVC: LINK : warning LNK4044: unrecognized option '...'; ignored
315   dnl * icc strings cribbed from automake's depend.m4
316   $GREP 'ignoring unknown option' conftest.err >/dev/null 2>&1 ||
317       $GREP 'unrecognized option' conftest.err >/dev/null 2>&1 ||
318       $GREP 'ignoring option' conftest.err >/dev/null 2>&1 ||
319       $GREP 'not supported' conftest.err >/dev/null 2>&1 ||
320       return 1
321   return 0
324 AC_DEFUN([XAPIAN_TEST_FLAGS_],
325   [
326   m4_define([cachevar],
327             [xo_cv_]m4_tolower(m4_bpatsubst([$1][_$3], [[^A-Za-z0-9]], [_])))
328   AC_CACHE_CHECK([for $CXX with $3 in $1], cachevar,
329     [
330     XTF_save_$1=${$1}
331     $1="${$1} $3"
332     $2([AC_LANG_PROGRAM([], [])],
333       [if xo_fn_unknown_option_check ; then
334          cachevar=no
335        else
336          cachevar=yes
337        fi],
338       [cachevar=no])
339     $1=$XTF_save_$1
340     if test "$cachevar" = yes ; then
341       $4="${$4} $3"
342       $5
343     else :
344       $6
345     fi
346     ])
347   ])
349 dnl Test if compiling works with $1 added to CXXFLAGS; if it does, add $1 to
350 dnl variable $2.  If the test passes, also do $3; if it fails, also do $4.
351 AC_DEFUN([XAPIAN_TEST_CXXFLAGS],
352   [XAPIAN_TEST_FLAGS_([CXXFLAGS], [AC_COMPILE_IFELSE], [$1], [$2], [$3], [$4])])
354 dnl Test if linking works with $1 added to LDFLAGS; if it does, add $1 to
355 dnl variable $2.  If the test passes, also do $3; if it fails, also do $4.
356 AC_DEFUN([XAPIAN_TEST_LDFLAGS],
357   [XAPIAN_TEST_FLAGS_([LDFLAGS], [AC_LINK_IFELSE], [$1], [$2], [$3], [$4])])
359 dnl Preserve the default CXXFLAGS.
360 save_CXXFLAGS=$CXXFLAGS
362 dnl x86 has excess precision issues with 387 FP instructions, which are
363 dnl avoided by using SSE instructions instead.  This is also faster (~6% in
364 dnl a CPU bound testcase).
365 AC_ARG_ENABLE([sse],
366 [AS_HELP_STRING([--disable-sse],
367                 [disable use of SSE FP instructions on x86])]
368 [AS_HELP_STRING([[--enable-sse[=sse|sse2]]],
369                 [set which SSE FP instructions to use on x86 (default: sse2)])],
370   [case ${enableval} in
371     sse|sse2|yes|no) ;;
372     *) AC_MSG_ERROR([bad value ${enableval} for --enable-sse or --disable-sse]) ;;
373   esac],
374   [enable_sse=yes])
376 dnl The maths functions we use include: exp log ceil fabs sqrt
377 AC_MSG_CHECKING([if -lm is required for maths functions])
378 dnl Don't use constant arguments as the compiler might simply evaluate the
379 dnl whole expression at compile time, and it might inline certain functions
380 dnl so test several functions.  Also write results using printf() so that
381 dnl the compiler can't optimise away the computations.
382 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <cmath>
383 #include <cstdio>
384 #include <ctime>
385 using namespace std;]], [[
386   double a = log(ceil(time(NULL)/7.0));
387   printf("%f %f %f\n", a, sqrt(a), exp(fabs(a - 12345.6)));
388   ]])], [AC_MSG_RESULT([no])], [
389     LIBS="-lm $LIBS"
390     AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <cmath>
391 #include <cstdio>
392 #include <ctime>
393 using namespace std;]], [[
394   double a = log(ceil(time(NULL)/7.0));
395   printf("%f %f %f\n", a, sqrt(a), exp(fabs(a - 12345.6)));]])],
396         [AC_MSG_RESULT([yes])],
397         [AC_MSG_ERROR([Failed to link a C++ program using <cmath>])
398     ])
401 dnl exp10() is a GNU libc extension.
402 AC_CHECK_DECLS([exp10(double)], [], [],
403 [#include <cmath>
404 using namespace std;])
406 dnl Darwin provides __exp10().
407 AC_CHECK_DECLS([__exp10(double)], [], [],
408 [#include <cmath>
409 using namespace std;])
411 dnl GCC provides __builtin_exp10() (but notably clang doesn't currently).
412 dnl On mingw, __builtin_exp10() causes GCC to generate a call to exp10() which
413 dnl then fails to link, so perform a link check here to catch that.
414 AC_CACHE_CHECK([for __builtin_exp10], xo_cv_link___builtin_exp10, [
415   AC_LINK_IFELSE([AC_LANG_PROGRAM([[
416 #include <cstdio>
417 #include <ctime>
418 using namespace std;]],
419     [[printf("%f", __builtin_exp10(double(time(NULL)*1e-8)));]])],
420     [xo_cv_link___builtin_exp10=yes],
421     [xo_cv_link___builtin_exp10=no])
423 if test $xo_cv_link___builtin_exp10 = yes ; then
424   AC_DEFINE([HAVE___BUILTIN_EXP10], [1], [Define to 1 if you have the '__builtin_exp10' function.])
427 dnl See if <typeinfo> can be used in the testsuite - at least for GCC and xlC,
428 dnl compilation of the test code below fails if RTTI isn't being generated
429 dnl (g++ -fno-rtti, or by default with xlC).
430 AC_MSG_CHECKING([if RTTI is supported])
431 save_CXXFLAGS=$CXXFLAGS
432 dnl xlC issues a warning for typeid() being used without RTTI being enabled,
433 dnl so for this test we pass the xlC option to make that warning into an error.
434 CXXFLAGS="$CXXFLAGS -qhaltonmsg=1540-2412"
435 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
436       [],
437       [CXXFLAGS=$save_CXXFLAGS])
438 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
439 #include <exception>
440 #include <typeinfo>]],
441         [[
442         int f();
443         try {
444             return f();
445         } catch (std::exception & e) {
446             return typeid(e).name()[0];
447         }]])],
448     [AC_MSG_RESULT([yes])
449     AC_DEFINE([USE_RTTI], [1], [Define if the testsuite can use RTTI])],
450     [AC_MSG_RESULT([no])])
451 CXXFLAGS=$save_CXXFLAGS
453 dnl We need to specify the argument types for builtin functions, or else
454 dnl AC_CHECK_DECLS fails to detect them when the compiler is clang.
455 AC_CHECK_DECLS([__builtin_add_overflow(int, int, int*),
456                 __builtin_sub_overflow(int, int, int*),
457                 __builtin_mul_overflow(int, int, int*)], [], [], [ ])
458 AC_CHECK_DECLS([__builtin_bswap16(uint16_t),
459                 __builtin_bswap32(uint32_t),
460                 __builtin_bswap64(uint64_t)], [], [],
461                [#include <stdint.h>])
462 AC_CHECK_DECLS([_byteswap_ushort, _byteswap_ulong, _byteswap_uint64], [], [],
463                [#include <stdlib.h>])
464 AC_CHECK_DECLS([__builtin_clz(unsigned),
465                 __builtin_clzl(unsigned long),
466                 __builtin_clzll(unsigned long long)], [], [], [ ])
467 AC_CHECK_DECLS([__builtin_ctz(unsigned),
468                 __builtin_ctzl(unsigned long),
469                 __builtin_ctzll(unsigned long long)], [], [], [ ])
470 AC_CHECK_DECLS([__builtin_expect(long, long)], [], [], [ ])
471 AC_CHECK_DECLS([__builtin_ffs(int)], [], [], [ ])
472 AC_CHECK_DECLS([__builtin_popcount(unsigned),
473                 __builtin_popcountl(unsigned long),
474                 __builtin_popcountll(unsigned long long)], [], [], [ ])
475 AC_CHECK_DECLS([__popcnt, __popcnt64], [], [], [#include <intrin.h>])
476 AC_CHECK_DECLS([_addcarry_u32(unsigned char, unsigned, unsigned, unsigned*),
477                 _addcarry_u64(unsigned char, unsigned __int64, unsigned __int64, unsigned __int64*),
478                 _subborrow_u32(unsigned char, unsigned, unsigned, unsigned*),
479                 _subborrow_u64(unsigned char, unsigned __int64, unsigned __int64, unsigned __int64*)],
480                [], [], [#include <intrin.h>])
482 dnl Check for poll().
483 AC_CHECK_FUNCS([poll])
485 dnl Check for time functions.
486 AC_CHECK_FUNCS([clock_gettime sleep nanosleep gettimeofday ftime])
488 case $host_os in
489   *mingw*)
490     AC_DEFINE([MINGW_HAS_SECURE_API], [1], [Define on mingw to get _s suffixed "secure" functions declared in headers])
491     ;;
492 esac
494 dnl Used by tests/harness/testsuite.cc
495 AC_CHECK_FUNCS([sigaction])
496 dnl These can be macros (and sigsetjmp is with glibc at least).
497 AC_CHECK_DECLS([sigsetjmp, siglongjmp], [], [], [#include <setjmp.h>])
499 dnl Used by tests/harness/cputimer.cc:
500 AC_CHECK_FUNCS([getrusage times sysconf])
502 dnl Used by tests/harness/unixcmd.cc
503 AC_CHECK_FUNCS([nftw])
505 dnl POSIX requires setenv().  The final Unix-like platform without it seems
506 dnl to have been Solaris 9, which is now out of support.
508 dnl Microsoft don't provide setenv() and have marked putenv() as deprecated, so
509 dnl we use _putenv_s() to avoid deprecation warnings with MSVC.  It's also a
510 dnl more similar interface to setenv() so easier to implement a setenv() wrapper
511 dnl around.  We probe for both the function and a declaration since mingw
512 dnl doesn't currently (v3.20) declare it but it is present in the C runtime DLL
513 dnl so we can provide our own declaration to access it.
514 AC_CHECK_FUNCS([setenv _putenv_s])
515 AC_CHECK_DECLS([_putenv_s(const char*, const char*)], [], [],
516 [#include <stdlib.h>])
518 dnl See if we have closefrom(), or some functions that are useful to implement
519 dnl closefrom() on platforms which don't provide it.
520 AC_CHECK_FUNCS([closefrom getdirentries getrlimit])
522 if test $ac_cv_func_ftime = yes ; then
523   dnl See if ftime returns void (as it does on mingw)
524   AC_MSG_CHECKING([return type of ftime])
525   AC_COMPILE_IFELSE(
526     [AC_LANG_PROGRAM([[#include <sys/timeb.h>]],
527                      [[struct timeb tp; int i = ftime(&tp);]])],
528     [AC_MSG_RESULT([int])],
529     [AC_MSG_RESULT([void])
530     AC_DEFINE([FTIME_RETURNS_VOID], [1], [Define if ftime returns void])])
533 dnl Check how to find the hostname: uname() in sys/utsname.h, or gethostname()
534 AC_CHECK_HEADERS([sys/utsname.h], [], [], [ ])
535 AC_CHECK_FUNCS([gethostname])
537 AC_MSG_CHECKING([whether std::from_chars() works for double])
538 AC_LINK_IFELSE([AC_LANG_PROGRAM(
539 dnl std::from_chars() was added in C++17, but support it with floating point
540 dnl types was slow to get implemented so probe for it.  We can fall back to
541 dnl using strtod() instead (which is affected by the currently set locale and
542 dnl less thread-safe.
543 [[#include <charconv>]],
544 [[  const char* p = "3.14";
545   double v;
546   const auto& r = std::from_chars(p, p + 4, v);
547   if (r.ec != std::errc() || r.ptr != p + 4) return 1;]])],
548   AC_DEFINE([HAVE_STD_FROM_CHARS_DOUBLE], [1], [Define if std::from_chars() works for double])
549   AC_MSG_RESULT([yes]),
550   AC_MSG_RESULT([no])
553 dnl mingw (for instance) lacks ssize_t
554 AC_TYPE_SSIZE_T
556 AC_TYPE_PID_T
558 AC_TYPE_MODE_T
560 AC_CHECK_SIZEOF([short])
561 AC_CHECK_SIZEOF([int])
562 AC_CHECK_SIZEOF([long])
563 AC_CHECK_SIZEOF([long long])
565 AC_CHECK_HEADERS([sys/types.h])
567 AC_MSG_CHECKING([for 32 bit integer type])
568 case 4 in
569     "$ac_cv_sizeof_int")   INT32_T=int ;;
570     "$ac_cv_sizeof_long")  INT32_T=long ;;
571     "$ac_cv_sizeof_short") INT32_T=short ;;
572     *)
573       AC_MSG_RESULT([none found])
574       AC_MSG_ERROR([No 32 bit integer type found])
575 esac
576 AC_MSG_RESULT([$INT32_T])
578 AC_MSG_CHECKING([for 64 bit integer type])
579 case 8 in
580     "$ac_cv_sizeof_int")       INT64_T=int ;;
581     "$ac_cv_sizeof_long")      INT64_T=long ;;
582     "$ac_cv_sizeof_long_long") INT64_T='long long' ;;
583     *)
584       AC_MSG_RESULT([none found])
585       AC_MSG_ERROR([No 64 bit integer type found])
586 esac
587 AC_MSG_RESULT([$INT64_T])
589 dnl Check for perl (needed to generate some sources and documentation).
590 AC_PATH_PROG([PERL], [perl], [])
591 AC_ARG_VAR([PERL], [Perl interpreter])
592 if test x$USE_MAINTAINER_MODE = xyes; then
593   test -z "$PERL" && AC_MSG_ERROR([perl is required in maintainer mode])
596 AC_ARG_ENABLE([64bit_docid],
597   [AS_HELP_STRING([--enable-64bit-docid], [enable 64bit docid])],
598   [case ${enableval} in
599     yes|no) ;;
600   *) AC_MSG_ERROR([bad value ${enableval} for --enable-64bit-docid]) ;;
601   esac],
602   [enable_64bit_docid=no])
604 AC_ARG_ENABLE([64bit_termcount],
605   [AS_HELP_STRING([--enable-64bit-termcount], [enable 64bit termcount])],
606   [case ${enableval} in
607     yes|no) ;;
608   *) AC_MSG_ERROR([bad value ${enableval} for --enable-64bit-termcount]) ;;
609   esac],
610   [enable_64bit_termcount=no])
612 AC_ARG_ENABLE([64bit_termpos],
613   [AS_HELP_STRING([--enable-64bit-termpos], [enable 64bit termpos])],
614   [case ${enableval} in
615     yes|no) ;;
616   *) AC_MSG_ERROR([bad value ${enableval} for --enable-64bit-termpos]) ;;
617   esac],
618   [enable_64bit_termpos=no])
620 AC_ARG_ENABLE([documentation],
621   [AS_HELP_STRING([--enable-documentation], [enable make rules to rebuild documentation [default=maintainer-mode]])],
622   [case ${enableval} in
623     yes|no) ;;
624     *) AC_MSG_ERROR([bad value ${enableval} for --enable-documentation]) ;;
625   esac],
626   [enable_documentation=$USE_MAINTAINER_MODE])
627 AM_CONDITIONAL([DOCUMENTATION_RULES], [test x"$enable_documentation" = xyes])
628 AM_CONDITIONAL([MAINTAINER_NO_DOCS], [test x"$USE_MAINTAINER_MODE$enable_documentation" = xyesno])
630 if test x"$enable_documentation" = xyes ; then
631   dnl Checks for dot.  (Diagrams in the documentation)
632   AC_PATH_PROG([DOT], [dot])
633   AC_ARG_VAR([DOT], [dot from graphviz])
634   test -z "$DOT" && AC_MSG_ERROR([dot (part of the graphviz package) is required to build documentation])
635   DOXYGEN_DOT_PATH=`echo "$DOT" | sed 's!/dot$!!'`
636   AC_SUBST([DOXYGEN_DOT_PATH])
638   dnl Check for doxygen. (Needed to make some more of the documentation)
639   AC_PATH_PROG([DOXYGEN], [doxygen], [])
640   AC_ARG_VAR([DOXYGEN], [Doxygen documentation system])
641   test -z "$DOXYGEN" && AC_MSG_ERROR([doxygen is required to build documentation])
643   dnl Check for help2man. (Needed to make man pages from "--help" output).
644   AC_PATH_PROG([HELP2MAN], [help2man], [])
645   AC_ARG_VAR([HELP2MAN], [help2man man page generator])
646   test -z "$HELP2MAN" && AC_MSG_ERROR([help2man is required to build documentation])
648   dnl Check for rst2html. (Needed to make HTML from reStructuredText format)
649   dnl Also look for rst2html.py, which archlinux reportedly installs it as.
650   AC_PATH_PROGS([RST2HTML], [rst2html rst2html.py], [])
651   AC_ARG_VAR([RST2HTML], [reST to HTML convertor])
652   test -z "$RST2HTML" && AC_MSG_ERROR([rst2html is required to build documentation (try package python-docutils)])
654   dnl Check for pngcrush, which we optionally use to reduce the size of the
655   dnl PNG files which doxygen generates.  We can get by without it, so don't
656   dnl fail here if it's not found.
657   AC_PATH_PROG([PNGCRUSH], [pngcrush], [])
658   AC_ARG_VAR([PNGCRUSH], [PNG optimiser])
661 dnl Checks for header files.
662 AC_CHECK_HEADERS([fcntl.h limits.h poll.h sys/select.h sys/uio.h sysexits.h],
663                  [], [], [ ])
664 AC_CHECK_HEADERS([sys/resource.h],
665                  [], [], [#include <sys/types.h>])
667 dnl cxxabi.h was added in GCC 3.1, but clang lies and defines __GNUC__ yet
668 dnl doesn't seem to reliably provide this header, so probe for it.
669 AC_CHECK_HEADERS([cxxabi.h], [], [], [ ])
671 dnl If valgrind is installed and new enough, we use it for leak checking in the
672 dnl testsuite.  If VALGRIND is set to an empty value, then skip the check and
673 dnl don't use valgrind.  On macOS only use valgrind if VALGRIND is set to a
674 dnl no empty value, as valgrind on macOS gives a lot of false positives.
675 use_valgrind_if_non_empty=
676 case $host in
677   *-*-darwin*)
678     use_valgrind_if_non_empty=$VALGRIND ;;
679   *)
680     use_valgrind_if_non_empty=${VALGRIND-unset} ;;
681 esac
683 if test -n "$use_valgrind_if_non_empty" ; then
684   AC_PATH_PROG([VALGRIND], [valgrind], [])
685   AC_ARG_VAR([VALGRIND], [debugging tool (optionally used by test harness)])
686   if test -n "$VALGRIND" ; then
687     dnl Check that the installed valgrind version works, and supports the
688     dnl options we use.  This means we won't try to use valgrind < 3.3.0
689     dnl (released 7/12/2007) since before that --log-file didn't expand
690     dnl %p (and appended the process id).
691     dnl
692     dnl No need to check for VALGRIND_COUNT_LEAKS now - that was added before
693     dnl 2.0.0.
694     AC_MSG_CHECKING([if valgrind supports --log-file with %p and --child-silent-after-fork=yes])
695     vglog=config.vglog.%p.tmp
696     vglogwild="config.vglog.*.tmp*"
697     rm -f $vglogwild
698     if $VALGRIND --log-file="$vglog" --child-silent-after-fork=yes -q true 2>&AS_MESSAGE_LOG_FD ; then
699       for f in $vglogwild ; do
700         case $f in
701         $vglog*) VALGRIND= ;;
702         esac
703       done
704       if test x"$VALGRIND" = x ; then
705         AC_MSG_RESULT([no])
706       else
707         AC_MSG_RESULT([yes])
708         AC_CHECK_HEADERS([valgrind/memcheck.h], [], [VALGRIND=], [ ])
709       fi
710     else
711       dnl The valgrind detected doesn't seem to work!  Perhaps this is an
712       dnl x86_64 box with a 32 bit valgrind.
713       AC_MSG_RESULT([$VALGRIND doesn't work])
714       VALGRIND=
715     fi
716     rm -f $vglogwild
717   fi
720 if test -n "$VALGRIND" ; then
721   AC_DEFINE([HAVE_VALGRIND], [1], [Define if a suitable valgrind is installed])
724 dnl If eatmydata is installed, we run the testsuite under it to speed it up.
725 dnl If EATMYDATA is set to an empty value, then skip this check and don't use
726 dnl eatmydata.
727 if test -n "${EATMYDATA-unset}" ; then
728   AC_PATH_PROG([EATMYDATA], [eatmydata], [])
729   AC_ARG_VAR([EATMYDATA], [wrapper to disable fsync (optionally used by test harness)])
732 dnl Checks for library functions.
733 AC_FUNC_STRERROR_R
735 AC_CACHE_CHECK([for sys_errlist and sys_nerr], xo_cv_sys_errlist_and_sys_nerr, [
736   AC_LINK_IFELSE([AC_LANG_PROGRAM(
737 dnl On Linux, sys_errlist and sys_nerr need <stdio.h>, though the man page
738 dnl says <errno.h>.  The man page seems to match other platforms such as
739 dnl NetBSD, so include both headers to ensure we get them.  With mingw and MSVC
740 dnl they're provided by <stdlib.h>.
741 [[#include <errno.h>
742 #include <stdio.h>
743 #include <stdlib.h>]],
744 [[  printf("%s", sys_errlist[sys_nerr - 1]);]])],
745   [ xo_cv_sys_errlist_and_sys_nerr=yes ],
746   [ xo_cv_sys_errlist_and_sys_nerr=no ])
748 if test "x$xo_cv_sys_errlist_and_sys_nerr" = "xyes" ; then
749   AC_DEFINE([HAVE_SYS_ERRLIST_AND_SYS_NERR], [1],[Define if you have 'sys_errlist' and 'sys_nerr'])
752 AC_CACHE_CHECK([for _sys_errlist and _sys_nerr], xo_cv__sys_errlist_and__sys_nerr, [
753   AC_LINK_IFELSE([AC_LANG_PROGRAM(
754 [[#include <errno.h>
755 #include <stdio.h>
756 #include <stdlib.h>]],
757 [[  printf("%s", _sys_errlist[_sys_nerr - 1]);]])],
758   [ xo_cv__sys_errlist_and__sys_nerr=yes ],
759   [ xo_cv__sys_errlist_and__sys_nerr=no
760   ])
762 if test "x$xo_cv__sys_errlist_and__sys_nerr" = "xyes" ; then
763   AC_DEFINE([HAVE__SYS_ERRLIST_AND__SYS_NERR], [1],[Define if you have '_sys_errlist' and '_sys_nerr'])
766 dnl GNU-specific replacement for sys_errlist and sys_nerr.
767 AC_CHECK_FUNCS([strerrordesc_np])
769 dnl Check for ICU, which we can optionally use to find word breaks.
770 AC_ARG_VAR([PKG_CONFIG], [Location of pkg-config])
771 AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
772 if test -n "$PKG_CONFIG" ; then
773   dnl ICU's UTF-8 word boundary code was broken before 54.1.
774   m4_define([icu_min], [54.1])
775   m4_define([icu_mod], [icu-uc])
776   AC_MSG_CHECKING([for ICU (icu_mod >= icu_min)])
777   icu_config="$PKG_CONFIG icu_mod"
778   try_libs=`$PKG_CONFIG 'icu_mod >= icu_min' --libs 2>&AS_MESSAGE_LOG_FD`
779   if test $? -eq 0 ; then
780     AC_MSG_RESULT([yes])
781     AC_DEFINE([USE_ICU], [1], [Define to use ICU to find word breaks])
782     dnl The split here isn't perfect - e.g. -DFOO really ought to be in
783     dnl CPPFLAGS, but hopefully this won't be a problem in practice.
784     ICU_CFLAGS=`$icu_config --cflags-only-other`
785     ICU_CPPFLAGS=`$icu_config --cflags-only-I`
786     ICU_LIBS=$try_libs
787   else
788     icu_version=`$icu_config --modversion 2>&AS_MESSAGE_LOG_FD`
789     if test $? -eq 0 ; then
790       AC_MSG_RESULT([no ($icu_version)])
791     else
792       AC_MSG_RESULT([no])
793     fi
794   fi
796 AC_SUBST([ICU_CFLAGS])
797 AC_SUBST([ICU_CPPFLAGS])
798 AC_SUBST([ICU_LIBS])
800 dnl ***************************
801 dnl * Select modules to build *
802 dnl ***************************
804 dnl Check if a non-GPL library build is specified.
806 AC_ARG_ENABLE([gpl-libxapian],
807   [AS_HELP_STRING([--disable-gpl-libxapian], [disable use of GPL code which we won't be able to relicense in libxapian (NB currently the resulting build still contains GPL code, but GPL code which it will be possible to relicense eventually)])],
808   [case ${enableval} in
809     yes) ;;
810     no)
811       AC_DEFINE([DISABLE_GPL_LIBXAPIAN], 1, [Define to error out if we try to include GPL code in libxapian])
812       ;;
813     *) AC_MSG_ERROR([bad value ${enableval} for --disable-gpl-libxapian]) ;;
814   esac],
815   [enable_gpl_libxapian=yes])
817 dnl Check which database backends should be built.
819 AC_DEFUN([_XAPIAN_BACKEND_ENABLE],
820   [AC_ARG_ENABLE([backend_$1],
821     [AS_HELP_STRING([--enable-backend-$1], [build the $1 database backend [default=$3]])],
822     [case $enableval in
823       yes|no) ;;
824       *) AC_MSG_ERROR([Invalid option: '--enable-backend-$1=$enableval']) ;;
825     esac], [enable_backend_$1=$2])
826   ])
828 AC_DEFUN([XAPIAN_BACKEND_ENABLE],
829   [_XAPIAN_BACKEND_ENABLE([$1],
830     m4_default([$2], [yes]),
831     m4_default([$3], [yes]))
832   ])
834 dnl When adding a new backend, update INSTALL too.
835 XAPIAN_BACKEND_ENABLE([glass], [$enable_gpl_libxapian], [yes (unless --disable-gpl-libxapian)])
836 XAPIAN_BACKEND_ENABLE([honey])
837 XAPIAN_BACKEND_ENABLE([inmemory], [$enable_gpl_libxapian], [yes (unless --disable-gpl-libxapian)])
838 default_enable_backend_remote=$enable_gpl_libxapian
839 case $host_os in
840   *djgpp* | *msdos* )
841     dnl We don't currently support the remote backend on this platform so
842     dnl disable it by default.
843     default_enable_backend_remote=no
844     ;;
845 esac
846 XAPIAN_BACKEND_ENABLE([remote], [$default_enable_backend_remote], [yes (except for MSDOS; unless --disable-gpl-libxapian)])
848 dnl Save and empty LIBS while we probe for libraries to link libxapian against
849 dnl so we can just use AC_SEARCH_LIBS then copy LIBS to XAPIAN_LIBS and restore
850 dnl the value saved here.
851 save_LIBS=$LIBS
852 LIBS=
854 dnl See if we have fdatasync, and what libraries are needed for it.
855 dnl We need to actually check for a declaration as macOS has a dummy
856 dnl implementation in the library which is not prototyped in any header.
857 AC_CHECK_DECL([fdatasync(int)], [
858   AC_SEARCH_LIBS([fdatasync], [rt], [])
859   AC_CHECK_FUNCS([fdatasync])
860   ],
861   [ac_cv_func_fdatasync=no],
862   [#include <unistd.h>]
865 dnl We use timer_create() if available to implement a search time limit.
866 AC_SEARCH_LIBS([timer_create], [rt],
867                [
868     AC_MSG_CHECKING([for timer_create() usability])
869     dnl Several platforms have timer_create() but it's non-functional.
870     dnl
871     dnl Some of these (at least those with a stub implementation which always
872     dnl fails with ENOSYS) could be probed for, but we'd have to run code
873     dnl which isn't possible when cross-compiling, so just maintain a list
874     dnl of such platforms for now.
875     AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
876 [[#if defined _AIX
877 #error timer_create always fails with EAGAIN on AIX 7.1
878 #elif defined __NetBSD__
879 #error SIGEV_THREAD not implemented in NetBSD 9.2 (see: man sigevent)
880 #elif defined __OpenBSD__
881 #error timer_create always fails with ENOSYS on OpenBSD 7.3 (and no prototype)
882 #endif]])],
883         [AC_MSG_RESULT([yes])
884         AC_DEFINE([HAVE_TIMER_CREATE], [1], [Define to 1 if you have the 'timer_create' function.])]
885         ,
886         [AC_MSG_RESULT([no])
887     ])
890 win32_need_lws2_32=0
891 case $enable_backend_glass$enable_backend_honey in
892 *yes*)
893   dnl We use zlib for compressing tags in glass and honey.  We could
894   dnl automatically disable support if zlib isn't found, but overall that
895   dnl probably does more harm than good - it's most likely that someone just
896   dnl forgot to install the -dev package for zlib.
897   dnl
898   dnl Similarly for uuid support.
900   dnl Check for zlib.h.
901   AC_CHECK_HEADERS([zlib.h], [], [
902     AC_MSG_ERROR([zlib.h not found - required for glass (you may need to install the zlib1g-dev or zlib-devel package)])
903     ], [ ])
905   dnl Check for zlibVersion - normally it's in -lz but the mingw build needs -lzlib or -lzdll.
906   AC_SEARCH_LIBS([zlibVersion], [z zlib zdll], [], [
907     AC_MSG_ERROR([zlibVersion() not found in -lz, -lzlib, or -lzdll - required for glass (you may need to install the zlib1g-dev or zlib-devel package)])
908     ])
910   dnl Find a way to generate UUIDs.
912   case $host_os-$win32 in
913     *-yes | cygwin* | msys*) dnl Use built-in win32 API.
914       AC_DEFINE([USE_WIN32_UUID_API], [1],
915                 [Define to 1 to use UuidCreate(), etc])
916       if test $win32 = yes ; then
917         dnl We need -lws2_32 for htonl(), etc, but not for Cygwin which
918         dnl provides these functions in its libc.
919         win32_need_lws2_32=1
920       fi
921       LIBS="$LIBS -lrpcrt4"
922       ;;
923     *)
924       dnl Check for uuid/uuid.h (e2fsprogs/util-linux-ng) or uuid.h
925       dnl (FreeBSD/NetBSD/OpenBSD/AIX).
926       AC_CHECK_HEADERS([uuid/uuid.h], [
927         dnl util-linux-ng's uuid/uuid.h found - check for uuid_generate in
928         dnl -luuid.
929         AC_SEARCH_LIBS([uuid_generate], [uuid], [], [
930           AC_MSG_ERROR([uuid_generate() not found in -luuid - required for glass and honey backends (you may need to install the uuid-dev, libuuid-devel or e2fsprogs-devel package)])
931           ])
932       ], [
933         dnl Try uuid.h as found on FreeBSD/NetBSD/OpenBSD/AIX, with associated
934         dnl code in libc.
935         AC_CHECK_HEADERS([uuid.h], [
936           dnl Check for uuid_create with no extra libraries required.
937           AC_CHECK_FUNC([uuid_create], [], [
938             AC_MSG_ERROR([uuid.h found, but uuid_create() not found.  You probably wants to install libuuid from util-linux-ng or e2fsprogs (you may need to install the uuid-dev, libuuid-devel or e2fsprogs-devel package)])
939           ])
940         ], [
941           dnl Especially useful for Android.
942           AC_MSG_CHECKING([if host platform supports /proc/sys/kernel/random/uuid])
943           case $host_os in
944             linux*)
945               AC_DEFINE([USE_PROC_FOR_UUID], [1],
946                         [Define to 1 to read UUID from '/proc/sys/kernel/random/uuid'])
947               AC_MSG_RESULT([yes])
948               ;;
949             *)
950               AC_MSG_RESULT([no])
951               AC_MSG_ERROR([Failed to find a way to generate UUIDs, required for glass and honey backends (you may need to install the uuid-dev, libuuid-devel or e2fsprogs-devel package)])
952               ;;
953           esac
954         ], [ ])
955       ], [ ])
956       ;;
957   esac
959   case $host_os in
960     *djgpp* | *msdos* )
961       dnl DJGPP has a dummy implementation of fork which always fails.
962       dnl
963       dnl For disk-based backends, use flock() for locking, which doesn't need
964       dnl fork() or socketpair().
965       AC_DEFINE([FLINTLOCK_USE_FLOCK], 1, [Define to use flock() for flint-compatible locking])
966       ;;
967   esac
968   ;;
969 esac
971 if test "$enable_backend_remote" = yes ; then
972   case $host_os-$win32 in
973     *-yes )
974       dnl For mingw and msvc we have an alternative implementation which
975       dnl doesn't need fork() or socketpair().
976       dnl
977       dnl We need -lws2_32 for getaddrinfo(), etc.
978       win32_need_lws2_32=1
979       dnl Vista is needed for the AI_ADDRCONFIG flag to getaddrinfo().
980       AC_DEFINE([WINVER], [0x600],
981                 [Version of Windows to assume (0x600 => Vista).])
982       AC_DEFINE([_WIN32_WINNT], [WINVER],
983                 [Version of Windows to assume.])
984       ;;
985     *djgpp* | *msdos* )
986       dnl DJGPP has a dummy implementation of fork which always fails.  If
987       dnl someone actually wanted remote backend support, then DJGPP has a
988       dnl pthreads port, so using threads like we do on Windows would make more
989       dnl sense.
990       AC_MSG_ERROR([The remote backend is not currently supported on this platform.])
991       ;;
992     *)
993       dnl On Unix, we need fork and socketpair for the remotebackend.
994       AC_CHECK_FUNCS([fork], [], [
995         AC_MSG_ERROR([fork() required for the remote backend - if an extra library is needed, pass LIBS=-lfoo to configure.  Or --disable-backend-remote to disable it.])
996       ])
997       dnl Check if -lsocket is required for socketpair (Solaris needs it).
998       dnl And on Haiku it's in -lnetwork.
999       AC_SEARCH_LIBS([socketpair], [socket network], [], [
1000         AC_MSG_ERROR([socketpair() required for the remote backend - if an extra library is needed, pass LIBS=-lfoo to configure.  Or --disable-backend-remote to disable it.])
1001       ])
1002       AC_DEFINE([HAVE_SOCKETPAIR], [1],
1003                 [Define to 1 if you have the 'socketpair' function.])
1004       dnl Check if extra libraries are needed for getaddrinfo or inet_ntop()
1005       dnl (e.g. on Solaris).
1006       dnl
1007       dnl We're currently assuming that any system that is worth trying to
1008       dnl support has getaddrinfo() and inet_ntop(), since these are the
1009       dnl standard route for supporting IPv6, and that's pretty much essential
1010       dnl for platforms to support now.
1011       AC_SEARCH_LIBS([getaddrinfo], [nsl socket], [], [
1012         AC_MSG_ERROR([getaddrinfo() required for the remote backend - if an extra library is needed, pass LIBS=-lfoo to configure.  Or --disable-backend-remote to disable it.])
1013       ])
1014       AC_SEARCH_LIBS([inet_ntop], [nsl socket], [], [
1015         AC_MSG_ERROR([inet_ntop() required for the remote backend - if an extra library is needed, pass LIBS=-lfoo to configure.  Or --disable-backend-remote to disable it.])
1016       ])
1017       ;;
1018   esac
1020   XAPIAN_TYPE_SOCKLEN_T
1023 if test "$win32_need_lws2_32" = 1 ; then
1024   LIBS="$LIBS -lws2_32"
1026 XAPIAN_LIBS=$LIBS
1027 LIBS=$save_LIBS
1029 AC_ARG_ENABLE([visibility],
1030   [AS_HELP_STRING([--disable-visibility], [disable use of GCC visibility])],
1031   [case ${enableval} in
1032     yes|no) ;;
1033     *) AC_MSG_ERROR([bad value ${enableval} for --disable-visibility]) ;;
1034   esac])
1036 vpath_build=no
1037 if test "`pwd`" != "`cd $srcdir;pwd`" ; then
1038   vpath_build=yes
1040 AM_CONDITIONAL([VPATH_BUILD], [test yes = "$vpath_build"])
1042 dnl Turn off compilation of anything that we don't have the requirements for
1044 dnl Set conditionals to specify what we compile
1046 AM_CONDITIONAL([BUILD_BACKEND_GLASS], [test yes = "$enable_backend_glass"])
1047 AM_CONDITIONAL([BUILD_BACKEND_HONEY], [test yes = "$enable_backend_honey"])
1048 AM_CONDITIONAL([BUILD_BACKEND_INMEMORY], [test yes = "$enable_backend_inmemory"])
1049 AM_CONDITIONAL([BUILD_BACKEND_REMOTE], [test yes = "$enable_backend_remote"])
1050 AM_CONDITIONAL([BUILD_BACKEND_TOOLS],
1051   [test nono != "$enable_backend_glass$enable_backend_honey"])
1053 dnl Decide if we should use the zlib-vg.so LD_PRELOAD hack.
1054 use_zlib_vg=no
1055 if test -n "$VALGRIND" ; then
1056   case $host_os in
1057     linux*) use_zlib_vg=yes ;;
1058   esac
1060 AM_CONDITIONAL([USE_ZLIB_VG], [test yes = "$use_zlib_vg"])
1062 AC_CHECK_FUNCS([fsync writev])
1063 AC_CHECK_FUNCS([posix_fadvise])
1064 if test "$win32" = no ; then
1065   dnl ftruncate() under Wine seems to be buggy and sometimes fails, though
1066   dnl a cut-down reproducer seems fine.  For now just avoid ftruncate()
1067   dnl entirely on this platform - we'll fallback to lseek() + write() of a
1068   dnl single zero byte, which is pretty efficient.
1069   AC_CHECK_FUNCS([ftruncate])
1072 dnl HP-UX has pread and pwrite, but they don't work!  Apparently this problem
1073 dnl manifests when largefile support is enabled, and we definitely want that
1074 dnl so don't use pread or pwrite on HP-UX.
1075 case $host_os in
1076   hpux*)
1077     AC_MSG_CHECKING([for pread])
1078     AC_MSG_RESULT([present but broken on $host_os])
1079     AC_MSG_CHECKING([for pwrite])
1080     AC_MSG_RESULT([present but broken on $host_os])
1081     ;;
1082   *)
1083     AC_CHECK_FUNC([pread],
1084        [AC_DEFINE([HAVE_PREAD], [1],
1085             [Define if pread is available on this system])
1086         AC_MSG_CHECKING([for any prototype needed for pread])
1087         AC_CACHE_VAL([xo_cv_pread_prototype],
1088           [
1089             for p in ' ' \
1090               'extern "C" ssize_t pread(int, void *, size_t, off_t) throw ();' \
1091               'extern "C" ssize_t pread(int, void *, size_t, off_t);' ; do
1092               AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1093 #include <sys/types.h>
1094 #include <unistd.h>
1096               ]],[[
1097                 char b[256];
1098                 pread(1, b, 256, 20);
1099               ]])],[
1100                 xo_cv_pread_prototype="$p"
1101                 break
1102               ], [])
1103             done
1104             if test -z "$xo_cv_pread_prototype"; then
1105               AC_MSG_RESULT([not found])
1106               AC_MSG_ERROR([Failed to find working prototype for pread])
1107             fi
1108           ])
1109           if test " " = "$xo_cv_pread_prototype" ; then
1110             AC_MSG_RESULT([none required])
1111           else
1112             AC_MSG_RESULT([$xo_cv_pread_prototype])
1113             AC_DEFINE_UNQUOTED([PREAD_PROTOTYPE], [$xo_cv_pread_prototype],
1114                                [explicit prototype needed for pread (if any)])
1115           fi
1116         ])
1117     AC_CHECK_FUNC([pwrite],
1118        [AC_DEFINE([HAVE_PWRITE], [1],
1119             [Define if pwrite is available on this system])
1120         AC_MSG_CHECKING([for any prototype needed for pwrite])
1121         AC_CACHE_VAL([xo_cv_pwrite_prototype],
1122           [
1123             for p in ' ' \
1124               'extern "C" ssize_t pwrite(int, const void *, size_t, off_t) throw ();' \
1125               'extern "C" ssize_t pwrite(int, const void *, size_t, off_t);' ; do
1126               AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1127 #include <sys/types.h>
1128 #include <unistd.h>
1130               ]],[[
1131                 const char *p = "hello";
1132                 pwrite(1, p, 5, 20);
1133               ]])],[
1134                 xo_cv_pwrite_prototype="$p"
1135                 break
1136               ], [])
1137             done
1138             if test -z "$xo_cv_pwrite_prototype"; then
1139               AC_MSG_RESULT([not found])
1140               AC_MSG_ERROR([Failed to find working prototype for pwrite])
1141             fi
1142           ])
1143           if test " " = "$xo_cv_pwrite_prototype" ; then
1144             AC_MSG_RESULT([none required])
1145           else
1146             AC_MSG_RESULT([$xo_cv_pwrite_prototype])
1147             AC_DEFINE_UNQUOTED([PWRITE_PROTOTYPE], [$xo_cv_pwrite_prototype],
1148                                [explicit prototype needed for pwrite (if any)])
1149           fi
1150         ])
1151     ;;
1152 esac
1154 AC_MSG_CHECKING([for directory separator(s)])
1155 case $host_os-$win32 in
1156   *-yes | cygwin* | msys* | os2* | *djgpp* | *msdos* )
1157     AC_MSG_RESULT([/ and \\])
1158     AC_DEFINE([DIR_SEPS], ["/\\"], [directory separator(s) as a character or string literal])
1159     AC_DEFINE([DIR_SEPS_LIST], [{ '/', '\\' }], [directory separator(s) as an initialiser list])
1160     ;;
1161   *)
1162     AC_MSG_RESULT([/])
1163     AC_DEFINE([DIR_SEPS], ['/'], [directory separator(s) as a character or string literal])
1164     AC_DEFINE([DIR_SEPS_LIST], [{ '/' }], [directory separator(s) as an initialiser list])
1165     ;;
1166 esac
1168 AC_CHECK_FUNCS([link])
1170 dnl *************************
1171 dnl * Set debugging options *
1172 dnl *************************
1174 dnl Which assertion types to enable in the code.
1176 AC_ARG_ENABLE([assertions],
1177   [AS_HELP_STRING([--enable-assertions], [enable debug assertions (no|partial|yes) [default=no]])],
1178   [case $enableval in
1179     yes|partial|no) ;;
1180     *)
1181       AC_MSG_ERROR([Invalid option: '--enable-assertions=$enableval']) ;;
1182   esac])
1184 AC_ARG_ENABLE([log],
1185   [AS_HELP_STRING([--enable-log], [generate a log of methods called, etc (no|yes|profile) [default=no]])],
1186   [case $enableval in
1187     yes|no) ;;
1188     profile)
1189       AC_MSG_ERROR(['--enable-log=profile' is no longer supported - see https://trac.xapian.org/wiki/ProfilingXapian for alternatives.]) ;;
1190     *)
1191       AC_MSG_ERROR([Invalid option: '--enable-log=$enableval']) ;;
1192   esac])
1194 dnl Set defines according to the --enable-assertions and --enable-log options
1195 dnl given.
1197 if test yes = "$enable_assertions" || test partial = "$enable_assertions" ; then
1198   AC_DEFINE([XAPIAN_ASSERTIONS],,
1199     [Define if you want assertions (causes some slow-down)])
1202 if test yes = "$enable_assertions"; then
1203   AC_DEFINE([XAPIAN_ASSERTIONS_PARANOID],,
1204     [Define if you want paranoid assertions (causes significant slow-down)])
1207 if test yes = "$enable_log"; then
1208   AC_DEFINE([XAPIAN_DEBUG_LOG],,
1209     [Define if you want a log of methods called and other debug messages])
1212 dnl Check if IEEE-754 is followed for representing floating point numbers by the platform.
1213 AC_RUN_IFELSE([
1214   AC_LANG_PROGRAM(
1215     [[
1216 #include <cstdint>
1217 #include <cstring>
1218 using namespace std;
1219     ]],
1220     [[
1221       double a = 2353.3523423;
1222       uint64_t bit_pattern = 0x40A262B46635BEFF;
1223       if (memcmp(&bit_pattern, &a, sizeof(double)) == 0) return 0;
1224       return 1;
1225     ]]
1226   )],
1227   [ieee_followed=1],
1228   [ieee_followed=0],
1229   [ieee_followed=0]
1232 if test "$ieee_followed" = 1; then
1233     AC_DEFINE([FOLLOWS_IEEE], [1], [Defined if system uses ieee format to store floating point numbers])
1236 dnl ******************************
1237 dnl * Set special compiler flags *
1238 dnl ******************************
1240 AC_ARG_ENABLE([werror],
1241   [AS_HELP_STRING([--enable-werror], [enable treating compiler warnings as errors [default=maintainer-mode]])],
1242   [case ${enableval} in
1243     yes|no) ;;
1244   *) AC_MSG_ERROR([bad value ${enableval} for --enable-werror]) ;;
1245   esac],
1246   [enable_werror=$USE_MAINTAINER_MODE])
1248 dnl Put -Werror or equivalent in its own make variable so that it can easily
1249 dnl be overridden by `make WERROR=` if needed during development (e.g. if
1250 dnl you want to get a full list of compile warnings to fix rather than
1251 dnl stopping at the first file with warnings).
1252 WERROR=
1253 AC_SUBST([WERROR])
1255 dnl Set flags to control warnings (enable more, or disable annoying ones).
1256 dash_d_visibility=
1257 if test yes = "$GXX"; then
1258   dnl Intel's C++ compiler and clang both lie and define __GNUC__, so check which
1259   dnl we actually have, as neither is really 100% compatible.
1260   echo __INTEL_COMPILER __clang__ > conftest.cc
1261   case `$CXX -E conftest.cc 2>&AS_MESSAGE_LOG_FD|grep -v '^#'` in
1262     *__INTEL_COMPILER*__clang__*)
1263       dnl GCC (since neither substituted):
1265       dnl The exact format of g++ --version seems to change with almost every
1266       dnl minor release so use the preprocessor macros which should be more
1267       dnl robust.  Pass -xc++ to avoid warnings about any command-line options
1268       dnl included in $CXX which aren't valid for C (such as -std=c++17).
1269       AC_MSG_CHECKING([for version of $CXX])
1270       gxx_version=`echo __GNUC__.__GNUC_MINOR__.__GNUC_PATCHLEVEL__|$CXX -xc++ -E -|sed '/^#/d;s/ //g'`
1271       AC_MSG_RESULT([GCC $gxx_version])
1273       dnl -Wundef was supported by g++ 3.0.
1274       dnl
1275       dnl -Wlogical-op and -Wmissing-declarations (for C++) were added in
1276       dnl GCC 4.3.
1277       dnl
1278       dnl -Wdouble-promotion was added in GCC 4.6.
1279       dnl
1280       dnl -Wduplicated-cond was added in GCC 6.
1281       dnl
1282       dnl -Wduplicated-branches was added in GCC 7.
1283       dnl
1284       dnl All the other options were supported by g++ 2.95.
1285       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"
1287       case $gxx_version in
1288       [[0-6]].*)
1289         AC_MSG_ERROR([Xapian requires GCC 7.0 or later])
1290         ;;
1291       esac
1293       dnl FIXME:
1294       dnl -Wold-style-cast is interesting, but triggers for macros from
1295       dnl system headers (e.g. FD_SET).  GCC 4.8 improved this by making
1296       dnl -ftrack-macro-expansion=2 the default, but we still see such
1297       dnl warnings on some platforms for some reason (e.g. Cygwin with GCC
1298       dnl 5.4.0 warns about FD_SET, and on Debian with GCC 4.9.2 we see
1299       dnl warnings from zlib.h).
1301       WERROR=-Werror
1302       ;;
1303     *__clang__*)
1304       dnl Intel's compiler (since __clang__ not substituted):
1305       dnl
1306       dnl -w1 stops the avalanche of uninteresting "remark" messages.
1307       dnl -wd... disables warnings which don't have good code workarounds.
1308       AM_CXXFLAGS="$AM_CXXFLAGS -Wall -w1 -wd177,1572"
1310       WERROR=-Werror
1311       ;;
1312     *__INTEL_COMPILER*)
1313       dnl clang (since __INTEL_COMPILER not substituted):
1315       dnl These options all work at least as far back as clang++ 3.0:
1316       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"
1318       WERROR=-Werror
1319       ;;
1320   esac
1321   rm -f conftest.cc
1323   if test no != "$enable_visibility"; then
1324     dnl GCC doesn't support symbol visibility on all platforms (e.g. it isn't
1325     dnl supported on mingw and visibility attributes result in warnings).
1326     AC_MSG_CHECKING([if $CXX -fvisibility=hidden -fvisibility-inlines-hidden works])
1327     if echo 'int bar() __attribute__((visibility("default"))); int baz() __attribute__((visibility("internal"))); int bar() { return 6; } int baz() { return 7; } int foo() {return 42;}'|$CXX -Werror -fvisibility=hidden -fvisibility-inlines-hidden -c -oconftest.o -xc++ - >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD ; then
1328       AC_MSG_RESULT([yes])
1329       AM_CXXFLAGS="$AM_CXXFLAGS -fvisibility=hidden -fvisibility-inlines-hidden"
1330       dash_d_visibility=-DXAPIAN_ENABLE_VISIBILITY
1331     else
1332       AC_MSG_RESULT([no])
1333     fi
1334   fi
1335 elif test yes = "$msvc"; then
1336   WERROR=-WX
1339 AC_MSG_CHECKING([for option to turn warnings into errors])
1340 if test x$enable_werror != xyes; then
1341   WERROR=
1342   AC_MSG_RESULT([not requested])
1343 elif test -z "$WERROR" ; then
1344   AC_MSG_RESULT([unknown for $CXX])
1345 else
1346   AC_MSG_RESULT([$WERROR])
1349 XAPIAN_TEST_LDFLAGS([-Wl,-Bsymbolic-functions], [XAPIAN_LDFLAGS])
1351 dnl New in GCC 5.  Sort of like -Bsymbolic-functions, but for the compiler
1352 dnl rather than the linker.
1353 XAPIAN_TEST_LDFLAGS([-fno-semantic-interposition], [XAPIAN_LDFLAGS])
1355 AC_MSG_CHECKING([whether to use SSE instructions on x86])
1356 case $host_cpu in
1357   i*86)
1358     if test "$enable_sse" = no ; then
1359       AC_MSG_RESULT([no])
1360       if test yes = "$msvc"; then
1361         dnl MSVC defaults to SSE2.
1362         AM_CXXFLAGS="$AM_CXXFLAGS -arch:IA32"
1363       fi
1364     else
1365       dnl Default to sse2.
1366       test "$enable_sse" != yes || enable_sse=sse2
1367       if test yes = "$GXX"; then
1368         AC_MSG_RESULT([yes (configure with --disable-sse to disable)])
1369         dnl We can unconditionally use -mtune=generic as it was added in GCC
1370         dnl 4.2, and supported at least as far back as clang 3.0.
1371         AM_CXXFLAGS="$AM_CXXFLAGS -mfpmath=sse -m$enable_sse -mtune=generic"
1372       elif test yes = "$msvc"; then
1373         AC_MSG_RESULT([yes (configure with --disable-sse to disable)])
1374         if test sse = "$enable_sse"; then
1375           dnl MSVC defaults to SSE2.
1376           AM_CXXFLAGS="$AM_CXXFLAGS -arch:SSE"
1377         fi
1378       else
1379         AC_MSG_RESULT([don't know how to for compiler $CXX])
1380       fi
1381     fi
1382     ;;
1383   *)
1384     AC_MSG_RESULT([non-x86 arch ($host_cpu)]) ;;
1385 esac
1387 if test "$GXX" = yes; then
1388   dnl Default to enabling _FORTIFY_SOURCE at level 2.  It shouldn't cause a
1389   dnl problem to define it where it's not supported, but we need to check for
1390   dnl an issue on mingw-w64 where some versions required linking with -lssp
1391   dnl (this was fixed in v11.0.0 released 2023-04-28).  We detect this with a
1392   dnl configure-time link test and don't auto-enable _FORTIFY_SOURCE if using
1393   dnl an affected version.
1394   AC_MSG_CHECKING([if _D_FORTIFY_SOURCE=2 links without extra libraries])
1395   save_CPPFLAGS=$CPPFLAGS
1396   CPPFLAGS="$CPPFLAGS -D_FORTIFY_SOURCE=2"
1397   AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1398     #include <string.h>
1399     static char a[20], b[10];]], [[
1400     strcpy(a, b);
1401     ]])],
1402     [AC_MSG_RESULT([yes])
1403     AC_DEFINE([FORTIFY_SOURCE_OK], [1], [Define to 1 if '-D_FORTIFY_SOURCE=2' link test passes])],
1404     [AC_MSG_RESULT([no])])
1405   CPPFLAGS=$save_CPPFLAGS
1408 AH_BOTTOM(
1409 [/* Disable stupid MSVC warnings. */
1410 #ifdef _MSC_VER
1411 /* Passing an empty parameter to a single parameter macro. */
1412 # pragma warning(disable:4003)
1413 /* Assignment in conditional expression; other compilers suppress with extra parentheses but not MSVC. */
1414 # pragma warning(disable:4706)
1415 /* A "performance" warning for converting int to bool. */
1416 # pragma warning(disable:4800)
1417 /* Character in string literal can't be represented in current code page. */
1418 # pragma warning(disable:4566)
1420 /* POSIX get to deprecate POSIX things, not Microsoft. */
1421 # ifndef _CRT_NONSTDC_NO_WARNINGS
1422 #  define _CRT_NONSTDC_NO_WARNINGS
1423 # endif
1424 # ifndef _CRT_SECURE_NO_WARNINGS
1425 #  define _CRT_SECURE_NO_WARNINGS
1426 # endif
1428 /* WSAAddressToStringA() is deprecated and we should apparently use
1429  * WSAAddressToStringW(), but we don't want wide character output so
1430  * that would mean we'd have to convert the result back to ASCII
1431  * which is a really stupid idea.
1432  */
1433 # ifndef _WINSOCK_DEPRECATED_NO_WARNINGS
1434 #  define _WINSOCK_DEPRECATED_NO_WARNINGS
1435 # endif
1437 /* Tell MSVC we want M_PI, etc defined. */
1438 # ifndef _USE_MATH_DEFINES
1439 #  define _USE_MATH_DEFINES
1440 # endif
1442 /* Tell MSVC we don't want max() and min() macros defined. */
1443 # ifndef NOMINMAX
1444 #  define NOMINMAX
1445 # endif
1446 #endif
1448 /* Tell zlib to include const in method signatures.  Define this in config.h
1449  * to ensure it always gets defined before zlib.h is included.
1450  */
1451 #define ZLIB_CONST
1453 /* Make the POSIX-like functions support large files.  MSVC needs this;
1454  * current mingw32 does too; mingw64 supports _FILE_OFFSET_BITS, which
1455  * AC_SYS_LARGEFILE should discover and enable automatically.
1456  */
1457 #if defined _MSC_VER || \
1458     (defined __MINGW32__ && !defined _FILE_OFFSET_BITS)
1460 # include <sys/stat.h>
1461 # include <sys/types.h>
1462 # include <io.h>
1463 /* zlib.h uses off_t so we need to include it before we redefine off_t. */
1464 # include <zlib.h>
1466 // The default stat() and fstat() use 32-bit filesizes and time_t, so we need
1467 // to arrange to use 64-bit variants instead.
1469 # ifdef stat
1470 // Break #undef lines to stop config.status from commenting them out.
1471 #  undef \
1472         stat
1473 # endif
1475 // This hack is a problem is we ever want a method called "stat".
1476 # ifdef _MSC_VER
1477 // MSVC needs to call _stat64() instead of stat() and the struct which holds
1478 // the information is `struct _stat64` instead of `struct stat` so we just
1479 // use #define to replace both in one go.
1480 #  define stat _stat64
1481 # else
1482 // Mingw32 has _stat64() but unhelpfully for our purposes, the struct is
1483 // called __stat64 (with an extra underscore).  We hack around this by
1484 // defining stat to __stat64 which sorts out the struct, and then using
1485 // a second macro to forward function-like uses of __stat64() to
1486 // _stat64().
1487 #  define stat __stat64
1488 #  define __stat64(PATH, STATBUF) _stat64((PATH), (STATBUF))
1489 # endif
1491 // We also want to use _fstat64() instead of fstat() but in this case we can
1492 // use a function-like macro, so we could have a method called fstat so long
1493 // as it didn't take two parameters.
1495 # ifdef fstat
1496 // Break #undef lines to stop config.status from commenting them out.
1497 #  undef \
1498         fstat
1499 # endif
1501 # define fstat(FD, BUF) _fstat64(FD, BUF)
1503 # ifdef lseek
1504 // Break #undef lines to stop config.status from commenting them out.
1505 #  undef \
1506         lseek
1507 # endif
1509 # ifdef off_t
1510 // Break #undef lines to stop config.status from commenting them out.
1511 #  undef \
1512         off_t
1513 # endif
1515 # define lseek(FD, OFF, WHENCE) _lseeki64(FD, OFF, WHENCE)
1516 /* Redefine via a typedef so C++ code off_t(-1) works - it wouldn't if we did:
1517  * #define off_t long long
1518  */
1519 typedef long long off_t_redefinition_typedef;
1520 # define off_t off_t_redefinition_typedef
1522 #endif
1524 /* MSVC defines _WIN32 but not __WIN32__. */
1525 #if !defined __WIN32__ && defined _WIN32
1526 # define __WIN32__
1527 #endif
1529 /* MSVC defines _WIN64 but not __WIN64__. */
1530 #if !defined __WIN64__ && defined _WIN64
1531 # define __WIN64__
1532 #endif
1534 /* Default to enabling _FORTIFY_SOURCE at level 2 for GCC-like compilers.  It
1535  * shouldn't cause a problem to define it where it's not supported.
1537  * The FORTIFY_SOURCE_OK check avoids auto-enabling on some mingw-w64 versions
1538  * which required linking with -lssp too.  This was addressed in v11.0.0
1539  * (released 2023-04-28).
1541  * Check if _FORTIFY_SOURCE is already defined to allow the user to override
1542  * our choice with "./configure CPPFLAGS=-D_FORTIFY_SOURCE=0" or "...=1" or
1543  * "...=3".
1544  */
1545 #if defined FORTIFY_SOURCE_OK && !defined _FORTIFY_SOURCE
1546 # define _FORTIFY_SOURCE 2
1547 #endif
1549 /* For compilers which support it (such as GCC, clang, Intel's C++ compiler)
1550  * we can use __builtin_expect to give the compiler hints about branch
1551  * prediction.  See HACKING for how to use these.
1552  */
1553 #if HAVE_DECL___BUILTIN_EXPECT
1554 /* The arguments of __builtin_expect() are both long, so use !! to ensure that
1555  * the first argument is always an integer expression, and always 0 or 1, but
1556  * still has the same truth value for the if or while it is used in.
1557  */
1558 # define rare(COND) __builtin_expect(!!(COND), 0)
1559 # define usual(COND) __builtin_expect(!!(COND), 1)
1560 #else
1561 # define rare(COND) (COND)
1562 # define usual(COND) (COND)
1563 #endif
1565 /* This macro can be used around expressions which intentionally make use of
1566  * unsigned integer overflow (which is defined behaviour, unlike signed integer
1567  * overflow) so that we can use UBSan's optional unsigned-integer-overflow
1568  * check to find potential bugs where we unintentionally overflow an unsigned
1569  * integer.
1570  */
1571 #ifdef __clang__
1572 #define UNSIGNED_OVERFLOW_OK(X) \
1573     ([&]() __attribute__((no_sanitize("unsigned-integer-overflow"))) {\
1574         return (X);\
1575     }())
1576 #else
1577 # define UNSIGNED_OVERFLOW_OK(X) (X)
1578 #endif
1580 /* Signal we're building the library so it's OK to include headers such as
1581  * xapian/query.h directly.
1582  */
1583 #define XAPIAN_LIB_BUILD 1
1586 AC_SUBST([AM_CXXFLAGS])
1588 dnl Restore CXXFLAGS to those the user specified or autoconf defaulted to.
1589 CXXFLAGS=$save_CXXFLAGS
1591 dnl Required for auto regeneration to work in a combined maintainer-mode tree.
1592 : ${AUTOM4TE=autom4te}
1593 AC_SUBST([AUTOM4TE])
1595 dnl Libtool sets this (to yes|no|unknown) and we use it in xapian-config.
1596 AC_SUBST([link_all_deplibs_CXX])
1598 dnl Shared library extension.
1599 module=no
1600 eval "SHLIBEXT=$shrext_cmds"
1601 AC_SUBST([SHLIBEXT])
1603 dnl We want to be able to use GNU make % pattern rules in maintainer targets
1604 dnl but automake warns these aren't portable, so we substitute the % to avoid
1605 dnl this warning.
1606 PERCENT='%'
1607 AC_SUBST([PERCENT])
1609 dnl Split up the version number into "MAJOR.MINOR.REVISION".
1610 MAJOR_VERSION=`echo "$VERSION"|sed 's/\..*//'`
1611 [MINOR_VERSION=`echo "$VERSION"|sed 's/[^.]*\.//;s/\..*//'`]
1612 [REVISION=`echo "$VERSION"|sed 's/.*\.//;s/_.*$//'`]
1614 dnl Convert the libs in $XAPIAN_LIBS to a CMake list.
1615 XAPIAN_CMAKE_LIBS=`echo " $XAPIAN_LIBS" | sed 's/ -l/;/g;s/ //g'`
1616 AC_SUBST([XAPIAN_CMAKE_LIBS])
1618 XAPIAN_CMAKE_SHARED=
1619 if test "$enable_shared" = yes; then
1620   XAPIAN_CMAKE_SHARED=ON
1621 else
1622   XAPIAN_CMAKE_SHARED=OFF
1624 AC_SUBST([XAPIAN_CMAKE_SHARED])
1626 LIBRARY_STATIC_EXT=.$libext
1627 AC_SUBST([LIBRARY_STATIC_EXT])
1629 if test "$win32" = yes; then
1630   LIBRARY_SHARED_IMP_EXT=$LIBRARY_STATIC_EXT
1631 else
1632   LIBRARY_SHARED_IMP_EXT=
1634 AC_SUBST([LIBRARY_SHARED_IMP_EXT])
1636 dnl We don't make use of maths function setting errno and if we tell the
1637 dnl compiler that it can optimise them better in some cases.  Apparently
1638 dnl most BSD-derived platforms don't set errno in this case anyway.
1639 XAPIAN_TEST_CXXFLAGS([-fno-math-errno], [CXXFLAGS])
1641 dnl **************************
1642 dnl * Build the output files *
1643 dnl **************************
1645 AC_CONFIG_FILES([
1646  Makefile
1647  tests/Makefile
1648  docs/Makefile
1649  docs/doxygen_api.conf
1650  docs/doxygen_source.conf
1651  cmake/xapian-config.cmake
1652  cmake/xapian-config-version.cmake
1653  pkgconfig/xapian-core"$LIBRARY_VERSION_SUFFIX".pc:pkgconfig/xapian-core.pc.in
1654  ])
1655 AC_CONFIG_FILES([makemanpage], [chmod +x makemanpage])
1656 AC_CONFIG_FILES([tests/runtest], [chmod +x tests/runtest])
1657 AC_CONFIG_FILES([tests/runsrv], [chmod +x tests/runsrv])
1658 AC_CONFIG_FILES([tests/submitperftest], [chmod +x tests/submitperftest])
1659 AC_CONFIG_FILES([tests/perftest/get_machine_info], [chmod +x tests/perftest/get_machine_info])
1660 AC_CONFIG_FILES([xapian-config], [chmod +x xapian-config])
1661 AC_OUTPUT
1663 dnl There are no files generated by AC_OUTPUT in the following directories
1664 dnl and we need to ensure they exist so that the rest of configure or make
1665 dnl won't fail because they don't exist when srcdir != builddir.
1666 if test yes = "$vpath_build" ; then
1667   for dir in include/xapian languages queryparser ; do
1668     AS_MKDIR_P(["$dir"])
1669   done
1672 dnl Generate include/xapian/version.h:
1674 dnl MAIN_VERSION is VERSION without any _git123 suffix.
1675 MAIN_VERSION="$MAJOR_VERSION.$MINOR_VERSION.$REVISION"
1676 cxxcpp_flags=-I.
1677 for backend in GLASS HONEY INMEMORY REMOTE ; do
1678   val=`eval echo "\\\$BUILD_BACKEND_${backend}_TRUE"`
1679   if test -z "$val" ; then
1680     cxxcpp_flags="$cxxcpp_flags -DXAPIAN_HAS_${backend}_BACKEND"
1681   fi
1682 done
1684 if test yes = "$enable_64bit_docid" ; then
1685   cxxcpp_flags="$cxxcpp_flags -DXAPIAN_DOCID_BASE_TYPE="`echo "$INT64_T"|sed 's/ /____/g'`
1686 else
1687   cxxcpp_flags="$cxxcpp_flags -DXAPIAN_DOCID_BASE_TYPE="`echo "$INT32_T"|sed 's/ /____/g'`
1690 if test yes = "$enable_64bit_termcount" ; then
1691   cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TERMCOUNT_BASE_TYPE="`echo "$INT64_T"|sed 's/ /____/g'`
1692 else
1693   cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TERMCOUNT_BASE_TYPE="`echo "$INT32_T"|sed 's/ /____/g'`
1696 if test yes = "$enable_64bit_termpos" ; then
1697   cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TERMPOS_BASE_TYPE="`echo "$INT64_T"|sed 's/ /____/g'`
1698 else
1699   cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TERMPOS_BASE_TYPE="`echo "$INT32_T"|sed 's/ /____/g'`
1702 dnl Always ought to be 64 bit.
1703 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TOTALLENGTH_TYPE="`echo "unsigned $INT64_T"|sed 's/ /____/g'`
1705 dnl Make revision numbers in the API 64 bit for future-proofing.
1706 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_REVISION_TYPE="`echo "unsigned $INT64_T"|sed 's/ /____/g'`
1708 dnl For GCC (and compilers which pretend to be GCC) and MSVC, we create checks
1709 dnl for some ABI-incompatible configurations in the generated version.h.
1710 dnl Such configurations may be specified via $CXXFLAGS so we should use this
1711 dnl when generating version.h.  For these compilers, CXXCPP="$CXX -E" so it
1712 dnl should understand all compiler options.
1714 dnl For other compilers, we only pass $CPPFLAGS to $CXXCPP in case it's an
1715 dnl external cpp which doesn't understand all options which might be in
1716 dnl $CXXFLAGS.
1717 case $GXX$msvc in
1718   *yes*)
1719     cxxcpp_flags="$cxxcpp_flags $CPPFLAGS $CXXFLAGS" ;;
1720   *)
1721     cxxcpp_flags="$cxxcpp_flags $CPPFLAGS" ;;
1722 esac
1723 rm -f include/xapian/version.h.tmp
1724 dnl "\r" in sed is a GNUism, but we only need to remove it on MS Windows
1725 dnl where we'll always have GNU sed, and other sed's will just interpret
1726 dnl it as "r" (Solaris sed) or maybe literal "\r" which won't match.
1728 dnl Use @@ around $MAIN_VERSION so we get " in the final output.
1729 $CXXCPP $cxxcpp_flags\
1730         -DSTRING_VERSION="\"@@$MAIN_VERSION@@\""\
1731         -DMAJOR_VERSION="\"$MAJOR_VERSION\""\
1732         -DMINOR_VERSION="\"$MINOR_VERSION\""\
1733         -DREVISION="\"$REVISION\""\
1734         $dash_d_visibility\
1735         $srcdir/include/xapian/version_h.cc|\
1736         ${SED-sed} '0,/const char \* dummy/d;/"/!d;s/^ *//;/^#/d;s/ *$//;s/" *,//;s/"//g;s/@@/"/g;s/  */ /g;s/ *,\r$//;s/ *,$//;s/____/ /g;s/\\\\$/\\/'\
1737         > include/xapian/version.h.tmp
1738 dnl Only update the file if it has changed, so we don't alter the timestamp
1739 dnl and cause lots of rebuilding needlessly.  However, the build system
1740 dnl needs a timestamp to know when to regenerate version.h because version_h.cc
1741 dnl has changed so we use a separate timestamp file.
1742 touch include/xapian/version.h.timestamp
1743 if cmp include/xapian/version.h.tmp include/xapian/version.h >/dev/null 2>&1
1744 then
1745   rm include/xapian/version.h.tmp
1746 else
1747   mv include/xapian/version.h.tmp include/xapian/version.h
1750 if test "$enable_gpl_libxapian" != yes ; then
1751   AC_MSG_WARN([--disable-gpl-libxapian disables use of GPL code which we won't be able to relicense in libxapian - currently the resulting build still contains GPL code, but GPL code which it will be possible to relicense eventually.])