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.18], [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 41:0:11 1.4.17 QueryParser::FLAG_ACCUMULATE
51 LIBRARY_VERSION_INFO=41:0:11
52 AC_SUBST([LIBRARY_VERSION_INFO])
54 LIBRARY_VERSION_SUFFIX=
55 AC_SUBST([LIBRARY_VERSION_SUFFIX])
57 dnl Disabled for stable release series.
58 test x"$program_suffix" != xNONE || program_suffix=
60 dnl Where xapian.h, etc go. In development release append "/xapian-1.3".
64 dnl Check the build directory doesn't contain a space, so we die early with
68 AC_MSG_ERROR([You can't build in a directory whose path contains a space])
72 dnl Check the source directory doesn't contain a space, so we die early with
73 dnl a helpful error. FIXME: Unfortunately, configure seems to choke before
74 dnl it gets to us so this code doesn't get a chance to fire.
77 dnl Note: for in-tree builds, the build directory test above will fire
79 AC_MSG_ERROR([You can't build with sources in a directory whose path contains a space])
83 dnl Check the prefix to install in doesn't contain a space, so we die early with
87 AC_MSG_ERROR([You can't install in a directory whose path contains a space])
91 dnl Note if the user specified a particular C++ compiler so we can give a more
92 dnl appropriate error message if we can't link a simple C++ program.
94 if test -n "$CXX" ; then
95 original_CXX="CXX=$CXX"
96 elif test -n "$CCC" ; then
97 original_CXX="CCC=$CCC"
100 dnl See HACKING document for details of the reasons for required versions.
101 AM_INIT_AUTOMAKE([1.11 -Wportability tar-ustar no-dist-gzip dist-xz std-options])
102 AC_CONFIG_SRCDIR([matcher/multiandpostlist.cc])
104 AC_CONFIG_HEADERS([config.h])
106 AC_CONFIG_MACRO_DIR([m4])
110 dnl Use libtool to manage our libraries.
112 dnl Default to only building shared libraries.
114 dnl Building both shared and static means having to compile the files which
115 dnl make up the library twice on most platforms. Shared libraries are the
116 dnl better option for most users, and if anyone really wants static libraries,
117 dnl they can configure with --enable-static (or --enable-static=xapian-core if
118 dnl configuring a combined tree with the bindings).
120 dnl We don't export any data items from the library, so it should be safe to
121 dnl enable win32-dll without decorating any declarations specially.
122 LT_INIT([disable-static win32-dll])
124 dnl -no-undefined causes problems on Solaris with Sun CC in C++11 mode, so only
125 dnl pass -no-undefined on platforms where it is required in order to link a
126 dnl shared library at all (Windows is the main one).
128 if test unsupported = "$allow_undefined_flag" ; then
129 NO_UNDEFINED=-no-undefined
131 AC_SUBST(NO_UNDEFINED)
135 dnl A standard "gotcha" for mingw and cygwin users is to not set up their
136 dnl PATH correctly, so that MSDOS FIND.EXE is found before Unix find. Help
137 dnl them out by checking for this condition, rather than letting libtool
138 dnl fail in obscure ways. NB check the *BUILD* OS, not the host one!
140 *mingw* | *cygwin* | pw32*)
141 find /dirunlikelytoexist >/dev/null 2>&1
142 if test $? = 2 ; then
143 dnl Unix find will return 1 if the directory didn't exist, or 0 if
146 *** You appear to have an MSDOS-like FIND.EXE in your PATH ahead of any
147 *** UNIX-like find. This misconfiguration will confuse libtool - you'll need
148 *** to make sure you have a UNIX-like find installed and fix your PATH, then
149 *** rerun configure. For more information, see:
151 *** https://www.cygwin.com/faq/faq.html#faq.using.find
157 dnl Add parameters for aclocal
158 dnl (This must come after AM_INIT_AUTOMAKE, since it modifies ACLOCAL)
159 ACLOCAL="$ACLOCAL $ACLOCAL_FLAGS"
161 dnl disable "maintainer only" rules by default
164 dnl Checks for programs.
169 # Checked: freebsd8.0 openbsd4.6 solaris2.9 solaris2.10
171 linux* | k*bsd*-gnu | freebsd* | openbsd* | solaris*)
172 dnl Vanilla libtool sets this to "unknown" which it then handles as "yes".
173 link_all_deplibs_CXX=no
179 dnl Extract search path from ldconfig which is more reliable than the way
180 dnl vanilla libtool extracts them from ld.so.conf.
181 d=`/sbin/ldconfig -N -X -v 2>&AS_MESSAGE_LOG_FD|$SED 's,^\(/.*\):\( (.*)\)\?$,\1,p;d'|tr '\n' ' '`
182 test -z "$d" || sys_lib_dlsearch_path_spec=$d
187 *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
188 dnl On these platforms, libtool emits a warning if -no-install is passed,
189 dnl and uses -no-fast-install instead - the least ugly way to avoid that
190 dnl warnings seems to be to duplicate the above list of platforms from
191 dnl libtool and use -no-fast-install on them directly.
192 NO_INSTALL=-no-fast-install ;;
194 NO_INSTALL=-no-install ;;
196 AC_SUBST([NO_INSTALL])
198 dnl For reasons which are beyond me, if autoconf can't find a C++ compiler
199 dnl it will set CXX to g++ (which obviously won't work) rather than actually
200 dnl telling the user that it couldn't find a C++ compiler and telling them
201 dnl to either install one or set CXX if there's one configure failed to find.
202 dnl It's probably worthwhile checking that the C++ compiler actually works
204 if test -n "$CXX" ; then
206 AC_MSG_CHECKING([whether $CXX is a working C++ compiler])
207 AC_CACHE_VAL([xo_cv_cxx_works],
209 AC_TRY_RUN([int main() {}],
212 AC_TRY_LINK([], [], xo_cv_cxx_works=yes, xo_cv_cxx_works=no))
214 AC_MSG_RESULT([$xo_cv_cxx_works])
218 if test no = "$xo_cv_cxx_works" ; then
219 case $original_CXX in
221 dnl CCC is handled in a slightly odd way - if its value isn't an
222 dnl executable (taking PATH into account) then it is ignored!
223 test "$original_CXX" = "CCC=$CXX" || original_CXX=
226 if test -z "$original_CXX" ; then
228 *** You need a working C++ compiler to compile Xapian, but configure failed to
229 *** find one. If you have a working C++ compiler, you can tell configure where
230 *** to find it by invoking it like so:
232 *** ./configure CXX=/opt/bin/c++
236 *** You need a working C++ compiler to compile Xapian, but the compiler you
237 *** specified (with '$original_CXX') doesn't appear to be able to successfully
238 *** compile and link a simple program.
243 dnl Probe for any options needed to enable C++11 support.
244 AX_CXX_COMPILE_STDCXX_11
246 dnl We don't use a C compiler to compile Xapian's code, but on some platforms
247 dnl (e.g. mingw) libtool uses $LTCC which defaults to $CC, and it's also use to
248 dnl build auxiliary tools like snowball and lemon.
251 dnl Check endianness.
254 dnl We want a non-cross-compiling C compiler for building lemon with.
255 if test -z "$CC_FOR_BUILD" ; then
256 if test yes = "$cross_compiling"; then
262 AC_ARG_VAR([CC_FOR_BUILD], [C compiler command for native compilation (needed to compile build tools during cross-builds)])
264 dnl Run tests using the C++ compiler.
267 dnl Enable large file support if possible.
269 dnl With xlC on AIX, -D_LARGE_FILES changes the ABI of std::string, so it
270 dnl also needs to be used when compiling user code.
271 abi_affecting_cxxflags=
272 if $GREP '^#define _LARGE_FILES 1$' confdefs.h > /dev/null 2>&1 ; then
273 abi_affecting_cxxflags=-D_LARGE_FILES
275 AC_SUBST([abi_affecting_cxxflags])
277 AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
278 #if defined __WIN32__ || defined _WIN32
281 ]])], [win32=no], [win32=yes])
283 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
287 ]])], [msvc=no], [msvc=yes])
291 AC_SUBST([XAPIAN_LDFLAGS])
292 AC_SUBST([XAPIAN_LIBS])
294 AC_DEFUN([XAPIAN_TEST_FLAGS_],
296 m4_define([cachevar],
297 [xo_cv_]m4_tolower(m4_bpatsubst([$1][_$3], [[^A-Za-z0-9]], [_])))
298 AC_CACHE_CHECK([for $CXX with $3 in $1], cachevar,
302 $2([AC_LANG_PROGRAM([], [])],
313 dnl Test if compiling works with $1 added to CXXFLAGS; if it does, add $1 to
314 dnl variable $2. If the test passes, also do $3; if it fails, also do $4.
315 AC_DEFUN([XAPIAN_TEST_CXXFLAGS],
316 [XAPIAN_TEST_FLAGS_([CXXFLAGS], [AC_COMPILE_IFELSE], [$1], [$2], [$3], [$4])])
318 dnl Test if linking works with $1 added to LDFLAGS; if it does, add $1 to
319 dnl variable $2. If the test passes, also do $3; if it fails, also do $4.
320 AC_DEFUN([XAPIAN_TEST_LDFLAGS],
321 [XAPIAN_TEST_FLAGS_([LDFLAGS], [AC_LINK_IFELSE], [$1], [$2], [$3], [$4])])
324 if test yesyes = "$GXX$enable_shared" ; then
328 [-Wl,--enable-runtime-pseudo-reloc],
332 dnl Can't use AC_DISABLE_SHARED after AC_PROG_LIBTOOL, but
333 dnl this test needs to be after AC_PROG_LIBTOOL, so we can't
334 dnl just disable the shared build automatically...
335 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])
340 dnl Only works for ldflags which can be specified anywhere on the link line.
343 dnl Preserve the default CXXFLAGS.
344 save_CXXFLAGS=$CXXFLAGS
346 dnl x86 has excess precision issues with 387 FP instructions, which are
347 dnl avoided by using SSE instructions instead. This is also faster (~6% in
348 dnl a CPU bound testcase).
350 [AS_HELP_STRING([--disable-sse],
351 [disable use of SSE FP instructions on x86])]
352 [AS_HELP_STRING([[--enable-sse[=sse|sse2]]],
353 [set which SSE FP instructions to use on x86 (default: sse2)])],
354 [case ${enableval} in
356 *) AC_MSG_ERROR([bad value ${enableval} for --enable-sse or --disable-sse]) ;;
360 dnl Some versions of Sun's C++ compiler reportedly need an explicit -lm.
361 dnl The maths functions we use include: exp log ceil fabs sqrt
362 AC_MSG_CHECKING([if -lm is required for maths functions])
363 dnl Don't use constant arguments as the compiler might simply evaluate the
364 dnl whole expression at compile time, and it might inline certain functions
365 dnl so test several functions. Also write results using printf() so that
366 dnl the compiler can't optimise away the computations.
367 AC_TRY_LINK([#ifdef __SUNPRO_CC
368 #error Need -lm for Sun C++ 5.9 under libtool 2.2.10
373 using namespace std;], [
374 double a = log(ceil(time(NULL)/7.0));
375 printf("%f %f %f\n", a, sqrt(a), exp(fabs(a - 12345.6)));
376 ], [AC_MSG_RESULT([no])], [
378 AC_TRY_LINK([#include <cmath>
381 using namespace std;], [
382 double a = log(ceil(time(NULL)/7.0));
383 printf("%f %f %f\n", a, sqrt(a), exp(fabs(a - 12345.6)));],
384 [AC_MSG_RESULT([yes])],
385 [AC_MSG_ERROR([Failed to link a C++ program using <cmath>])
389 dnl C++11 should have log2(double), but keep this check for now to allow for
390 dnl compilers with incomplete library support for C++11.
391 AC_CHECK_DECLS([log2(double)], [], [],
393 using namespace std;])
395 dnl exp10() is a GNU libc extension.
396 AC_CHECK_DECLS([exp10(double)], [], [],
398 using namespace std;])
400 dnl Darwin provides __exp10().
401 AC_CHECK_DECLS([__exp10(double)], [], [],
403 using namespace std;])
405 dnl GCC provides __builtin_exp10() (but notably clang doesn't currently).
406 dnl On mingw, __builtin_exp10() causes GCC to generate a call to exp10() which
407 dnl then fails to link, so perform a link check here to catch that.
408 AC_CACHE_CHECK([for __builtin_exp10], xo_cv_link___builtin_exp10, [
409 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
412 using namespace std;]],
413 [[printf("%f", __builtin_exp10(double(time(NULL)*1e-8)));]])],
414 [xo_cv_link___builtin_exp10=yes],
415 [xo_cv_link___builtin_exp10=no])
417 if test $xo_cv_link___builtin_exp10 = yes ; then
418 AC_DEFINE([HAVE___BUILTIN_EXP10], [1], [Define to 1 if you have the '__builtin_exp10' function.])
421 dnl See if <typeinfo> can be used in the testsuite - at least for GCC and xlC,
422 dnl compilation of the test code below fails if RTTI isn't being generated
423 dnl (g++ -fno-rtti, or by default with xlC).
424 AC_MSG_CHECKING([if RTTI is supported])
425 save_CXXFLAGS=$CXXFLAGS
426 dnl xlC issues a warning for typeid() being used without RTTI being enabled,
427 dnl so for this test we pass the xlC option to make that warning into an error.
428 CXXFLAGS="$CXXFLAGS -qhaltonmsg=1540-2412"
429 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])],
431 [CXXFLAGS=$save_CXXFLAGS])
434 #include <typeinfo>],
439 } catch (std::exception & e) {
440 return typeid(e).name()[0];
443 AC_DEFINE([USE_RTTI], [1], [Define if the testsuite can use RTTI]),
445 CXXFLAGS=$save_CXXFLAGS
447 dnl We need to specify the argument types for builtin functions, or else
448 dnl AC_CHECK_DECLS fails to detect them when the compiler is clang.
449 AC_CHECK_DECLS([__builtin_add_overflow(int, int, int*),
450 __builtin_mul_overflow(int, int, int*)], [], [], [ ])
451 AC_CHECK_DECLS([__builtin_bswap16(uint16_t),
452 __builtin_bswap32(uint32_t),
453 __builtin_bswap64(uint64_t)], [], [],
454 [#include <stdint.h>])
455 AC_CHECK_DECLS([_byteswap_ushort, _byteswap_ulong, _byteswap_uint64], [], [],
456 [#include <stdlib.h>])
457 AC_CHECK_DECLS([__builtin_clz(unsigned),
458 __builtin_clzl(unsigned long),
459 __builtin_clzll(unsigned long long)], [], [], [ ])
460 AC_CHECK_DECLS([__builtin_ctz(unsigned),
461 __builtin_ctzl(unsigned long),
462 __builtin_ctzll(unsigned long long)], [], [], [ ])
463 AC_CHECK_DECLS([__builtin_expect(long, long)], [], [], [ ])
464 AC_CHECK_DECLS([__builtin_popcount(unsigned),
465 __builtin_popcountl(unsigned long),
466 __builtin_popcountll(unsigned long long)], [], [], [ ])
467 AC_CHECK_DECLS([__popcnt, __popcnt64], [], [], [#include <intrin.h>])
469 dnl Check for poll().
470 AC_CHECK_FUNCS([poll])
472 dnl Check for time functions.
473 AC_CHECK_FUNCS([clock_gettime sleep nanosleep gettimeofday ftime])
477 dnl For _ftime64() on mingw we need to tell it we're happy to require
478 dnl MSVCRT 6.10 or higher, which isn't too onerous a requirement it seems.
479 AC_DEFINE([__MSVCRT_VERSION__], [0x0601], [Define on mingw to the minimum msvcrt version to assume])
480 AC_DEFINE([MINGW_HAS_SECURE_API], [1], [Define on mingw to get _s suffixed "secure" functions declared in headers])
484 dnl We use timer_create() if available to implement a search time limit.
486 AC_SEARCH_LIBS([timer_create], [rt],
488 AC_MSG_CHECKING([for timer_create() usability])
489 dnl Several platforms have timer_create() but it's non-functional.
491 dnl Some of these (at least those with a stub implementation which always
492 dnl fails with ENOSYS) could be probed for, but we'd have to run code
493 dnl which isn't possible when cross-compiling, so just maintain a list
494 dnl of such platforms for now.
495 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
497 #error timer_create always fails with EAGAIN on AIX 7.1
498 #elif defined __GNU__
499 #error timer_create always fails with ENOSYS on GNU Hurd
500 #elif defined __NetBSD__
501 #error timer_create timers never fire on NetBSD 7.1
502 #elif defined __OpenBSD__
503 #error timer_create always fails with ENOSYS on OpenBSD 6.2 (and no prototype)
505 [AC_MSG_RESULT([yes])
506 XAPIAN_LIBS="$LIBS $XAPIAN_LIBS"
507 AC_DEFINE([HAVE_TIMER_CREATE], [1], [Define to 1 if you have the 'timer_create' function.])]
514 dnl Used by tests/soaktest/soaktest.cc
515 AC_CHECK_FUNCS([srandom random])
517 dnl Used by tests/harness/testsuite.cc
518 AC_CHECK_FUNCS([sigaction])
519 AC_MSG_CHECKING([for sigsetjmp and siglongjmp])
520 AC_TRY_COMPILE([#include <setjmp.h>],
521 [sigjmp_buf jb; if (sigsetjmp(jb, 1)) { siglongjmp(jb, 1); }],
522 AC_DEFINE([HAVE_SIGSETJMP], [1], [Define to 1 if you have the 'sigsetjmp' function])
523 AC_MSG_RESULT([yes]),
526 dnl Used by tests/harness/cputimer.cc:
527 AC_CHECK_FUNCS([getrusage times sysconf])
529 dnl Used by tests/harness/unixcmd.cc
530 AC_CHECK_FUNCS([nftw])
532 dnl POSIX requires setenv(). The final Unix-like platform without it seems
533 dnl to have been Solaris 9, which is now out of support.
535 dnl Microsoft don't provide setenv() and have marked putenv() as deprecated, so
536 dnl we use _putenv_s() to avoid deprecation warnings with MSVC. It's also a
537 dnl more similar interface to setenv() so easier to implement a setenv() wrapper
538 dnl around. We probe for both the function and a declaration since mingw
539 dnl doesn't currently (v3.20) declare it but it is present in the C runtime DLL
540 dnl so we can provide our own declaration to access it.
541 AC_CHECK_FUNCS([setenv _putenv_s])
542 AC_CHECK_DECLS([_putenv_s(const char*, const char*)], [], [],
543 [#include <stdlib.h>])
545 dnl See if we have closefrom(), or some functions that are useful to implement
546 dnl closefrom() on platforms which don't provide it.
547 AC_CHECK_FUNCS([closefrom getdirentries getrlimit])
549 dnl See if ftime returns void (as it does on mingw)
550 AC_MSG_CHECKING([return type of ftime])
551 if test $ac_cv_func_ftime = yes ; then
552 AC_TRY_COMPILE([#include <sys/timeb.h>],
553 [struct timeb tp; int i = ftime(&tp);],
554 AC_MSG_RESULT([int]),
555 AC_MSG_RESULT([void])
556 AC_DEFINE([FTIME_RETURNS_VOID], [1], [Define if ftime returns void]))
559 dnl Check how to find the hostname: uname() in sys/utsname.h, or gethostname()
560 AC_CHECK_HEADERS([sys/utsname.h], [], [], [ ])
561 AC_CHECK_FUNCS([gethostname])
563 dnl mingw (for instance) lacks ssize_t
570 AC_CHECK_SIZEOF([short])
571 AC_CHECK_SIZEOF([int])
572 AC_CHECK_SIZEOF([long])
573 AC_CHECK_SIZEOF([long long])
575 AC_CHECK_HEADERS([sys/types.h])
577 AC_MSG_CHECKING([for 32 bit integer type])
579 "$ac_cv_sizeof_int") INT32_T=int ;;
580 "$ac_cv_sizeof_long") INT32_T=long ;;
581 "$ac_cv_sizeof_short") INT32_T=short ;;
583 AC_MSG_RESULT([none found])
584 AC_MSG_ERROR([No 32 bit integer type found])
586 AC_MSG_RESULT([$INT32_T])
588 AC_MSG_CHECKING([for 64 bit integer type])
590 "$ac_cv_sizeof_int") INT64_T=int ;;
591 "$ac_cv_sizeof_long") INT64_T=long ;;
592 "$ac_cv_sizeof_long_long") INT64_T='long long' ;;
594 AC_MSG_RESULT([none found])
595 AC_MSG_ERROR([No 64 bit integer type found])
597 AC_MSG_RESULT([$INT64_T])
599 dnl Check for perl (needed to generate some sources and documentation).
600 AC_PATH_PROG([PERL], [perl], [])
601 if test x$USE_MAINTAINER_MODE = xyes; then
602 test -z "$PERL" && AC_MSG_ERROR([perl is required in maintainer mode])
605 AC_ARG_ENABLE([64bit_docid],
606 [AS_HELP_STRING([--enable-64bit-docid], [enable 64bit docid])],
607 [case ${enableval} in
609 *) AC_MSG_ERROR([bad value ${enableval} for --enable-64bit-docid]) ;;
611 [enable_64bit_docid=no])
613 AC_ARG_ENABLE([64bit_termcount],
614 [AS_HELP_STRING([--enable-64bit-termcount], [enable 64bit termcount])],
615 [case ${enableval} in
617 *) AC_MSG_ERROR([bad value ${enableval} for --enable-64bit-termcount]) ;;
619 [enable_64bit_termcount=no])
621 AC_ARG_ENABLE([64bit_termpos],
622 [AS_HELP_STRING([--enable-64bit-termpos], [enable 64bit termpos])],
623 [case ${enableval} in
625 *) AC_MSG_ERROR([bad value ${enableval} for --enable-64bit-termpos]) ;;
627 [enable_64bit_termpos=no])
629 AC_ARG_ENABLE([documentation],
630 [AS_HELP_STRING([--enable-documentation], [enable make rules to rebuild documentation [default=maintainer-mode]])],
631 [case ${enableval} in
633 *) AC_MSG_ERROR([bad value ${enableval} for --enable-documentation]) ;;
635 [enable_documentation=$USE_MAINTAINER_MODE])
636 AM_CONDITIONAL([DOCUMENTATION_RULES], [test x"$enable_documentation" = xyes])
637 AM_CONDITIONAL([MAINTAINER_NO_DOCS], [test x"$USE_MAINTAINER_MODE$enable_documentation" = xyesno])
639 if test x"$enable_documentation" = xyes ; then
640 dnl Checks for dot. (Diagrams in the documentation)
641 AC_PATH_PROG([DOT], [dot])
642 test -z "$DOT" && AC_MSG_ERROR([dot (part of the graphviz package) is required to build documentation])
643 DOXYGEN_DOT_PATH=`echo "$DOT" | sed 's!/dot$!!'`
644 AC_SUBST([DOXYGEN_DOT_PATH])
646 dnl Check for doxygen. (Needed to make some more of the documentation)
647 AC_PATH_PROG([DOXYGEN], [doxygen], [])
648 test -z "$DOXYGEN" && AC_MSG_ERROR([doxygen is required to build documentation])
650 dnl Check for help2man. (Needed to make man pages from "--help" output).
651 AC_PATH_PROG([HELP2MAN], [help2man], [])
652 test -z "$HELP2MAN" && AC_MSG_ERROR([help2man is required to build documentation])
654 dnl Check for rst2html. (Needed to make HTML from reStructuredText format)
655 dnl Also look for rst2html.py, which archlinux reportedly installs it as.
656 AC_PATH_PROGS([RST2HTML], [rst2html rst2html.py], [])
657 test -z "$RST2HTML" && AC_MSG_ERROR([rst2html is required to build documentation (try package python-docutils)])
659 dnl Check for pngcrush, which we optionally use to reduce the size of the
660 dnl PNG files which doxygen generates. We can get by without it, so don't
661 dnl fail here if it's not found.
662 AC_PATH_PROG([PNGCRUSH], [pngcrush], [])
665 dnl Checks for header files.
666 AC_CHECK_HEADERS([fcntl.h limits.h poll.h sys/select.h],
668 AC_CHECK_HEADERS([sys/resource.h],
669 [], [], [#include <sys/types.h>])
671 dnl cxxabi.h was added in GCC 3.1, but clang lies and defines __GNUC__ yet
672 dnl doesn't seem to reliably provide this header, so probe for it.
673 AC_CHECK_HEADERS([cxxabi.h], [], [], [ ])
675 dnl If valgrind is installed and new enough, we use it for leak checking in the
676 dnl testsuite. If VALGRIND is set to an empty value, then skip the check and
677 dnl don't use valgrind. On macOS only use valgrind if VALGRIND is set to a
678 dnl no empty value, as valgrind on macOS gives a lot of false positives.
679 use_valgrind_if_non_empty=
682 use_valgrind_if_non_empty=$VALGRIND ;;
684 use_valgrind_if_non_empty=${VALGRIND-unset} ;;
687 if test -n "$use_valgrind_if_non_empty" ; then
688 AC_PATH_PROG([VALGRIND], [valgrind], [])
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], [])
734 dnl Checks for library functions.
737 AC_CACHE_CHECK([for sys_errlist and sys_nerr], xo_cv_sys_errlist_and_sys_nerr, [
738 AC_LINK_IFELSE([AC_LANG_PROGRAM(
739 dnl On Linux, sys_errlist and sys_nerr need <stdio.h>, though the man page
740 dnl says <errno.h>. The man page seems to match other platforms such as
741 dnl NetBSD, so include both headers to ensure we get them.
743 #include <stdio.h>]],
744 [[ printf("%s", sys_errlist[sys_nerr - 1]);]])],
745 [ xo_cv_sys_errlist_and_sys_nerr=yes ],
746 [ xo_cv_sys_errlist_and_sys_nerr=no ])
748 if test "x$xo_cv_sys_errlist_and_sys_nerr" = "xyes" ; then
749 AC_DEFINE([HAVE_SYS_ERRLIST_AND_SYS_NERR], [1],[Define if you have 'sys_errlist' and 'sys_nerr'])
752 AC_CACHE_CHECK([for _sys_errlist and _sys_nerr], xo_cv__sys_errlist_and__sys_nerr, [
753 AC_LINK_IFELSE([AC_LANG_PROGRAM(
755 #include <stdio.h>]],
756 [[ printf("%s", _sys_errlist[_sys_nerr - 1]);]])],
757 [ xo_cv__sys_errlist_and__sys_nerr=yes ],
758 [ xo_cv__sys_errlist_and__sys_nerr=no
761 if test "x$xo_cv__sys_errlist_and__sys_nerr" = "xyes" ; then
762 AC_DEFINE([HAVE__SYS_ERRLIST_AND__SYS_NERR], [1],[Define if you have '_sys_errlist' and '_sys_nerr'])
765 dnl mingw has _snprintf so check for that too.
766 AC_MSG_CHECKING([for snprintf])
767 AC_CACHE_VAL([xo_cv_func_snprintf],
769 xo_cv_func_snprintf=no
770 for func in snprintf _snprintf ; do
778 char buffer[4] = "abc";
779 int res = $func(buffer, 4, "%s", "XYZ");
783 [xo_cv_func_snprintf=$func;break],
788 AC_MSG_RESULT([$xo_cv_func_snprintf])
789 if test "$xo_cv_func_snprintf" != no ; then
790 AC_DEFINE_UNQUOTED([SNPRINTF], [$xo_cv_func_snprintf],
791 [Define to the name of a function implementing snprintf but not caring about ISO C99 return value semantics (if one exists)])
794 dnl ***************************
795 dnl * Select modules to build *
796 dnl ***************************
798 dnl Check which database backends should be built.
800 AC_DEFUN([_XAPIAN_BACKEND_ENABLE],
801 [AC_ARG_ENABLE([backend_$1],
802 [AS_HELP_STRING([--enable-backend-$1], [build the $1 database backend [default=$3]])],
805 *) AC_MSG_ERROR([Invalid option: '--enable-backend-$1=$enableval']) ;;
806 esac], [enable_backend_$1=$2])
809 AC_DEFUN([XAPIAN_BACKEND_ENABLE],
810 [_XAPIAN_BACKEND_ENABLE([$1],
811 m4_default([$2], [yes]),
812 m4_default([$3], [yes]))
815 dnl When adding a new backend, update INSTALL too.
816 XAPIAN_BACKEND_ENABLE([chert])
817 XAPIAN_BACKEND_ENABLE([glass])
818 XAPIAN_BACKEND_ENABLE([inmemory])
819 default_enable_backend_remote=yes
822 dnl We don't currently support the remote backend on this platform so
823 dnl disable it by default.
824 default_enable_backend_remote=no
827 XAPIAN_BACKEND_ENABLE([remote], [$default_enable_backend_remote], [yes (except for MSDOS)])
830 case $enable_backend_chert$enable_backend_glass in
832 dnl We use zlib for compressing tags in chert/glass. We could
833 dnl automatically disable support if zlib isn't found, but overall that
834 dnl probably does more harm than good - it's most likely that someone just
835 dnl forgot to install the -dev package for zlib.
837 dnl Similarly for uuid support.
839 dnl Check for zlib.h.
840 AC_CHECK_HEADERS([zlib.h], [], [
841 AC_MSG_ERROR([zlib.h not found - required for chert and glass (you may need to install the zlib1g-dev or zlib-devel package)])
844 dnl Check for zlibVersion in -lz.
846 dnl mingw build needs -lzlib or -lzdll.
847 AC_SEARCH_LIBS([zlibVersion], [z zlib zdll], [], [
848 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)])
850 if test x != x"$LIBS" ; then
851 XAPIAN_LIBS="$XAPIAN_LIBS $LIBS"
855 dnl Find the UUID library (from e2fsprogs/util-linux-ng, not the OSSP one).
857 case $host_os-$win32 in
858 *-yes | *cygwin*) dnl Use built-in win32 API.
859 AC_DEFINE([USE_WIN32_UUID_API], [1],
860 [Define to 1 to use UuidCreate(), etc])
861 if test $win32 = yes ; then
862 dnl We need -lws2_32 for htonl(), etc, but not for Cygwin which
863 dnl provides these functions in its libc.
866 XAPIAN_LIBS="$XAPIAN_LIBS -lrpcrt4"
869 dnl Check for uuid/uuid.h (e2fsprogs/util-linux-ng) or uuid.h
870 dnl (FreeBSD/NetBSD/OpenBSD/AIX).
871 AC_CHECK_HEADERS([uuid/uuid.h], [
872 dnl util-linux-ng's uuid/uuid.h found - check for uuid_generate in
875 AC_SEARCH_LIBS([uuid_generate], [uuid], [], [
876 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)])
878 if test x != x"$LIBS" ; then
879 XAPIAN_LIBS="$XAPIAN_LIBS $LIBS"
882 dnl Try uuid.h as found on FreeBSD/NetBSD/OpenBSD/AIX, with associated
884 AC_CHECK_HEADERS([uuid.h], [
885 dnl Check for uuid_create with no extra libraries required.
886 AC_CHECK_FUNC([uuid_create], [], [
887 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)])
890 dnl Especially useful for Android.
891 AC_MSG_CHECKING([if host platform supports /proc/sys/kernel/random/uuid])
894 AC_DEFINE([USE_PROC_FOR_UUID], [1],
895 [Define to 1 to read UUID from '/proc/sys/kernel/random/uuid'])
900 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)])
911 dnl DJGPP has a dummy implementation of fork which always fails.
913 dnl For disk-based backends, use flock() for locking, which doesn't need
914 dnl fork() or socketpair().
915 AC_DEFINE([FLINTLOCK_USE_FLOCK], 1, [Define to use flock() for flint-compatible locking])
921 if test "$enable_backend_remote" = yes ; then
922 case $host_os-$win32 in
924 dnl For mingw and msvc we have an alternative implementation which
925 dnl doesn't need fork() or socketpair().
927 dnl We need -lws2_32 for getaddrinfo(), etc.
929 dnl Vista is needed for the AI_ADDRCONFIG flag to getaddrinfo().
930 AC_DEFINE([WINVER], [0x600],
931 [Version of Windows to assume (0x600 => Vista).])
932 AC_DEFINE([_WIN32_WINNT], [WINVER],
933 [Version of Windows to assume.])
936 dnl DJGPP has a dummy implementation of fork which always fails. If
937 dnl someone actually wanted remote backend support, then DJGPP has a
938 dnl pthreads port, so using threads like we do on Windows would make more
940 AC_MSG_ERROR([The remote backend is not currently supported on this platform.])
943 dnl On Unix, we need fork and socketpair for the remotebackend.
945 AC_CHECK_FUNCS([fork], [], [
946 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.)])
948 dnl Check if -lsocket is required for socketpair (Solaris needs it).
949 dnl And on Haiku it's in -lnetwork.
950 AC_SEARCH_LIBS([socketpair], [socket network], [], [
951 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.)])
953 AC_DEFINE([HAVE_SOCKETPAIR], [1],
954 [Define to 1 if you have the 'socketpair' function.])
955 dnl Check if extra libraries are needed for getaddrinfo or inet_ntop()
956 dnl (e.g. on Solaris).
958 dnl We're currently assuming that any system that is worth trying to
959 dnl support has getaddrinfo() and inet_ntop(), since these are the
960 dnl standard route for supporting IPv6, and that's pretty much essential
961 dnl for platforms to support now.
962 AC_SEARCH_LIBS([getaddrinfo], [nsl socket], [], [
963 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.)])
965 AC_SEARCH_LIBS([inet_ntop], [nsl socket], [], [
966 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.)])
968 XAPIAN_LIBS="$XAPIAN_LIBS $LIBS"
973 XAPIAN_TYPE_SOCKLEN_T
976 if test "$win32_need_lws2_32" = 1 ; then
977 XAPIAN_LIBS="$XAPIAN_LIBS -lws2_32"
980 AC_ARG_ENABLE([visibility],
981 [AS_HELP_STRING([--disable-visibility], [disable use of GCC visibility])],
982 [case ${enableval} in
984 *) AC_MSG_ERROR([bad value ${enableval} for --disable-visibility]) ;;
988 if test "`pwd`" != "`cd $srcdir;pwd`" ; then
991 AM_CONDITIONAL([VPATH_BUILD], [test yes = "$vpath_build"])
993 dnl Turn off compilation of anything that we don't have the requirements for
995 dnl Set conditionals to specify what we compile
997 AM_CONDITIONAL([BUILD_BACKEND_CHERT], [test yes = "$enable_backend_chert"])
998 AM_CONDITIONAL([BUILD_BACKEND_GLASS], [test yes = "$enable_backend_glass"])
999 AM_CONDITIONAL([BUILD_BACKEND_INMEMORY], [test yes = "$enable_backend_inmemory"])
1000 AM_CONDITIONAL([BUILD_BACKEND_REMOTE], [test yes = "$enable_backend_remote"])
1001 AM_CONDITIONAL([BUILD_BACKEND_CHERT_OR_GLASS],
1002 [test nono != "$enable_backend_chert$enable_backend_glass"])
1004 dnl Decide if we should use the zlib-vg.so LD_PRELOAD hack.
1006 if test -n "$VALGRIND" ; then
1008 linux*) use_zlib_vg=yes ;;
1011 AM_CONDITIONAL([USE_ZLIB_VG], [test yes = "$use_zlib_vg"])
1013 dnl See if we have fdatasync, and what libraries are needed for it.
1014 dnl We need to actually check for a declaration as OS X has a dummy
1015 dnl implementation in the library which is not prototyped in any header.
1016 AC_CHECK_DECL([fdatasync(int)], [
1018 AC_SEARCH_LIBS([fdatasync], [rt], [XAPIAN_LIBS="$LIBS $XAPIAN_LIBS"])
1020 AC_CHECK_FUNCS([fdatasync])
1022 [ac_cv_func_fdatasync=no],
1023 [#include <unistd.h>]
1026 AC_CHECK_FUNCS([fsync])
1027 AC_CHECK_FUNCS([posix_fadvise])
1028 if test "$win32" = no ; then
1029 dnl ftruncate() under Wine seems to be buggy and sometimes fails, though
1030 dnl a cut-down reproducer seems fine. For now just avoid ftruncate()
1031 dnl entirely on this platform - we'll fallback to lseek() + write() of a
1032 dnl single zero byte, which is pretty efficient.
1033 AC_CHECK_FUNCS([ftruncate])
1036 dnl HP-UX has pread and pwrite, but they don't work! Apparently this problem
1037 dnl manifests when largefile support is enabled, and we definitely want that
1038 dnl so don't use pread or pwrite on HP-UX.
1041 AC_MSG_CHECKING([for pread])
1042 AC_MSG_RESULT([present but broken on $host_os])
1043 AC_MSG_CHECKING([for pwrite])
1044 AC_MSG_RESULT([present but broken on $host_os])
1047 AC_CHECK_FUNC([pread],
1048 [AC_DEFINE([HAVE_PREAD], [1],
1049 [Define if pread is available on this system])
1050 AC_MSG_CHECKING([for any prototype needed for pread])
1051 AC_CACHE_VAL([xo_cv_pread_prototype],
1054 'extern "C" ssize_t pread(int, void *, size_t, off_t) throw ();' \
1055 'extern "C" ssize_t pread(int, void *, size_t, off_t);' ; do
1057 #include <sys/types.h>
1062 pread(1, b, 256, 20);
1064 xo_cv_pread_prototype="$p"
1068 if test -z "$xo_cv_pread_prototype"; then
1069 AC_MSG_RESULT([not found])
1070 AC_MSG_ERROR([Failed to find working prototype for pread])
1073 if test " " = "$xo_cv_pread_prototype" ; then
1074 AC_MSG_RESULT([none required])
1076 AC_MSG_RESULT([$xo_cv_pread_prototype])
1077 AC_DEFINE_UNQUOTED([PREAD_PROTOTYPE], [$xo_cv_pread_prototype],
1078 [explicit prototype needed for pread (if any)])
1081 AC_CHECK_FUNC([pwrite],
1082 [AC_DEFINE([HAVE_PWRITE], [1],
1083 [Define if pwrite is available on this system])
1084 AC_MSG_CHECKING([for any prototype needed for pwrite])
1085 AC_CACHE_VAL([xo_cv_pwrite_prototype],
1088 'extern "C" ssize_t pwrite(int, const void *, size_t, off_t) throw ();' \
1089 'extern "C" ssize_t pwrite(int, const void *, size_t, off_t);' ; do
1091 #include <sys/types.h>
1095 const char *p = "hello";
1096 pwrite(1, p, 5, 20);
1098 xo_cv_pwrite_prototype="$p"
1102 if test -z "$xo_cv_pwrite_prototype"; then
1103 AC_MSG_RESULT([not found])
1104 AC_MSG_ERROR([Failed to find working prototype for pwrite])
1107 if test " " = "$xo_cv_pwrite_prototype" ; then
1108 AC_MSG_RESULT([none required])
1110 AC_MSG_RESULT([$xo_cv_pwrite_prototype])
1111 AC_DEFINE_UNQUOTED([PWRITE_PROTOTYPE], [$xo_cv_pwrite_prototype],
1112 [explicit prototype needed for pwrite (if any)])
1118 AC_MSG_CHECKING([for directory separator(s)])
1119 case $host_os-$win32 in
1120 *-yes | cygwin* | os2* | *djgpp* | *msdos* )
1121 AC_MSG_RESULT([/ and \\])
1122 AC_DEFINE([DIR_SEPS], ["/\\"], [directory separator(s) as a character or string literal])
1123 AC_DEFINE([DIR_SEPS_LIST], [{ '/', '\\' }], [directory separator(s) as an initialiser list])
1127 AC_DEFINE([DIR_SEPS], ['/'], [directory separator(s) as a character or string literal])
1128 AC_DEFINE([DIR_SEPS_LIST], [{ '/' }], [directory separator(s) as an initialiser list])
1132 AC_CHECK_FUNCS([link])
1134 dnl *************************
1135 dnl * Set debugging options *
1136 dnl *************************
1138 dnl Which assertion types to enable in the code.
1140 AC_ARG_ENABLE([assertions],
1141 [AS_HELP_STRING([--enable-assertions], [enable debug assertions (no|partial|yes) [default=no]])],
1145 AC_MSG_ERROR([Invalid option: '--enable-assertions=$enableval']) ;;
1148 AC_ARG_ENABLE([log],
1149 [AS_HELP_STRING([--enable-log], [generate a log of methods called, etc (no|yes|profile) [default=no]])],
1153 AC_MSG_ERROR(['--enable-log=profile' is no longer supported - see https://trac.xapian.org/wiki/ProfilingXapian for alternatives.]) ;;
1155 AC_MSG_ERROR([Invalid option: '--enable-log=$enableval']) ;;
1158 dnl Set defines according to the --enable-assertions and --enable-log options
1161 if test yes = "$enable_assertions" || test partial = "$enable_assertions" ; then
1162 AC_DEFINE([XAPIAN_ASSERTIONS],,
1163 [Define if you want assertions (causes some slow-down)])
1166 if test yes = "$enable_assertions"; then
1167 AC_DEFINE([XAPIAN_ASSERTIONS_PARANOID],,
1168 [Define if you want paranoid assertions (causes significant slow-down)])
1171 if test yes = "$enable_log"; then
1172 AC_DEFINE([XAPIAN_DEBUG_LOG],,
1173 [Define if you want a log of methods called and other debug messages])
1176 dnl ******************************
1177 dnl * Set special compiler flags *
1178 dnl ******************************
1180 dnl Set flags to control warnings (enable more, or disable annoying ones).
1182 if test yes = "$GXX"; then
1183 dnl Intel's C++ compiler and clang both lie and define __GNUC__, so check which
1184 dnl we actually have, as neither is really 100% compatible.
1185 case `echo __INTEL_COMPILER __clang__|$CXX -E - 2>&AS_MESSAGE_LOG_FD|grep -v '^#'` in
1186 *__INTEL_COMPILER*__clang__*)
1187 dnl GCC (since neither substituted):
1189 dnl The exact format of g++ --version seems to change with almost every
1190 dnl minor release so use the preprocessor macros which should be more
1192 AC_MSG_CHECKING([for version of $CXX])
1193 gxx_version=`echo __GNUC__.__GNUC_MINOR__.__GNUC_PATCHLEVEL__|$CXX -E -|sed '/^#/d;s/ //g'`
1194 AC_MSG_RESULT([GCC $gxx_version])
1196 case $gxx_version in
1197 [[0123]].*|4.[[0-6]].*)
1198 AC_MSG_ERROR([Xapian requires GCC 4.7 or later])
1202 dnl -Wundef was supported by g++ 3.0.
1204 dnl -Wlogical-op and -Wmissing-declarations (for C++) were added in
1207 dnl -Wdouble-promotion was added in GCC 4.6.
1209 dnl -Winit-self was added in GCC 3.4, but for GCC < 4.7 g++ always
1210 dnl warns for this case with -Wuninitialized (implied by -W). We
1211 dnl don't intend to use this idiom, so any instances are bugs we'd
1212 dnl like to know about.
1214 dnl All the other options were supported by g++ 2.95.
1215 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"
1218 dnl -Wold-style-cast is interesting, but triggers for macros from
1219 dnl system headers (e.g. FD_SET). GCC 4.8 improved this by making
1220 dnl -ftrack-macro-expansion=2 the default, but we still see such
1221 dnl warnings on some platforms for some reason (e.g. Cygwin with GCC
1222 dnl 5.4.0 warns about FD_SET, and on Debian with GCC 4.9.2 we see
1223 dnl warnings from zlib.h).
1225 dnl Automatically add -Werror if maintainer mode is enabled.
1226 if test x$USE_MAINTAINER_MODE = xyes; then
1227 AM_CXXFLAGS="$AM_CXXFLAGS -Werror"
1231 dnl Intel's compiler (since __clang__ not substituted):
1233 dnl -w1 stops the avalanche of uninteresting "remark" messages.
1234 dnl -wd... disables warnings which don't have good code workarounds.
1235 AM_CXXFLAGS="$AM_CXXFLAGS -Wall -w1 -wd177,1572"
1237 dnl Automatically add -Werror if maintainer mode is enabled.
1238 if test x$USE_MAINTAINER_MODE = xyes; then
1239 AM_CXXFLAGS="$AM_CXXFLAGS -Werror"
1243 dnl clang (since __INTEL_COMPILER not substituted):
1245 dnl These options all work at least as far back as clang++ 3.0:
1246 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"
1248 dnl Automatically add -Werror if maintainer mode is enabled.
1249 if test x$USE_MAINTAINER_MODE = xyes; then
1250 AM_CXXFLAGS="$AM_CXXFLAGS -Werror"
1255 if test no != "$enable_visibility"; then
1256 dnl GCC doesn't support symbol visibility on all platforms (e.g. it isn't
1257 dnl supported on mingw and visibility attributes result in warnings).
1258 AC_MSG_CHECKING([if $CXX -fvisibility=hidden -fvisibility-inlines-hidden works])
1259 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
1260 AC_MSG_RESULT([yes])
1261 AM_CXXFLAGS="$AM_CXXFLAGS -fvisibility=hidden -fvisibility-inlines-hidden"
1262 dash_d_visibility=-DXAPIAN_ENABLE_VISIBILITY
1268 dnl Not GCC, nor a compiler masquerading as GCC.
1271 dnl +w turns on more warnings.
1272 dnl +wlint turns on "lint-like" warnings.
1273 dnl +W<n1>,<n2>,... suppresses warnings n1, n2, ...
1274 dnl 2340 (remark) "value copied to temporary, reference to temporary
1275 dnl use", in: throw Xapian::UnimplementedError("...");
1276 dnl 2401 "destructor for base class ... is non-virtual" (we don't need a
1277 dnl virtual destructor for intrusive_base, since we never delete
1278 dnl its subclasses by a intrusive_base *).
1279 dnl 3348 "declaration hides constant ..." which seems to misfire!
1280 dnl 4255 (remark) "padding size of struct "..." with ... bytes to
1281 dnl alignment boundary".
1282 dnl 4273 "floating-point equality and inequality comparisons may be
1283 dnl inappropriate due to roundoff common in floating-point computation"
1284 dnl No obvious workaround for when you really do want == or !=.
1285 dnl 4285 "operator= does not have a check for the source and destination
1286 dnl addresses being non-identical" - fires for AutoPtr which
1287 dnl includes such a check indirectly (internaltest's autoptr1 check this).
1288 dnl 20201 "Memory leak is detected" which triggers for "return new Foo;"!
1289 AM_CXXFLAGS="$AM_CXXFLAGS +w +wlint +W2340,2401,3348,4255,4273,4285,20201" ;;
1291 dnl Sun's C++ compiler.
1293 dnl We use -errtags to report the tag for each warning emitted.
1295 dnl We use -erroff to suppress some unhelpful warnings:
1297 dnl oklambdaretmulti warns about a lambda with more than one return
1298 dnl statement even if they all return the same type.
1300 dnl voidretw warns about functions failing to return a value even when the
1301 dnl function ends with a "throw" statement. That's just unhelpful noise,
1302 dnl and adding a dummy "return" after "throw" seems a worse solution than
1303 dnl simply disabling this warning - any genuinely missing return statements
1304 dnl will get reported by compilers with superior warning machinery.
1305 XAPIAN_TEST_CXXFLAGS([-errtags -erroff=oklambdaretmulti,voidretw], [AM_CXXFLAGS])
1310 XAPIAN_TEST_LDFLAGS([-Wl,-Bsymbolic-functions], [XAPIAN_LDFLAGS])
1311 dnl Roughly equivalent Sun C++ option.
1312 XAPIAN_TEST_LDFLAGS([-xldscope=symbolic], [XAPIAN_LDFLAGS])
1314 AC_MSG_CHECKING([whether to use SSE instructions on x86])
1317 if test "$enable_sse" = no ; then
1319 if test yes = "$msvc"; then
1320 dnl MSVC defaults to SSE2.
1321 AM_CXXFLAGS="$AM_CXXFLAGS -arch:IA32"
1324 dnl Default to sse2.
1325 test "$enable_sse" != yes || enable_sse=sse2
1326 if test yes = "$GXX"; then
1327 AC_MSG_RESULT([yes (configure with --disable-sse to disable)])
1328 dnl We can unconditionally use -mtune=generic as it was added in GCC
1329 dnl 4.2, and supported at least as far back as clang 3.0.
1330 AM_CXXFLAGS="$AM_CXXFLAGS -mfpmath=sse -m$enable_sse -mtune=generic"
1331 elif test yes = "$msvc"; then
1332 AC_MSG_RESULT([yes (configure with --disable-sse to disable)])
1333 if test sse = "$enable_sse"; then
1334 dnl MSVC defaults to SSE2.
1335 AM_CXXFLAGS="$AM_CXXFLAGS -arch:SSE"
1338 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
1339 [[#ifndef __SUNPRO_CC
1340 #error Not Sun compiler
1342 [AC_MSG_RESULT([yes (configure with --disable-sse to disable)])
1343 AM_CXXFLAGS="$AM_CXXFLAGS -xarch=$enable_sse"]
1345 [AC_MSG_RESULT([don't know how to for compiler $CXX])]
1351 AC_MSG_RESULT([non-x86 arch ($host_cpu)]) ;;
1355 [/* Disable stupid MSVC warnings. */
1357 /* Passing an empty parameter to a single parameter macro. */
1358 # pragma warning(disable:4003)
1359 /* A "performance" warning for converting int to bool. */
1360 # pragma warning(disable:4800)
1362 /* Tell MSVC we want M_PI, etc defined. */
1363 # define _USE_MATH_DEFINES
1365 /* Tell MSVC we don't want max() and min() macros defined. */
1369 /* Make the POSIX-like functions support large files. MSVC needs this;
1370 * current mingw32 does too; mingw64 supports _FILE_OFFSET_BITS, which
1371 * AC_SYS_LARGEFILE should discover and enable automatically.
1373 #if defined _MSC_VER || \
1374 (defined __MINGW32__ && !defined _FILE_OFFSET_BITS)
1376 # include <sys/stat.h>
1377 # include <sys/types.h>
1379 /* zlib.h uses off_t so we need to include it before we redefine off_t. */
1382 // The default stat() and fstat() use 32-bit filesizes and time_t, so we need
1383 // to arrange to use 64-bit variants instead.
1386 // Break #undef lines to stop config.status from commenting them out.
1391 // This hack is a problem is we ever want a method called "stat".
1393 // MSVC needs to call _stat64() instead of stat() and the struct which holds
1394 // the information is `struct _stat64` instead of `struct stat` so we just
1395 // use #define to replace both in one go.
1396 # define stat _stat64
1398 // Mingw32 has _stat64() but unhelpfully for our purposes, the struct is
1399 // called __stat64 (with an extra underscore). We hack around this by
1400 // defining stat to __stat64 which sorts out the struct, and then using
1401 // a second macro to forward function-like uses of __stat64() to
1403 # define stat __stat64
1404 # define __stat64(PATH, STATBUF) _stat64((PATH), (STATBUF))
1407 // We also want to use _fstat64() instead of fstat() but in this case we can
1408 // use a function-like macro, so we could have a method called fstat so long
1409 // as it didn't take two parameters.
1412 // Break #undef lines to stop config.status from commenting them out.
1417 # define fstat(FD, BUF) _fstat64(FD, BUF)
1420 // Break #undef lines to stop config.status from commenting them out.
1426 // Break #undef lines to stop config.status from commenting them out.
1431 # define lseek(FD, OFF, WHENCE) _lseeki64(FD, OFF, WHENCE)
1432 /* Redefine via a typedef so C++ code off_t(-1) works - it wouldn't if we did:
1433 * #define off_t long long
1435 typedef long long off_t_redefinition_typedef;
1436 # define off_t off_t_redefinition_typedef
1440 /* MSVC defines _WIN32 but not __WIN32__. */
1441 #if !defined __WIN32__ && defined _WIN32
1445 /* MSVC defines _WIN64 but not __WIN64__. */
1446 #if !defined __WIN64__ && defined _WIN64
1450 /* _FORTIFY_SOURCE is only supported by GCC >= 4.1 and glibc >= 2.3.4, but it
1451 * shouldn't cause a problem to define it where it's not supported and some
1452 * distros may have backported support, so hardcoding version checks is
1453 * counter-productive.
1455 * Check if _FORTIFY_SOURCE is already defined to allow the user to override
1456 * our choice with "./configure CPPFLAGS=-D_FORTIFY_SOURCE=0" or "...=1".
1458 #if defined __GNUC__ && !defined _FORTIFY_SOURCE
1459 # define _FORTIFY_SOURCE 2
1462 /* For compilers which support it (such as GCC, clang, Intel's C++ compiler)
1463 * we can use __builtin_expect to give the compiler hints about branch
1464 * prediction. See HACKING for how to use these.
1466 #if HAVE_DECL___BUILTIN_EXPECT
1467 /* The arguments of __builtin_expect() are both long, so use !! to ensure that
1468 * the first argument is always an integer expression, and always 0 or 1, but
1469 * still has the same truth value for the if or while it is used in.
1471 # define rare(COND) __builtin_expect(!!(COND), 0)
1472 # define usual(COND) __builtin_expect(!!(COND), 1)
1474 # define rare(COND) (COND)
1475 # define usual(COND) (COND)
1478 /* Signal we're building the library so it's OK to include headers such as
1479 * xapian/query.h directly.
1481 #define XAPIAN_LIB_BUILD 1
1483 /* With Sun CC 5.13 (Studio 12.4) on Solaris 11.2, <math.h> seems to get
1484 * implicitly included somehow before <cmath>, and compilation fails due
1485 * to 'std::exception' colliding with 'struct exception'. It's not clear
1486 * how to avoid this, so just define the same magic macro which <cmath> does
1487 * before it includes <math.h>.
1489 #if defined __SUNPRO_CC && !defined __MATHERR_RENAME_EXCEPTION
1490 # define __MATHERR_RENAME_EXCEPTION
1494 AC_SUBST([AM_CXXFLAGS])
1496 dnl Restore CXXFLAGS to those the user specified or autoconf defaulted to.
1497 CXXFLAGS=$save_CXXFLAGS
1499 dnl Required for auto regeneration to work in a combined maintainer-mode tree.
1500 : ${AUTOM4TE=autom4te}
1501 AC_SUBST([AUTOM4TE])
1503 dnl Libtool sets this (to yes|no|unknown) and we use it in xapian-config.
1504 AC_SUBST([link_all_deplibs_CXX])
1506 dnl Shared library extension.
1508 eval "SHLIBEXT=$shrext_cmds"
1509 AC_SUBST([SHLIBEXT])
1511 dnl We want to be able to use GNU make % pattern rules in maintainer targets
1512 dnl but automake warns these aren't portable, so we substitute the % to avoid
1517 dnl Split up the version number into "MAJOR.MINOR.REVISION".
1518 MAJOR_VERSION=`echo "$VERSION"|sed 's/\..*//'`
1519 [MINOR_VERSION=`echo "$VERSION"|sed 's/[^.]*\.//;s/\..*//'`]
1520 [REVISION=`echo "$VERSION"|sed 's/.*\.//;s/_.*$//'`]
1522 dnl **************************
1523 dnl * Build the output files *
1524 dnl **************************
1530 docs/doxygen_api.conf
1531 docs/doxygen_source.conf
1533 cmake/xapian-config.cmake
1534 cmake/xapian-config-version.cmake
1535 pkgconfig/xapian-core"$LIBRARY_VERSION_SUFFIX".pc:pkgconfig/xapian-core.pc.in
1537 AC_CONFIG_FILES([makemanpage], [chmod +x makemanpage])
1538 AC_CONFIG_FILES([tests/runtest], [chmod +x tests/runtest])
1539 AC_CONFIG_FILES([tests/runsrv], [chmod +x tests/runsrv])
1540 AC_CONFIG_FILES([tests/submitperftest], [chmod +x tests/submitperftest])
1541 AC_CONFIG_FILES([tests/perftest/get_machine_info], [chmod +x tests/perftest/get_machine_info])
1542 AC_CONFIG_FILES([xapian-config], [chmod +x xapian-config])
1545 dnl There are no files generated by AC_OUTPUT in the following directories
1546 dnl and we need to ensure they exist so that the rest of configure or make
1547 dnl won't fail because they don't exist when srcdir != builddir.
1548 if test yes = "$vpath_build" ; then
1549 for dir in include/xapian languages queryparser ; do
1550 AS_MKDIR_P(["$dir"])
1554 dnl Generate include/xapian/version.h:
1556 dnl MAIN_VERSION is VERSION without any _git123 suffix.
1557 MAIN_VERSION="$MAJOR_VERSION.$MINOR_VERSION.$REVISION"
1559 for backend in CHERT GLASS INMEMORY REMOTE ; do
1560 val=`eval echo "\\\$BUILD_BACKEND_${backend}_TRUE"`
1561 if test -z "$val" ; then
1562 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_HAS_${backend}_BACKEND"
1566 if test yes = "$enable_64bit_docid" ; then
1567 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_DOCID_BASE_TYPE="`echo "$INT64_T"|sed 's/ /____/g'`
1569 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_DOCID_BASE_TYPE="`echo "$INT32_T"|sed 's/ /____/g'`
1572 if test yes = "$enable_64bit_termcount" ; then
1573 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TERMCOUNT_BASE_TYPE="`echo "$INT64_T"|sed 's/ /____/g'`
1575 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TERMCOUNT_BASE_TYPE="`echo "$INT32_T"|sed 's/ /____/g'`
1578 if test yes = "$enable_64bit_termpos" ; then
1579 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TERMPOS_BASE_TYPE="`echo "$INT64_T"|sed 's/ /____/g'`
1581 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TERMPOS_BASE_TYPE="`echo "$INT32_T"|sed 's/ /____/g'`
1584 dnl Always ought to be 64 bit.
1585 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TOTALLENGTH_TYPE="`echo "unsigned $INT64_T"|sed 's/ /____/g'`
1587 dnl Make revision numbers in the API 64 bit for future-proofing.
1588 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_REVISION_TYPE="`echo "unsigned $INT64_T"|sed 's/ /____/g'`
1590 dnl For GCC (and compilers which pretend to be GCC) and MSVC, we create some
1591 dnl ABI checks in the generated version.h, and $CXXFLAGS may contain options
1592 dnl which affect the ABI (e.g. -fabi-version for GCC) so we want to use these
1593 dnl options when generating version.h. For these compilers, CXXCPP="$CXX -E"
1594 dnl so it should understand all compiler options.
1596 dnl For other compilers, we only pass $CPPFLAGS to $CXXCPP in case it's an
1597 dnl external cpp which doesn't understand flags which might be in $CXXFLAGS.
1598 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[#ifndef __GNUC__
1604 [cxxcpp_flags="$cxxcpp_flags $CPPFLAGS $CXXFLAGS"],
1605 [cxxcpp_flags="$cxxcpp_flags $CPPFLAGS"])
1606 rm -f include/xapian/version.h.tmp
1607 dnl "\r" in sed is a GNUism, but we only need to remove it on MS Windows
1608 dnl where we'll always have GNU sed, and other sed's will just interpret
1609 dnl it as "r" (Solaris sed) or maybe literal "\r" which won't match.
1611 dnl Use @@ around $MAIN_VERSION so we get " in the final output.
1612 $CXXCPP $cxxcpp_flags\
1613 -DSTRING_VERSION="\"@@$MAIN_VERSION@@\""\
1614 -DMAJOR_VERSION="\"$MAJOR_VERSION\""\
1615 -DMINOR_VERSION="\"$MINOR_VERSION\""\
1616 -DREVISION="\"$REVISION\""\
1618 $srcdir/include/xapian/version_h.cc|\
1619 ${SED-sed} '0,/const char \* dummy/d;/"/!d;s/^ *//;/^#/d;s/ *$//;s/" *,//;s/"//g;s/@@/"/g;s/ */ /g;s/ *,\r$//;s/ *,$//;s/____/ /g;s/\\\\$/\\/'\
1620 > include/xapian/version.h.tmp
1621 dnl Only update the file if it has changed, so we don't alter the timestamp
1622 dnl and cause lots of rebuilding needlessly. However, the build system
1623 dnl needs a timestamp to know when to regenerate version.h because version_h.cc
1624 dnl has changed so we use a separate timestamp file.
1625 touch include/xapian/version.h.timestamp
1626 if cmp include/xapian/version.h.tmp include/xapian/version.h >/dev/null 2>&1
1628 rm include/xapian/version.h.tmp
1630 mv include/xapian/version.h.tmp include/xapian/version.h