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
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.
8 dnl Extract from the libtool info manual:
10 dnl Here are a set of rules to help you update your library version information:
12 dnl 1. Start with version information of '0:0:0' for each libtool library.
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
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').
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.
25 dnl 5. If any interfaces have been added since the last public release,
26 dnl then increment AGE.
28 dnl 6. If any interfaces have been removed since the last public release
29 dnl then set AGE to 0.
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.
39 case $PACKAGE_VERSION in
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
54 AC_SUBST([LIBRARY_VERSION_SUFFIX])
57 dnl Check the build directory doesn't contain a space, so we die early with
61 AC_MSG_ERROR([You can't build in a directory whose path contains a space])
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.
70 dnl Note: for in-tree builds, the build directory test above will fire
72 AC_MSG_ERROR([You can't build with sources in a directory whose path contains a space])
76 dnl Check the prefix to install in doesn't contain a space, so we die early with
80 AC_MSG_ERROR([You can't install in a directory whose path contains a space])
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.
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])
103 dnl Use libtool to manage our libraries.
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).
122 if test unsupported = "$allow_undefined_flag" ; then
123 NO_UNDEFINED=-no-undefined
125 AC_SUBST(NO_UNDEFINED)
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!
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
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
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
158 dnl Checks for programs.
163 # Checked: dragonfly6.4 freebsd8.0 netbsd9.3 openbsd4.6 solaris2.9 solaris2.10
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
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
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 ;;
188 NO_INSTALL=-no-install ;;
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
198 if test -n "$CXX" ; then
200 AC_MSG_CHECKING([whether $CXX is a working C++ compiler])
201 AC_CACHE_VAL([xo_cv_cxx_works],
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])])
210 AC_MSG_RESULT([$xo_cv_cxx_works])
214 if test no = "$xo_cv_cxx_works" ; then
215 case $original_CXX in
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=
222 if test -z "$original_CXX" ; then
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++
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.
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])
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.
255 dnl Check endianness.
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
266 AC_ARG_VAR([CC_FOR_BUILD], [C compiler command for native compilation (needed to compile build tools during cross-builds)])
268 dnl Run tests using the C++ compiler.
271 dnl Enable large file support if possible.
273 dnl With xlC on AIX, -D_LARGE_FILES changes the ABI of std::string, so it
274 dnl also needs to be used when compiling user code.
275 abi_affecting_cxxflags=
276 if $GREP '^#define _LARGE_FILES 1$' confdefs.h > /dev/null 2>&1 ; then
277 abi_affecting_cxxflags=-D_LARGE_FILES
279 AC_SUBST([abi_affecting_cxxflags])
281 AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
282 #if defined __WIN32__ || defined _WIN32
285 ]])], [win32=no], [win32=yes])
287 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
291 ]])], [msvc=no], [msvc=yes])
295 AC_SUBST([XAPIAN_LDFLAGS])
296 AC_SUBST([XAPIAN_LIBS])
298 xo_fn_unknown_option_check() {
299 dnl Some compilers don't error out on unknown options which unhelpfully
300 dnl means we would think the option is supported, use it, and end up
301 dnl with a warning or note diagnostic every time we use the option.
303 dnl Check compiler stderr for known strings:
304 dnl * MSVC: Command line warning D9002 : ignoring unknown option '...'
305 dnl * MSVC: LINK : warning LNK4044: unrecognized option '...'; ignored
306 dnl * icc strings cribbed from automake's depend.m4
307 $GREP 'ignoring unknown option' conftest.err >/dev/null 2>&1 ||
308 $GREP 'unrecognized option' conftest.err >/dev/null 2>&1 ||
309 $GREP 'ignoring option' conftest.err >/dev/null 2>&1 ||
310 $GREP 'not supported' conftest.err >/dev/null 2>&1 ||
315 AC_DEFUN([XAPIAN_TEST_FLAGS_],
317 m4_define([cachevar],
318 [xo_cv_]m4_tolower(m4_bpatsubst([$1][_$3], [[^A-Za-z0-9]], [_])))
319 AC_CACHE_CHECK([for $CXX with $3 in $1], cachevar,
323 $2([AC_LANG_PROGRAM([], [])],
324 [if xo_fn_unknown_option_check ; then
331 if test "$cachevar" = yes ; then
340 dnl Test if compiling works with $1 added to CXXFLAGS; if it does, add $1 to
341 dnl variable $2. If the test passes, also do $3; if it fails, also do $4.
342 AC_DEFUN([XAPIAN_TEST_CXXFLAGS],
343 [XAPIAN_TEST_FLAGS_([CXXFLAGS], [AC_COMPILE_IFELSE], [$1], [$2], [$3], [$4])])
345 dnl Test if linking works with $1 added to LDFLAGS; if it does, add $1 to
346 dnl variable $2. If the test passes, also do $3; if it fails, also do $4.
347 AC_DEFUN([XAPIAN_TEST_LDFLAGS],
348 [XAPIAN_TEST_FLAGS_([LDFLAGS], [AC_LINK_IFELSE], [$1], [$2], [$3], [$4])])
350 dnl Preserve the default CXXFLAGS.
351 save_CXXFLAGS=$CXXFLAGS
353 dnl x86 has excess precision issues with 387 FP instructions, which are
354 dnl avoided by using SSE instructions instead. This is also faster (~6% in
355 dnl a CPU bound testcase).
357 [AS_HELP_STRING([--disable-sse],
358 [disable use of SSE FP instructions on x86])]
359 [AS_HELP_STRING([[--enable-sse[=sse|sse2]]],
360 [set which SSE FP instructions to use on x86 (default: sse2)])],
361 [case ${enableval} in
363 *) AC_MSG_ERROR([bad value ${enableval} for --enable-sse or --disable-sse]) ;;
367 dnl The maths functions we use include: exp log ceil fabs sqrt
368 AC_MSG_CHECKING([if -lm is required for maths functions])
369 dnl Don't use constant arguments as the compiler might simply evaluate the
370 dnl whole expression at compile time, and it might inline certain functions
371 dnl so test several functions. Also write results using printf() so that
372 dnl the compiler can't optimise away the computations.
373 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <cmath>
376 using namespace std;]], [[
377 double a = log(ceil(time(NULL)/7.0));
378 printf("%f %f %f\n", a, sqrt(a), exp(fabs(a - 12345.6)));
379 ]])], [AC_MSG_RESULT([no])], [
381 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <cmath>
384 using namespace std;]], [[
385 double a = log(ceil(time(NULL)/7.0));
386 printf("%f %f %f\n", a, sqrt(a), exp(fabs(a - 12345.6)));]])],
387 [AC_MSG_RESULT([yes])],
388 [AC_MSG_ERROR([Failed to link a C++ program using <cmath>])
392 dnl exp10() is a GNU libc extension.
393 AC_CHECK_DECLS([exp10(double)], [], [],
395 using namespace std;])
397 dnl Darwin provides __exp10().
398 AC_CHECK_DECLS([__exp10(double)], [], [],
400 using namespace std;])
402 dnl GCC provides __builtin_exp10() (but notably clang doesn't currently).
403 dnl On mingw, __builtin_exp10() causes GCC to generate a call to exp10() which
404 dnl then fails to link, so perform a link check here to catch that.
405 AC_CACHE_CHECK([for __builtin_exp10], xo_cv_link___builtin_exp10, [
406 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
409 using namespace std;]],
410 [[printf("%f", __builtin_exp10(double(time(NULL)*1e-8)));]])],
411 [xo_cv_link___builtin_exp10=yes],
412 [xo_cv_link___builtin_exp10=no])
414 if test $xo_cv_link___builtin_exp10 = yes ; then
415 AC_DEFINE([HAVE___BUILTIN_EXP10], [1], [Define to 1 if you have the '__builtin_exp10' function.])
418 dnl See if <typeinfo> can be used in the testsuite - at least for GCC and xlC,
419 dnl compilation of the test code below fails if RTTI isn't being generated
420 dnl (g++ -fno-rtti, or by default with xlC).
421 AC_MSG_CHECKING([if RTTI is supported])
422 save_CXXFLAGS=$CXXFLAGS
423 dnl xlC issues a warning for typeid() being used without RTTI being enabled,
424 dnl so for this test we pass the xlC option to make that warning into an error.
425 CXXFLAGS="$CXXFLAGS -qhaltonmsg=1540-2412"
426 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
428 [CXXFLAGS=$save_CXXFLAGS])
429 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
431 #include <typeinfo>]],
436 } catch (std::exception & e) {
437 return typeid(e).name()[0];
439 [AC_MSG_RESULT([yes])
440 AC_DEFINE([USE_RTTI], [1], [Define if the testsuite can use RTTI])],
441 [AC_MSG_RESULT([no])])
442 CXXFLAGS=$save_CXXFLAGS
444 dnl We need to specify the argument types for builtin functions, or else
445 dnl AC_CHECK_DECLS fails to detect them when the compiler is clang.
446 AC_CHECK_DECLS([__builtin_add_overflow(int, int, int*),
447 __builtin_sub_overflow(int, int, int*),
448 __builtin_mul_overflow(int, int, int*)], [], [], [ ])
449 AC_CHECK_DECLS([__builtin_bswap16(uint16_t),
450 __builtin_bswap32(uint32_t),
451 __builtin_bswap64(uint64_t)], [], [],
452 [#include <stdint.h>])
453 AC_CHECK_DECLS([_byteswap_ushort, _byteswap_ulong, _byteswap_uint64], [], [],
454 [#include <stdlib.h>])
455 AC_CHECK_DECLS([__builtin_clz(unsigned),
456 __builtin_clzl(unsigned long),
457 __builtin_clzll(unsigned long long)], [], [], [ ])
458 AC_CHECK_DECLS([__builtin_ctz(unsigned),
459 __builtin_ctzl(unsigned long),
460 __builtin_ctzll(unsigned long long)], [], [], [ ])
461 AC_CHECK_DECLS([__builtin_expect(long, long)], [], [], [ ])
462 AC_CHECK_DECLS([__builtin_ffs(int)], [], [], [ ])
463 AC_CHECK_DECLS([__builtin_popcount(unsigned),
464 __builtin_popcountl(unsigned long),
465 __builtin_popcountll(unsigned long long)], [], [], [ ])
466 AC_CHECK_DECLS([__popcnt, __popcnt64], [], [], [#include <intrin.h>])
467 AC_CHECK_DECLS([_addcarry_u32(unsigned char, unsigned, unsigned, unsigned*),
468 _addcarry_u64(unsigned char, unsigned __int64, unsigned __int64, unsigned __int64*),
469 _subborrow_u32(unsigned char, unsigned, unsigned, unsigned*),
470 _subborrow_u64(unsigned char, unsigned __int64, unsigned __int64, unsigned __int64*)],
471 [], [], [#include <intrin.h>])
473 dnl Check for poll().
474 AC_CHECK_FUNCS([poll])
476 dnl Check for time functions.
477 AC_CHECK_FUNCS([clock_gettime sleep nanosleep gettimeofday ftime])
481 AC_DEFINE([MINGW_HAS_SECURE_API], [1], [Define on mingw to get _s suffixed "secure" functions declared in headers])
485 dnl Used by tests/harness/testsuite.cc
486 AC_CHECK_FUNCS([sigaction])
487 dnl These can be macros (and sigsetjmp is with glibc at least).
488 AC_CHECK_DECLS([sigsetjmp, siglongjmp], [], [], [#include <setjmp.h>])
490 dnl Used by tests/harness/cputimer.cc:
491 AC_CHECK_FUNCS([getrusage times sysconf])
493 dnl Used by tests/harness/unixcmd.cc
494 AC_CHECK_FUNCS([nftw])
496 dnl POSIX requires setenv(). The final Unix-like platform without it seems
497 dnl to have been Solaris 9, which is now out of support.
499 dnl Microsoft don't provide setenv() and have marked putenv() as deprecated, so
500 dnl we use _putenv_s() to avoid deprecation warnings with MSVC. It's also a
501 dnl more similar interface to setenv() so easier to implement a setenv() wrapper
502 dnl around. We probe for both the function and a declaration since mingw
503 dnl doesn't currently (v3.20) declare it but it is present in the C runtime DLL
504 dnl so we can provide our own declaration to access it.
505 AC_CHECK_FUNCS([setenv _putenv_s])
506 AC_CHECK_DECLS([_putenv_s(const char*, const char*)], [], [],
507 [#include <stdlib.h>])
509 dnl See if we have closefrom(), or some functions that are useful to implement
510 dnl closefrom() on platforms which don't provide it.
511 AC_CHECK_FUNCS([closefrom getdirentries getrlimit])
513 if test $ac_cv_func_ftime = yes ; then
514 dnl See if ftime returns void (as it does on mingw)
515 AC_MSG_CHECKING([return type of ftime])
517 [AC_LANG_PROGRAM([[#include <sys/timeb.h>]],
518 [[struct timeb tp; int i = ftime(&tp);]])],
519 [AC_MSG_RESULT([int])],
520 [AC_MSG_RESULT([void])
521 AC_DEFINE([FTIME_RETURNS_VOID], [1], [Define if ftime returns void])])
524 dnl Check how to find the hostname: uname() in sys/utsname.h, or gethostname()
525 AC_CHECK_HEADERS([sys/utsname.h], [], [], [ ])
526 AC_CHECK_FUNCS([gethostname])
528 AC_MSG_CHECKING([whether std::from_chars() works for double])
529 AC_LINK_IFELSE([AC_LANG_PROGRAM(
530 dnl std::from_chars() was added in C++17, but support it with floating point
531 dnl types was slow to get implemented so probe for it. We can fall back to
532 dnl using strtod() instead (which is affected by the currently set locale and
533 dnl less thread-safe.
534 [[#include <charconv>]],
535 [[ const char* p = "3.14";
537 const auto& r = std::from_chars(p, p + 4, v);
538 if (r.ec != std::errc() || r.ptr != p + 4) return 1;]])],
539 AC_DEFINE([HAVE_STD_FROM_CHARS_DOUBLE], [1], [Define if std::from_chars() works for double])
540 AC_MSG_RESULT([yes]),
544 dnl mingw (for instance) lacks ssize_t
551 AC_CHECK_SIZEOF([short])
552 AC_CHECK_SIZEOF([int])
553 AC_CHECK_SIZEOF([long])
554 AC_CHECK_SIZEOF([long long])
556 AC_CHECK_HEADERS([sys/types.h])
558 AC_MSG_CHECKING([for 32 bit integer type])
560 "$ac_cv_sizeof_int") INT32_T=int ;;
561 "$ac_cv_sizeof_long") INT32_T=long ;;
562 "$ac_cv_sizeof_short") INT32_T=short ;;
564 AC_MSG_RESULT([none found])
565 AC_MSG_ERROR([No 32 bit integer type found])
567 AC_MSG_RESULT([$INT32_T])
569 AC_MSG_CHECKING([for 64 bit integer type])
571 "$ac_cv_sizeof_int") INT64_T=int ;;
572 "$ac_cv_sizeof_long") INT64_T=long ;;
573 "$ac_cv_sizeof_long_long") INT64_T='long long' ;;
575 AC_MSG_RESULT([none found])
576 AC_MSG_ERROR([No 64 bit integer type found])
578 AC_MSG_RESULT([$INT64_T])
580 dnl Check for perl (needed to generate some sources and documentation).
581 AC_PATH_PROG([PERL], [perl], [])
582 AC_ARG_VAR([PERL], [Perl interpreter])
583 if test x$USE_MAINTAINER_MODE = xyes; then
584 test -z "$PERL" && AC_MSG_ERROR([perl is required in maintainer mode])
587 AC_ARG_ENABLE([64bit_docid],
588 [AS_HELP_STRING([--enable-64bit-docid], [enable 64bit docid])],
589 [case ${enableval} in
591 *) AC_MSG_ERROR([bad value ${enableval} for --enable-64bit-docid]) ;;
593 [enable_64bit_docid=no])
595 AC_ARG_ENABLE([64bit_termcount],
596 [AS_HELP_STRING([--enable-64bit-termcount], [enable 64bit termcount])],
597 [case ${enableval} in
599 *) AC_MSG_ERROR([bad value ${enableval} for --enable-64bit-termcount]) ;;
601 [enable_64bit_termcount=no])
603 AC_ARG_ENABLE([64bit_termpos],
604 [AS_HELP_STRING([--enable-64bit-termpos], [enable 64bit termpos])],
605 [case ${enableval} in
607 *) AC_MSG_ERROR([bad value ${enableval} for --enable-64bit-termpos]) ;;
609 [enable_64bit_termpos=no])
611 AC_ARG_ENABLE([documentation],
612 [AS_HELP_STRING([--enable-documentation], [enable make rules to rebuild documentation [default=maintainer-mode]])],
613 [case ${enableval} in
615 *) AC_MSG_ERROR([bad value ${enableval} for --enable-documentation]) ;;
617 [enable_documentation=$USE_MAINTAINER_MODE])
618 AM_CONDITIONAL([DOCUMENTATION_RULES], [test x"$enable_documentation" = xyes])
619 AM_CONDITIONAL([MAINTAINER_NO_DOCS], [test x"$USE_MAINTAINER_MODE$enable_documentation" = xyesno])
621 if test x"$enable_documentation" = xyes ; then
622 dnl Checks for dot. (Diagrams in the documentation)
623 AC_PATH_PROG([DOT], [dot])
624 AC_ARG_VAR([DOT], [dot from graphviz])
625 test -z "$DOT" && AC_MSG_ERROR([dot (part of the graphviz package) is required to build documentation])
626 DOXYGEN_DOT_PATH=`echo "$DOT" | sed 's!/dot$!!'`
627 AC_SUBST([DOXYGEN_DOT_PATH])
629 dnl Check for doxygen. (Needed to make some more of the documentation)
630 AC_PATH_PROG([DOXYGEN], [doxygen], [])
631 AC_ARG_VAR([DOXYGEN], [Doxygen documentation system])
632 test -z "$DOXYGEN" && AC_MSG_ERROR([doxygen is required to build documentation])
634 dnl Check for help2man. (Needed to make man pages from "--help" output).
635 AC_PATH_PROG([HELP2MAN], [help2man], [])
636 AC_ARG_VAR([HELP2MAN], [help2man man page generator])
637 test -z "$HELP2MAN" && AC_MSG_ERROR([help2man is required to build documentation])
639 dnl Check for rst2html. (Needed to make HTML from reStructuredText format)
640 dnl Also look for rst2html.py, which archlinux reportedly installs it as.
641 AC_PATH_PROGS([RST2HTML], [rst2html rst2html.py], [])
642 AC_ARG_VAR([RST2HTML], [reST to HTML convertor])
643 test -z "$RST2HTML" && AC_MSG_ERROR([rst2html is required to build documentation (try package python-docutils)])
645 dnl Check for pngcrush, which we optionally use to reduce the size of the
646 dnl PNG files which doxygen generates. We can get by without it, so don't
647 dnl fail here if it's not found.
648 AC_PATH_PROG([PNGCRUSH], [pngcrush], [])
649 AC_ARG_VAR([PNGCRUSH], [PNG optimiser])
652 dnl Checks for header files.
653 AC_CHECK_HEADERS([fcntl.h limits.h poll.h sys/select.h sys/uio.h sysexits.h],
655 AC_CHECK_HEADERS([sys/resource.h],
656 [], [], [#include <sys/types.h>])
658 dnl cxxabi.h was added in GCC 3.1, but clang lies and defines __GNUC__ yet
659 dnl doesn't seem to reliably provide this header, so probe for it.
660 AC_CHECK_HEADERS([cxxabi.h], [], [], [ ])
662 dnl If valgrind is installed and new enough, we use it for leak checking in the
663 dnl testsuite. If VALGRIND is set to an empty value, then skip the check and
664 dnl don't use valgrind. On macOS only use valgrind if VALGRIND is set to a
665 dnl no empty value, as valgrind on macOS gives a lot of false positives.
666 use_valgrind_if_non_empty=
669 use_valgrind_if_non_empty=$VALGRIND ;;
671 use_valgrind_if_non_empty=${VALGRIND-unset} ;;
674 if test -n "$use_valgrind_if_non_empty" ; then
675 AC_PATH_PROG([VALGRIND], [valgrind], [])
676 AC_ARG_VAR([VALGRIND], [debugging tool (optionally used by test harness)])
677 if test -n "$VALGRIND" ; then
678 dnl Check that the installed valgrind version works, and supports the
679 dnl options we use. This means we won't try to use valgrind < 3.3.0
680 dnl (released 7/12/2007) since before that --log-file didn't expand
681 dnl %p (and appended the process id).
683 dnl No need to check for VALGRIND_COUNT_LEAKS now - that was added before
685 AC_MSG_CHECKING([if valgrind supports --log-file with %p and --child-silent-after-fork=yes])
686 vglog=config.vglog.%p.tmp
687 vglogwild="config.vglog.*.tmp*"
689 if $VALGRIND --log-file="$vglog" --child-silent-after-fork=yes -q true 2>&AS_MESSAGE_LOG_FD ; then
690 for f in $vglogwild ; do
692 $vglog*) VALGRIND= ;;
695 if test x"$VALGRIND" = x ; then
699 AC_CHECK_HEADERS([valgrind/memcheck.h], [], [VALGRIND=], [ ])
702 dnl The valgrind detected doesn't seem to work! Perhaps this is an
703 dnl x86_64 box with a 32 bit valgrind.
704 AC_MSG_RESULT([$VALGRIND doesn't work])
711 if test -n "$VALGRIND" ; then
712 AC_DEFINE([HAVE_VALGRIND], [1], [Define if a suitable valgrind is installed])
715 dnl If eatmydata is installed, we run the testsuite under it to speed it up.
716 dnl If EATMYDATA is set to an empty value, then skip this check and don't use
718 if test -n "${EATMYDATA-unset}" ; then
719 AC_PATH_PROG([EATMYDATA], [eatmydata], [])
720 AC_ARG_VAR([EATMYDATA], [wrapper to disable fsync (optionally used by test harness)])
723 dnl Checks for library functions.
726 AC_CACHE_CHECK([for sys_errlist and sys_nerr], xo_cv_sys_errlist_and_sys_nerr, [
727 AC_LINK_IFELSE([AC_LANG_PROGRAM(
728 dnl On Linux, sys_errlist and sys_nerr need <stdio.h>, though the man page
729 dnl says <errno.h>. The man page seems to match other platforms such as
730 dnl NetBSD, so include both headers to ensure we get them. With mingw and MSVC
731 dnl they're provided by <stdlib.h>.
734 #include <stdlib.h>]],
735 [[ printf("%s", sys_errlist[sys_nerr - 1]);]])],
736 [ xo_cv_sys_errlist_and_sys_nerr=yes ],
737 [ xo_cv_sys_errlist_and_sys_nerr=no ])
739 if test "x$xo_cv_sys_errlist_and_sys_nerr" = "xyes" ; then
740 AC_DEFINE([HAVE_SYS_ERRLIST_AND_SYS_NERR], [1],[Define if you have 'sys_errlist' and 'sys_nerr'])
743 AC_CACHE_CHECK([for _sys_errlist and _sys_nerr], xo_cv__sys_errlist_and__sys_nerr, [
744 AC_LINK_IFELSE([AC_LANG_PROGRAM(
747 #include <stdlib.h>]],
748 [[ printf("%s", _sys_errlist[_sys_nerr - 1]);]])],
749 [ xo_cv__sys_errlist_and__sys_nerr=yes ],
750 [ xo_cv__sys_errlist_and__sys_nerr=no
753 if test "x$xo_cv__sys_errlist_and__sys_nerr" = "xyes" ; then
754 AC_DEFINE([HAVE__SYS_ERRLIST_AND__SYS_NERR], [1],[Define if you have '_sys_errlist' and '_sys_nerr'])
757 dnl GNU-specific replacement for sys_errlist and sys_nerr.
758 AC_CHECK_FUNCS([strerrordesc_np])
760 dnl Check for ICU, which we can optionally use to find word breaks.
761 AC_ARG_VAR([PKG_CONFIG], [Location of pkg-config])
762 AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
763 if test -n "$PKG_CONFIG" ; then
764 dnl ICU's UTF-8 word boundary code was broken before 54.1.
765 m4_define([icu_min], [54.1])
766 m4_define([icu_mod], [icu-uc])
767 AC_MSG_CHECKING([for ICU (icu_mod >= icu_min)])
768 icu_config="$PKG_CONFIG icu_mod"
769 try_libs=`$PKG_CONFIG 'icu_mod >= icu_min' --libs 2>&AS_MESSAGE_LOG_FD`
770 if test $? -eq 0 ; then
772 AC_DEFINE([USE_ICU], [1], [Define to use ICU to find word breaks])
773 dnl The split here isn't perfect - e.g. -DFOO really ought to be in
774 dnl CPPFLAGS, but hopefully this won't be a problem in practice.
775 ICU_CFLAGS=`$icu_config --cflags-only-other`
776 ICU_CPPFLAGS=`$icu_config --cflags-only-I`
779 icu_version=`$icu_config --modversion 2>&AS_MESSAGE_LOG_FD`
780 if test $? -eq 0 ; then
781 AC_MSG_RESULT([no ($icu_version)])
787 AC_SUBST([ICU_CFLAGS])
788 AC_SUBST([ICU_CPPFLAGS])
791 dnl ***************************
792 dnl * Select modules to build *
793 dnl ***************************
795 dnl Check if a non-GPL library build is specified.
797 AC_ARG_ENABLE([gpl-libxapian],
798 [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)])],
799 [case ${enableval} in
802 AC_DEFINE([DISABLE_GPL_LIBXAPIAN], 1, [Define to error out if we try to include GPL code in libxapian])
804 *) AC_MSG_ERROR([bad value ${enableval} for --disable-gpl-libxapian]) ;;
806 [enable_gpl_libxapian=yes])
808 dnl Check which database backends should be built.
810 AC_DEFUN([_XAPIAN_BACKEND_ENABLE],
811 [AC_ARG_ENABLE([backend_$1],
812 [AS_HELP_STRING([--enable-backend-$1], [build the $1 database backend [default=$3]])],
815 *) AC_MSG_ERROR([Invalid option: '--enable-backend-$1=$enableval']) ;;
816 esac], [enable_backend_$1=$2])
819 AC_DEFUN([XAPIAN_BACKEND_ENABLE],
820 [_XAPIAN_BACKEND_ENABLE([$1],
821 m4_default([$2], [yes]),
822 m4_default([$3], [yes]))
825 dnl When adding a new backend, update INSTALL too.
826 XAPIAN_BACKEND_ENABLE([glass], [$enable_gpl_libxapian], [yes (unless --disable-gpl-libxapian)])
827 XAPIAN_BACKEND_ENABLE([honey])
828 XAPIAN_BACKEND_ENABLE([inmemory], [$enable_gpl_libxapian], [yes (unless --disable-gpl-libxapian)])
829 default_enable_backend_remote=$enable_gpl_libxapian
832 dnl We don't currently support the remote backend on this platform so
833 dnl disable it by default.
834 default_enable_backend_remote=no
837 XAPIAN_BACKEND_ENABLE([remote], [$default_enable_backend_remote], [yes (except for MSDOS; unless --disable-gpl-libxapian)])
839 dnl Save and empty LIBS while we probe for libraries to link libxapian against
840 dnl so we can just use AC_SEARCH_LIBS then copy LIBS to XAPIAN_LIBS and restore
841 dnl the value saved here.
845 dnl See if we have fdatasync, and what libraries are needed for it.
846 dnl We need to actually check for a declaration as macOS has a dummy
847 dnl implementation in the library which is not prototyped in any header.
848 AC_CHECK_DECL([fdatasync(int)], [
849 AC_SEARCH_LIBS([fdatasync], [rt], [])
850 AC_CHECK_FUNCS([fdatasync])
852 [ac_cv_func_fdatasync=no],
853 [#include <unistd.h>]
856 dnl We use timer_create() if available to implement a search time limit.
857 AC_SEARCH_LIBS([timer_create], [rt],
859 AC_MSG_CHECKING([for timer_create() usability])
860 dnl Several platforms have timer_create() but it's non-functional.
862 dnl Some of these (at least those with a stub implementation which always
863 dnl fails with ENOSYS) could be probed for, but we'd have to run code
864 dnl which isn't possible when cross-compiling, so just maintain a list
865 dnl of such platforms for now.
866 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
868 #error timer_create always fails with EAGAIN on AIX 7.1
869 #elif defined __NetBSD__
870 #error SIGEV_THREAD not implemented in NetBSD 9.2 (see: man sigevent)
871 #elif defined __OpenBSD__
872 #error timer_create always fails with ENOSYS on OpenBSD 7.3 (and no prototype)
874 [AC_MSG_RESULT([yes])
875 AC_DEFINE([HAVE_TIMER_CREATE], [1], [Define to 1 if you have the 'timer_create' function.])]
882 case $enable_backend_glass$enable_backend_honey in
884 dnl We use zlib for compressing tags in glass and honey. We could
885 dnl automatically disable support if zlib isn't found, but overall that
886 dnl probably does more harm than good - it's most likely that someone just
887 dnl forgot to install the -dev package for zlib.
889 dnl Similarly for uuid support.
891 dnl Check for zlib.h.
892 AC_CHECK_HEADERS([zlib.h], [], [
893 AC_MSG_ERROR([zlib.h not found - required for glass (you may need to install the zlib1g-dev or zlib-devel package)])
896 dnl Check for zlibVersion - normally it's in -lz but the mingw build needs -lzlib or -lzdll.
897 AC_SEARCH_LIBS([zlibVersion], [z zlib zdll], [], [
898 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)])
901 dnl Find a way to generate UUIDs.
903 case $host_os-$win32 in
904 *-yes | cygwin* | msys*) dnl Use built-in win32 API.
905 AC_DEFINE([USE_WIN32_UUID_API], [1],
906 [Define to 1 to use UuidCreate(), etc])
907 if test $win32 = yes ; then
908 dnl We need -lws2_32 for htonl(), etc, but not for Cygwin which
909 dnl provides these functions in its libc.
912 LIBS="$LIBS -lrpcrt4"
915 dnl Check for uuid/uuid.h (e2fsprogs/util-linux-ng) or uuid.h
916 dnl (FreeBSD/NetBSD/OpenBSD/AIX).
917 AC_CHECK_HEADERS([uuid/uuid.h], [
918 dnl util-linux-ng's uuid/uuid.h found - check for uuid_generate in
920 AC_SEARCH_LIBS([uuid_generate], [uuid], [], [
921 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)])
924 dnl Try uuid.h as found on FreeBSD/NetBSD/OpenBSD/AIX, with associated
926 AC_CHECK_HEADERS([uuid.h], [
927 dnl Check for uuid_create with no extra libraries required.
928 AC_CHECK_FUNC([uuid_create], [], [
929 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)])
932 dnl Especially useful for Android.
933 AC_MSG_CHECKING([if host platform supports /proc/sys/kernel/random/uuid])
936 AC_DEFINE([USE_PROC_FOR_UUID], [1],
937 [Define to 1 to read UUID from '/proc/sys/kernel/random/uuid'])
942 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 dnl DJGPP has a dummy implementation of fork which always fails.
954 dnl For disk-based backends, use flock() for locking, which doesn't need
955 dnl fork() or socketpair().
956 AC_DEFINE([FLINTLOCK_USE_FLOCK], 1, [Define to use flock() for flint-compatible locking])
962 if test "$enable_backend_remote" = yes ; then
963 case $host_os-$win32 in
965 dnl For mingw and msvc we have an alternative implementation which
966 dnl doesn't need fork() or socketpair().
968 dnl We need -lws2_32 for getaddrinfo(), etc.
970 dnl Vista is needed for the AI_ADDRCONFIG flag to getaddrinfo().
971 AC_DEFINE([WINVER], [0x600],
972 [Version of Windows to assume (0x600 => Vista).])
973 AC_DEFINE([_WIN32_WINNT], [WINVER],
974 [Version of Windows to assume.])
977 dnl DJGPP has a dummy implementation of fork which always fails. If
978 dnl someone actually wanted remote backend support, then DJGPP has a
979 dnl pthreads port, so using threads like we do on Windows would make more
981 AC_MSG_ERROR([The remote backend is not currently supported on this platform.])
984 dnl On Unix, we need fork and socketpair for the remotebackend.
985 AC_CHECK_FUNCS([fork], [], [
986 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.])
988 dnl Check if -lsocket is required for socketpair (Solaris needs it).
989 dnl And on Haiku it's in -lnetwork.
990 AC_SEARCH_LIBS([socketpair], [socket network], [], [
991 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.])
993 AC_DEFINE([HAVE_SOCKETPAIR], [1],
994 [Define to 1 if you have the 'socketpair' function.])
995 dnl Check if extra libraries are needed for getaddrinfo or inet_ntop()
996 dnl (e.g. on Solaris).
998 dnl We're currently assuming that any system that is worth trying to
999 dnl support has getaddrinfo() and inet_ntop(), since these are the
1000 dnl standard route for supporting IPv6, and that's pretty much essential
1001 dnl for platforms to support now.
1002 AC_SEARCH_LIBS([getaddrinfo], [nsl socket], [], [
1003 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.])
1005 AC_SEARCH_LIBS([inet_ntop], [nsl socket], [], [
1006 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.])
1011 XAPIAN_TYPE_SOCKLEN_T
1014 if test "$win32_need_lws2_32" = 1 ; then
1015 LIBS="$LIBS -lws2_32"
1020 AC_ARG_ENABLE([visibility],
1021 [AS_HELP_STRING([--disable-visibility], [disable use of GCC visibility])],
1022 [case ${enableval} in
1024 *) AC_MSG_ERROR([bad value ${enableval} for --disable-visibility]) ;;
1028 if test "`pwd`" != "`cd $srcdir;pwd`" ; then
1031 AM_CONDITIONAL([VPATH_BUILD], [test yes = "$vpath_build"])
1033 dnl Turn off compilation of anything that we don't have the requirements for
1035 dnl Set conditionals to specify what we compile
1037 AM_CONDITIONAL([BUILD_BACKEND_GLASS], [test yes = "$enable_backend_glass"])
1038 AM_CONDITIONAL([BUILD_BACKEND_HONEY], [test yes = "$enable_backend_honey"])
1039 AM_CONDITIONAL([BUILD_BACKEND_INMEMORY], [test yes = "$enable_backend_inmemory"])
1040 AM_CONDITIONAL([BUILD_BACKEND_REMOTE], [test yes = "$enable_backend_remote"])
1041 AM_CONDITIONAL([BUILD_BACKEND_TOOLS],
1042 [test nono != "$enable_backend_glass$enable_backend_honey"])
1044 dnl Decide if we should use the zlib-vg.so LD_PRELOAD hack.
1046 if test -n "$VALGRIND" ; then
1048 linux*) use_zlib_vg=yes ;;
1051 AM_CONDITIONAL([USE_ZLIB_VG], [test yes = "$use_zlib_vg"])
1053 AC_CHECK_FUNCS([fsync writev])
1054 AC_CHECK_FUNCS([posix_fadvise])
1055 if test "$win32" = no ; then
1056 dnl ftruncate() under Wine seems to be buggy and sometimes fails, though
1057 dnl a cut-down reproducer seems fine. For now just avoid ftruncate()
1058 dnl entirely on this platform - we'll fallback to lseek() + write() of a
1059 dnl single zero byte, which is pretty efficient.
1060 AC_CHECK_FUNCS([ftruncate])
1063 dnl HP-UX has pread and pwrite, but they don't work! Apparently this problem
1064 dnl manifests when largefile support is enabled, and we definitely want that
1065 dnl so don't use pread or pwrite on HP-UX.
1068 AC_MSG_CHECKING([for pread])
1069 AC_MSG_RESULT([present but broken on $host_os])
1070 AC_MSG_CHECKING([for pwrite])
1071 AC_MSG_RESULT([present but broken on $host_os])
1074 AC_CHECK_FUNC([pread],
1075 [AC_DEFINE([HAVE_PREAD], [1],
1076 [Define if pread is available on this system])
1077 AC_MSG_CHECKING([for any prototype needed for pread])
1078 AC_CACHE_VAL([xo_cv_pread_prototype],
1081 'extern "C" ssize_t pread(int, void *, size_t, off_t) throw ();' \
1082 'extern "C" ssize_t pread(int, void *, size_t, off_t);' ; do
1083 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1084 #include <sys/types.h>
1089 pread(1, b, 256, 20);
1091 xo_cv_pread_prototype="$p"
1095 if test -z "$xo_cv_pread_prototype"; then
1096 AC_MSG_RESULT([not found])
1097 AC_MSG_ERROR([Failed to find working prototype for pread])
1100 if test " " = "$xo_cv_pread_prototype" ; then
1101 AC_MSG_RESULT([none required])
1103 AC_MSG_RESULT([$xo_cv_pread_prototype])
1104 AC_DEFINE_UNQUOTED([PREAD_PROTOTYPE], [$xo_cv_pread_prototype],
1105 [explicit prototype needed for pread (if any)])
1108 AC_CHECK_FUNC([pwrite],
1109 [AC_DEFINE([HAVE_PWRITE], [1],
1110 [Define if pwrite is available on this system])
1111 AC_MSG_CHECKING([for any prototype needed for pwrite])
1112 AC_CACHE_VAL([xo_cv_pwrite_prototype],
1115 'extern "C" ssize_t pwrite(int, const void *, size_t, off_t) throw ();' \
1116 'extern "C" ssize_t pwrite(int, const void *, size_t, off_t);' ; do
1117 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1118 #include <sys/types.h>
1122 const char *p = "hello";
1123 pwrite(1, p, 5, 20);
1125 xo_cv_pwrite_prototype="$p"
1129 if test -z "$xo_cv_pwrite_prototype"; then
1130 AC_MSG_RESULT([not found])
1131 AC_MSG_ERROR([Failed to find working prototype for pwrite])
1134 if test " " = "$xo_cv_pwrite_prototype" ; then
1135 AC_MSG_RESULT([none required])
1137 AC_MSG_RESULT([$xo_cv_pwrite_prototype])
1138 AC_DEFINE_UNQUOTED([PWRITE_PROTOTYPE], [$xo_cv_pwrite_prototype],
1139 [explicit prototype needed for pwrite (if any)])
1145 AC_MSG_CHECKING([for directory separator(s)])
1146 case $host_os-$win32 in
1147 *-yes | cygwin* | msys* | os2* | *djgpp* | *msdos* )
1148 AC_MSG_RESULT([/ and \\])
1149 AC_DEFINE([DIR_SEPS], ["/\\"], [directory separator(s) as a character or string literal])
1150 AC_DEFINE([DIR_SEPS_LIST], [{ '/', '\\' }], [directory separator(s) as an initialiser list])
1154 AC_DEFINE([DIR_SEPS], ['/'], [directory separator(s) as a character or string literal])
1155 AC_DEFINE([DIR_SEPS_LIST], [{ '/' }], [directory separator(s) as an initialiser list])
1159 AC_CHECK_FUNCS([link])
1161 dnl *************************
1162 dnl * Set debugging options *
1163 dnl *************************
1165 dnl Which assertion types to enable in the code.
1167 AC_ARG_ENABLE([assertions],
1168 [AS_HELP_STRING([--enable-assertions], [enable debug assertions (no|partial|yes) [default=no]])],
1172 AC_MSG_ERROR([Invalid option: '--enable-assertions=$enableval']) ;;
1175 AC_ARG_ENABLE([log],
1176 [AS_HELP_STRING([--enable-log], [generate a log of methods called, etc (no|yes|profile) [default=no]])],
1180 AC_MSG_ERROR(['--enable-log=profile' is no longer supported - see https://trac.xapian.org/wiki/ProfilingXapian for alternatives.]) ;;
1182 AC_MSG_ERROR([Invalid option: '--enable-log=$enableval']) ;;
1185 dnl Set defines according to the --enable-assertions and --enable-log options
1188 if test yes = "$enable_assertions" || test partial = "$enable_assertions" ; then
1189 AC_DEFINE([XAPIAN_ASSERTIONS],,
1190 [Define if you want assertions (causes some slow-down)])
1193 if test yes = "$enable_assertions"; then
1194 AC_DEFINE([XAPIAN_ASSERTIONS_PARANOID],,
1195 [Define if you want paranoid assertions (causes significant slow-down)])
1198 if test yes = "$enable_log"; then
1199 AC_DEFINE([XAPIAN_DEBUG_LOG],,
1200 [Define if you want a log of methods called and other debug messages])
1203 dnl Check if IEEE-754 is followed for representing floating point numbers by the platform.
1209 using namespace std;
1212 double a = 2353.3523423;
1213 uint64_t bit_pattern = 0x40A262B46635BEFF;
1214 if (memcmp(&bit_pattern, &a, sizeof(double)) == 0) return 0;
1223 if test "$ieee_followed" = 1; then
1224 AC_DEFINE([FOLLOWS_IEEE], [1], [Defined if system uses ieee format to store floating point numbers])
1227 dnl ******************************
1228 dnl * Set special compiler flags *
1229 dnl ******************************
1231 AC_ARG_ENABLE([werror],
1232 [AS_HELP_STRING([--enable-werror], [enable treating compiler warnings as errors [default=maintainer-mode]])],
1233 [case ${enableval} in
1235 *) AC_MSG_ERROR([bad value ${enableval} for --enable-werror]) ;;
1237 [enable_werror=$USE_MAINTAINER_MODE])
1239 dnl Put -Werror or equivalent in its own make variable so that it can easily
1240 dnl be overridden by `make WERROR=` if needed during development (e.g. if
1241 dnl you want to get a full list of compile warnings to fix rather than
1242 dnl stopping at the first file with warnings).
1246 dnl Set flags to control warnings (enable more, or disable annoying ones).
1248 if test yes = "$GXX"; then
1249 dnl Intel's C++ compiler and clang both lie and define __GNUC__, so check which
1250 dnl we actually have, as neither is really 100% compatible.
1251 echo __INTEL_COMPILER __clang__ > conftest.cc
1252 case `$CXX -E conftest.cc 2>&AS_MESSAGE_LOG_FD|grep -v '^#'` in
1253 *__INTEL_COMPILER*__clang__*)
1254 dnl GCC (since neither substituted):
1256 dnl The exact format of g++ --version seems to change with almost every
1257 dnl minor release so use the preprocessor macros which should be more
1258 dnl robust. Pass -xc++ to avoid warnings about any command-line options
1259 dnl included in $CXX which aren't valid for C (such as -std=c++17).
1260 AC_MSG_CHECKING([for version of $CXX])
1261 gxx_version=`echo __GNUC__.__GNUC_MINOR__.__GNUC_PATCHLEVEL__|$CXX -xc++ -E -|sed '/^#/d;s/ //g'`
1262 AC_MSG_RESULT([GCC $gxx_version])
1264 dnl -Wundef was supported by g++ 3.0.
1266 dnl -Wlogical-op and -Wmissing-declarations (for C++) were added in
1269 dnl -Wdouble-promotion was added in GCC 4.6.
1271 dnl -Wduplicated-cond was added in GCC 6.
1273 dnl -Wduplicated-branches was added in GCC 7.
1275 dnl All the other options were supported by g++ 2.95.
1276 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"
1278 case $gxx_version in
1280 AC_MSG_ERROR([Xapian requires GCC 7.0 or later])
1285 dnl -Wold-style-cast is interesting, but triggers for macros from
1286 dnl system headers (e.g. FD_SET). GCC 4.8 improved this by making
1287 dnl -ftrack-macro-expansion=2 the default, but we still see such
1288 dnl warnings on some platforms for some reason (e.g. Cygwin with GCC
1289 dnl 5.4.0 warns about FD_SET, and on Debian with GCC 4.9.2 we see
1290 dnl warnings from zlib.h).
1295 dnl Intel's compiler (since __clang__ not substituted):
1297 dnl -w1 stops the avalanche of uninteresting "remark" messages.
1298 dnl -wd... disables warnings which don't have good code workarounds.
1299 AM_CXXFLAGS="$AM_CXXFLAGS -Wall -w1 -wd177,1572"
1304 dnl clang (since __INTEL_COMPILER not substituted):
1306 dnl These options all work at least as far back as clang++ 3.0:
1307 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"
1314 if test no != "$enable_visibility"; then
1315 dnl GCC doesn't support symbol visibility on all platforms (e.g. it isn't
1316 dnl supported on mingw and visibility attributes result in warnings).
1317 AC_MSG_CHECKING([if $CXX -fvisibility=hidden -fvisibility-inlines-hidden works])
1318 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
1319 AC_MSG_RESULT([yes])
1320 AM_CXXFLAGS="$AM_CXXFLAGS -fvisibility=hidden -fvisibility-inlines-hidden"
1321 dash_d_visibility=-DXAPIAN_ENABLE_VISIBILITY
1326 elif test yes = "$msvc"; then
1330 AC_MSG_CHECKING([for option to turn warnings into errors])
1331 if test x$enable_werror != xyes; then
1333 AC_MSG_RESULT([not requested])
1334 elif test -z "$WERROR" ; then
1335 AC_MSG_RESULT([unknown for $CXX])
1337 AC_MSG_RESULT([$WERROR])
1340 XAPIAN_TEST_LDFLAGS([-Wl,-Bsymbolic-functions], [XAPIAN_LDFLAGS])
1342 dnl New in GCC 5. Sort of like -Bsymbolic-functions, but for the compiler
1343 dnl rather than the linker.
1344 XAPIAN_TEST_LDFLAGS([-fno-semantic-interposition], [XAPIAN_LDFLAGS])
1346 AC_MSG_CHECKING([whether to use SSE instructions on x86])
1349 if test "$enable_sse" = no ; then
1351 if test yes = "$msvc"; then
1352 dnl MSVC defaults to SSE2.
1353 AM_CXXFLAGS="$AM_CXXFLAGS -arch:IA32"
1356 dnl Default to sse2.
1357 test "$enable_sse" != yes || enable_sse=sse2
1358 if test yes = "$GXX"; then
1359 AC_MSG_RESULT([yes (configure with --disable-sse to disable)])
1360 dnl We can unconditionally use -mtune=generic as it was added in GCC
1361 dnl 4.2, and supported at least as far back as clang 3.0.
1362 AM_CXXFLAGS="$AM_CXXFLAGS -mfpmath=sse -m$enable_sse -mtune=generic"
1363 elif test yes = "$msvc"; then
1364 AC_MSG_RESULT([yes (configure with --disable-sse to disable)])
1365 if test sse = "$enable_sse"; then
1366 dnl MSVC defaults to SSE2.
1367 AM_CXXFLAGS="$AM_CXXFLAGS -arch:SSE"
1370 AC_MSG_RESULT([don't know how to for compiler $CXX])
1375 AC_MSG_RESULT([non-x86 arch ($host_cpu)]) ;;
1378 if test "$GXX" = yes; then
1379 dnl Default to enabling _FORTIFY_SOURCE at level 2. It shouldn't cause a
1380 dnl problem to define it where it's not supported, but we need to check for
1381 dnl an issue on mingw-w64 where some versions required linking with -lssp
1382 dnl (this was fixed in v11.0.0 released 2023-04-28). We detect this with a
1383 dnl configure-time link test and don't auto-enable _FORTIFY_SOURCE if using
1384 dnl an affected version.
1385 AC_MSG_CHECKING([if _D_FORTIFY_SOURCE=2 links without extra libraries])
1386 save_CPPFLAGS=$CPPFLAGS
1387 CPPFLAGS="$CPPFLAGS -D_FORTIFY_SOURCE=2"
1388 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1390 static char a[20], b[10];]], [[
1393 [AC_MSG_RESULT([yes])
1394 AC_DEFINE([FORTIFY_SOURCE_OK], [1], [Define to 1 if '-D_FORTIFY_SOURCE=2' link test passes])],
1395 [AC_MSG_RESULT([no])])
1396 CPPFLAGS=$save_CPPFLAGS
1400 [/* Disable stupid MSVC warnings. */
1402 /* Passing an empty parameter to a single parameter macro. */
1403 # pragma warning(disable:4003)
1404 /* Assignment in conditional expression; other compilers suppress with extra parentheses but not MSVC. */
1405 # pragma warning(disable:4706)
1406 /* A "performance" warning for converting int to bool. */
1407 # pragma warning(disable:4800)
1408 /* Character in string literal can't be represented in current code page. */
1409 # pragma warning(disable:4566)
1411 /* POSIX get to deprecate POSIX things, not Microsoft. */
1412 # ifndef _CRT_NONSTDC_NO_WARNINGS
1413 # define _CRT_NONSTDC_NO_WARNINGS
1415 # ifndef _CRT_SECURE_NO_WARNINGS
1416 # define _CRT_SECURE_NO_WARNINGS
1419 /* WSAAddressToStringA() is deprecated and we should apparently use
1420 * WSAAddressToStringW(), but we don't want wide character output so
1421 * that would mean we'd have to convert the result back to ASCII
1422 * which is a really stupid idea.
1424 # ifndef _WINSOCK_DEPRECATED_NO_WARNINGS
1425 # define _WINSOCK_DEPRECATED_NO_WARNINGS
1428 /* Tell MSVC we want M_PI, etc defined. */
1429 # ifndef _USE_MATH_DEFINES
1430 # define _USE_MATH_DEFINES
1433 /* Tell MSVC we don't want max() and min() macros defined. */
1439 /* Tell zlib to include const in method signatures. Define this in config.h
1440 * to ensure it always gets defined before zlib.h is included.
1444 /* Make the POSIX-like functions support large files. MSVC needs this;
1445 * current mingw32 does too; mingw64 supports _FILE_OFFSET_BITS, which
1446 * AC_SYS_LARGEFILE should discover and enable automatically.
1448 #if defined _MSC_VER || \
1449 (defined __MINGW32__ && !defined _FILE_OFFSET_BITS)
1451 # include <sys/stat.h>
1452 # include <sys/types.h>
1454 /* zlib.h uses off_t so we need to include it before we redefine off_t. */
1457 // The default stat() and fstat() use 32-bit filesizes and time_t, so we need
1458 // to arrange to use 64-bit variants instead.
1461 // Break #undef lines to stop config.status from commenting them out.
1466 // This hack is a problem is we ever want a method called "stat".
1468 // MSVC needs to call _stat64() instead of stat() and the struct which holds
1469 // the information is `struct _stat64` instead of `struct stat` so we just
1470 // use #define to replace both in one go.
1471 # define stat _stat64
1473 // Mingw32 has _stat64() but unhelpfully for our purposes, the struct is
1474 // called __stat64 (with an extra underscore). We hack around this by
1475 // defining stat to __stat64 which sorts out the struct, and then using
1476 // a second macro to forward function-like uses of __stat64() to
1478 # define stat __stat64
1479 # define __stat64(PATH, STATBUF) _stat64((PATH), (STATBUF))
1482 // We also want to use _fstat64() instead of fstat() but in this case we can
1483 // use a function-like macro, so we could have a method called fstat so long
1484 // as it didn't take two parameters.
1487 // Break #undef lines to stop config.status from commenting them out.
1492 # define fstat(FD, BUF) _fstat64(FD, BUF)
1495 // Break #undef lines to stop config.status from commenting them out.
1501 // Break #undef lines to stop config.status from commenting them out.
1506 # define lseek(FD, OFF, WHENCE) _lseeki64(FD, OFF, WHENCE)
1507 /* Redefine via a typedef so C++ code off_t(-1) works - it wouldn't if we did:
1508 * #define off_t long long
1510 typedef long long off_t_redefinition_typedef;
1511 # define off_t off_t_redefinition_typedef
1515 /* MSVC defines _WIN32 but not __WIN32__. */
1516 #if !defined __WIN32__ && defined _WIN32
1520 /* MSVC defines _WIN64 but not __WIN64__. */
1521 #if !defined __WIN64__ && defined _WIN64
1525 /* Default to enabling _FORTIFY_SOURCE at level 2 for GCC-like compilers. It
1526 * shouldn't cause a problem to define it where it's not supported.
1528 * The FORTIFY_SOURCE_OK check avoids auto-enabling on some mingw-w64 versions
1529 * which required linking with -lssp too. This was addressed in v11.0.0
1530 * (released 2023-04-28).
1532 * Check if _FORTIFY_SOURCE is already defined to allow the user to override
1533 * our choice with "./configure CPPFLAGS=-D_FORTIFY_SOURCE=0" or "...=1" or
1536 #if defined FORTIFY_SOURCE_OK && !defined _FORTIFY_SOURCE
1537 # define _FORTIFY_SOURCE 2
1540 /* For compilers which support it (such as GCC, clang, Intel's C++ compiler)
1541 * we can use __builtin_expect to give the compiler hints about branch
1542 * prediction. See HACKING for how to use these.
1544 #if HAVE_DECL___BUILTIN_EXPECT
1545 /* The arguments of __builtin_expect() are both long, so use !! to ensure that
1546 * the first argument is always an integer expression, and always 0 or 1, but
1547 * still has the same truth value for the if or while it is used in.
1549 # define rare(COND) __builtin_expect(!!(COND), 0)
1550 # define usual(COND) __builtin_expect(!!(COND), 1)
1552 # define rare(COND) (COND)
1553 # define usual(COND) (COND)
1556 /* This macro can be used around expressions which intentionally make use of
1557 * unsigned integer overflow (which is defined behaviour, unlike signed integer
1558 * overflow) so that we can use UBSan's optional unsigned-integer-overflow
1559 * check to find potential bugs where we unintentionally overflow an unsigned
1563 #define UNSIGNED_OVERFLOW_OK(X) \
1564 ([&]() __attribute__((no_sanitize("unsigned-integer-overflow"))) {\
1568 # define UNSIGNED_OVERFLOW_OK(X) (X)
1571 /* Signal we're building the library so it's OK to include headers such as
1572 * xapian/query.h directly.
1574 #define XAPIAN_LIB_BUILD 1
1577 AC_SUBST([AM_CXXFLAGS])
1579 dnl Restore CXXFLAGS to those the user specified or autoconf defaulted to.
1580 CXXFLAGS=$save_CXXFLAGS
1582 dnl Required for auto regeneration to work in a combined maintainer-mode tree.
1583 : ${AUTOM4TE=autom4te}
1584 AC_SUBST([AUTOM4TE])
1586 dnl Libtool sets this (to yes|no|unknown) and we use it in xapian-config.
1587 AC_SUBST([link_all_deplibs_CXX])
1589 dnl Shared library extension.
1591 eval "SHLIBEXT=$shrext_cmds"
1592 AC_SUBST([SHLIBEXT])
1594 dnl We want to be able to use GNU make % pattern rules in maintainer targets
1595 dnl but automake warns these aren't portable, so we substitute the % to avoid
1600 dnl Split up the version number into "MAJOR.MINOR.REVISION".
1601 MAJOR_VERSION=`echo "$VERSION"|sed 's/\..*//'`
1602 [MINOR_VERSION=`echo "$VERSION"|sed 's/[^.]*\.//;s/\..*//'`]
1603 [REVISION=`echo "$VERSION"|sed 's/.*\.//;s/_.*$//'`]
1605 dnl Convert the libs in $XAPIAN_LIBS to a CMake list.
1606 XAPIAN_CMAKE_LIBS=`echo " $XAPIAN_LIBS" | sed 's/ -l/;/g;s/ //g'`
1607 AC_SUBST([XAPIAN_CMAKE_LIBS])
1609 XAPIAN_CMAKE_SHARED=
1610 if test "$enable_shared" = yes; then
1611 XAPIAN_CMAKE_SHARED=ON
1613 XAPIAN_CMAKE_SHARED=OFF
1615 AC_SUBST([XAPIAN_CMAKE_SHARED])
1617 LIBRARY_STATIC_EXT=.$libext
1618 AC_SUBST([LIBRARY_STATIC_EXT])
1620 if test "$win32" = yes; then
1621 LIBRARY_SHARED_IMP_EXT=$LIBRARY_STATIC_EXT
1623 LIBRARY_SHARED_IMP_EXT=
1625 AC_SUBST([LIBRARY_SHARED_IMP_EXT])
1627 dnl We don't make use of maths function setting errno and if we tell the
1628 dnl compiler that it can optimise them better in some cases. Apparently
1629 dnl most BSD-derived platforms don't set errno in this case anyway.
1630 XAPIAN_TEST_CXXFLAGS([-fno-math-errno], [CXXFLAGS])
1632 dnl **************************
1633 dnl * Build the output files *
1634 dnl **************************
1640 docs/doxygen_api.conf
1641 docs/doxygen_source.conf
1642 cmake/xapian-config.cmake
1643 cmake/xapian-config-version.cmake
1644 pkgconfig/xapian-core"$LIBRARY_VERSION_SUFFIX".pc:pkgconfig/xapian-core.pc.in
1646 AC_CONFIG_FILES([makemanpage], [chmod +x makemanpage])
1647 AC_CONFIG_FILES([tests/runtest], [chmod +x tests/runtest])
1648 AC_CONFIG_FILES([tests/runsrv], [chmod +x tests/runsrv])
1649 AC_CONFIG_FILES([tests/submitperftest], [chmod +x tests/submitperftest])
1650 AC_CONFIG_FILES([tests/perftest/get_machine_info], [chmod +x tests/perftest/get_machine_info])
1651 AC_CONFIG_FILES([xapian-config], [chmod +x xapian-config])
1654 dnl There are no files generated by AC_OUTPUT in the following directories
1655 dnl and we need to ensure they exist so that the rest of configure or make
1656 dnl won't fail because they don't exist when srcdir != builddir.
1657 if test yes = "$vpath_build" ; then
1658 for dir in include/xapian languages queryparser ; do
1659 AS_MKDIR_P(["$dir"])
1663 dnl Generate include/xapian/version.h:
1665 dnl MAIN_VERSION is VERSION without any _git123 suffix.
1666 MAIN_VERSION="$MAJOR_VERSION.$MINOR_VERSION.$REVISION"
1668 for backend in GLASS HONEY INMEMORY REMOTE ; do
1669 val=`eval echo "\\\$BUILD_BACKEND_${backend}_TRUE"`
1670 if test -z "$val" ; then
1671 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_HAS_${backend}_BACKEND"
1675 if test yes = "$enable_64bit_docid" ; then
1676 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_DOCID_BASE_TYPE="`echo "$INT64_T"|sed 's/ /____/g'`
1678 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_DOCID_BASE_TYPE="`echo "$INT32_T"|sed 's/ /____/g'`
1681 if test yes = "$enable_64bit_termcount" ; then
1682 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TERMCOUNT_BASE_TYPE="`echo "$INT64_T"|sed 's/ /____/g'`
1684 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TERMCOUNT_BASE_TYPE="`echo "$INT32_T"|sed 's/ /____/g'`
1687 if test yes = "$enable_64bit_termpos" ; then
1688 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TERMPOS_BASE_TYPE="`echo "$INT64_T"|sed 's/ /____/g'`
1690 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TERMPOS_BASE_TYPE="`echo "$INT32_T"|sed 's/ /____/g'`
1693 dnl Always ought to be 64 bit.
1694 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TOTALLENGTH_TYPE="`echo "unsigned $INT64_T"|sed 's/ /____/g'`
1696 dnl Make revision numbers in the API 64 bit for future-proofing.
1697 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_REVISION_TYPE="`echo "unsigned $INT64_T"|sed 's/ /____/g'`
1699 dnl For GCC (and compilers which pretend to be GCC) and MSVC, we create checks
1700 dnl for some ABI-incompatible configurations in the generated version.h.
1701 dnl Such configurations may be specified via $CXXFLAGS so we should use this
1702 dnl when generating version.h. For these compilers, CXXCPP="$CXX -E" so it
1703 dnl should understand all compiler options.
1705 dnl For other compilers, we only pass $CPPFLAGS to $CXXCPP in case it's an
1706 dnl external cpp which doesn't understand all options which might be in
1710 cxxcpp_flags="$cxxcpp_flags $CPPFLAGS $CXXFLAGS" ;;
1712 cxxcpp_flags="$cxxcpp_flags $CPPFLAGS" ;;
1714 rm -f include/xapian/version.h.tmp
1715 dnl "\r" in sed is a GNUism, but we only need to remove it on MS Windows
1716 dnl where we'll always have GNU sed, and other sed's will just interpret
1717 dnl it as "r" (Solaris sed) or maybe literal "\r" which won't match.
1719 dnl Use @@ around $MAIN_VERSION so we get " in the final output.
1720 $CXXCPP $cxxcpp_flags\
1721 -DSTRING_VERSION="\"@@$MAIN_VERSION@@\""\
1722 -DMAJOR_VERSION="\"$MAJOR_VERSION\""\
1723 -DMINOR_VERSION="\"$MINOR_VERSION\""\
1724 -DREVISION="\"$REVISION\""\
1726 $srcdir/include/xapian/version_h.cc|\
1727 ${SED-sed} '0,/const char \* dummy/d;/"/!d;s/^ *//;/^#/d;s/ *$//;s/" *,//;s/"//g;s/@@/"/g;s/ */ /g;s/ *,\r$//;s/ *,$//;s/____/ /g;s/\\\\$/\\/'\
1728 > include/xapian/version.h.tmp
1729 dnl Only update the file if it has changed, so we don't alter the timestamp
1730 dnl and cause lots of rebuilding needlessly. However, the build system
1731 dnl needs a timestamp to know when to regenerate version.h because version_h.cc
1732 dnl has changed so we use a separate timestamp file.
1733 touch include/xapian/version.h.timestamp
1734 if cmp include/xapian/version.h.tmp include/xapian/version.h >/dev/null 2>&1
1736 rm include/xapian/version.h.tmp
1738 mv include/xapian/version.h.tmp include/xapian/version.h
1741 if test "$enable_gpl_libxapian" != yes ; then
1742 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.])