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.7], [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 LIBRARY_VERSION_INFO=35:1:5
42 AC_SUBST([LIBRARY_VERSION_INFO])
44 LIBRARY_VERSION_SUFFIX=
45 AC_SUBST([LIBRARY_VERSION_SUFFIX])
47 dnl Disabled for stable release series.
48 test x"$program_suffix" != xNONE || program_suffix=
50 dnl Where xapian.h, etc go. In development release append "/xapian-1.3".
54 dnl Check the build directory doesn't contain a space, so we die early with
58 AC_MSG_ERROR([You can't build in a directory whose path contains a space])
62 dnl Check the source directory doesn't contain a space, so we die early with
63 dnl a helpful error. FIXME: Unfortunately, configure seems to choke before
64 dnl it gets to us so this code doesn't get a chance to fire.
67 dnl Note: for in-tree builds, the build directory test above will fire
69 AC_MSG_ERROR([You can't build with sources in a directory whose path contains a space])
73 dnl Check the prefix to install in doesn't contain a space, so we die early with
77 AC_MSG_ERROR([You can't install in a directory whose path contains a space])
81 dnl Note if the user specified a particular C++ compiler so we can give a more
82 dnl appropriate error message if we can't link a simple C++ program.
84 if test -n "$CXX" ; then
85 original_CXX="CXX=$CXX"
86 elif test -n "$CCC" ; then
87 original_CXX="CCC=$CCC"
90 dnl See HACKING document for details of the reasons for required versions.
91 AM_INIT_AUTOMAKE([1.11 -Wportability tar-ustar no-dist-gzip dist-xz std-options])
92 AC_CONFIG_SRCDIR([matcher/multiandpostlist.cc])
94 AC_CONFIG_HEADERS([config.h])
96 AC_CONFIG_MACRO_DIR([m4])
100 dnl Use libtool to manage our libraries.
102 dnl Default to only building shared libraries.
104 dnl Building both shared and static means having to compile the files which
105 dnl make up the library twice on most platforms. Shared libraries are the
106 dnl better option for most users, and if anyone really wants static libraries,
107 dnl they can configure with --enable-static (or --enable-static=xapian-core if
108 dnl configuring a combined tree with the bindings).
110 dnl We don't export any data items from the library, so it should be safe to
111 dnl enable win32-dll without decorating any declarations specially.
112 LT_INIT([disable-static win32-dll])
114 dnl -no-undefined causes problems on Solaris with Sun CC in C++11 mode, so only
115 dnl pass -no-undefined on platforms where it is required in order to link a
116 dnl shared library at all (Windows is the main one).
118 if test unsupported = "$allow_undefined_flag" ; then
119 NO_UNDEFINED=-no-undefined
121 AC_SUBST(NO_UNDEFINED)
125 dnl A standard "gotcha" for mingw and cygwin users is to not set up their
126 dnl PATH correctly, so that MSDOS FIND.EXE is found before Unix find. Help
127 dnl them out by checking for this condition, rather than letting libtool
128 dnl fail in obscure ways. NB check the *BUILD* OS, not the host one!
130 *mingw* | *cygwin* | pw32*)
131 find /dirunlikelytoexist >/dev/null 2>&1
132 if test $? = 2 ; then
133 dnl Unix find will return 1 if the directory didn't exist, or 0 if
136 *** You appear to have an MSDOS-like FIND.EXE in your PATH ahead of any
137 *** UNIX-like find. This misconfiguration will confuse libtool - you'll need
138 *** to make sure you have a UNIX-like find installed and fix your PATH, then
139 *** rerun configure. For more information, see:
141 *** https://www.cygwin.com/faq/faq.html#faq.using.find
147 dnl Add parameters for aclocal
148 dnl (This must come after AM_INIT_AUTOMAKE, since it modifies ACLOCAL)
149 ACLOCAL="$ACLOCAL $ACLOCAL_FLAGS"
151 dnl disable "maintainer only" rules by default
154 dnl Checks for programs.
159 # Checked: freebsd8.0 openbsd4.6 solaris2.9 solaris2.10
161 linux* | k*bsd*-gnu | freebsd* | openbsd* | solaris*)
162 dnl Vanilla libtool sets this to "unknown" which it then handles as "yes".
163 link_all_deplibs_CXX=no
169 dnl Extract search path from ldconfig which is more reliable than the way
170 dnl vanilla libtool extracts them from ld.so.conf.
171 d=`/sbin/ldconfig -N -X -v 2>&AS_MESSAGE_LOG_FD|$SED 's,^\(/.*\):\( (.*)\)\?$,\1,p;d'|tr '\n' ' '`
172 test -z "$d" || sys_lib_dlsearch_path_spec=$d
177 *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
178 dnl On these platforms, libtool emits a warning if -no-install is passed,
179 dnl and uses -no-fast-install instead - the least ugly way to avoid that
180 dnl warnings seems to be to duplicate the above list of platforms from
181 dnl libtool and use -no-fast-install on them directly.
182 NO_INSTALL=-no-fast-install ;;
184 NO_INSTALL=-no-install ;;
186 AC_SUBST([NO_INSTALL])
188 dnl For reasons which are beyond me, if autoconf can't find a C++ compiler
189 dnl it will set CXX to g++ (which obviously won't work) rather than actually
190 dnl telling the user that it couldn't find a C++ compiler and telling them
191 dnl to either install one or set CXX if there's one configure failed to find.
192 dnl It's probably worthwhile checking that the C++ compiler actually works
194 if test -n "$CXX" ; then
196 AC_MSG_CHECKING([whether $CXX is a working C++ compiler])
197 AC_CACHE_VAL([xo_cv_cxx_works],
199 AC_TRY_RUN([int main() {}],
202 AC_TRY_LINK([], [], xo_cv_cxx_works=yes, xo_cv_cxx_works=no))
204 AC_MSG_RESULT([$xo_cv_cxx_works])
208 if test no = "$xo_cv_cxx_works" ; then
209 case $original_CXX in
211 dnl CCC is handled in a slightly odd way - if its value isn't an
212 dnl executable (taking PATH into account) then it is ignored!
213 test "$original_CXX" = "CCC=$CXX" || original_CXX=
216 if test -z "$original_CXX" ; then
218 *** You need a working C++ compiler to compile Xapian, but configure failed to
219 *** find one. If you have a working C++ compiler, you can tell configure where
220 *** to find it by invoking it like so:
222 *** ./configure CXX=/opt/bin/c++
226 *** You need a working C++ compiler to compile Xapian, but the compiler you
227 *** specified (with '$original_CXX') doesn't appear to be able to successfully
228 *** compile and link a simple program.
233 dnl Probe for any options needed to enable C++11 support.
234 AX_CXX_COMPILE_STDCXX_11
236 dnl We don't use a C compiler to compile Xapian's code, but on some platforms
237 dnl (e.g. mingw) libtool uses $LTCC which defaults to $CC, and it's also use to
238 dnl build auxiliary tools like snowball and lemon.
241 dnl Check endianness.
244 dnl We want a non-cross-compiling C compiler for building lemon with.
245 if test -z "$CC_FOR_BUILD" ; then
246 if test yes = "$cross_compiling"; then
252 AC_ARG_VAR([CC_FOR_BUILD], [C compiler command for native compilation (needed to compile build tools during cross-builds)])
254 dnl Run tests using the C++ compiler.
257 dnl Enable large file support if possible.
259 dnl With xlC on AIX, -D_LARGE_FILES changes the ABI of std::string, so it
260 dnl also needs to be used when compiling user code.
261 abi_affecting_cxxflags=
262 if $GREP '^#define _LARGE_FILES 1$' confdefs.h > /dev/null 2>&1 ; then
263 abi_affecting_cxxflags=-D_LARGE_FILES
265 AC_SUBST([abi_affecting_cxxflags])
267 AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
268 #if defined __WIN32__ || defined _WIN32
271 ]])], [win32=no], [win32=yes])
273 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
277 ]])], [msvc=no], [msvc=yes])
281 AC_SUBST([XAPIAN_LDFLAGS])
282 AC_SUBST([XAPIAN_LIBS])
284 AC_DEFUN([XAPIAN_TEST_LINKER_FLAG],
286 AC_MSG_CHECKING([for $CXX -Wl,$1])
287 AC_CACHE_VAL([xo_cv_ldflag_$2],
289 save_LDFLAGS=$LDFLAGS
290 LDFLAGS="$LDFLAGS -Wl,$1"
292 AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
297 LDFLAGS=$save_LDFLAGS
299 AC_MSG_RESULT([$xo_cv_ldflag_$2])
302 dnl Test if the compiler works with $1 added to CXXFLAGS; if it does, add $1 to
303 dnl variable $2. If the test passes, also do $3; if it fails, also do $4.
304 AC_DEFUN([XAPIAN_TEST_CXXFLAGS],
306 XTC_save_CXXFLAGS=$CXXFLAGS
307 CXXFLAGS="$CXXFLAGS $1"
308 AC_TRY_COMPILE([], [],
309 [CXXFLAGS=$XTC_save_CXXFLAGS
312 [CXXFLAGS=$XTC_save_CXXFLAGS
317 if test yesyes = "$GXX$enable_shared" ; then
320 XAPIAN_TEST_LINKER_FLAG([--enable-runtime-pseudo-reloc], [enable_runtime_pseudo_reloc],
321 [ldflags="-Wl,$flag"],
323 dnl Can't use AC_DISABLE_SHARED after AC_PROG_LIBTOOL, but
324 dnl this test needs to be after AC_PROG_LIBTOOL, so we can't
325 dnl just disable the shared build automatically...
326 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])
331 dnl Only works for ldflags which can be specified anywhere on the link line.
334 dnl Preserve the default CXXFLAGS.
335 save_CXXFLAGS=$CXXFLAGS
337 dnl x86 has excess precision issues with 387 FP instructions, which are
338 dnl avoided by using SSE instructions instead. This is also faster (~6% in
339 dnl a CPU bound testcase).
341 [AS_HELP_STRING([--disable-sse],
342 [disable use of SSE FP instructions on x86])]
343 [AS_HELP_STRING([[--enable-sse[=sse|sse2]]],
344 [set which SSE FP instructions to use on x86 (default: sse2)])],
345 [case ${enableval} in
347 *) AC_MSG_ERROR([bad value ${enableval} for --enable-sse or --disable-sse]) ;;
351 dnl Some versions of Sun's C++ compiler reportedly need an explicit -lm.
352 dnl The maths functions we use include: exp log ceil fabs sqrt
353 AC_MSG_CHECKING([if -lm is required for maths functions])
354 dnl Don't use constant arguments as the compiler might simply evaluate the
355 dnl whole expression at compile time, and it might inline certain functions
356 dnl so test several functions. Also write results using printf() so that
357 dnl the compiler can't optimise away the computations.
358 AC_TRY_LINK([#ifdef __SUNPRO_CC
359 #error Need -lm for Sun C++ 5.9 under libtool 2.2.10
364 using namespace std;], [
365 double a = log(ceil(time(NULL)/7.0));
366 printf("%f %f %f\n", a, sqrt(a), exp(fabs(a - 12345.6)));
367 ], [AC_MSG_RESULT([no])], [
369 AC_TRY_LINK([#include <cmath>
372 using namespace std;], [
373 double a = log(ceil(time(NULL)/7.0));
374 printf("%f %f %f\n", a, sqrt(a), exp(fabs(a - 12345.6)));],
375 [AC_MSG_RESULT([yes])],
376 [AC_MSG_ERROR([Failed to link a C++ program using <cmath>])
380 dnl C++11 should have log2(double), but keep this check for now to allow for
381 dnl compilers with incomplete library support for C++11.
382 AC_CHECK_DECLS([log2(double)], [], [],
384 using namespace std;])
386 dnl exp10() is a GNU libc extension.
387 AC_CHECK_DECLS([exp10(double)], [], [],
389 using namespace std;])
391 dnl Darwin provides __exp10().
392 AC_CHECK_DECLS([__exp10(double)], [], [],
394 using namespace std;])
396 dnl GCC provides __builtin_exp10() (but notably clang doesn't currently).
397 dnl On mingw, __builtin_exp10() causes GCC to generate a call to exp10() which
398 dnl then fails to link, so perform a link check here to catch that.
399 AC_CACHE_CHECK([for __builtin_exp10], ac_cv_link___builtin_exp10, [
400 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
403 using namespace std;]],
404 [[printf("%f", __builtin_exp10(double(time(NULL)*1e-8)));]])],
405 [ac_cv_link___builtin_exp10=yes],
406 [ac_cv_link___builtin_exp10=no])
408 if test $ac_cv_link___builtin_exp10 = yes ; then
409 AC_DEFINE([HAVE___BUILTIN_EXP10], [1], [Define to 1 if you have the '__builtin_exp10' function.])
412 dnl See if <typeinfo> can be used in the testsuite - at least for GCC and xlC,
413 dnl compilation of the test code below fails if RTTI isn't being generated
414 dnl (g++ -fno-rtti, or by default with xlC).
415 AC_MSG_CHECKING([if RTTI is supported])
416 save_CXXFLAGS=$CXXFLAGS
417 dnl xlC issues a warning for typeid() being used without RTTI being enabled,
418 dnl so for this test we pass the xlC option to make that warning into an error.
419 XAPIAN_TEST_CXXFLAGS([-qhaltonmsg=1540-2412], [CXXFLAGS])
422 #include <typeinfo>],
427 } catch (std::exception & e) {
428 return typeid(e).name()[0];
431 AC_DEFINE([USE_RTTI], [1], [Define if the testsuite can use RTTI]),
433 CXXFLAGS=$save_CXXFLAGS
435 dnl We need to specify the argument types for builtin functions, or else
436 dnl AC_CHECK_DECLS fails to detect them when the compiler is clang.
437 AC_CHECK_DECLS([__builtin_add_overflow(int, int, int*),
438 __builtin_mul_overflow(int, int, int*)], [], [], [ ])
439 AC_CHECK_DECLS([__builtin_bswap16(uint16_t),
440 __builtin_bswap32(uint32_t)], [], [],
441 [#include <stdint.h>])
442 AC_CHECK_DECLS([_byteswap_ushort, _byteswap_ulong], [], [],
443 [#include <stdlib.h>])
444 AC_CHECK_DECLS([__builtin_clz(unsigned),
445 __builtin_clzl(unsigned long),
446 __builtin_clzll(unsigned long long)], [], [], [ ])
447 AC_CHECK_DECLS([__builtin_ctz(unsigned),
448 __builtin_ctzl(unsigned long),
449 __builtin_ctzll(unsigned long long)], [], [], [ ])
450 AC_CHECK_DECLS([__builtin_expect(long, long)], [], [], [ ])
451 AC_CHECK_DECLS([__builtin_popcount(unsigned),
452 __builtin_popcountl(unsigned long),
453 __builtin_popcountll(unsigned long long)], [], [], [ ])
454 AC_CHECK_DECLS([__popcnt, __popcnt64], [], [], [#include <intrin.h>])
456 dnl Check for time functions.
457 AC_CHECK_FUNCS([clock_gettime sleep nanosleep gettimeofday ftime])
461 dnl For _ftime64() on mingw we need to tell it we're happy to require
462 dnl MSVCRT 6.10 or higher, which isn't too onerous a requirement it seems.
463 AC_DEFINE([__MSVCRT_VERSION__], [0x0601], [Define on mingw to the minimum msvcrt version to assume])
464 AC_DEFINE([MINGW_HAS_SECURE_API], [1], [Define on mingw to get _s suffixed "secure" functions declared in headers])
468 dnl We use timer_create() if available to implement a search time limit.
470 AC_SEARCH_LIBS([timer_create], [rt],
472 AC_MSG_CHECKING([for timer_create() usability])
473 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
474 [[#if defined _AIX || defined __GNU__
475 #error timer_create known not to work
477 [AC_MSG_RESULT([yes])
478 XAPIAN_LIBS="$LIBS $XAPIAN_LIBS"
479 AC_DEFINE([HAVE_TIMER_CREATE], [1], [Define to 1 if you have the 'timer_create' function.])]
486 dnl Used by tests/soaktest/soaktest.cc
487 AC_CHECK_FUNCS([srandom random])
489 dnl Used by tests/harness/testsuite.cc
490 AC_CHECK_FUNCS([sigaction])
491 AC_MSG_CHECKING([for sigsetjmp and siglongjmp])
492 AC_TRY_COMPILE([#include <setjmp.h>],
493 [sigjmp_buf jb; if (sigsetjmp(jb, 1)) { siglongjmp(jb, 1); }],
494 AC_DEFINE([HAVE_SIGSETJMP], [1], [Define to 1 if you have the 'sigsetjmp' function])
495 AC_MSG_RESULT([yes]),
498 dnl Used by tests/harness/cputimer.cc:
499 AC_CHECK_FUNCS([getrusage times sysconf])
501 dnl Used by tests/harness/unixcmd.cc
502 AC_CHECK_FUNCS([nftw])
504 dnl Used by tests/api_replicate.cc.
506 dnl Solaris < 10 only has putenv().
508 dnl Microsoft have marked putenv() as deprecated, so we use _putenv_s() under
509 dnl MSVC to avoid deprecation warnings. We probe here since mingw doesn't
510 dnl currently (v3.20) provide _putenv_s(), so we can't just use it conditional
511 dnl on __WIN32__ being defined. We need to check for a declaration rather
512 dnl than just seeing if the symbol exists, as the symbol will exist in the C
513 dnl runtime DLL even if mingw doesn't declare it in its headers.
514 AC_CHECK_FUNCS([setenv])
515 AC_CHECK_DECLS([_putenv_s(const char *,const char *)], [], [],
516 [#include <stdlib.h>])
518 dnl See if we have closefrom(), or some functions that are useful to implement
519 dnl closefrom() on platforms which don't provide it.
520 AC_CHECK_FUNCS([closefrom getdirentries getrlimit])
522 dnl See if ftime returns void (as it does on mingw)
523 AC_MSG_CHECKING([return type of ftime])
524 if test $ac_cv_func_ftime = yes ; then
525 AC_TRY_COMPILE([#include <sys/timeb.h>],
526 [struct timeb tp; int i = ftime(&tp);],
527 AC_MSG_RESULT([int]),
528 AC_MSG_RESULT([void])
529 AC_DEFINE([FTIME_RETURNS_VOID], [1], [Define if ftime returns void]))
532 dnl Check how to find the hostname: uname() in sys/utsname.h, or gethostname()
533 dnl Don't use default includes as inttypes.h is found by Compaq C but not C++
534 dnl so it causes all header probes to fail.
535 AC_CHECK_HEADERS([sys/utsname.h], [], [], [ ])
536 AC_CHECK_FUNCS([gethostname])
538 dnl mingw (for instance) lacks ssize_t
545 AC_CHECK_SIZEOF([short])
546 AC_CHECK_SIZEOF([int])
547 AC_CHECK_SIZEOF([long])
548 AC_CHECK_SIZEOF([long long])
550 AC_CHECK_HEADERS([sys/types.h])
552 AC_MSG_CHECKING([for 32 bit integer type])
554 "$ac_cv_sizeof_int") INT32_T=int ;;
555 "$ac_cv_sizeof_long") INT32_T=long ;;
556 "$ac_cv_sizeof_short") INT32_T=short ;;
558 AC_MSG_RESULT([none found])
559 AC_MSG_ERROR([No 32 bit integer type found])
561 AC_MSG_RESULT([$INT32_T])
563 AC_MSG_CHECKING([for 64 bit integer type])
565 "$ac_cv_sizeof_int") INT64_T=int ;;
566 "$ac_cv_sizeof_long") INT64_T=long ;;
567 "$ac_cv_sizeof_long_long") INT64_T='long long' ;;
569 AC_MSG_RESULT([none found])
570 AC_MSG_ERROR([No 64 bit integer type found])
572 AC_MSG_RESULT([$INT64_T])
574 dnl Check for perl (needed to generate some sources and documentation).
575 AC_PATH_PROG([PERL], [perl], [])
576 if test x$USE_MAINTAINER_MODE = xyes; then
577 test -z "$PERL" && AC_MSG_ERROR([perl is required in maintainer mode])
580 AC_ARG_ENABLE([64bit_docid],
581 [AS_HELP_STRING([--enable-64bit-docid], [enable 64bit docid [default=no]])],
582 [case ${enableval} in
584 *) AC_MSG_ERROR([bad value ${enableval} for --enable-64bit-docid]) ;;
586 [enable_64bit_docid=no])
588 AC_ARG_ENABLE([64bit_termcount],
589 [AS_HELP_STRING([--enable-64bit-termcount], [enable 64bit termcount [default=no]])],
590 [case ${enableval} in
592 *) AC_MSG_ERROR([bad value ${enableval} for --enable-64bit-termcount]) ;;
594 [enable_64bit_termcount=no])
596 AC_ARG_ENABLE([64bit_termpos],
597 [AS_HELP_STRING([--enable-64bit-termpos], [enable 64bit termpos [default=no]])],
598 [case ${enableval} in
600 *) AC_MSG_ERROR([bad value ${enableval} for --enable-64bit-termpos]) ;;
602 [enable_64bit_termpos=no])
604 AC_ARG_ENABLE([documentation],
605 [AS_HELP_STRING([--enable-documentation], [enable make rules to rebuild documentation [default=maintainer-mode]])],
606 [case ${enableval} in
608 *) AC_MSG_ERROR([bad value ${enableval} for --enable-documentation]) ;;
610 [enable_documentation=$USE_MAINTAINER_MODE])
611 AM_CONDITIONAL([DOCUMENTATION_RULES], [test x"$enable_documentation" = xyes])
612 AM_CONDITIONAL([MAINTAINER_NO_DOCS], [test x"$USE_MAINTAINER_MODE$enable_documentation" = xyesno])
614 if test x"$enable_documentation" = xyes ; then
615 dnl Checks for dot. (Diagrams in the documentation)
616 AC_PATH_PROG([DOT], [dot])
617 test -z "$DOT" && AC_MSG_ERROR([dot (part of the graphviz package) is required to build documentation])
618 DOXYGEN_DOT_PATH=`echo "$DOT" | sed 's!/dot$!!'`
619 AC_SUBST([DOXYGEN_DOT_PATH])
621 dnl Check for doxygen. (Needed to make some more of the documentation)
622 AC_PATH_PROG([DOXYGEN], [doxygen], [])
623 test -z "$DOXYGEN" && AC_MSG_ERROR([doxygen is required to build documentation])
625 dnl Check for help2man. (Needed to make man pages from "--help" output).
626 AC_PATH_PROG([HELP2MAN], [help2man], [])
627 test -z "$HELP2MAN" && AC_MSG_ERROR([help2man is required to build documentation])
629 dnl Check for rst2html. (Needed to make HTML from reStructuredText format)
630 dnl Also look for rst2html.py, which archlinux reportedly installs it as.
631 AC_PATH_PROGS([RST2HTML], [rst2html rst2html.py], [])
632 test -z "$RST2HTML" && AC_MSG_ERROR([rst2html is required to build documentation (try package python-docutils)])
634 dnl Check for pngcrush, which we optionally use to reduce the size of the
635 dnl PNG files which doxygen generates. We can get by without it, so don't
636 dnl fail here if it's not found.
637 AC_PATH_PROG([PNGCRUSH], [pngcrush], [])
640 dnl Checks for header files.
641 AC_CHECK_HEADERS([fcntl.h limits.h sys/errno.h sys/select.h], [], [], [ ])
642 AC_CHECK_HEADERS([sys/resource.h],
643 [], [], [#include <sys/types.h>])
645 dnl cxxabi.h was added in GCC 3.1, but clang lies and defines __GNUC__ yet
646 dnl doesn't seem to reliably provide this header, so probe for it.
647 AC_CHECK_HEADERS([cxxabi.h], [], [], [ ])
649 dnl If valgrind is installed and new enough, we use it for leak checking in the
650 dnl testsuite. If VALGRIND is set to an empty value, then skip the check and
651 dnl don't use valgrind.
652 if test -n "${VALGRIND-unset}" ; then
653 AC_PATH_PROG([VALGRIND], [valgrind], [])
654 if test -n "$VALGRIND" ; then
655 dnl Check that the installed valgrind version works, and supports the
656 dnl options we use. This means we won't try to use valgrind < 3.3.0
657 dnl (released 7/12/2007) since before that --log-file didn't expand
658 dnl %p (and appended the process id).
660 dnl No need to check for VALGRIND_COUNT_LEAKS now - that was added before
662 AC_MSG_CHECKING([if valgrind supports --log-file with %p and --child-silent-after-fork=yes])
663 vglog=config.vglog.%p.tmp
664 vglogwild="config.vglog.*.tmp*"
666 if $VALGRIND --log-file="$vglog" --child-silent-after-fork=yes -q true 2>&AS_MESSAGE_LOG_FD ; then
667 for f in $vglogwild ; do
669 $vglog*) VALGRIND= ;;
672 if test x"$VALGRIND" = x ; then
676 AC_CHECK_HEADERS([valgrind/memcheck.h], [], [VALGRIND=], [ ])
679 dnl The valgrind detected doesn't seem to work! Perhaps this is an
680 dnl x86_64 box with a 32 bit valgrind.
681 AC_MSG_RESULT([$VALGRIND doesn't work])
688 if test -n "$VALGRIND" ; then
689 AC_DEFINE([HAVE_VALGRIND], [1], [Define if a suitable valgrind is installed])
692 dnl If eatmydata is installed, we run the testsuite under it to speed it up.
693 dnl If EATMYDATA is set to an empty value, then skip this check and don't use
695 if test -n "${EATMYDATA-unset}" ; then
696 AC_PATH_PROG([EATMYDATA], [eatmydata], [])
699 dnl Checks for library functions.
703 AC_CACHE_CHECK([for sys_errlist and sys_nerr], ac_cv_sys_errlist_and_sys_nerr, [
704 AC_LINK_IFELSE([AC_LANG_PROGRAM(
705 dnl On Linux, sys_errlist and sys_nerr need <stdio.h>, though the man page
706 dnl says <errno.h>. The man page seems to match other platforms such as
707 dnl NetBSD, so include both headers to ensure we get them.
709 #include <stdio.h>]],
710 [[ printf("%s", sys_errlist[sys_nerr - 1]);]])],
711 [ ac_cv_sys_errlist_and_sys_nerr=yes ],
712 [ ac_cv_sys_errlist_and_sys_nerr=no ])
714 if test "x$ac_cv_sys_errlist_and_sys_nerr" = "xyes" ; then
715 AC_DEFINE([HAVE_SYS_ERRLIST_AND_SYS_NERR], [1],[Define if you have 'sys_errlist' and 'sys_nerr'])
718 AC_CACHE_CHECK([for _sys_errlist and _sys_nerr], ac_cv__sys_errlist_and__sys_nerr, [
719 AC_LINK_IFELSE([AC_LANG_PROGRAM(
721 #include <stdio.h>]],
722 [[ printf("%s", _sys_errlist[_sys_nerr - 1]);]])],
723 [ ac_cv__sys_errlist_and__sys_nerr=yes ],
724 [ ac_cv__sys_errlist_and__sys_nerr=no
727 if test "x$ac_cv__sys_errlist_and__sys_nerr" = "xyes" ; then
728 AC_DEFINE([HAVE__SYS_ERRLIST_AND__SYS_NERR], [1],[Define if you have '_sys_errlist' and '_sys_nerr'])
731 dnl Check that snprintf actually works as it's meant to.
733 dnl Linux 'man snprintf' warns:
734 dnl Linux libc4.[45] does not have a snprintf, but provides a libbsd that
735 dnl contains an snprintf equivalent to sprintf, i.e., one that ignores the
736 dnl size argument. Thus, the use of snprintf with early libc4 leads to
737 dnl serious security problems.
739 dnl It also warns that glibc < 2.0.6 (and presumably other pre-C99
740 dnl implementations) return -1 when truncating so check that we get the
741 dnl ISO C99 semantics for the returned length when truncating. If we
742 dnl have a working snprintf but with non-ISO return semantics, handle
743 dnl that case separately as it may still be useful in many cases.
745 dnl mingw has _snprintf so check for that too.
746 AC_MSG_CHECKING([for working ISO C99 conforming snprintf])
747 ac_cv_func_snprintf_noniso=no
748 for func in snprintf _snprintf ; do
756 dnl Return different exit status for each error so we can see which
757 dnl check failed by consulting config.log.
759 char buffer[4] = "abc";
760 int res1 = $func(buffer, 2, "%s", "XYZ");
761 if (memcmp(buffer, "X\0c", 4) != 0) return 2;
762 int res2 = $func(buffer, 2, "%x", 0x12);
763 if (memcmp(buffer, "1\0c", 4) != 0) return 3;
764 if (res1 == -1 && res2 == -1) return 15; /* Pre-ISO semantics. */
765 if (res1 != 3) return 4;
766 if (res2 != 2) return 5;
769 [ac_cv_func_snprintf=$func;break],
771 if test 15no = "$?$ac_cv_func_snprintf_noniso" ; then
772 ac_cv_func_snprintf_noniso=$func
774 ac_cv_func_snprintf=no
776 [ac_cv_func_snprintf=unknown;break]
779 AC_MSG_RESULT([$ac_cv_func_snprintf])
780 case $ac_cv_func_snprintf in
782 AC_MSG_CHECKING([for working non-ISO C99 conforming snprintf])
783 AC_MSG_RESULT([$ac_cv_func_snprintf_noniso])
784 if test no != "$ac_cv_func_snprintf_noniso" ; then
785 AC_DEFINE_UNQUOTED([SNPRINTF], [$ac_cv_func_snprintf_noniso],
786 [Define to the name of a function implementing snprintf but not caring about ISO C99 return value semantics (if one exists)])
790 dnl be conservative when crosscompiling
793 AC_DEFINE_UNQUOTED([SNPRINTF_ISO], [$ac_cv_func_snprintf],
794 [Define to the name of a function implementing snprintf with ISO C99 semantics (if one exists)])
795 AC_DEFINE_UNQUOTED([SNPRINTF], [$ac_cv_func_snprintf],
796 [Define to the name of a function implementing snprintf but not caring about ISO C99 return value semantics (if one exists)])
800 dnl ***************************
801 dnl * Select modules to build *
802 dnl ***************************
804 dnl Check which database backends should be built.
806 AC_DEFUN([_XAPIAN_BACKEND_ENABLE],
807 [AC_ARG_ENABLE([backend_$1],
808 [AS_HELP_STRING([--enable-backend-$1], [build the $1 database backend [default=$3]])],
811 *) AC_MSG_ERROR([Invalid option: '--enable-backend-$1=$enableval']) ;;
812 esac], [enable_backend_$1=$2])
815 AC_DEFUN([XAPIAN_BACKEND_ENABLE],
816 [_XAPIAN_BACKEND_ENABLE([$1],
817 m4_default([$2], [yes]),
818 m4_default([$3], [yes]))
821 dnl When adding a new backend, update INSTALL too.
822 XAPIAN_BACKEND_ENABLE([chert])
823 XAPIAN_BACKEND_ENABLE([glass])
824 XAPIAN_BACKEND_ENABLE([inmemory])
825 default_enable_backend_remote=yes
828 dnl We don't currently support the remote backend on this platform so
829 dnl disable it by default.
830 default_enable_backend_remote=no
833 XAPIAN_BACKEND_ENABLE([remote], [$default_enable_backend_remote], [yes (except for MSDOS)])
838 case $enable_backend_chert$enable_backend_glass in
840 dnl We use zlib for compressing tags in chert/glass. We could
841 dnl automatically disable support if zlib isn't found, but overall that
842 dnl probably does more harm than good - it's most likely that someone just
843 dnl forgot to install the -dev package for zlib.
845 dnl Similarly for uuid support.
847 dnl Check for zlib.h.
848 AC_CHECK_HEADERS([zlib.h], [], [
849 AC_MSG_ERROR([zlib.h not found - required for chert and glass (you may need to install the zlib1g-dev or zlib-devel package)])
852 dnl Check for zlibVersion in -lz.
854 dnl mingw build needs -lzlib or -lzdll.
855 AC_SEARCH_LIBS([zlibVersion], [z zlib zdll], [], [
856 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)])
858 if test x != x"$LIBS" ; then
859 XAPIAN_LIBS="$XAPIAN_LIBS $LIBS"
863 dnl Find the UUID library (from e2fsprogs/util-linux-ng, not the OSSP one).
865 case $host_os-$win32 in
866 *-yes | *cygwin*) dnl Use built-in win32 API.
868 AC_DEFINE([USE_WIN32_UUID_API], [1],
869 [Define to 1 to use UuidCreate(), etc])
870 if test $win32 = yes ; then
871 dnl We need -lws2_32 for htonl(), etc, but not for Cygwin which
872 dnl provides these functions in its libc.
875 XAPIAN_LIBS="$XAPIAN_LIBS -lrpcrt4"
878 dnl Check for uuid/uuid.h (e2fsprogs/util-linux-ng) or uuid.h
879 dnl (FreeBSD/NetBSD).
880 AC_CHECK_HEADERS([uuid/uuid.h], [
881 dnl util-linux-ng's uuid/uuid.h found - check for uuid_generate in
884 AC_SEARCH_LIBS([uuid_generate], [uuid], [], [
885 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)])
887 if test x != x"$LIBS" ; then
888 XAPIAN_LIBS="$XAPIAN_LIBS $LIBS"
891 dnl Try uuid.h as found on FreeBSD/NetBSD, with associated code in libc.
892 AC_CHECK_HEADERS([uuid.h], [
893 dnl Check for uuid_create with no extra libraries required.
894 AC_CHECK_FUNC([uuid_create], [], [
895 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)])
898 dnl Especially useful for Android.
899 AC_MSG_CHECKING([if host platform supports /proc/sys/kernel/random/uuid])
903 AC_DEFINE([USE_PROC_FOR_UUID], [1],
904 [Define to 1 to read UUID from '/proc/sys/kernel/random/uuid'])
909 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)])
917 dnl Older versions of libuuid (such as that on CentOS 4.7) don't have
918 dnl uuid_unparse_lower(), only uuid_unparse().
919 AC_LINK_IFELSE([AC_LANG_CALL([], [uuid_unparse_lower])],
921 AC_DEFINE([HAVE_UUID_UNPARSE_LOWER], [1],
922 [Define to 1 if you have the 'uuid_unparse_lower' function.])
928 dnl DJGPP has a dummy implementation of fork which always fails.
930 dnl For disk-based backends, use flock() for locking, which doesn't need
931 dnl fork() or socketpair().
932 AC_DEFINE([FLINTLOCK_USE_FLOCK], 1, [Define to use flock() for flint-compatible locking])
937 AM_CONDITIONAL([USE_PROC_FOR_UUID], [test "$use_proc_for_uuid" = 1])
938 AM_CONDITIONAL([USE_WIN32_UUID_API], [test "$use_win32_uuid_api" = 1])
940 if test "$enable_backend_remote" = yes ; then
941 case $host_os-$win32 in
943 dnl For mingw and msvc we have an alternative implementation which
944 dnl doesn't need fork() or socketpair().
946 dnl We need -lws2_32 for getaddrinfo(), etc.
948 dnl Vista is needed for the AI_ADDRCONFIG flag to getaddrinfo().
949 AC_DEFINE([WINVER], [0x600],
950 [Version of Windows to assume (0x600 => Vista).])
951 AC_DEFINE([_WIN32_WINNT], [WINVER],
952 [Version of Windows to assume.])
955 dnl DJGPP has a dummy implementation of fork which always fails. If
956 dnl someone actually wanted remote backend support, then DJGPP has a
957 dnl pthreads port, so using threads like we do on Windows would make more
959 AC_MSG_ERROR([The remote backend is not currently supported on this platform.])
962 dnl On Unix, we need fork and socketpair for the remotebackend.
964 AC_CHECK_FUNCS([fork], [], [
965 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.)])
967 dnl Check if -lsocket is required for socketpair (Solaris needs it).
968 dnl And on Haiku it's in -lnetwork.
969 AC_SEARCH_LIBS([socketpair], [socket network], [], [
970 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.)])
972 AC_DEFINE([HAVE_SOCKETPAIR], [1],
973 [Define to 1 if you have the 'socketpair' function.])
974 dnl Check if extra libraries are needed for getaddrinfo or inet_ntop()
975 dnl (e.g. on Solaris).
977 dnl We're currently assuming that any system that is worth trying to
978 dnl support has getaddrinfo() and inet_ntop(), since these are the
979 dnl standard route for supporting IPv6, and that's pretty much essential
980 dnl for platforms to support now.
981 AC_SEARCH_LIBS([getaddrinfo], [nsl socket], [], [
982 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.)])
984 AC_SEARCH_LIBS([inet_ntop], [nsl socket], [], [
985 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.)])
987 XAPIAN_LIBS="$XAPIAN_LIBS $LIBS"
995 if test "$win32_need_lws2_32" = 1 ; then
996 XAPIAN_LIBS="$XAPIAN_LIBS -lws2_32"
999 AC_ARG_ENABLE([visibility],
1000 [AS_HELP_STRING([--disable-visibility], [disable use of GCC visibility])],
1001 [case ${enableval} in
1003 *) AC_MSG_ERROR([bad value ${enableval} for --disable-visibility]) ;;
1007 if test "`pwd`" != "`cd $srcdir;pwd`" ; then
1010 AM_CONDITIONAL([VPATH_BUILD], [test yes = "$vpath_build"])
1012 dnl Turn off compilation of anything that we don't have the requirements for
1014 dnl Set conditionals to specify what we compile
1016 AM_CONDITIONAL([BUILD_BACKEND_CHERT], [test yes = "$enable_backend_chert"])
1017 AM_CONDITIONAL([BUILD_BACKEND_GLASS], [test yes = "$enable_backend_glass"])
1018 AM_CONDITIONAL([BUILD_BACKEND_INMEMORY], [test yes = "$enable_backend_inmemory"])
1019 AM_CONDITIONAL([BUILD_BACKEND_REMOTE], [test yes = "$enable_backend_remote"])
1020 AM_CONDITIONAL([BUILD_BACKEND_CHERT_OR_GLASS],
1021 [test nono != "$enable_backend_chert$enable_backend_glass"])
1023 dnl Decide if we should use the zlib-vg.so LD_PRELOAD hack.
1025 if test -n "$VALGRIND" ; then
1027 linux*) use_zlib_vg=yes ;;
1030 AM_CONDITIONAL([USE_ZLIB_VG], [test yes = "$use_zlib_vg"])
1032 dnl See if we have fdatasync, and what libraries are needed for it.
1033 dnl We need to actually check for a declaration as OS X has a dummy
1034 dnl implementation in the library which is not prototyped in any header.
1035 AC_CHECK_DECL([fdatasync(int)], [
1037 AC_SEARCH_LIBS([fdatasync], [rt], [XAPIAN_LIBS="$LIBS $XAPIAN_LIBS"])
1039 AC_CHECK_FUNCS([fdatasync])
1041 [ac_cv_func_fdatasync=no],
1042 [#include <unistd.h>]
1045 AC_CHECK_FUNCS([fsync])
1046 AC_CHECK_FUNCS([posix_fadvise])
1047 if test "$win32" = no ; then
1048 dnl ftruncate() under Wine seems to be buggy and sometimes fails, though
1049 dnl a cut-down reproducer seems fine. For now just avoid ftruncate()
1050 dnl entirely on this platform - we'll fallback to lseek() + write() of a
1051 dnl single zero byte, which is pretty efficient.
1052 AC_CHECK_FUNCS([ftruncate])
1055 dnl HP-UX has pread and pwrite, but they don't work! Apparently this problem
1056 dnl manifests when largefile support is enabled, and we definitely want that
1057 dnl so don't use pread or pwrite on HP-UX.
1060 AC_MSG_CHECKING([for pread])
1061 AC_MSG_RESULT([present but broken on $host_os])
1062 AC_MSG_CHECKING([for pwrite])
1063 AC_MSG_RESULT([present but broken on $host_os])
1066 AC_CHECK_FUNC([pread],
1067 [AC_DEFINE([HAVE_PREAD], [1],
1068 [Define if pread is available on this system])
1069 AC_MSG_CHECKING([for any prototype needed for pread])
1070 AC_CACHE_VAL([xo_cv_pread_prototype],
1073 'extern "C" ssize_t pread(int, void *, size_t, off_t) throw ();' \
1074 'extern "C" ssize_t pread(int, void *, size_t, off_t);' ; do
1076 #include <sys/types.h>
1081 pread(1, b, 256, 20);
1083 xo_cv_pread_prototype="$p"
1087 if test -z "$xo_cv_pread_prototype"; then
1088 AC_MSG_RESULT([not found])
1089 AC_MSG_ERROR([Failed to find working prototype for pread])
1092 if test " " = "$xo_cv_pread_prototype" ; then
1093 AC_MSG_RESULT([none required])
1095 AC_MSG_RESULT([$xo_cv_pread_prototype])
1096 AC_DEFINE_UNQUOTED([PREAD_PROTOTYPE], [$xo_cv_pread_prototype],
1097 [explicit prototype needed for pread (if any)])
1100 AC_CHECK_FUNC([pwrite],
1101 [AC_DEFINE([HAVE_PWRITE], [1],
1102 [Define if pwrite is available on this system])
1103 AC_MSG_CHECKING([for any prototype needed for pwrite])
1104 AC_CACHE_VAL([xo_cv_pwrite_prototype],
1107 'extern "C" ssize_t pwrite(int, const void *, size_t, off_t) throw ();' \
1108 'extern "C" ssize_t pwrite(int, const void *, size_t, off_t);' ; do
1110 #include <sys/types.h>
1114 const char *p = "hello";
1115 pwrite(1, p, 5, 20);
1117 xo_cv_pwrite_prototype="$p"
1121 if test -z "$xo_cv_pwrite_prototype"; then
1122 AC_MSG_RESULT([not found])
1123 AC_MSG_ERROR([Failed to find working prototype for pwrite])
1126 if test " " = "$xo_cv_pwrite_prototype" ; then
1127 AC_MSG_RESULT([none required])
1129 AC_MSG_RESULT([$xo_cv_pwrite_prototype])
1130 AC_DEFINE_UNQUOTED([PWRITE_PROTOTYPE], [$xo_cv_pwrite_prototype],
1131 [explicit prototype needed for pwrite (if any)])
1137 AC_MSG_CHECKING([for directory separator(s)])
1138 case $host_os-$win32 in
1139 *-yes | cygwin* | os2* | *djgpp* | *msdos* )
1140 AC_MSG_RESULT([/ and \\])
1141 AC_DEFINE([DIR_SEPS], ["/\\"], [directory separator(s) as a character or string literal])
1142 AC_DEFINE([DIR_SEPS_LIST], [{ '/', '\\' }], [directory separator(s) as an initialiser list])
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_CHECK_FUNCS([link])
1153 dnl *************************
1154 dnl * Set debugging options *
1155 dnl *************************
1157 dnl Which assertion types to enable in the code.
1159 AC_ARG_ENABLE([assertions],
1160 [AS_HELP_STRING([--enable-assertions], [enable debug assertions (no|partial|yes) [default=no]])],
1164 AC_MSG_ERROR([Invalid option: '--enable-assertions=$enableval']) ;;
1167 AC_ARG_ENABLE([log],
1168 [AS_HELP_STRING([--enable-log], [generate a log of methods called, etc (no|yes|profile) [default=no]])],
1172 AC_MSG_ERROR(['--enable-log=profile' is no longer supported - see https://trac.xapian.org/wiki/ProfilingXapian for alternatives.]) ;;
1174 AC_MSG_ERROR([Invalid option: '--enable-log=$enableval']) ;;
1177 dnl Set defines according to the --enable-assertions and --enable-log options
1180 if test yes = "$enable_assertions" || test partial = "$enable_assertions" ; then
1181 AC_DEFINE([XAPIAN_ASSERTIONS],,
1182 [Define if you want assertions (causes some slow-down)])
1185 if test yes = "$enable_assertions"; then
1186 AC_DEFINE([XAPIAN_ASSERTIONS_PARANOID],,
1187 [Define if you want paranoid assertions (causes significant slow-down)])
1190 if test yes = "$enable_log"; then
1191 AC_DEFINE([XAPIAN_DEBUG_LOG],,
1192 [Define if you want a log of methods called and other debug messages])
1195 dnl ******************************
1196 dnl * Set special compiler flags *
1197 dnl ******************************
1199 dnl Set flags to control warnings (enable more, or disable annoying ones).
1201 if test yes = "$GXX"; then
1202 dnl Intel's C++ compiler and clang both lie and define __GNUC__, so check which
1203 dnl we actually have, as neither is really 100% compatible.
1204 case `echo __INTEL_COMPILER __clang__|$CXX -E - 2>&AS_MESSAGE_LOG_FD|grep -v '^#'` in
1205 *__INTEL_COMPILER*__clang__*)
1206 dnl GCC (since neither substituted):
1208 dnl The exact format of g++ --version seems to change with almost every
1209 dnl minor release so use the preprocessor macros which should be more
1211 AC_MSG_CHECKING([for version of $CXX])
1212 gxx_version=`echo __GNUC__.__GNUC_MINOR__.__GNUC_PATCHLEVEL__|$CXX -E -|sed '/^#/d;s/ //g'`
1213 AC_MSG_RESULT([GCC $gxx_version])
1215 case $gxx_version in
1216 [[0123]].*|4.[[0-6]].*)
1217 AC_MSG_ERROR([Xapian requires GCC 4.7 or later])
1221 dnl -Wundef was supported by g++ 3.0.
1223 dnl -Wlogical-op and -Wmissing-declarations (for C++) were added in
1226 dnl -Wdouble-promotion was added in GCC 4.6.
1228 dnl -Winit-self was added in GCC 3.4, but for GCC < 4.7 g++ always
1229 dnl warns for this case with -Wuninitialized (implied by -W). We
1230 dnl don't intend to use this idiom, so any instances are bugs we'd
1231 dnl like to know about.
1233 dnl All the other options were supported by g++ 2.95.
1234 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"
1237 dnl -Wconversion in older GCC versions is intended to help migration
1238 dnl from K&R to ISO C, and isn't useful for us. In 4.3 it was renamed
1239 dnl to -Wtraditional-conversion and a new -Wconversion added which
1240 dnl sounds useful but is a bit buggy currently. So we should consider
1241 dnl enabling -Wconversion once it is stabilised (GCC 4.4 or ...)
1243 dnl -Wold-style-cast is interesting, but triggers for macros from
1244 dnl system headers (e.g. FD_SET). GCC 4.8 improved this by making
1245 dnl -ftrack-macro-expansion=2 the default, but we still see such
1246 dnl warnings on some platforms for some reason (e.g. Cygwin with GCC
1247 dnl 5.4.0 warns about FD_SET, and on Debian with GCC 4.9.2 we see
1248 dnl warnings from zlib.h).
1250 dnl Automatically add -Werror if maintainer mode is enabled.
1251 if test x$USE_MAINTAINER_MODE = xyes; then
1252 AM_CXXFLAGS="$AM_CXXFLAGS -Werror"
1256 dnl Intel's compiler (since __clang__ not substituted):
1258 dnl -w1 stops the avalanche of uninteresting "remark" messages.
1259 dnl -wd... disables warnings which don't have good code workarounds.
1260 AM_CXXFLAGS="$AM_CXXFLAGS -Wall -w1 -wd177,1572"
1262 dnl Automatically add -Werror if maintainer mode is enabled.
1263 if test x$USE_MAINTAINER_MODE = xyes; then
1264 AM_CXXFLAGS="$AM_CXXFLAGS -Werror"
1268 dnl clang (since __INTEL_COMPILER not substituted):
1270 dnl These options all work at least as far back as clang++ 3.0:
1271 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"
1273 dnl Automatically add -Werror if maintainer mode is enabled.
1274 if test x$USE_MAINTAINER_MODE = xyes; then
1275 AM_CXXFLAGS="$AM_CXXFLAGS -Werror"
1280 if test no != "$enable_visibility"; then
1281 dnl GCC doesn't support symbol visibility on all platforms (e.g. it isn't
1282 dnl supported on mingw and visibility attributes result in warnings).
1283 AC_MSG_CHECKING([if $CXX -fvisibility=hidden -fvisibility-inlines-hidden works])
1284 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
1285 AC_MSG_RESULT([yes])
1286 AM_CXXFLAGS="$AM_CXXFLAGS -fvisibility=hidden -fvisibility-inlines-hidden"
1287 dash_d_visibility=-DXAPIAN_ENABLE_VISIBILITY
1293 dnl Not GCC, nor a compiler masquerading as GCC.
1296 dnl +w turns on more warnings.
1297 dnl +wlint turns on "lint-like" warnings.
1298 dnl +W<n1>,<n2>,... suppresses warnings n1, n2, ...
1299 dnl 2340 (remark) "value copied to temporary, reference to temporary
1300 dnl use", in: throw Xapian::UnimplementedError("...");
1301 dnl 2401 "destructor for base class ... is non-virtual" (we don't need a
1302 dnl virtual destructor for intrusive_base, since we never delete
1303 dnl its subclasses by a intrusive_base *).
1304 dnl 3348 "declaration hides constant ..." which seems to misfire!
1305 dnl 4255 (remark) "padding size of struct "..." with ... bytes to
1306 dnl alignment boundary".
1307 dnl 4273 "floating-point equality and inequality comparisons may be
1308 dnl inappropriate due to roundoff common in floating-point computation"
1309 dnl No obvious workaround for when you really do want == or !=.
1310 dnl 4285 "operator= does not have a check for the source and destination
1311 dnl addresses being non-identical" - fires for AutoPtr which
1312 dnl includes such a check indirectly (internaltest's autoptr1 check this).
1313 dnl 20201 "Memory leak is detected" which triggers for "return new Foo;"!
1314 AM_CXXFLAGS="$AM_CXXFLAGS +w +wlint +W2340,2401,3348,4255,4273,4285,20201" ;;
1316 dnl Sun's C++ compiler warns about functions failing to return a value even
1317 dnl when the function ends with a "throw" statement. That's just unhelpful
1318 dnl noise, and adding a dummy "return" after "throw" seems a worse solution
1319 dnl than simply disabling this warning - any genuinely missing return
1320 dnl statements will get reported by compilers with superior warning
1322 XAPIAN_TEST_CXXFLAGS([-erroff=voidretw], [AM_CXXFLAGS])
1327 XAPIAN_TEST_LINKER_FLAG([-Bsymbolic-functions], [symbolic_functions],
1328 [XAPIAN_LDFLAGS="$XAPIAN_LDFLAGS $flag"])
1330 FP_EXCESS_PRECISION=no
1331 AC_MSG_CHECKING([whether to use SSE instructions on x86])
1334 if test "$enable_sse" = no ; then
1336 FP_EXCESS_PRECISION=yes
1337 if test yes = "$msvc"; then
1338 dnl MSVC defaults to SSE2.
1339 AM_CXXFLAGS="$AM_CXXFLAGS -arch:IA32"
1342 dnl Default to sse2.
1343 test "$enable_sse" != yes || enable_sse=sse2
1344 if test yes = "$GXX"; then
1345 AC_MSG_RESULT([yes (configure with --disable-sse to disable)])
1346 dnl We can unconditionally use -mtune=generic as it was added in GCC
1347 dnl 4.2, and supported at least as far back as clang 3.0.
1348 AM_CXXFLAGS="$AM_CXXFLAGS -mfpmath=sse -m$enable_sse -mtune=generic"
1349 elif test yes = "$msvc"; then
1350 AC_MSG_RESULT([yes (configure with --disable-sse to disable)])
1351 if test sse = "$enable_sse"; then
1352 dnl MSVC defaults to SSE2.
1353 AM_CXXFLAGS="$AM_CXXFLAGS -arch:SSE"
1356 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
1357 [[#ifndef __SUNPRO_CC
1358 #error Not Sun compiler
1360 [AC_MSG_RESULT([yes (configure with --disable-sse to disable)])
1361 AM_CXXFLAGS="$AM_CXXFLAGS -xarch=$enable_sse"]
1363 [AC_MSG_RESULT([don't know how to for compiler $CXX])
1364 FP_EXCESS_PRECISION=yes]
1370 AC_MSG_RESULT([non-x86 arch ($host_cpu)]) ;;
1372 AC_SUBST([FP_EXCESS_PRECISION])
1375 [/* Disable stupid MSVC warnings. */
1377 /* Passing an empty parameter to a single parameter macro. */
1378 # pragma warning(disable:4003)
1379 /* A "performance" warning for converting int to bool. */
1380 # pragma warning(disable:4800)
1382 /* Tell MSVC we want M_PI, etc defined. */
1383 # define _USE_MATH_DEFINES
1385 /* Tell MSVC we don't want max() and min() macros defined. */
1389 /* Make the POSIX-like functions support large files. MSVC needs this;
1390 * current mingw32 does too; mingw64 supports _FILE_OFFSET_BITS, which
1391 * AC_SYS_LARGEFILE should discover and enable automatically.
1393 #if defined _MSC_VER || \
1394 (defined __MINGW32__ && !defined _FILE_OFFSET_BITS)
1396 # include <sys/stat.h>
1397 # include <sys/types.h>
1399 /* zlib.h uses off_t so we need to include it before we redefine off_t. */
1402 // MSVC needs to call _stat64() instead of stat() and the struct which holds
1403 // the information is "struct _stat64" instead of "struct stat" so we just
1404 // use #define to replace both in one go. We also want to use _fstat64()
1405 // instead of fstat() but in this case we can use a function-like macro.
1407 // Mingw has _stat64() but unhelpfully for our purposes, it has an extra
1408 // underscore prefix on the struct name ("struct __stat64") so there we
1409 // target _stati64 instead. This has 64-bit file size but the time_t size
1410 // is switchable. We don't really care about file timestamps in the
1411 // library, so this should be fine.
1413 // This hack is a problem is we ever want a method called "stat", or one called
1414 // fstat which takes 2 parameters, but we can probably live with these
1426 # define stat _stat64
1427 # define fstat(FD, BUF) _fstat64(FD, BUF)
1429 # define stat _stati64
1430 # define fstat(FD, BUF) _fstati64(FD, BUF)
1441 # define lseek(FD, OFF, WHENCE) _lseeki64(FD, OFF, WHENCE)
1442 /* Redefine via a typedef so C++ code off_t(-1) works - it wouldn't if we did:
1443 * #define off_t long long
1445 typedef long long off_t_redefinition_typedef;
1446 # define off_t off_t_redefinition_typedef
1450 /* MSVC defines _WIN32 but not __WIN32__. */
1451 #if !defined __WIN32__ && defined _WIN32
1455 /* MSVC defines _WIN64 but not __WIN64__. */
1456 #if !defined __WIN64__ && defined _WIN64
1460 /* _FORTIFY_SOURCE is only supported by GCC >= 4.1 and glibc >= 2.3.4, but it
1461 * shouldn't cause a problem to define it where it's not supported and some
1462 * distros may have backported support, so hardcoding version checks is
1463 * counter-productive.
1465 * Check if _FORTIFY_SOURCE is already defined to allow the user to override
1466 * our choice with "./configure CPPFLAGS=-D_FORTIFY_SOURCE=0" or "...=1".
1468 #if defined __GNUC__ && !defined _FORTIFY_SOURCE
1469 # define _FORTIFY_SOURCE 2
1472 /* For compilers which support it (such as GCC, clang, Intel's C++ compiler)
1473 * we can use __builtin_expect to give the compiler hints about branch
1474 * prediction. See HACKING for how to use these.
1476 #if HAVE_DECL___BUILTIN_EXPECT
1477 /* The arguments of __builtin_expect() are both long, so use !! to ensure that
1478 * the first argument is always an integer expression, and always 0 or 1, but
1479 * still has the same truth value for the if or while it is used in.
1481 # define rare(COND) __builtin_expect(!!(COND), 0)
1482 # define usual(COND) __builtin_expect(!!(COND), 1)
1484 # define rare(COND) (COND)
1485 # define usual(COND) (COND)
1488 /* Signal we're building the library so it's OK to include headers such as
1489 * xapian/query.h directly.
1491 #define XAPIAN_LIB_BUILD 1
1493 /* With Sun CC 5.13 (Studio 12.4) on Solaris 11.2, <math.h> seems to get
1494 * implicitly included somehow before <cmath>, and compilation fails due
1495 * to 'std::exception' colliding with 'struct exception'. It's not clear
1496 * how to avoid this, so just define the same magic macro which <cmath> does
1497 * before it includes <math.h>.
1500 # define __MATHERR_RENAME_EXCEPTION
1504 AC_SUBST([AM_CXXFLAGS])
1506 dnl Restore CXXFLAGS to those the user specified or autoconf defaulted to.
1507 CXXFLAGS=$save_CXXFLAGS
1509 dnl Required for auto regeneration to work in a combined maintainer-mode tree.
1510 : ${AUTOM4TE=autom4te}
1511 AC_SUBST([AUTOM4TE])
1513 dnl Libtool sets this (to yes|no|unknown) and we use it in xapian-config.
1514 AC_SUBST([link_all_deplibs_CXX])
1516 dnl Shared library extension.
1518 eval "SHLIBEXT=$shrext_cmds"
1519 AC_SUBST([SHLIBEXT])
1521 dnl We want to be able to use GNU make % pattern rules in maintainer targets
1522 dnl but automake warns these aren't portable, so we substitute the % to avoid
1527 dnl Split up the version number into "MAJOR.MINOR.REVISION".
1528 MAJOR_VERSION=`echo "$VERSION"|sed 's/\..*//'`
1529 [MINOR_VERSION=`echo "$VERSION"|sed 's/[^.]*\.//;s/\..*//'`]
1530 [REVISION=`echo "$VERSION"|sed 's/.*\.//;s/_.*$//'`]
1532 dnl **************************
1533 dnl * Build the output files *
1534 dnl **************************
1540 docs/doxygen_api.conf
1541 docs/doxygen_source.conf
1543 cmake/xapian-config.cmake
1544 cmake/xapian-config-version.cmake
1545 pkgconfig/xapian-core"$LIBRARY_VERSION_SUFFIX".pc:pkgconfig/xapian-core.pc.in
1547 AC_CONFIG_FILES([tests/runtest], [chmod +x tests/runtest])
1548 AC_CONFIG_FILES([tests/runsrv], [chmod +x tests/runsrv])
1549 AC_CONFIG_FILES([tests/submitperftest], [chmod +x tests/submitperftest])
1550 AC_CONFIG_FILES([tests/perftest/get_machine_info], [chmod +x tests/perftest/get_machine_info])
1551 AC_CONFIG_FILES([xapian-config], [chmod +x xapian-config])
1552 AC_CONFIG_FILES([makemanpage], [chmod +x makemanpage])
1555 dnl There are no files generated by AC_OUTPUT in the following directories
1556 dnl and we need to ensure they exist so that the rest of configure or make
1557 dnl won't fail because they don't exist when srcdir != builddir.
1558 if test yes = "$vpath_build" ; then
1559 for dir in include/xapian languages queryparser ; do
1560 AS_MKDIR_P(["$dir"])
1564 dnl Generate include/xapian/version.h:
1566 dnl MAIN_VERSION is VERSION without any _git123 suffix.
1567 MAIN_VERSION="$MAJOR_VERSION.$MINOR_VERSION.$REVISION"
1569 for backend in CHERT GLASS INMEMORY REMOTE ; do
1570 val=`eval echo "\\\$BUILD_BACKEND_${backend}_TRUE"`
1571 if test -z "$val" ; then
1572 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_HAS_${backend}_BACKEND"
1576 if test yes = "$enable_64bit_docid" ; then
1577 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_DOCID_BASE_TYPE="`echo "$INT64_T"|sed 's/ /____/g'`
1579 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_DOCID_BASE_TYPE="`echo "$INT32_T"|sed 's/ /____/g'`
1582 if test yes = "$enable_64bit_termcount" ; then
1583 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TERMCOUNT_BASE_TYPE="`echo "$INT64_T"|sed 's/ /____/g'`
1585 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TERMCOUNT_BASE_TYPE="`echo "$INT32_T"|sed 's/ /____/g'`
1588 if test yes = "$enable_64bit_termpos" ; then
1589 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TERMPOS_BASE_TYPE="`echo "$INT64_T"|sed 's/ /____/g'`
1591 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TERMPOS_BASE_TYPE="`echo "$INT32_T"|sed 's/ /____/g'`
1594 dnl Always ought to be 64 bit.
1595 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TOTALLENGTH_TYPE="`echo "unsigned $INT64_T"|sed 's/ /____/g'`
1597 dnl Make revision numbers in the API 64 bit for future-proofing.
1598 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_REVISION_TYPE="`echo "unsigned $INT64_T"|sed 's/ /____/g'`
1600 dnl For GCC (and compilers which pretend to be GCC) and MSVC, we create some
1601 dnl ABI checks in the generated version.h, and $CXXFLAGS may contain options
1602 dnl which affect the ABI (e.g. -fabi-version for GCC) so we want to use these
1603 dnl options when generating version.h. For these compilers, CXXCPP="$CXX -E"
1604 dnl so it should understand all compiler options.
1606 dnl For other compilers, we only pass $CPPFLAGS to $CXXCPP in case it's an
1607 dnl external cpp which doesn't understand flags which might be in $CXXFLAGS.
1608 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[#ifndef __GNUC__
1614 [cxxcpp_flags="$cxxcpp_flags $CPPFLAGS $CXXFLAGS"],
1615 [cxxcpp_flags="$cxxcpp_flags $CPPFLAGS"])
1616 rm -f include/xapian/version.h.tmp
1617 dnl "\r" in sed is a GNUism, but we only need to remove it on MS Windows
1618 dnl where we'll always have GNU sed, and other sed's will just interpret
1619 dnl it as "r" (Solaris sed) or maybe literal "\r" which won't match.
1621 dnl Use @@ around $MAIN_VERSION so we get " in the final output.
1622 $CXXCPP $cxxcpp_flags\
1623 -DSTRING_VERSION="\"@@$MAIN_VERSION@@\""\
1624 -DMAJOR_VERSION="\"$MAJOR_VERSION\""\
1625 -DMINOR_VERSION="\"$MINOR_VERSION\""\
1626 -DREVISION="\"$REVISION\""\
1628 $srcdir/include/xapian/version_h.cc|\
1629 ${SED-sed} '0,/const char \* dummy/d;/"/!d;s/^ *//;/^#/d;s/ *$//;s/" *,//;s/"//g;s/@@/"/g;s/ */ /g;s/ *,\r$//;s/ *,$//;s/____/ /g;s/\\\\$/\\/'\
1630 > include/xapian/version.h.tmp
1631 dnl Only update the file if it has changed, so we don't alter the timestamp
1632 dnl and cause lots of rebuilding needlessly. However, the build system
1633 dnl needs a timestamp to know when to regenerate version.h because version_h.cc
1634 dnl has changed so we use a separate timestamp file.
1635 touch include/xapian/version.h.timestamp
1636 if cmp include/xapian/version.h.tmp include/xapian/version.h >/dev/null 2>&1
1638 rm include/xapian/version.h.tmp
1640 mv include/xapian/version.h.tmp include/xapian/version.h