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.4.24], [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 libxapian:
32 dnl 29:1:7 1.2.23 No API changes (except new inline methods)
33 dnl 30:0:0 1.4.0 Extensive API changes
34 dnl 31:0:1 1.4.1 New Weight subclasses, etc
35 dnl 32:0:2 1.4.2 Database::get_document() with flags
36 dnl 33:0:3 1.4.3 Database::locked() method
37 dnl 33:1:3 1.4.4 No API changes
38 dnl 34:0:4 1.4.5 Database::get_total_length() method
39 dnl 35:0:5 1.4.6 C++11 move support added
40 dnl 35:1:5 1.4.7 No API changes
41 dnl 36:0:6 1.4.8 STEM_SOME_FULL_POS added
42 dnl 36:1:6 1.4.9 No API changes
43 dnl 37:0:7 1.4.10 Added DatabaseClosedError, etc
44 dnl 38:0:8 1.4.11 Added SNIPPET_CJK_NGRAM
45 dnl 39:0:9 1.4.12 Database::size() method
46 dnl 39:1:9 1.4.13 No API changes
47 dnl 40:0:10 1.4.14 Xapian::Stem changes
48 dnl 40:1:10 1.4.15 No API changes
49 dnl 40:2:10 1.4.16 No API changes
50 dnl 40:3:10 1.4.17 No API changes (except a new inlined method)
51 dnl 41:0:11 1.4.18 QueryParser::FLAG_ACCUMULATE
52 dnl 42:0:12 1.4.19 QueryParser::FLAG_NO_POSITIONS
53 dnl 42:1:12 1.4.20 No API changes
54 dnl 42:2:12 1.4.21 No API changes
55 dnl 42:3:12 1.4.22 No API changes
56 dnl 42:4:12 1.4.23 No API changes
57 dnl 42:5:12 1.4.24 No API changes
58 LIBRARY_VERSION_INFO=42:5:12
59 AC_SUBST([LIBRARY_VERSION_INFO])
61 LIBRARY_VERSION_SUFFIX=
62 AC_SUBST([LIBRARY_VERSION_SUFFIX])
64 dnl Disabled for stable release series.
65 test x"$program_suffix" != xNONE || program_suffix=
67 dnl Where xapian.h, etc go. In development release append "/xapian-1.3".
71 dnl Check the build directory doesn't contain a space, so we die early with
75 AC_MSG_ERROR([You can't build in a directory whose path contains a space])
79 dnl Check the source directory doesn't contain a space, so we die early with
80 dnl a helpful error. FIXME: Unfortunately, configure seems to choke before
81 dnl it gets to us so this code doesn't get a chance to fire.
84 dnl Note: for in-tree builds, the build directory test above will fire
86 AC_MSG_ERROR([You can't build with sources in a directory whose path contains a space])
90 dnl Check the prefix to install in doesn't contain a space, so we die early with
94 AC_MSG_ERROR([You can't install in a directory whose path contains a space])
98 dnl Note if the user specified a particular C++ compiler so we can give a more
99 dnl appropriate error message if we can't link a simple C++ program.
101 if test -n "$CXX" ; then
102 original_CXX="CXX=$CXX"
103 elif test -n "$CCC" ; then
104 original_CXX="CCC=$CCC"
107 dnl See HACKING document for details of the reasons for required versions.
108 AM_INIT_AUTOMAKE([1.11 -Wportability tar-ustar no-dist-gzip dist-xz std-options])
109 AC_CONFIG_SRCDIR([matcher/multiandpostlist.cc])
111 AC_CONFIG_HEADERS([config.h])
113 AC_CONFIG_MACRO_DIR([m4])
117 dnl Use libtool to manage our libraries.
119 dnl Default to only building shared libraries.
121 dnl Building both shared and static means having to compile the files which
122 dnl make up the library twice on most platforms. Shared libraries are the
123 dnl better option for most users, and if anyone really wants static libraries,
124 dnl they can configure with --enable-static (or --enable-static=xapian-core if
125 dnl configuring a combined tree with the bindings).
127 dnl We don't export any data items from the library, so it should be safe to
128 dnl enable win32-dll without decorating any declarations specially.
129 LT_INIT([disable-static win32-dll])
131 dnl -no-undefined causes problems on Solaris with Sun CC in C++11 mode, so only
132 dnl pass -no-undefined on platforms where it is required in order to link a
133 dnl shared library at all (Windows is the main one).
135 if test unsupported = "$allow_undefined_flag" ; then
136 NO_UNDEFINED=-no-undefined
138 AC_SUBST(NO_UNDEFINED)
142 dnl A standard "gotcha" for mingw and cygwin users is to not set up their
143 dnl PATH correctly, so that MSDOS FIND.EXE is found before Unix find. Help
144 dnl them out by checking for this condition, rather than letting libtool
145 dnl fail in obscure ways. NB check the *BUILD* OS, not the host one!
147 cygwin* | mingw* | msys* | pw32*)
148 find /dirunlikelytoexist >/dev/null 2>&1
149 if test $? = 2 ; then
150 dnl Unix find will return 1 if the directory didn't exist, or 0 if
153 *** You appear to have an MSDOS-like FIND.EXE in your PATH ahead of any
154 *** UNIX-like find. This misconfiguration will confuse libtool - you'll need
155 *** to make sure you have a UNIX-like find installed and fix your PATH, then
156 *** rerun configure. For more information, see:
158 *** https://www.cygwin.com/faq/faq.html#faq.using.find
164 dnl Add parameters for aclocal
165 dnl (This must come after AM_INIT_AUTOMAKE, since it modifies ACLOCAL)
166 ACLOCAL="$ACLOCAL $ACLOCAL_FLAGS"
168 dnl disable "maintainer only" rules by default
171 dnl Checks for programs.
176 # Checked: dragonfly6.4 freebsd8.0 openbsd4.6 solaris2.9 solaris2.10
178 linux* | k*bsd*-gnu | dragonfly* | freebsd* | openbsd* | solaris*)
179 dnl Vanilla libtool sets this to "unknown" which it then handles as "yes".
180 link_all_deplibs_CXX=no
186 dnl Extract search path from ldconfig which is more reliable than the way
187 dnl vanilla libtool extracts them from ld.so.conf.
188 d=`/sbin/ldconfig -N -X -v 2>&AS_MESSAGE_LOG_FD|$SED 's,^\(/.*\):\( (.*)\)\?$,\1,p;d'|tr '\n' ' '`
189 test -z "$d" || sys_lib_dlsearch_path_spec=$d
194 *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
195 dnl On these platforms, libtool emits a warning if -no-install is passed,
196 dnl and uses -no-fast-install instead - the least ugly way to avoid that
197 dnl warnings seems to be to duplicate the above list of platforms from
198 dnl libtool and use -no-fast-install on them directly.
199 NO_INSTALL=-no-fast-install ;;
201 NO_INSTALL=-no-install ;;
203 AC_SUBST([NO_INSTALL])
205 dnl For reasons which are beyond me, if autoconf can't find a C++ compiler
206 dnl it will set CXX to g++ (which obviously won't work) rather than actually
207 dnl telling the user that it couldn't find a C++ compiler and telling them
208 dnl to either install one or set CXX if there's one configure failed to find.
209 dnl It's probably worthwhile checking that the C++ compiler actually works
211 if test -n "$CXX" ; then
213 AC_MSG_CHECKING([whether $CXX is a working C++ compiler])
214 AC_CACHE_VAL([xo_cv_cxx_works],
216 AC_RUN_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
217 [xo_cv_cxx_works=yes],
218 [xo_cv_cxx_works=no],
219 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
220 [xo_cv_cxx_works=yes],
221 [xo_cv_cxx_works=no])])
223 AC_MSG_RESULT([$xo_cv_cxx_works])
227 if test no = "$xo_cv_cxx_works" ; then
228 case $original_CXX in
230 dnl CCC is handled in a slightly odd way - if its value isn't an
231 dnl executable (taking PATH into account) then it is ignored!
232 test "$original_CXX" = "CCC=$CXX" || original_CXX=
235 if test -z "$original_CXX" ; then
237 *** You need a working C++ compiler to compile Xapian, but configure failed to
238 *** find one. If you have a working C++ compiler, you can tell configure where
239 *** to find it by invoking it like so:
241 *** ./configure CXX=/opt/bin/c++
245 *** You need a working C++ compiler to compile Xapian, but the compiler you
246 *** specified (with '$original_CXX') doesn't appear to be able to successfully
247 *** compile and link a simple program.
252 dnl Probe for any options needed to enable C++11 support.
253 AX_CXX_COMPILE_STDCXX([11])
255 dnl We don't use a C compiler to compile Xapian's code, but on some platforms
256 dnl (e.g. mingw) libtool uses $LTCC which defaults to $CC, and it's also use to
257 dnl build auxiliary tools like snowball and lemon.
260 dnl Check endianness.
263 dnl We want a non-cross-compiling C compiler for building lemon with.
264 if test -z "$CC_FOR_BUILD" ; then
265 if test yes = "$cross_compiling"; then
271 AC_ARG_VAR([CC_FOR_BUILD], [C compiler command for native compilation (needed to compile build tools during cross-builds)])
273 dnl Run tests using the C++ compiler.
276 dnl Enable large file support if possible.
278 dnl With xlC on AIX, -D_LARGE_FILES changes the ABI of std::string, so it
279 dnl also needs to be used when compiling user code.
280 abi_affecting_cxxflags=
281 if $GREP '^#define _LARGE_FILES 1$' confdefs.h > /dev/null 2>&1 ; then
282 abi_affecting_cxxflags=-D_LARGE_FILES
284 AC_SUBST([abi_affecting_cxxflags])
286 AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
287 #if defined __WIN32__ || defined _WIN32
290 ]])], [win32=no], [win32=yes])
292 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
296 ]])], [msvc=no], [msvc=yes])
300 AC_SUBST([XAPIAN_LDFLAGS])
301 AC_SUBST([XAPIAN_LIBS])
303 xo_fn_unknown_option_check() {
304 dnl Some compilers don't error out on unknown options which unhelpfully
305 dnl means we would think the option is supported, use it, and end up
306 dnl with a warning or note diagnostic every time we use the option.
308 dnl Check compiler stderr for known strings:
309 dnl * MSVC: Command line warning D9002 : ignoring unknown option '...'
310 dnl * icc strings cribbed from automake's depend.m4
311 $GREP 'ignoring unknown option' conftest.err >/dev/null 2>&1 ||
312 $GREP 'ignoring option' conftest.err >/dev/null 2>&1 ||
313 $GREP 'not supported' conftest.err >/dev/null 2>&1 ||
318 AC_DEFUN([XAPIAN_TEST_FLAGS_],
320 m4_define([cachevar],
321 [xo_cv_]m4_tolower(m4_bpatsubst([$1][_$3], [[^A-Za-z0-9]], [_])))
322 AC_CACHE_CHECK([for $CXX with $3 in $1], cachevar,
326 $2([AC_LANG_PROGRAM([], [])],
327 [if xo_fn_unknown_option_check ; then
334 if test "$cachevar" = yes ; then
343 dnl Test if compiling works with $1 added to CXXFLAGS; if it does, add $1 to
344 dnl variable $2. If the test passes, also do $3; if it fails, also do $4.
345 AC_DEFUN([XAPIAN_TEST_CXXFLAGS],
346 [XAPIAN_TEST_FLAGS_([CXXFLAGS], [AC_COMPILE_IFELSE], [$1], [$2], [$3], [$4])])
348 dnl Test if linking works with $1 added to LDFLAGS; if it does, add $1 to
349 dnl variable $2. If the test passes, also do $3; if it fails, also do $4.
350 AC_DEFUN([XAPIAN_TEST_LDFLAGS],
351 [XAPIAN_TEST_FLAGS_([LDFLAGS], [AC_LINK_IFELSE], [$1], [$2], [$3], [$4])])
354 if test yesyes = "$GXX$enable_shared" ; then
356 cygwin* | mingw* | msys*)
358 [-Wl,--enable-runtime-pseudo-reloc],
362 dnl Can't use AC_DISABLE_SHARED after AC_PROG_LIBTOOL, but
363 dnl this test needs to be after AC_PROG_LIBTOOL, so we can't
364 dnl just disable the shared build automatically...
365 AC_MSG_ERROR([ld version too old to support a shared build - configure with --disable-shared, or install binutils 2.13.90-20030111-1 or later])
370 dnl Only works for ldflags which can be specified anywhere on the link line.
373 dnl Preserve the default CXXFLAGS.
374 save_CXXFLAGS=$CXXFLAGS
376 dnl x86 has excess precision issues with 387 FP instructions, which are
377 dnl avoided by using SSE instructions instead. This is also faster (~6% in
378 dnl a CPU bound testcase).
380 [AS_HELP_STRING([--disable-sse],
381 [disable use of SSE FP instructions on x86])]
382 [AS_HELP_STRING([[--enable-sse[=sse|sse2]]],
383 [set which SSE FP instructions to use on x86 (default: sse2)])],
384 [case ${enableval} in
386 *) AC_MSG_ERROR([bad value ${enableval} for --enable-sse or --disable-sse]) ;;
390 dnl The maths functions we use include: exp log ceil fabs sqrt
391 AC_MSG_CHECKING([if -lm is required for maths functions])
392 dnl Don't use constant arguments as the compiler might simply evaluate the
393 dnl whole expression at compile time, and it might inline certain functions
394 dnl so test several functions. Also write results using printf() so that
395 dnl the compiler can't optimise away the computations.
396 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <cmath>
399 using namespace std;]], [[
400 double a = log(ceil(time(NULL)/7.0));
401 printf("%f %f %f\n", a, sqrt(a), exp(fabs(a - 12345.6)));
402 ]])], [AC_MSG_RESULT([no])], [
404 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <cmath>
407 using namespace std;]], [[
408 double a = log(ceil(time(NULL)/7.0));
409 printf("%f %f %f\n", a, sqrt(a), exp(fabs(a - 12345.6)));]])],
410 [AC_MSG_RESULT([yes])],
411 [AC_MSG_ERROR([Failed to link a C++ program using <cmath>])
415 dnl C++11 should have log2(double), but keep this check for now to allow for
416 dnl compilers with incomplete library support for C++11.
417 AC_CHECK_DECLS([log2(double)], [], [],
419 using namespace std;])
421 dnl exp10() is a GNU libc extension.
422 AC_CHECK_DECLS([exp10(double)], [], [],
424 using namespace std;])
426 dnl Darwin provides __exp10().
427 AC_CHECK_DECLS([__exp10(double)], [], [],
429 using namespace std;])
431 dnl GCC provides __builtin_exp10() (but notably clang doesn't currently).
432 dnl On mingw, __builtin_exp10() causes GCC to generate a call to exp10() which
433 dnl then fails to link, so perform a link check here to catch that.
434 AC_CACHE_CHECK([for __builtin_exp10], xo_cv_link___builtin_exp10, [
435 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
438 using namespace std;]],
439 [[printf("%f", __builtin_exp10(double(time(NULL)*1e-8)));]])],
440 [xo_cv_link___builtin_exp10=yes],
441 [xo_cv_link___builtin_exp10=no])
443 if test $xo_cv_link___builtin_exp10 = yes ; then
444 AC_DEFINE([HAVE___BUILTIN_EXP10], [1], [Define to 1 if you have the '__builtin_exp10' function.])
447 dnl See if <typeinfo> can be used in the testsuite - at least for GCC and xlC,
448 dnl compilation of the test code below fails if RTTI isn't being generated
449 dnl (g++ -fno-rtti, or by default with xlC).
450 AC_MSG_CHECKING([if RTTI is supported])
451 save_CXXFLAGS=$CXXFLAGS
452 dnl xlC issues a warning for typeid() being used without RTTI being enabled,
453 dnl so for this test we pass the xlC option to make that warning into an error.
454 CXXFLAGS="$CXXFLAGS -qhaltonmsg=1540-2412"
455 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
457 [CXXFLAGS=$save_CXXFLAGS])
458 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
460 #include <typeinfo>]],
465 } catch (std::exception & e) {
466 return typeid(e).name()[0];
468 [AC_MSG_RESULT([yes])
469 AC_DEFINE([USE_RTTI], [1], [Define if the testsuite can use RTTI])],
470 [AC_MSG_RESULT([no])])
471 CXXFLAGS=$save_CXXFLAGS
473 dnl We need to specify the argument types for builtin functions, or else
474 dnl AC_CHECK_DECLS fails to detect them when the compiler is clang.
475 AC_CHECK_DECLS([__builtin_add_overflow(int, int, int*),
476 __builtin_sub_overflow(int, int, int*),
477 __builtin_mul_overflow(int, int, int*)], [], [], [ ])
478 AC_CHECK_DECLS([__builtin_bswap16(uint16_t),
479 __builtin_bswap32(uint32_t),
480 __builtin_bswap64(uint64_t)], [], [],
481 [#include <stdint.h>])
482 AC_CHECK_DECLS([_byteswap_ushort, _byteswap_ulong, _byteswap_uint64], [], [],
483 [#include <stdlib.h>])
484 AC_CHECK_DECLS([__builtin_clz(unsigned),
485 __builtin_clzl(unsigned long),
486 __builtin_clzll(unsigned long long)], [], [], [ ])
487 AC_CHECK_DECLS([__builtin_ctz(unsigned),
488 __builtin_ctzl(unsigned long),
489 __builtin_ctzll(unsigned long long)], [], [], [ ])
490 AC_CHECK_DECLS([__builtin_expect(long, long)], [], [], [ ])
491 AC_CHECK_DECLS([__builtin_popcount(unsigned),
492 __builtin_popcountl(unsigned long),
493 __builtin_popcountll(unsigned long long)], [], [], [ ])
494 AC_CHECK_DECLS([__popcnt, __popcnt64], [], [], [#include <intrin.h>])
495 AC_CHECK_DECLS([_addcarry_u32(unsigned char, unsigned, unsigned, unsigned*),
496 _addcarry_u64(unsigned char, unsigned __int64, unsigned __int64, unsigned __int64*),
497 _subborrow_u32(unsigned char, unsigned, unsigned, unsigned*),
498 _subborrow_u64(unsigned char, unsigned __int64, unsigned __int64, unsigned __int64*)],
499 [], [], [#include <intrin.h>])
501 dnl Check for poll().
502 AC_CHECK_FUNCS([poll])
504 dnl Check for time functions.
505 AC_CHECK_FUNCS([clock_gettime sleep nanosleep gettimeofday ftime])
509 AC_DEFINE([MINGW_HAS_SECURE_API], [1], [Define on mingw to get _s suffixed "secure" functions declared in headers])
513 dnl Used by tests/harness/testsuite.cc
514 AC_CHECK_FUNCS([sigaction])
515 dnl These can be macros (and sigsetjmp is with glibc at least).
516 AC_CHECK_DECLS([sigsetjmp, siglongjmp], [], [], [#include <setjmp.h>])
518 dnl Used by tests/harness/cputimer.cc:
519 AC_CHECK_FUNCS([getrusage times sysconf])
521 dnl Used by tests/harness/unixcmd.cc
522 AC_CHECK_FUNCS([nftw])
524 dnl POSIX requires setenv(). The final Unix-like platform without it seems
525 dnl to have been Solaris 9, which is now out of support.
527 dnl Microsoft don't provide setenv() and have marked putenv() as deprecated, so
528 dnl we use _putenv_s() to avoid deprecation warnings with MSVC. It's also a
529 dnl more similar interface to setenv() so easier to implement a setenv() wrapper
530 dnl around. We probe for both the function and a declaration since mingw
531 dnl doesn't currently (v3.20) declare it but it is present in the C runtime DLL
532 dnl so we can provide our own declaration to access it.
533 AC_CHECK_FUNCS([setenv _putenv_s])
534 AC_CHECK_DECLS([_putenv_s(const char*, const char*)], [], [],
535 [#include <stdlib.h>])
537 dnl See if we have closefrom(), or some functions that are useful to implement
538 dnl closefrom() on platforms which don't provide it.
539 AC_CHECK_FUNCS([closefrom getdirentries getrlimit])
541 if test $ac_cv_func_ftime = yes ; then
542 dnl See if ftime returns void (as it does on mingw)
543 AC_MSG_CHECKING([return type of ftime])
545 [AC_LANG_PROGRAM([[#include <sys/timeb.h>]],
546 [[struct timeb tp; int i = ftime(&tp);]])],
547 [AC_MSG_RESULT([int])],
548 [AC_MSG_RESULT([void])
549 AC_DEFINE([FTIME_RETURNS_VOID], [1], [Define if ftime returns void])])
552 dnl Check how to find the hostname: uname() in sys/utsname.h, or gethostname()
553 AC_CHECK_HEADERS([sys/utsname.h], [], [], [ ])
554 AC_CHECK_FUNCS([gethostname])
556 dnl mingw (for instance) lacks ssize_t
563 AC_CHECK_SIZEOF([short])
564 AC_CHECK_SIZEOF([int])
565 AC_CHECK_SIZEOF([long])
566 AC_CHECK_SIZEOF([long long])
568 AC_CHECK_HEADERS([sys/types.h])
570 AC_MSG_CHECKING([for 32 bit integer type])
572 "$ac_cv_sizeof_int") INT32_T=int ;;
573 "$ac_cv_sizeof_long") INT32_T=long ;;
574 "$ac_cv_sizeof_short") INT32_T=short ;;
576 AC_MSG_RESULT([none found])
577 AC_MSG_ERROR([No 32 bit integer type found])
579 AC_MSG_RESULT([$INT32_T])
581 AC_MSG_CHECKING([for 64 bit integer type])
583 "$ac_cv_sizeof_int") INT64_T=int ;;
584 "$ac_cv_sizeof_long") INT64_T=long ;;
585 "$ac_cv_sizeof_long_long") INT64_T='long long' ;;
587 AC_MSG_RESULT([none found])
588 AC_MSG_ERROR([No 64 bit integer type found])
590 AC_MSG_RESULT([$INT64_T])
592 dnl Check for perl (needed to generate some sources and documentation).
593 AC_PATH_PROG([PERL], [perl], [])
594 AC_ARG_VAR([PERL], [Perl interpreter])
595 if test x$USE_MAINTAINER_MODE = xyes; then
596 test -z "$PERL" && AC_MSG_ERROR([perl is required in maintainer mode])
599 AC_ARG_ENABLE([64bit_docid],
600 [AS_HELP_STRING([--enable-64bit-docid], [enable 64bit docid])],
601 [case ${enableval} in
603 *) AC_MSG_ERROR([bad value ${enableval} for --enable-64bit-docid]) ;;
605 [enable_64bit_docid=no])
607 AC_ARG_ENABLE([64bit_termcount],
608 [AS_HELP_STRING([--enable-64bit-termcount], [enable 64bit termcount])],
609 [case ${enableval} in
611 *) AC_MSG_ERROR([bad value ${enableval} for --enable-64bit-termcount]) ;;
613 [enable_64bit_termcount=no])
615 AC_ARG_ENABLE([64bit_termpos],
616 [AS_HELP_STRING([--enable-64bit-termpos], [enable 64bit termpos])],
617 [case ${enableval} in
619 *) AC_MSG_ERROR([bad value ${enableval} for --enable-64bit-termpos]) ;;
621 [enable_64bit_termpos=no])
623 AC_ARG_ENABLE([documentation],
624 [AS_HELP_STRING([--enable-documentation], [enable make rules to rebuild documentation [default=maintainer-mode]])],
625 [case ${enableval} in
627 *) AC_MSG_ERROR([bad value ${enableval} for --enable-documentation]) ;;
629 [enable_documentation=$USE_MAINTAINER_MODE])
630 AM_CONDITIONAL([DOCUMENTATION_RULES], [test x"$enable_documentation" = xyes])
631 AM_CONDITIONAL([MAINTAINER_NO_DOCS], [test x"$USE_MAINTAINER_MODE$enable_documentation" = xyesno])
633 if test x"$enable_documentation" = xyes ; then
634 dnl Checks for dot. (Diagrams in the documentation)
635 AC_PATH_PROG([DOT], [dot])
636 AC_ARG_VAR([DOT], [dot from graphviz])
637 test -z "$DOT" && AC_MSG_ERROR([dot (part of the graphviz package) is required to build documentation])
638 DOXYGEN_DOT_PATH=`echo "$DOT" | sed 's!/dot$!!'`
639 AC_SUBST([DOXYGEN_DOT_PATH])
641 dnl Check for doxygen. (Needed to make some more of the documentation)
642 AC_PATH_PROG([DOXYGEN], [doxygen], [])
643 AC_ARG_VAR([DOXYGEN], [Doxygen documentation system])
644 test -z "$DOXYGEN" && AC_MSG_ERROR([doxygen is required to build documentation])
646 dnl Check for help2man. (Needed to make man pages from "--help" output).
647 AC_PATH_PROG([HELP2MAN], [help2man], [])
648 AC_ARG_VAR([HELP2MAN], [help2man man page generator])
649 test -z "$HELP2MAN" && AC_MSG_ERROR([help2man is required to build documentation])
651 dnl Check for rst2html. (Needed to make HTML from reStructuredText format)
652 dnl Also look for rst2html.py, which archlinux reportedly installs it as.
653 AC_PATH_PROGS([RST2HTML], [rst2html rst2html.py], [])
654 AC_ARG_VAR([RST2HTML], [reST to HTML convertor])
655 test -z "$RST2HTML" && AC_MSG_ERROR([rst2html is required to build documentation (try package python-docutils)])
657 dnl Check for pngcrush, which we optionally use to reduce the size of the
658 dnl PNG files which doxygen generates. We can get by without it, so don't
659 dnl fail here if it's not found.
660 AC_PATH_PROG([PNGCRUSH], [pngcrush], [])
661 AC_ARG_VAR([PNGCRUSH], [PNG optimiser])
664 dnl Checks for header files.
665 AC_CHECK_HEADERS([fcntl.h limits.h poll.h sys/select.h sysexits.h],
667 AC_CHECK_HEADERS([sys/resource.h],
668 [], [], [#include <sys/types.h>])
670 dnl cxxabi.h was added in GCC 3.1, but clang lies and defines __GNUC__ yet
671 dnl doesn't seem to reliably provide this header, so probe for it.
672 AC_CHECK_HEADERS([cxxabi.h], [], [], [ ])
674 dnl If valgrind is installed and new enough, we use it for leak checking in the
675 dnl testsuite. If VALGRIND is set to an empty value, then skip the check and
676 dnl don't use valgrind. On macOS only use valgrind if VALGRIND is set to a
677 dnl no empty value, as valgrind on macOS gives a lot of false positives.
678 use_valgrind_if_non_empty=
681 use_valgrind_if_non_empty=$VALGRIND ;;
683 use_valgrind_if_non_empty=${VALGRIND-unset} ;;
686 if test -n "$use_valgrind_if_non_empty" ; then
687 AC_PATH_PROG([VALGRIND], [valgrind], [])
688 AC_ARG_VAR([VALGRIND], [debugging tool (optionally used by test harness)])
689 if test -n "$VALGRIND" ; then
690 dnl Check that the installed valgrind version works, and supports the
691 dnl options we use. This means we won't try to use valgrind < 3.3.0
692 dnl (released 7/12/2007) since before that --log-file didn't expand
693 dnl %p (and appended the process id).
695 dnl No need to check for VALGRIND_COUNT_LEAKS now - that was added before
697 AC_MSG_CHECKING([if valgrind supports --log-file with %p and --child-silent-after-fork=yes])
698 vglog=config.vglog.%p.tmp
699 vglogwild="config.vglog.*.tmp*"
701 if $VALGRIND --log-file="$vglog" --child-silent-after-fork=yes -q true 2>&AS_MESSAGE_LOG_FD ; then
702 for f in $vglogwild ; do
704 $vglog*) VALGRIND= ;;
707 if test x"$VALGRIND" = x ; then
711 AC_CHECK_HEADERS([valgrind/memcheck.h], [], [VALGRIND=], [ ])
714 dnl The valgrind detected doesn't seem to work! Perhaps this is an
715 dnl x86_64 box with a 32 bit valgrind.
716 AC_MSG_RESULT([$VALGRIND doesn't work])
723 if test -n "$VALGRIND" ; then
724 AC_DEFINE([HAVE_VALGRIND], [1], [Define if a suitable valgrind is installed])
727 dnl If eatmydata is installed, we run the testsuite under it to speed it up.
728 dnl If EATMYDATA is set to an empty value, then skip this check and don't use
730 if test -n "${EATMYDATA-unset}" ; then
731 AC_PATH_PROG([EATMYDATA], [eatmydata], [])
732 AC_ARG_VAR([EATMYDATA], [wrapper to disable fsync (optionally used by test harness)])
735 dnl Checks for library functions.
738 AC_CACHE_CHECK([for sys_errlist and sys_nerr], xo_cv_sys_errlist_and_sys_nerr, [
739 AC_LINK_IFELSE([AC_LANG_PROGRAM(
740 dnl On Linux, sys_errlist and sys_nerr need <stdio.h>, though the man page
741 dnl says <errno.h>. The man page seems to match other platforms such as
742 dnl NetBSD, so include both headers to ensure we get them. With mingw and MSVC
743 dnl they're provided by <stdlib.h>.
746 #include <stdlib.h>]],
747 [[ printf("%s", sys_errlist[sys_nerr - 1]);]])],
748 [ xo_cv_sys_errlist_and_sys_nerr=yes ],
749 [ xo_cv_sys_errlist_and_sys_nerr=no ])
751 if test "x$xo_cv_sys_errlist_and_sys_nerr" = "xyes" ; then
752 AC_DEFINE([HAVE_SYS_ERRLIST_AND_SYS_NERR], [1],[Define if you have 'sys_errlist' and 'sys_nerr'])
755 AC_CACHE_CHECK([for _sys_errlist and _sys_nerr], xo_cv__sys_errlist_and__sys_nerr, [
756 AC_LINK_IFELSE([AC_LANG_PROGRAM(
759 #include <stdlib.h>]],
760 [[ printf("%s", _sys_errlist[_sys_nerr - 1]);]])],
761 [ xo_cv__sys_errlist_and__sys_nerr=yes ],
762 [ xo_cv__sys_errlist_and__sys_nerr=no
765 if test "x$xo_cv__sys_errlist_and__sys_nerr" = "xyes" ; then
766 AC_DEFINE([HAVE__SYS_ERRLIST_AND__SYS_NERR], [1],[Define if you have '_sys_errlist' and '_sys_nerr'])
769 dnl GNU-specific replacement for sys_errlist and sys_nerr.
770 AC_CHECK_FUNCS([strerrordesc_np])
772 dnl mingw has _snprintf so check for that too.
773 AC_MSG_CHECKING([for snprintf])
774 AC_CACHE_VAL([xo_cv_func_snprintf],
776 xo_cv_func_snprintf=no
777 for func in snprintf _snprintf ; do
785 char buffer[4] = "abc";
786 int res = $func(buffer, 4, "%s", "XYZ");
790 [xo_cv_func_snprintf=$func;break],
795 AC_MSG_RESULT([$xo_cv_func_snprintf])
796 if test "$xo_cv_func_snprintf" != no ; then
797 AC_DEFINE_UNQUOTED([SNPRINTF], [$xo_cv_func_snprintf],
798 [Define to the name of a function implementing snprintf but not caring about ISO C99 return value semantics (if one exists)])
801 dnl ***************************
802 dnl * Select modules to build *
803 dnl ***************************
805 dnl Check which database backends should be built.
807 AC_DEFUN([_XAPIAN_BACKEND_ENABLE],
808 [AC_ARG_ENABLE([backend_$1],
809 [AS_HELP_STRING([--enable-backend-$1], [build the $1 database backend [default=$3]])],
812 *) AC_MSG_ERROR([Invalid option: '--enable-backend-$1=$enableval']) ;;
813 esac], [enable_backend_$1=$2])
816 AC_DEFUN([XAPIAN_BACKEND_ENABLE],
817 [_XAPIAN_BACKEND_ENABLE([$1],
818 m4_default([$2], [yes]),
819 m4_default([$3], [yes]))
822 dnl When adding a new backend, update INSTALL too.
823 XAPIAN_BACKEND_ENABLE([chert])
824 XAPIAN_BACKEND_ENABLE([glass])
825 XAPIAN_BACKEND_ENABLE([inmemory])
826 default_enable_backend_remote=yes
829 dnl We don't currently support the remote backend on this platform so
830 dnl disable it by default.
831 default_enable_backend_remote=no
834 XAPIAN_BACKEND_ENABLE([remote], [$default_enable_backend_remote], [yes (except for MSDOS)])
836 dnl Save and empty LIBS while we probe for libraries to link libxapian against
837 dnl so we can just use AC_SEARCH_LIBS then copy LIBS to XAPIAN_LIBS and restore
838 dnl the value saved here.
842 dnl See if we have fdatasync, and what libraries are needed for it.
843 dnl We need to actually check for a declaration as macOS has a dummy
844 dnl implementation in the library which is not prototyped in any header.
845 AC_CHECK_DECL([fdatasync(int)], [
846 AC_SEARCH_LIBS([fdatasync], [rt], [])
847 AC_CHECK_FUNCS([fdatasync])
849 [ac_cv_func_fdatasync=no],
850 [#include <unistd.h>]
853 dnl We use timer_create() if available to implement a search time limit.
854 AC_SEARCH_LIBS([timer_create], [rt],
856 AC_MSG_CHECKING([for timer_create() usability])
857 dnl Several platforms have timer_create() but it's non-functional.
859 dnl Some of these (at least those with a stub implementation which always
860 dnl fails with ENOSYS) could be probed for, but we'd have to run code
861 dnl which isn't possible when cross-compiling, so just maintain a list
862 dnl of such platforms for now.
863 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
865 #error timer_create always fails with EAGAIN on AIX 7.1
866 #elif defined __NetBSD__
867 #error SIGEV_THREAD not implemented in NetBSD 9.2 (see: man sigevent)
868 #elif defined __OpenBSD__
869 #error timer_create always fails with ENOSYS on OpenBSD 7.3 (and no prototype)
871 [AC_MSG_RESULT([yes])
872 AC_DEFINE([HAVE_TIMER_CREATE], [1], [Define to 1 if you have the 'timer_create' function.])]
879 case $enable_backend_chert$enable_backend_glass in
881 dnl We use zlib for compressing tags in chert/glass. We could
882 dnl automatically disable support if zlib isn't found, but overall that
883 dnl probably does more harm than good - it's most likely that someone just
884 dnl forgot to install the -dev package for zlib.
886 dnl Similarly for uuid support.
888 dnl Check for zlib.h.
889 AC_CHECK_HEADERS([zlib.h], [], [
890 AC_MSG_ERROR([zlib.h not found - required for chert and glass (you may need to install the zlib1g-dev or zlib-devel package)])
893 dnl Check for zlibVersion - normally it's in -lz but the mingw build needs -lzlib or -lzdll.
894 AC_SEARCH_LIBS([zlibVersion], [z zlib zdll], [], [
895 AC_MSG_ERROR([zlibVersion() not found in -lz, -lzlib, or -lzdll - required for chert and glass (you may need to install the zlib1g-dev or zlib-devel package)])
898 dnl Find a way to generate UUIDs.
900 case $host_os-$win32 in
901 *-yes | cygwin* | msys*) dnl Use built-in win32 API.
902 AC_DEFINE([USE_WIN32_UUID_API], [1],
903 [Define to 1 to use UuidCreate(), etc])
904 if test $win32 = yes ; then
905 dnl We need -lws2_32 for htonl(), etc, but not for Cygwin which
906 dnl provides these functions in its libc.
909 LIBS="$LIBS -lrpcrt4"
912 dnl Check for uuid/uuid.h (e2fsprogs/util-linux-ng) or uuid.h
913 dnl (FreeBSD/NetBSD/OpenBSD/AIX).
914 AC_CHECK_HEADERS([uuid/uuid.h], [
915 dnl util-linux-ng's uuid/uuid.h found - check for uuid_generate in
917 AC_SEARCH_LIBS([uuid_generate], [uuid], [], [
918 AC_MSG_ERROR([uuid_generate() not found in -luuid - required for chert and glass (you may need to install the uuid-dev, libuuid-devel or e2fsprogs-devel package)])
921 dnl Try uuid.h as found on FreeBSD/NetBSD/OpenBSD/AIX, with associated
923 AC_CHECK_HEADERS([uuid.h], [
924 dnl Check for uuid_create with no extra libraries required.
925 AC_CHECK_FUNC([uuid_create], [], [
926 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)])
929 dnl Especially useful for Android.
930 AC_MSG_CHECKING([if host platform supports /proc/sys/kernel/random/uuid])
933 AC_DEFINE([USE_PROC_FOR_UUID], [1],
934 [Define to 1 to read UUID from '/proc/sys/kernel/random/uuid'])
939 AC_MSG_ERROR([Failed to find a way to generate UUIDs, required for chert and glass backends (you may need to install the uuid-dev, libuuid-devel or e2fsprogs-devel package)])
949 dnl DJGPP has a dummy implementation of fork which always fails.
951 dnl For disk-based backends, use flock() for locking, which doesn't need
952 dnl fork() or socketpair().
953 AC_DEFINE([FLINTLOCK_USE_FLOCK], 1, [Define to use flock() for flint-compatible locking])
959 if test "$enable_backend_remote" = yes ; then
960 case $host_os-$win32 in
962 dnl For mingw and msvc we have an alternative implementation which
963 dnl doesn't need fork() or socketpair().
965 dnl We need -lws2_32 for getaddrinfo(), etc.
967 dnl Vista is needed for the AI_ADDRCONFIG flag to getaddrinfo().
968 AC_DEFINE([WINVER], [0x600],
969 [Version of Windows to assume (0x600 => Vista).])
970 AC_DEFINE([_WIN32_WINNT], [WINVER],
971 [Version of Windows to assume.])
974 dnl DJGPP has a dummy implementation of fork which always fails. If
975 dnl someone actually wanted remote backend support, then DJGPP has a
976 dnl pthreads port, so using threads like we do on Windows would make more
978 AC_MSG_ERROR([The remote backend is not currently supported on this platform.])
981 dnl On Unix, we need fork and socketpair for the remotebackend.
982 AC_CHECK_FUNCS([fork], [], [
983 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.])
985 dnl Check if -lsocket is required for socketpair (Solaris needs it).
986 dnl And on Haiku it's in -lnetwork.
987 AC_SEARCH_LIBS([socketpair], [socket network], [], [
988 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.])
990 AC_DEFINE([HAVE_SOCKETPAIR], [1],
991 [Define to 1 if you have the 'socketpair' function.])
992 dnl Check if extra libraries are needed for getaddrinfo or inet_ntop()
993 dnl (e.g. on Solaris).
995 dnl We're currently assuming that any system that is worth trying to
996 dnl support has getaddrinfo() and inet_ntop(), since these are the
997 dnl standard route for supporting IPv6, and that's pretty much essential
998 dnl for platforms to support now.
999 AC_SEARCH_LIBS([getaddrinfo], [nsl socket], [], [
1000 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.])
1002 AC_SEARCH_LIBS([inet_ntop], [nsl socket], [], [
1003 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.])
1008 XAPIAN_TYPE_SOCKLEN_T
1011 if test "$win32_need_lws2_32" = 1 ; then
1012 LIBS="$LIBS -lws2_32"
1017 AC_ARG_ENABLE([visibility],
1018 [AS_HELP_STRING([--disable-visibility], [disable use of GCC visibility])],
1019 [case ${enableval} in
1021 *) AC_MSG_ERROR([bad value ${enableval} for --disable-visibility]) ;;
1025 if test "`pwd`" != "`cd $srcdir;pwd`" ; then
1028 AM_CONDITIONAL([VPATH_BUILD], [test yes = "$vpath_build"])
1030 dnl Turn off compilation of anything that we don't have the requirements for
1032 dnl Set conditionals to specify what we compile
1034 AM_CONDITIONAL([BUILD_BACKEND_CHERT], [test yes = "$enable_backend_chert"])
1035 AM_CONDITIONAL([BUILD_BACKEND_GLASS], [test yes = "$enable_backend_glass"])
1036 AM_CONDITIONAL([BUILD_BACKEND_INMEMORY], [test yes = "$enable_backend_inmemory"])
1037 AM_CONDITIONAL([BUILD_BACKEND_REMOTE], [test yes = "$enable_backend_remote"])
1038 AM_CONDITIONAL([BUILD_BACKEND_CHERT_OR_GLASS],
1039 [test nono != "$enable_backend_chert$enable_backend_glass"])
1041 dnl Decide if we should use the zlib-vg.so LD_PRELOAD hack.
1043 if test -n "$VALGRIND" ; then
1045 linux*) use_zlib_vg=yes ;;
1048 AM_CONDITIONAL([USE_ZLIB_VG], [test yes = "$use_zlib_vg"])
1050 AC_CHECK_FUNCS([fsync])
1051 AC_CHECK_FUNCS([posix_fadvise])
1052 if test "$win32" = no ; then
1053 dnl ftruncate() under Wine seems to be buggy and sometimes fails, though
1054 dnl a cut-down reproducer seems fine. For now just avoid ftruncate()
1055 dnl entirely on this platform - we'll fallback to lseek() + write() of a
1056 dnl single zero byte, which is pretty efficient.
1057 AC_CHECK_FUNCS([ftruncate])
1060 dnl HP-UX has pread and pwrite, but they don't work! Apparently this problem
1061 dnl manifests when largefile support is enabled, and we definitely want that
1062 dnl so don't use pread or pwrite on HP-UX.
1065 AC_MSG_CHECKING([for pread])
1066 AC_MSG_RESULT([present but broken on $host_os])
1067 AC_MSG_CHECKING([for pwrite])
1068 AC_MSG_RESULT([present but broken on $host_os])
1071 AC_CHECK_FUNC([pread],
1072 [AC_DEFINE([HAVE_PREAD], [1],
1073 [Define if pread is available on this system])
1074 AC_MSG_CHECKING([for any prototype needed for pread])
1075 AC_CACHE_VAL([xo_cv_pread_prototype],
1078 'extern "C" ssize_t pread(int, void *, size_t, off_t) throw ();' \
1079 'extern "C" ssize_t pread(int, void *, size_t, off_t);' ; do
1080 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1081 #include <sys/types.h>
1086 pread(1, b, 256, 20);
1088 xo_cv_pread_prototype="$p"
1092 if test -z "$xo_cv_pread_prototype"; then
1093 AC_MSG_RESULT([not found])
1094 AC_MSG_ERROR([Failed to find working prototype for pread])
1097 if test " " = "$xo_cv_pread_prototype" ; then
1098 AC_MSG_RESULT([none required])
1100 AC_MSG_RESULT([$xo_cv_pread_prototype])
1101 AC_DEFINE_UNQUOTED([PREAD_PROTOTYPE], [$xo_cv_pread_prototype],
1102 [explicit prototype needed for pread (if any)])
1105 AC_CHECK_FUNC([pwrite],
1106 [AC_DEFINE([HAVE_PWRITE], [1],
1107 [Define if pwrite is available on this system])
1108 AC_MSG_CHECKING([for any prototype needed for pwrite])
1109 AC_CACHE_VAL([xo_cv_pwrite_prototype],
1112 'extern "C" ssize_t pwrite(int, const void *, size_t, off_t) throw ();' \
1113 'extern "C" ssize_t pwrite(int, const void *, size_t, off_t);' ; do
1114 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1115 #include <sys/types.h>
1119 const char *p = "hello";
1120 pwrite(1, p, 5, 20);
1122 xo_cv_pwrite_prototype="$p"
1126 if test -z "$xo_cv_pwrite_prototype"; then
1127 AC_MSG_RESULT([not found])
1128 AC_MSG_ERROR([Failed to find working prototype for pwrite])
1131 if test " " = "$xo_cv_pwrite_prototype" ; then
1132 AC_MSG_RESULT([none required])
1134 AC_MSG_RESULT([$xo_cv_pwrite_prototype])
1135 AC_DEFINE_UNQUOTED([PWRITE_PROTOTYPE], [$xo_cv_pwrite_prototype],
1136 [explicit prototype needed for pwrite (if any)])
1142 AC_MSG_CHECKING([for directory separator(s)])
1143 case $host_os-$win32 in
1144 *-yes | cygwin* | msys* | os2* | *djgpp* | *msdos* )
1145 AC_MSG_RESULT([/ and \\])
1146 AC_DEFINE([DIR_SEPS], ["/\\"], [directory separator(s) as a character or string literal])
1147 AC_DEFINE([DIR_SEPS_LIST], [{ '/', '\\' }], [directory separator(s) as an initialiser list])
1151 AC_DEFINE([DIR_SEPS], ['/'], [directory separator(s) as a character or string literal])
1152 AC_DEFINE([DIR_SEPS_LIST], [{ '/' }], [directory separator(s) as an initialiser list])
1156 AC_CHECK_FUNCS([link])
1158 dnl *************************
1159 dnl * Set debugging options *
1160 dnl *************************
1162 dnl Which assertion types to enable in the code.
1164 AC_ARG_ENABLE([assertions],
1165 [AS_HELP_STRING([--enable-assertions], [enable debug assertions (no|partial|yes) [default=no]])],
1169 AC_MSG_ERROR([Invalid option: '--enable-assertions=$enableval']) ;;
1172 AC_ARG_ENABLE([log],
1173 [AS_HELP_STRING([--enable-log], [generate a log of methods called, etc (no|yes|profile) [default=no]])],
1177 AC_MSG_ERROR(['--enable-log=profile' is no longer supported - see https://trac.xapian.org/wiki/ProfilingXapian for alternatives.]) ;;
1179 AC_MSG_ERROR([Invalid option: '--enable-log=$enableval']) ;;
1182 dnl Set defines according to the --enable-assertions and --enable-log options
1185 if test yes = "$enable_assertions" || test partial = "$enable_assertions" ; then
1186 AC_DEFINE([XAPIAN_ASSERTIONS],,
1187 [Define if you want assertions (causes some slow-down)])
1190 if test yes = "$enable_assertions"; then
1191 AC_DEFINE([XAPIAN_ASSERTIONS_PARANOID],,
1192 [Define if you want paranoid assertions (causes significant slow-down)])
1195 if test yes = "$enable_log"; then
1196 AC_DEFINE([XAPIAN_DEBUG_LOG],,
1197 [Define if you want a log of methods called and other debug messages])
1200 dnl ******************************
1201 dnl * Set special compiler flags *
1202 dnl ******************************
1204 AC_ARG_ENABLE([werror],
1205 [AS_HELP_STRING([--enable-werror], [enable treating compiler warnings as errors [default=maintainer-mode]])],
1206 [case ${enableval} in
1208 *) AC_MSG_ERROR([bad value ${enableval} for --enable-werror]) ;;
1210 [enable_werror=$USE_MAINTAINER_MODE])
1212 dnl Put -Werror or equivalent in its own make variable so that it can easily
1213 dnl be overridden by `make WERROR=` if needed during development (e.g. if
1214 dnl you want to get a full list of compile warnings to fix rather than
1215 dnl stopping at the first file with warnings).
1219 dnl Set flags to control warnings (enable more, or disable annoying ones).
1221 if test yes = "$GXX"; then
1222 dnl Intel's C++ compiler and clang both lie and define __GNUC__, so check which
1223 dnl we actually have, as neither is really 100% compatible.
1224 case `echo __INTEL_COMPILER __clang__|$CXX -E - 2>&AS_MESSAGE_LOG_FD|grep -v '^#'` in
1225 *__INTEL_COMPILER*__clang__*)
1226 dnl GCC (since neither substituted):
1228 dnl The exact format of g++ --version seems to change with almost every
1229 dnl minor release so use the preprocessor macros which should be more
1230 dnl robust. Pass -xc++ to avoid warnings about any command-line options
1231 dnl included in $CXX which aren't valid for C (such as -std=c++17).
1232 AC_MSG_CHECKING([for version of $CXX])
1233 gxx_version=`echo __GNUC__.__GNUC_MINOR__.__GNUC_PATCHLEVEL__|$CXX -xc++ -E -|sed '/^#/d;s/ //g'`
1234 AC_MSG_RESULT([GCC $gxx_version])
1236 dnl -Wundef was supported by g++ 3.0.
1238 dnl -Wlogical-op and -Wmissing-declarations (for C++) were added in
1241 dnl -Wdouble-promotion was added in GCC 4.6.
1243 dnl -Winit-self was added in GCC 3.4, but for GCC < 4.7 g++ always
1244 dnl warns for this case with -Wuninitialized (implied by -W). We
1245 dnl don't intend to use this idiom, so any instances are bugs we'd
1246 dnl like to know about.
1248 dnl All the other options were supported by g++ 2.95.
1249 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 -Winit-self"
1251 case $gxx_version in
1252 [[0123]].*|4.[[0-6]].*)
1253 AC_MSG_ERROR([Xapian requires GCC 4.7 or later])
1258 AM_CXXFLAGS="$AM_CXXFLAGS -Wduplicated-cond"
1261 AM_CXXFLAGS="$AM_CXXFLAGS -Wduplicated-cond -Wduplicated-branches"
1266 dnl -Wold-style-cast is interesting, but triggers for macros from
1267 dnl system headers (e.g. FD_SET). GCC 4.8 improved this by making
1268 dnl -ftrack-macro-expansion=2 the default, but we still see such
1269 dnl warnings on some platforms for some reason (e.g. Cygwin with GCC
1270 dnl 5.4.0 warns about FD_SET, and on Debian with GCC 4.9.2 we see
1271 dnl warnings from zlib.h).
1276 dnl Intel's compiler (since __clang__ not substituted):
1278 dnl -w1 stops the avalanche of uninteresting "remark" messages.
1279 dnl -wd... disables warnings which don't have good code workarounds.
1280 AM_CXXFLAGS="$AM_CXXFLAGS -Wall -w1 -wd177,1572"
1285 dnl clang (since __INTEL_COMPILER not substituted):
1287 dnl These options all work at least as far back as clang++ 3.0:
1288 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"
1294 if test no != "$enable_visibility"; then
1295 dnl GCC doesn't support symbol visibility on all platforms (e.g. it isn't
1296 dnl supported on mingw and visibility attributes result in warnings).
1297 AC_MSG_CHECKING([if $CXX -fvisibility=hidden -fvisibility-inlines-hidden works])
1298 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
1299 AC_MSG_RESULT([yes])
1300 AM_CXXFLAGS="$AM_CXXFLAGS -fvisibility=hidden -fvisibility-inlines-hidden"
1301 dash_d_visibility=-DXAPIAN_ENABLE_VISIBILITY
1306 elif test yes = "$msvc"; then
1309 dnl Not GCC, nor a compiler masquerading as GCC.
1312 dnl +w turns on more warnings.
1313 dnl +wlint turns on "lint-like" warnings.
1314 dnl +W<n1>,<n2>,... suppresses warnings n1, n2, ...
1315 dnl 2340 (remark) "value copied to temporary, reference to temporary
1316 dnl use", in: throw Xapian::UnimplementedError("...");
1317 dnl 2401 "destructor for base class ... is non-virtual" (we don't need a
1318 dnl virtual destructor for intrusive_base, since we never delete
1319 dnl its subclasses by a intrusive_base *).
1320 dnl 3348 "declaration hides constant ..." which seems to misfire!
1321 dnl 4255 (remark) "padding size of struct "..." with ... bytes to
1322 dnl alignment boundary".
1323 dnl 4273 "floating-point equality and inequality comparisons may be
1324 dnl inappropriate due to roundoff common in floating-point computation"
1325 dnl No obvious workaround for when you really do want == or !=.
1326 dnl 4285 "operator= does not have a check for the source and destination
1327 dnl addresses being non-identical" - fires for AutoPtr which
1328 dnl includes such a check indirectly (internaltest's autoptr1 check this).
1329 dnl 20201 "Memory leak is detected" which triggers for "return new Foo;"!
1330 AM_CXXFLAGS="$AM_CXXFLAGS +w +wlint +W2340,2401,3348,4255,4273,4285,20201" ;;
1332 dnl Sun's C++ compiler.
1334 dnl We use -errtags to report the tag for each warning emitted.
1336 dnl We use -erroff to suppress some unhelpful warnings:
1338 dnl oklambdaretmulti warns about a lambda with more than one return
1339 dnl statement even if they all return the same type.
1341 dnl voidretw warns about functions failing to return a value even when the
1342 dnl function ends with a "throw" statement. That's just unhelpful noise,
1343 dnl and adding a dummy "return" after "throw" seems a worse solution than
1344 dnl simply disabling this warning - any genuinely missing return statements
1345 dnl will get reported by compilers with superior warning machinery.
1346 XAPIAN_TEST_CXXFLAGS([-errtags -erroff=oklambdaretmulti,voidretw], [AM_CXXFLAGS])
1351 if test x$enable_werror != xyes; then
1355 XAPIAN_TEST_LDFLAGS([-Wl,-Bsymbolic-functions], [XAPIAN_LDFLAGS])
1356 dnl Roughly equivalent Sun C++ option.
1357 XAPIAN_TEST_LDFLAGS([-xldscope=symbolic], [XAPIAN_LDFLAGS])
1359 dnl New in GCC 5. Sort of like -Bsymbolic-functions, but for the compiler
1360 dnl rather than the linker.
1361 XAPIAN_TEST_LDFLAGS([-fno-semantic-interposition], [XAPIAN_LDFLAGS])
1363 AC_MSG_CHECKING([whether to use SSE instructions on x86])
1366 if test "$enable_sse" = no ; then
1368 if test yes = "$msvc"; then
1369 dnl MSVC defaults to SSE2.
1370 AM_CXXFLAGS="$AM_CXXFLAGS -arch:IA32"
1373 dnl Default to sse2.
1374 test "$enable_sse" != yes || enable_sse=sse2
1375 if test yes = "$GXX"; then
1376 AC_MSG_RESULT([yes (configure with --disable-sse to disable)])
1377 dnl We can unconditionally use -mtune=generic as it was added in GCC
1378 dnl 4.2, and supported at least as far back as clang 3.0.
1379 AM_CXXFLAGS="$AM_CXXFLAGS -mfpmath=sse -m$enable_sse -mtune=generic"
1380 elif test yes = "$msvc"; then
1381 AC_MSG_RESULT([yes (configure with --disable-sse to disable)])
1382 if test sse = "$enable_sse"; then
1383 dnl MSVC defaults to SSE2.
1384 AM_CXXFLAGS="$AM_CXXFLAGS -arch:SSE"
1387 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
1388 [[#ifndef __SUNPRO_CC
1389 #error Not Sun compiler
1391 [AC_MSG_RESULT([yes (configure with --disable-sse to disable)])
1392 AM_CXXFLAGS="$AM_CXXFLAGS -xarch=$enable_sse"]
1394 [AC_MSG_RESULT([don't know how to for compiler $CXX])]
1400 AC_MSG_RESULT([non-x86 arch ($host_cpu)]) ;;
1403 if test "$GXX" = yes; then
1404 dnl Default to enabling _FORTIFY_SOURCE at level 2. It shouldn't cause a
1405 dnl problem to define it where it's not supported, but we need to check for
1406 dnl an issue on mingw-w64 where some versions required linking with -lssp
1407 dnl (this was fixed in v11.0.0 released 2023-04-28). We detect this with a
1408 dnl configure-time link test and don't auto-enable _FORTIFY_SOURCE if using
1409 dnl an affected version.
1410 AC_MSG_CHECKING([if _D_FORTIFY_SOURCE=2 links without extra libraries])
1411 save_CPPFLAGS=$CPPFLAGS
1412 CPPFLAGS="$CPPFLAGS -D_FORTIFY_SOURCE=2"
1413 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1415 static char a[20], b[10];]], [[
1418 [AC_MSG_RESULT([yes])
1419 AC_DEFINE([FORTIFY_SOURCE_OK], [1], [Define to 1 if '-D_FORTIFY_SOURCE=2' link test passes])],
1420 [AC_MSG_RESULT([no])])
1421 CPPFLAGS=$save_CPPFLAGS
1425 [/* Disable stupid MSVC warnings. */
1427 /* Passing an empty parameter to a single parameter macro. */
1428 # pragma warning(disable:4003)
1429 /* A "performance" warning for converting int to bool. */
1430 # pragma warning(disable:4800)
1432 /* POSIX get to deprecate POSIX things, not Microsoft. */
1433 # define _CRT_NONSTDC_NO_WARNINGS
1434 # define _CRT_SECURE_NO_WARNINGS
1436 /* WSAAddressToStringA() is deprecated and we should apparently use
1437 * WSAAddressToStringW(), but we don't want wide character output so
1438 * that would mean we'd have to convert the result back to ASCII
1439 * which is a really stupid idea.
1441 # define _WINSOCK_DEPRECATED_NO_WARNINGS
1443 /* Tell MSVC we want M_PI, etc defined. */
1444 # define _USE_MATH_DEFINES
1446 /* Tell MSVC we don't want max() and min() macros defined. */
1450 /* Make the POSIX-like functions support large files. MSVC needs this;
1451 * current mingw32 does too; mingw64 supports _FILE_OFFSET_BITS, which
1452 * AC_SYS_LARGEFILE should discover and enable automatically.
1454 #if defined _MSC_VER || \
1455 (defined __MINGW32__ && !defined _FILE_OFFSET_BITS)
1457 # include <sys/stat.h>
1458 # include <sys/types.h>
1460 /* zlib.h uses off_t so we need to include it before we redefine off_t. */
1463 // The default stat() and fstat() use 32-bit filesizes and time_t, so we need
1464 // to arrange to use 64-bit variants instead.
1467 // Break #undef lines to stop config.status from commenting them out.
1472 // This hack is a problem is we ever want a method called "stat".
1474 // MSVC needs to call _stat64() instead of stat() and the struct which holds
1475 // the information is `struct _stat64` instead of `struct stat` so we just
1476 // use #define to replace both in one go.
1477 # define stat _stat64
1479 // Mingw32 has _stat64() but unhelpfully for our purposes, the struct is
1480 // called __stat64 (with an extra underscore). We hack around this by
1481 // defining stat to __stat64 which sorts out the struct, and then using
1482 // a second macro to forward function-like uses of __stat64() to
1484 # define stat __stat64
1485 # define __stat64(PATH, STATBUF) _stat64((PATH), (STATBUF))
1488 // We also want to use _fstat64() instead of fstat() but in this case we can
1489 // use a function-like macro, so we could have a method called fstat so long
1490 // as it didn't take two parameters.
1493 // Break #undef lines to stop config.status from commenting them out.
1498 # define fstat(FD, BUF) _fstat64(FD, BUF)
1501 // Break #undef lines to stop config.status from commenting them out.
1507 // Break #undef lines to stop config.status from commenting them out.
1512 # define lseek(FD, OFF, WHENCE) _lseeki64(FD, OFF, WHENCE)
1513 /* Redefine via a typedef so C++ code off_t(-1) works - it wouldn't if we did:
1514 * #define off_t long long
1516 typedef long long off_t_redefinition_typedef;
1517 # define off_t off_t_redefinition_typedef
1521 /* MSVC defines _WIN32 but not __WIN32__. */
1522 #if !defined __WIN32__ && defined _WIN32
1526 /* MSVC defines _WIN64 but not __WIN64__. */
1527 #if !defined __WIN64__ && defined _WIN64
1531 /* Default to enabling _FORTIFY_SOURCE at level 2 for GCC-like compilers. It
1532 * shouldn't cause a problem to define it where it's not supported.
1534 * The FORTIFY_SOURCE_OK check avoids auto-enabling on some mingw-w64 versions
1535 * which required linking with -lssp too. This was addressed in v11.0.0
1536 * (released 2023-04-28).
1538 * Check if _FORTIFY_SOURCE is already defined to allow the user to override
1539 * our choice with "./configure CPPFLAGS=-D_FORTIFY_SOURCE=0" or "...=1" or
1542 #if defined FORTIFY_SOURCE_OK && !defined _FORTIFY_SOURCE
1543 # define _FORTIFY_SOURCE 2
1546 /* For compilers which support it (such as GCC, clang, Intel's C++ compiler)
1547 * we can use __builtin_expect to give the compiler hints about branch
1548 * prediction. See HACKING for how to use these.
1550 #if HAVE_DECL___BUILTIN_EXPECT
1551 /* The arguments of __builtin_expect() are both long, so use !! to ensure that
1552 * the first argument is always an integer expression, and always 0 or 1, but
1553 * still has the same truth value for the if or while it is used in.
1555 # define rare(COND) __builtin_expect(!!(COND), 0)
1556 # define usual(COND) __builtin_expect(!!(COND), 1)
1558 # define rare(COND) (COND)
1559 # define usual(COND) (COND)
1562 /* Signal we're building the library so it's OK to include headers such as
1563 * xapian/query.h directly.
1565 #define XAPIAN_LIB_BUILD 1
1567 /* With Sun CC 5.13 (Studio 12.4) on Solaris 11.2, <math.h> seems to get
1568 * implicitly included somehow before <cmath>, and compilation fails due
1569 * to 'std::exception' colliding with 'struct exception'. It's not clear
1570 * how to avoid this, so just define the same magic macro which <cmath> does
1571 * before it includes <math.h>.
1573 #if defined __SUNPRO_CC && !defined __MATHERR_RENAME_EXCEPTION
1574 # define __MATHERR_RENAME_EXCEPTION
1578 AC_SUBST([AM_CXXFLAGS])
1580 dnl Restore CXXFLAGS to those the user specified or autoconf defaulted to.
1581 CXXFLAGS=$save_CXXFLAGS
1583 dnl Required for auto regeneration to work in a combined maintainer-mode tree.
1584 : ${AUTOM4TE=autom4te}
1585 AC_SUBST([AUTOM4TE])
1587 dnl Libtool sets this (to yes|no|unknown) and we use it in xapian-config.
1588 AC_SUBST([link_all_deplibs_CXX])
1590 dnl Shared library extension.
1592 eval "SHLIBEXT=$shrext_cmds"
1593 AC_SUBST([SHLIBEXT])
1595 dnl We want to be able to use GNU make % pattern rules in maintainer targets
1596 dnl but automake warns these aren't portable, so we substitute the % to avoid
1601 dnl Split up the version number into "MAJOR.MINOR.REVISION".
1602 MAJOR_VERSION=`echo "$VERSION"|sed 's/\..*//'`
1603 [MINOR_VERSION=`echo "$VERSION"|sed 's/[^.]*\.//;s/\..*//'`]
1604 [REVISION=`echo "$VERSION"|sed 's/.*\.//;s/_.*$//'`]
1606 dnl Convert the libs in $XAPIAN_LIBS to a CMake list.
1607 XAPIAN_CMAKE_LIBS=`echo " $XAPIAN_LIBS" | sed 's/ -l/;/g;s/ //g'`
1608 AC_SUBST([XAPIAN_CMAKE_LIBS])
1610 XAPIAN_CMAKE_SHARED=
1611 if test "$enable_shared" = yes; then
1612 XAPIAN_CMAKE_SHARED=ON
1614 XAPIAN_CMAKE_SHARED=OFF
1616 AC_SUBST([XAPIAN_CMAKE_SHARED])
1618 LIBRARY_STATIC_EXT=.$libext
1619 AC_SUBST([LIBRARY_STATIC_EXT])
1621 if test "$win32" = yes; then
1622 LIBRARY_SHARED_IMP_EXT=$LIBRARY_STATIC_EXT
1624 LIBRARY_SHARED_IMP_EXT=
1626 AC_SUBST([LIBRARY_SHARED_IMP_EXT])
1628 dnl We don't make use of maths function setting errno and if we tell the
1629 dnl compiler that it can optimise them better in some cases. Apparently
1630 dnl most BSD-derived platforms don't set errno in this case anyway.
1631 XAPIAN_TEST_CXXFLAGS([-fno-math-errno], [CXXFLAGS])
1633 dnl **************************
1634 dnl * Build the output files *
1635 dnl **************************
1641 docs/doxygen_api.conf
1642 docs/doxygen_source.conf
1644 cmake/xapian-config.cmake
1645 cmake/xapian-config-version.cmake
1646 pkgconfig/xapian-core"$LIBRARY_VERSION_SUFFIX".pc:pkgconfig/xapian-core.pc.in
1648 AC_CONFIG_FILES([makemanpage], [chmod +x makemanpage])
1649 AC_CONFIG_FILES([tests/runtest], [chmod +x tests/runtest])
1650 AC_CONFIG_FILES([tests/runsrv], [chmod +x tests/runsrv])
1651 AC_CONFIG_FILES([tests/submitperftest], [chmod +x tests/submitperftest])
1652 AC_CONFIG_FILES([tests/perftest/get_machine_info], [chmod +x tests/perftest/get_machine_info])
1653 AC_CONFIG_FILES([xapian-config], [chmod +x xapian-config])
1656 dnl There are no files generated by AC_OUTPUT in the following directories
1657 dnl and we need to ensure they exist so that the rest of configure or make
1658 dnl won't fail because they don't exist when srcdir != builddir.
1659 if test yes = "$vpath_build" ; then
1660 for dir in include/xapian languages queryparser ; do
1661 AS_MKDIR_P(["$dir"])
1665 dnl Generate include/xapian/version.h:
1667 dnl MAIN_VERSION is VERSION without any _git123 suffix.
1668 MAIN_VERSION="$MAJOR_VERSION.$MINOR_VERSION.$REVISION"
1670 for backend in CHERT GLASS INMEMORY REMOTE ; do
1671 val=`eval echo "\\\$BUILD_BACKEND_${backend}_TRUE"`
1672 if test -z "$val" ; then
1673 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_HAS_${backend}_BACKEND"
1677 if test yes = "$enable_64bit_docid" ; then
1678 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_DOCID_BASE_TYPE="`echo "$INT64_T"|sed 's/ /____/g'`
1680 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_DOCID_BASE_TYPE="`echo "$INT32_T"|sed 's/ /____/g'`
1683 if test yes = "$enable_64bit_termcount" ; then
1684 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TERMCOUNT_BASE_TYPE="`echo "$INT64_T"|sed 's/ /____/g'`
1686 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TERMCOUNT_BASE_TYPE="`echo "$INT32_T"|sed 's/ /____/g'`
1689 if test yes = "$enable_64bit_termpos" ; then
1690 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TERMPOS_BASE_TYPE="`echo "$INT64_T"|sed 's/ /____/g'`
1692 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TERMPOS_BASE_TYPE="`echo "$INT32_T"|sed 's/ /____/g'`
1695 dnl Always ought to be 64 bit.
1696 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TOTALLENGTH_TYPE="`echo "unsigned $INT64_T"|sed 's/ /____/g'`
1698 dnl Make revision numbers in the API 64 bit for future-proofing.
1699 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_REVISION_TYPE="`echo "unsigned $INT64_T"|sed 's/ /____/g'`
1701 dnl For GCC (and compilers which pretend to be GCC) and MSVC, we create checks
1702 dnl for some ABI-incompatible configurations in the generated version.h.
1703 dnl Such configurations may be specified via $CXXFLAGS so we should use this
1704 dnl when generating version.h. For these compilers, CXXCPP="$CXX -E" so it
1705 dnl should understand all compiler options.
1707 dnl For other compilers, we only pass $CPPFLAGS to $CXXCPP in case it's an
1708 dnl external cpp which doesn't understand all options which might be in
1712 cxxcpp_flags="$cxxcpp_flags $CPPFLAGS $CXXFLAGS" ;;
1714 cxxcpp_flags="$cxxcpp_flags $CPPFLAGS" ;;
1716 rm -f include/xapian/version.h.tmp
1717 dnl "\r" in sed is a GNUism, but we only need to remove it on MS Windows
1718 dnl where we'll always have GNU sed, and other sed's will just interpret
1719 dnl it as "r" (Solaris sed) or maybe literal "\r" which won't match.
1721 dnl Use @@ around $MAIN_VERSION so we get " in the final output.
1722 $CXXCPP $cxxcpp_flags\
1723 -DSTRING_VERSION="\"@@$MAIN_VERSION@@\""\
1724 -DMAJOR_VERSION="\"$MAJOR_VERSION\""\
1725 -DMINOR_VERSION="\"$MINOR_VERSION\""\
1726 -DREVISION="\"$REVISION\""\
1728 $srcdir/include/xapian/version_h.cc|\
1729 ${SED-sed} '0,/const char \* dummy/d;/"/!d;s/^ *//;/^#/d;s/ *$//;s/" *,//;s/"//g;s/@@/"/g;s/ */ /g;s/ *,\r$//;s/ *,$//;s/____/ /g;s/\\\\$/\\/'\
1730 > include/xapian/version.h.tmp
1731 dnl Only update the file if it has changed, so we don't alter the timestamp
1732 dnl and cause lots of rebuilding needlessly. However, the build system
1733 dnl needs a timestamp to know when to regenerate version.h because version_h.cc
1734 dnl has changed so we use a separate timestamp file.
1735 touch include/xapian/version.h.timestamp
1736 if cmp include/xapian/version.h.tmp include/xapian/version.h >/dev/null 2>&1
1738 rm include/xapian/version.h.tmp
1740 mv include/xapian/version.h.tmp include/xapian/version.h