Add XAPIAN_AT_LEAST(A,B,C) macro
[xapian.git] / xapian-core / configure.ac
blob858e05c67f9678c47b535364c8588a1f8766156f
1 dnl Process this file with autoconf to produce a configure script.
3 dnl NB When updating the version for a release, update LIBRARY_VERSION_INFO
4 dnl below too.
5 AC_INIT([xapian-core], [1.4.0], [https://xapian.org/bugs])
6 dnl See HACKING document for details of the reasons for required versions.
7 AC_PREREQ([2.64])
8 dnl Extract from the libtool info manual:
9 dnl
10 dnl Here are a set of rules to help you update your library version information:
11 dnl
12 dnl 1. Start with version information of '0:0:0' for each libtool library.
13 dnl
14 dnl 2. Update the version information only immediately before a public
15 dnl    release of your software.  More frequent updates are unnecessary,
16 dnl    and only guarantee that the current interface number gets larger
17 dnl    faster.
18 dnl
19 dnl 3. If the library source code has changed at all since the last
20 dnl    update, then increment REVISION ('C:R:A' becomes 'C:r+1:A').
21 dnl
22 dnl 4. If any interfaces have been added, removed, or changed since the
23 dnl    last update, increment CURRENT, and set REVISION to 0.
24 dnl
25 dnl 5. If any interfaces have been added since the last public release,
26 dnl    then increment AGE.
27 dnl
28 dnl 6. If any interfaces have been removed since the last public release
29 dnl    then set AGE to 0.
30 dnl
31 dnl LIBRARY_VERSION_INFO for 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 LIBRARY_VERSION_INFO=30:0:0
35 AC_SUBST([LIBRARY_VERSION_INFO])
37 LIBRARY_VERSION_SUFFIX=
38 AC_SUBST([LIBRARY_VERSION_SUFFIX])
40 dnl Disabled for stable release series.
41 test x"$program_suffix" != xNONE || program_suffix=
43 dnl Where xapian.h, etc go.  In development release append "/xapian-1.3".
44 incdir=$includedir
45 AC_SUBST([incdir])
47 dnl Check the build directory doesn't contain a space, so we die early with
48 dnl a helpful error.
49 case `pwd` in
50 *' '*)
51    AC_MSG_ERROR([You can't build in a directory whose path contains a space])
52    ;;
53 esac
55 dnl Check the source directory doesn't contain a space, so we die early with
56 dnl a helpful error.  FIXME: Unfortunately, configure seems to choke before
57 dnl it gets to us so this code doesn't get a chance to fire.
58 case $0 in
59 *' '*)
60    dnl Note: for in-tree builds, the build directory test above will fire
61    dnl before this can.
62    AC_MSG_ERROR([You can't build with sources in a directory whose path contains a space])
63    ;;
64 esac
66 dnl Check the prefix to install in doesn't contain a space, so we die early with
67 dnl a helpful error.
68 case $prefix in
69 *' '*)
70    AC_MSG_ERROR([You can't install in a directory whose path contains a space])
71    ;;
72 esac
74 dnl Note if the user specified a particular C++ compiler so we can give a more
75 dnl appropriate error message if we can't link a simple C++ program.
76 original_CXX=
77 if test -n "$CXX" ; then
78   original_CXX="CXX=$CXX"
79 elif test -n "$CCC" ; then
80   original_CXX="CCC=$CCC"
83 dnl See HACKING document for details of the reasons for required versions.
84 AM_INIT_AUTOMAKE([1.11 -Wportability tar-ustar no-dist-gzip dist-xz std-options])
85 AC_CONFIG_SRCDIR([matcher/multiandpostlist.cc])
87 AC_CONFIG_HEADERS([config.h])
89 AC_CONFIG_MACRO_DIR([m4])
91 dnl Use libtool to manage our libraries.
92 LT_PREREQ([2.2.8])
93 dnl Default to only building shared libraries.
94 dnl
95 dnl Building both shared and static means having to compile the files which
96 dnl make up the library twice on most platforms.  Shared libraries are the
97 dnl better option for most users, and if anyone really wants static libraries,
98 dnl they can configure with --enable-static (or --enable-static=xapian-core if
99 dnl configuring a combined tree with the bindings).
101 dnl We don't export any data items from the library, so it should be safe to
102 dnl enable win32-dll without decorating any declarations specially.
103 LT_INIT([disable-static win32-dll])
105 dnl -no-undefined causes problems on Solaris with Sun CC in C++11 mode, so only
106 dnl pass -no-undefined on platforms where it is required in order to link a
107 dnl shared library at all (Windows is the main one).
108 NO_UNDEFINED=
109 if test unsupported = "$allow_undefined_flag" ; then
110   NO_UNDEFINED=-no-undefined
112 AC_SUBST(NO_UNDEFINED)
114 AM_CXXFLAGS=
116 dnl A standard "gotcha" for mingw and cygwin users is to not set up their
117 dnl PATH correctly, so that MSDOS FIND.EXE is found before Unix find.  Help
118 dnl them out by checking for this condition, rather than letting libtool
119 dnl fail in obscure ways.  NB check the *BUILD* OS, not the host one!
120 case $build_os in
121   *mingw* | *cygwin* | pw32*)
122     find /dirunlikelytoexist >/dev/null 2>&1
123     if test $? = 2 ; then
124         dnl Unix find will return 1 if the directory didn't exist, or 0 if
125         dnl it did.
126         AC_MSG_ERROR([
127 *** You appear to have an MSDOS-like FIND.EXE in your PATH ahead of any
128 *** UNIX-like find.  This misconfiguration will confuse libtool - you'll need
129 *** to make sure you have a UNIX-like find installed and fix your PATH, then
130 *** rerun configure.  For more information, see:
132 ***   https://www.cygwin.com/faq/faq.html#faq.using.find
134     fi
135   ;;
136 esac
138 dnl Add parameters for aclocal
139 dnl (This must come after AM_INIT_AUTOMAKE, since it modifies ACLOCAL)
140 ACLOCAL="$ACLOCAL $ACLOCAL_FLAGS"
142 dnl disable "maintainer only" rules by default
143 AM_MAINTAINER_MODE
145 dnl Checks for programs.
146 AC_PROG_CXX
148 AC_CANONICAL_HOST
150 # Checked: freebsd8.0 openbsd4.6 solaris2.9 solaris2.10
151 case $host_os in
152   linux* | k*bsd*-gnu | freebsd* | openbsd* | solaris*)
153     dnl Vanilla libtool sets this to "unknown" which it then handles as "yes".
154     link_all_deplibs_CXX=no
155     ;;
156 esac
158 case $host_os in
159   linux*)
160     dnl Extract search path from ldconfig which is more reliable than the way
161     dnl vanilla libtool extracts them from ld.so.conf.
162     d=`/sbin/ldconfig -N -X -v 2>&AS_MESSAGE_LOG_FD|$SED 's,^\(/.*\):\( (.*)\)\?$,\1,p;d'|tr '\n' ' '`
163     test -z "$d" || sys_lib_dlsearch_path_spec=$d
164     ;;
165 esac
167 case $host in
168   *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
169     dnl On these platforms, libtool emits a warning if -no-install is passed,
170     dnl and uses -no-fast-install instead - the least ugly way to avoid that
171     dnl warnings seems to be to duplicate the above list of platforms from
172     dnl libtool and use -no-fast-install on them directly.
173     NO_INSTALL=-no-fast-install ;;
174   *)
175     NO_INSTALL=-no-install ;;
176 esac
177 AC_SUBST([NO_INSTALL])
179 dnl For reasons which are beyond me, if autoconf can't find a C++ compiler
180 dnl it will set CXX to g++ (which obviously won't work) rather than actually
181 dnl telling the user that it couldn't find a C++ compiler and telling them
182 dnl to either install one or set CXX if there's one configure failed to find.
183 dnl It's probably worthwhile checking that the C++ compiler actually works
184 dnl anyway!
185 if test -n "$CXX" ; then
186   AC_LANG_CPLUSPLUS
187   AC_MSG_CHECKING([whether $CXX is a working C++ compiler])
188   AC_CACHE_VAL([xo_cv_cxx_works],
189     [
190     AC_TRY_RUN([int main() {}],
191                xo_cv_cxx_works=yes,
192                xo_cv_cxx_works=no,
193                AC_TRY_LINK([], [], xo_cv_cxx_works=yes, xo_cv_cxx_works=no))
194     ])
195   AC_MSG_RESULT([$xo_cv_cxx_works])
196 else
197   xo_cv_cxx_works=no
199 if test no = "$xo_cv_cxx_works" ; then
200   case $original_CXX in
201   CCC=*)
202     dnl CCC is handled in a slightly odd way - if its value isn't an
203     dnl executable (taking PATH into account) then it is ignored!
204     test "$original_CXX" = "CCC=$CXX" || original_CXX=
205     ;;
206   esac
207   if test -z "$original_CXX" ; then
208   AC_MSG_ERROR([
209 *** You need a working C++ compiler to compile Xapian, but configure failed to
210 *** find one.  If you have a working C++ compiler, you can tell configure where
211 *** to find it by invoking it like so:
213 ***   ./configure CXX=/opt/bin/c++
215   else
216   AC_MSG_ERROR([
217 *** You need a working C++ compiler to compile Xapian, but the compiler you
218 *** specified (with '$original_CXX') doesn't appear to be able to successfully
219 *** compile and link a simple program.
221   fi
224 dnl Probe for any options needed to enable C++11 support.
225 AX_CXX_COMPILE_STDCXX_11
227 dnl We don't use a C compiler to compile Xapian's code, but on some platforms
228 dnl (e.g. mingw) libtool uses $LTCC which defaults to $CC, and it's also use to
229 dnl build auxiliary tools like snowball and lemon.
230 AC_PROG_CC
232 dnl Check endianness.
233 AC_C_BIGENDIAN
235 dnl We want a non-cross-compiling C compiler for building lemon with.
236 if test -z "$CC_FOR_BUILD" ; then
237   if test yes = "$cross_compiling"; then
238     CC_FOR_BUILD=cc
239   else
240     CC_FOR_BUILD="$CC"
241   fi
243 AC_ARG_VAR([CC_FOR_BUILD], [C compiler command for native compilation (needed to compile build tools during cross-builds)])
245 dnl Run tests using the C++ compiler.
246 AC_LANG_CPLUSPLUS
248 dnl Enable large file support if possible.
249 AC_SYS_LARGEFILE
250 dnl With xlC on AIX, -D_LARGE_FILES changes the ABI of std::string, so it
251 dnl also needs to be used when compiling user code.
252 abi_affecting_cxxflags=
253 if $GREP '^#define _LARGE_FILES 1$' confdefs.h > /dev/null 2>&1 ; then
254   abi_affecting_cxxflags=-D_LARGE_FILES
256 AC_SUBST([abi_affecting_cxxflags])
258 XAPIAN_LDFLAGS=
259 XAPIAN_LIBS=
260 AC_SUBST([XAPIAN_LDFLAGS])
261 AC_SUBST([XAPIAN_LIBS])
263 AC_DEFUN([XAPIAN_TEST_LINKER_FLAG],
264   [
265   AC_MSG_CHECKING([for $CXX -Wl,$1])
266   AC_CACHE_VAL([xo_cv_ldflag_$2],
267     [
268     save_LDFLAGS=$LDFLAGS
269     LDFLAGS="$LDFLAGS -Wl,$1"
270     flag=$1
271     AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
272       [xo_cv_ldflag_$2=yes
273       $3],
274       [xo_cv_ldflag_$2=no
275       $4])
276     LDFLAGS=$save_LDFLAGS
277     ])
278   AC_MSG_RESULT([$xo_cv_ldflag_$2])
279   ])
281 dnl Test if the compiler works with $1 added to CXXFLAGS; if it does, add $1 to
282 dnl variable $2.  If the test passes, also do $3; if it fails, also do $4.
283 AC_DEFUN([XAPIAN_TEST_CXXFLAGS],
284   [
285   XTC_save_CXXFLAGS=$CXXFLAGS
286   CXXFLAGS="$CXXFLAGS $1"
287   AC_TRY_COMPILE([], [],
288                  [$2="${$2} $1"
289                   CXXFLAGS=$XTC_save_CXXFLAGS
290                   $3],
291                  [CXXFLAGS=$XTC_save_CXXFLAGS
292                   $4])
293   ])
295 ldflags=
296 if test yesyes = "$GXX$enable_shared" ; then
297   case $host_os in
298     *mingw* | *cygwin*)
299       XAPIAN_TEST_LINKER_FLAG([--enable-runtime-pseudo-reloc], [enable_runtime_pseudo_reloc],
300         [ldflags="-Wl,$flag"],
301         [
302         dnl Can't use AC_DISABLE_SHARED after AC_PROG_LIBTOOL, but
303         dnl this test needs to be after AC_PROG_LIBTOOL, so we can't
304         dnl just disable the shared build automatically...
305         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])
306         ])
307     ;;
308   esac
310 dnl Only works for ldflags which can be specified anywhere on the link line.
311 AC_SUBST([ldflags])
313 dnl Preserve the default CXXFLAGS.
314 save_CXXFLAGS=$CXXFLAGS
316 dnl x86 has excess precision issues with 387 FP instructions, which are
317 dnl avoided by using SSE instructions instead.  This is also faster (~6% in
318 dnl a CPU bound testcase).
319 AC_ARG_ENABLE([sse],
320 [AS_HELP_STRING([--disable-sse],
321                 [disable use of SSE FP instructions on x86])]
322 [AS_HELP_STRING([[--enable-sse[=sse|sse2]]],
323                 [set which SSE FP instructions to use on x86 (default: sse2)])],
324   [case ${enableval} in
325     sse|sse2|yes|no) ;;
326     *) AC_MSG_ERROR([bad value ${enableval} for --enable-sse or --disable-sse]) ;;
327   esac],
328   [enable_sse=yes])
330 dnl Some versions of Sun's C++ compiler reportedly need an explicit -lm.
331 dnl The maths functions we use include: exp log ceil fabs sqrt
332 AC_MSG_CHECKING([if -lm is required for maths functions])
333 dnl Don't use constant arguments as the compiler might simply evaluate the
334 dnl whole expression at compile time, and it might inline certain functions
335 dnl so test several functions.  Also write results using printf() so that
336 dnl the compiler can't optimise away the computations.
337 AC_TRY_LINK([#ifdef __SUNPRO_CC
338 #error Need -lm for Sun C++ 5.9 under libtool 2.2.10
339 #endif
340 #include <cmath>
341 #include <cstdio>
342 #include <ctime>
343 using namespace std;], [
344   double a = log(ceil(time(NULL)/7.0));
345   printf("%f %f %f\n", a, sqrt(a), exp(fabs(a - 12345.6)));
346   ], [AC_MSG_RESULT([no])], [
347     LIBS="-lm $LIBS"
348     AC_TRY_LINK([#include <cmath>
349 #include <cstdio>
350 #include <ctime>
351 using namespace std;], [
352   double a = log(ceil(time(NULL)/7.0));
353   printf("%f %f %f\n", a, sqrt(a), exp(fabs(a - 12345.6)));],
354         [AC_MSG_RESULT([yes])],
355         [AC_MSG_ERROR([Failed to link a C++ program using <cmath>])
356     ])
359 dnl C++11 should have log2(), but keep this check for now to allow for
360 dnl compilers with incomplete library support for C++11.
361 AC_CHECK_DECLS([log2], [], [],
362 [#include <cmath>
363 using namespace std;])
365 dnl See if <typeinfo> can be used in the testsuite - at least for GCC and xlC,
366 dnl compilation of the test code below fails if RTTI isn't being generated
367 dnl (g++ -fno-rtti, or by default with xlC).
368 AC_MSG_CHECKING([if RTTI is supported])
369 save_CXXFLAGS=$CXXFLAGS
370 dnl xlC issues a warning for typeid() being used without RTTI being enabled,
371 dnl so for this test we pass the xlC option to make that warning into an error.
372 XAPIAN_TEST_CXXFLAGS([-qhaltonmsg=1540-2412], [CXXFLAGS])
373 AC_TRY_COMPILE([
374 #include <exception>
375 #include <typeinfo>],
376         [
377         int f();
378         try {
379             return f();
380         } catch (std::exception & e) {
381             return typeid(e).name()[0];
382         }],
383     AC_MSG_RESULT([yes])
384     AC_DEFINE([USE_RTTI], [1], [Define if the testsuite can use RTTI]),
385     AC_MSG_RESULT([no]))
386 CXXFLAGS=$save_CXXFLAGS
388 AC_CHECK_DECLS([__builtin_bswap16, __builtin_bswap32], [], [], [ ])
389 AC_CHECK_DECLS([__builtin_clz, __builtin_clzl, __builtin_clzll], [], [], [ ])
390 AC_CHECK_DECLS([__builtin_ctz, __builtin_ctzl, __builtin_ctzll], [], [], [ ])
391 AC_CHECK_DECLS([__builtin_expect], [], [], [ ])
392 AC_CHECK_DECLS([__builtin_popcount, __builtin_popcountl, __builtin_popcountll], [], [], [ ])
394 dnl Check for time functions.
395 AC_CHECK_FUNCS([clock_gettime sleep nanosleep gettimeofday ftime])
397 case $host_os in
398   *mingw*)
399     dnl For _ftime64() on mingw we need to tell it we're happy to require
400     dnl MSVCRT 6.10 or higher, which isn't too onerous a requirement it seems.
401     AC_DEFINE([__MSVCRT_VERSION__], [0x0601], [Define on mingw to the minimum msvcrt version to assume])
402     AC_DEFINE([MINGW_HAS_SECURE_API], [1], [Define on mingw to get _s suffixed "secure" functions declared in headers])
403     ;;
404 esac
406 dnl We use timer_create() if available to implement a search time limit.
407 SAVE_LIBS=$LIBS
408 AC_SEARCH_LIBS([timer_create], [rt],
409                [
410     AC_MSG_CHECKING([for timer_create() usability])
411     AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
412 [[#if defined _AIX || defined __GNU__
413 #error timer_create known not to work
414 #endif]])],
415         [AC_MSG_RESULT([yes])
416         XAPIAN_LIBS="$LIBS $XAPIAN_LIBS"
417         AC_DEFINE([HAVE_TIMER_CREATE], [1], [Define to 1 if you have the 'timer_create' function.])]
418         ,
419         [AC_MSG_RESULT([no])
420     ])
422 LIBS=$SAVE_LIBS
424 dnl Used by tests/soaktest/soaktest.cc
425 AC_CHECK_FUNCS([srandom random])
427 dnl Used by tests/harness/testsuite.cc
428 AC_CHECK_FUNCS([sigaction])
429 AC_MSG_CHECKING([for sigsetjmp and siglongjmp])
430 AC_TRY_COMPILE([#include <setjmp.h>],
431   [sigjmp_buf jb; if (sigsetjmp(jb, 1)) { siglongjmp(jb, 1);  }],
432   AC_DEFINE([HAVE_SIGSETJMP], [1], [Define to 1 if you have the 'sigsetjmp' function])
433   AC_MSG_RESULT([yes]),
434   AC_MSG_RESULT([no]))
436 dnl Used by tests/harness/cputimer.cc:
437 AC_CHECK_FUNCS([getrusage times sysconf])
439 dnl Used by tests/api_replicate.cc.
441 dnl Solaris < 10 only has putenv().
443 dnl Microsoft have marked putenv() as deprecated, so we use _putenv_s() under
444 dnl MSVC to avoid deprecation warnings.  We probe here since mingw doesn't
445 dnl currently (v3.20) provide _putenv_s(), so we can't just use it conditional
446 dnl on __WIN32__ being defined.
447 AC_CHECK_FUNCS([setenv _putenv_s])
449 dnl See if we have closefrom(), or some functions that are useful to implement
450 dnl closefrom() on platforms which don't provide it.
451 AC_CHECK_FUNCS([closefrom getdirentries getrlimit])
453 dnl See if ftime returns void (as it does on mingw)
454 AC_MSG_CHECKING([return type of ftime])
455 if test $ac_cv_func_ftime = yes ; then
456   AC_TRY_COMPILE([#include <sys/timeb.h>],
457     [struct timeb tp; int i = ftime(&tp);],
458     AC_MSG_RESULT([int]),
459     AC_MSG_RESULT([void])
460     AC_DEFINE([FTIME_RETURNS_VOID], [1], [Define if ftime returns void]))
463 dnl Check how to find the hostname: uname() in sys/utsname.h, or gethostname()
464 dnl Don't use default includes as inttypes.h is found by Compaq C but not C++
465 dnl so it causes all header probes to fail.
466 AC_CHECK_HEADERS([sys/utsname.h], [], [], [ ])
467 AC_CHECK_FUNCS([gethostname])
469 dnl mingw (for instance) lacks ssize_t
470 AC_TYPE_SSIZE_T
472 AC_TYPE_PID_T
474 AC_TYPE_MODE_T
476 AC_CHECK_SIZEOF([short])
477 AC_CHECK_SIZEOF([int])
478 AC_CHECK_SIZEOF([long])
479 AC_CHECK_SIZEOF([long long])
481 AC_CHECK_HEADERS([sys/types.h])
482 AC_CHECK_SIZEOF([off_t])
484 AC_MSG_CHECKING([for 32 bit integer type])
485 case 4 in
486     "$ac_cv_sizeof_int")   INT32_T=int ;;
487     "$ac_cv_sizeof_long")  INT32_T=long ;;
488     "$ac_cv_sizeof_short") INT32_T=short ;;
489     *)
490       AC_MSG_RESULT([none found])
491       AC_MSG_ERROR([No 32 bit integer type found])
492 esac
493 AC_MSG_RESULT([$INT32_T])
495 AC_MSG_CHECKING([for 64 bit integer type])
496 case 8 in
497     "$ac_cv_sizeof_int")       INT64_T=int ;;
498     "$ac_cv_sizeof_long")      INT64_T=long ;;
499     "$ac_cv_sizeof_long_long") INT64_T='long long' ;;
500     *)
501       AC_MSG_RESULT([none found])
502       AC_MSG_ERROR([No 64 bit integer type found])
503 esac
504 AC_MSG_RESULT([$INT64_T])
506 dnl Used to avoid undefined behaviour left shifting file sizes.
507 AC_MSG_CHECKING([for unsigned equivalent of off_t])
508 case $ac_cv_sizeof_off_t in
509     "$ac_cv_sizeof_int")       UNSIGNED_OFF_T=unsigned ;;
510     "$ac_cv_sizeof_long")      UNSIGNED_OFF_T='unsigned long' ;;
511     "$ac_cv_sizeof_long_long") UNSIGNED_OFF_T='unsigned long long' ;;
512     *)
513       AC_MSG_RESULT([none found])
514       AC_MSG_ERROR([No unsigned type equivalent to off_t found])
515 esac
516 AC_DEFINE_UNQUOTED([UNSIGNED_OFF_T], [$UNSIGNED_OFF_T], [Define to an unsigned type equivalent to off_t])
517 AC_MSG_RESULT([$UNSIGNED_OFF_T])
519 dnl Check for perl (needed to generate some sources and documentation).
520 AC_PATH_PROG([PERL], [perl], [])
521 if test x$USE_MAINTAINER_MODE = xyes; then
522   test -z "$PERL" && AC_MSG_ERROR([perl is required in maintainer mode])
525 AC_ARG_ENABLE([64bit_docid],
526   [AS_HELP_STRING([--enable-64bit-docid], [enable 64bit docid [default=no]])],
527   [case ${enableval} in
528     yes|no) ;;
529   *) AC_MSG_ERROR([bad value ${enableval} for --enable-64bit-docid]) ;;
530   esac],
531   [enable_64bit_docid=no])
533 AC_ARG_ENABLE([64bit_termcount],
534   [AS_HELP_STRING([--enable-64bit-termcount], [enable 64bit termcount [default=no]])],
535   [case ${enableval} in
536     yes|no) ;;
537   *) AC_MSG_ERROR([bad value ${enableval} for --enable-64bit-termcount]) ;;
538   esac],
539   [enable_64bit_termcount=no])
541 AC_ARG_ENABLE([documentation],
542   [AS_HELP_STRING([--enable-documentation], [enable make rules to rebuild documentation [default=maintainer-mode]])],
543   [case ${enableval} in
544     yes|no) ;;
545     *) AC_MSG_ERROR([bad value ${enableval} for --enable-documentation]) ;;
546   esac],
547   [enable_documentation=$USE_MAINTAINER_MODE])
548 AM_CONDITIONAL([DOCUMENTATION_RULES], [test x"$enable_documentation" = xyes])
549 AM_CONDITIONAL([MAINTAINER_NO_DOCS], [test x"$USE_MAINTAINER_MODE$enable_documentation" = xyesno])
551 if test x"$enable_documentation" = xyes ; then
552   dnl Checks for dot.  (Diagrams in the documentation)
553   AC_PATH_PROG([DOT], [dot])
554   test -z "$DOT" && AC_MSG_ERROR([dot (part of the graphviz package) is required to build documentation])
555   DOXYGEN_DOT_PATH=`echo "$DOT" | sed 's!/dot$!!'`
556   AC_SUBST([DOXYGEN_DOT_PATH])
558   dnl Check for doxygen. (Needed to make some more of the documentation)
559   AC_PATH_PROG([DOXYGEN], [doxygen], [])
560   test -z "$DOXYGEN" && AC_MSG_ERROR([doxygen is required to build documentation])
562   dnl Check for help2man. (Needed to make man pages from "--help" output).
563   AC_PATH_PROG([HELP2MAN], [help2man], [])
564   test -z "$HELP2MAN" && AC_MSG_ERROR([help2man is required to build documentation])
566   dnl Check for rst2html. (Needed to make HTML from reStructuredText format)
567   dnl Also look for rst2html.py, which archlinux reportedly installs it as.
568   AC_PATH_PROGS([RST2HTML], [rst2html rst2html.py], [])
569   test -z "$RST2HTML" && AC_MSG_ERROR([rst2html is required to build documentation (try package python-docutils)])
571   dnl Check for pngcrush, which we optionally use to reduce the size of the
572   dnl PNG files which doxygen generates.  We can get by without it, so don't
573   dnl fail here if it's not found.
574   AC_PATH_PROG([PNGCRUSH], [pngcrush], [])
577 dnl Check whether we need -ldl for dlsym() etc.
578 dnl No longer used...
579 dnl AC_TRY_LINK_FUNC([dlsym], ,
580 dnl     [AC_CHECK_LIB([dl], [dlsym], [DL_LIBS="-ldl"])])
581 dnl AC_SUBST([DL_LIBS])
583 dnl Checks for header files.
584 AC_CHECK_HEADERS([fcntl.h limits.h sys/errno.h sys/select.h], [], [], [ ])
585 AC_CHECK_HEADERS([sys/resource.h],
586                  [], [], [#include <sys/types.h>])
588 dnl cxxabi.h was added in GCC 3.1, but clang lies and defines __GNUC__ yet
589 dnl doesn't seem to reliably provide this header, so probe for it.
590 AC_CHECK_HEADERS([cxxabi.h], [], [], [ ])
592 dnl If valgrind is installed and new enough, we use it for leak checking in the
593 dnl testsuite.  If VALGRIND is set to an empty value, then skip the check and
594 dnl don't use valgrind.
595 if test -n "${VALGRIND-unset}" ; then
596   AC_PATH_PROG([VALGRIND], [valgrind], [])
597   if test -n "$VALGRIND" ; then
598     dnl Check that the installed valgrind version works, and supports the
599     dnl options we use.  This means we won't try to use valgrind < 3.3.0
600     dnl (released 7/12/2007) since before that --log-file didn't expand
601     dnl %p (and appended the process id).
602     dnl
603     dnl No need to check for VALGRIND_COUNT_LEAKS now - that was added before
604     dnl 2.0.0.
605     AC_MSG_CHECKING([if valgrind supports --log-file with %p])
606     vglog=config.vglog.%p.tmp
607     vglogwild="config.vglog.*.tmp*"
608     rm -f $vglogwild
609     if $VALGRIND --log-file="$vglog" -q true 2>&AS_MESSAGE_LOG_FD ; then
610       for f in $vglogwild ; do
611         case $f in
612         $vglog*) VALGRIND= ;;
613         esac
614       done
615       if test x"$VALGRIND" = x ; then
616         AC_MSG_RESULT([no])
617       else
618         AC_MSG_RESULT([yes])
619         AC_CHECK_HEADERS([valgrind/memcheck.h], [], [VALGRIND=], [ ])
620       fi
621     else
622       dnl The valgrind detected doesn't seem to work!  Perhaps this is an
623       dnl x86_64 box with a 32 bit valgrind.
624       AC_MSG_RESULT([$VALGRIND doesn't work])
625       VALGRIND=
626     fi
627     rm -f $vglogwild
628   fi
631 if test -n "$VALGRIND" ; then
632   AC_DEFINE([HAVE_VALGRIND], [1], [Define if a suitable valgrind is installed])
635 dnl If eatmydata is installed, we run the testsuite under it to speed it up.
636 dnl If EATMYDATA is set to an empty value, then skip this check and don't use
637 dnl eatmydata.
638 if test -n "${EATMYDATA-unset}" ; then
639   AC_PATH_PROG([EATMYDATA], [eatmydata], [])
642 dnl Checks for library functions.
643 AC_FUNC_MEMCMP
644 AC_FUNC_STRERROR_R
646 AC_CACHE_CHECK([for sys_errlist and sys_nerr], ac_cv_sys_errlist_and_sys_nerr, [
647   AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>]],
648 [[  printf("%s", sys_errlist[sys_nerr - 1]);]])],
649   [ ac_cv_sys_errlist_and_sys_nerr=yes ],
650   [ ac_cv_sys_errlist_and_sys_nerr=no ])
652 if test "x$ac_cv_sys_errlist_and_sys_nerr" = "xyes" ; then
653   AC_DEFINE([HAVE_SYS_ERRLIST_AND_SYS_NERR], [1],[Define if you have 'sys_errlist' and 'sys_nerr'])
656 AC_CACHE_CHECK([for _sys_errlist and _sys_nerr], ac_cv__sys_errlist_and__sys_nerr, [
657   AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>]],
658 [[  printf("%s", _sys_errlist[_sys_nerr - 1]);]])],
659   [ ac_cv__sys_errlist_and__sys_nerr=yes ],
660   [ ac_cv__sys_errlist_and__sys_nerr=no
661   ])
663 if test "x$ac_cv__sys_errlist_and__sys_nerr" = "xyes" ; then
664   AC_DEFINE([HAVE__SYS_ERRLIST_AND__SYS_NERR], [1],[Define if you have '_sys_errlist' and '_sys_nerr'])
667 dnl Check that snprintf actually works as it's meant to.
669 dnl Linux 'man snprintf' warns:
670 dnl  Linux libc4.[45] does not have a snprintf, but provides a libbsd that
671 dnl  contains an snprintf equivalent to sprintf, i.e., one that ignores the
672 dnl  size argument.  Thus, the use of snprintf with early libc4 leads to
673 dnl  serious security problems.
675 dnl It also warns that glibc < 2.0.6 (and presumably other pre-C90
676 dnl implementations) return -1 when truncating so check that we get the
677 dnl ISO C90 semantics for the returned length when truncating.  If we
678 dnl have a working snprintf but with non-ISO return semantics, handle
679 dnl that case separately as it may still be useful in many cases.
681 dnl mingw has _snprintf so check for that too.
682 AC_MSG_CHECKING([for working ISO C90 conforming snprintf])
683 ac_cv_func_snprintf_noniso=no
684 for func in snprintf _snprintf ; do
685   AC_RUN_IFELSE([
686     AC_LANG_PROGRAM(
687       [[
688 #include <cstdio>
689 #include <cstring>
690 using namespace std;
691       ]],
692       dnl Return different exit status for each error so we can see which
693       dnl check failed by consulting config.log.
694       [[
695         char buffer[4] = "abc";
696         int res1 = $func(buffer, 2, "%s", "XYZ");
697         if (memcmp(buffer, "X\0c", 4) != 0) return 2;
698         int res2 = $func(buffer, 2, "%x", 0x12);
699         if (memcmp(buffer, "1\0c", 4) != 0) return 3;
700         if (res1 == -1 && res2 == -1) return 15; /* Pre-ISO semantics. */
701         if (res1 != 3) return 4;
702         if (res2 != 2) return 5;
703       ]]
704     )],
705     [ac_cv_func_snprintf=$func;break],
706     [
707     if test 15no = "$?$ac_cv_func_snprintf_noniso" ; then
708       ac_cv_func_snprintf_noniso=$func
709     fi
710     ac_cv_func_snprintf=no
711     ],
712     [ac_cv_func_snprintf=unknown;break]
713   )
714 done
715 AC_MSG_RESULT([$ac_cv_func_snprintf])
716 case $ac_cv_func_snprintf in
717   no)
718     AC_MSG_CHECKING([for working non-ISO C90 conforming snprintf])
719     AC_MSG_RESULT([$ac_cv_func_snprintf_noniso])
720     if test no != "$ac_cv_func_snprintf_noniso" ; then
721       AC_DEFINE_UNQUOTED([SNPRINTF], [$ac_cv_func_snprintf_noniso],
722         [Define to the name of a function implementing snprintf but not caring about ISO C99 return value semantics (if one exists)])
723     fi
724     ;;
725   unknown)
726     dnl be conservative when crosscompiling
727     ;;
728   *)
729     AC_DEFINE_UNQUOTED([SNPRINTF_ISO], [$ac_cv_func_snprintf],
730        [Define to the name of a function implementing snprintf with ISO C99 semantics (if one exists)])
731     AC_DEFINE_UNQUOTED([SNPRINTF], [$ac_cv_func_snprintf],
732        [Define to the name of a function implementing snprintf but not caring about ISO C99 return value semantics (if one exists)])
733     ;;
734 esac
736 dnl ***************************
737 dnl * Select modules to build *
738 dnl ***************************
740 dnl Check which database backends should be built.
742 AC_DEFUN([XAPIAN_BACKEND_ENABLE],
743   [AC_ARG_ENABLE([backend_$1],
744     [AS_HELP_STRING([--enable-backend-$1], [build the $1 database backend [default=yes]])],
745     [case $enableval in
746       yes|no) ;;
747       *) AC_MSG_ERROR([Invalid option: '--enable-backend-$1=$enableval']) ;;
748     esac], [enable_backend_$1=yes])
749   ])
751 dnl When adding a new backend, update INSTALL too.
752 XAPIAN_BACKEND_ENABLE([glass])
753 XAPIAN_BACKEND_ENABLE([inmemory])
754 XAPIAN_BACKEND_ENABLE([remote])
756 use_proc_for_uuid=0
757 use_win32_uuid_api=0
758 case $enable_backend_glass in
759 *yes*)
760   dnl We use zlib for compressing tags in glass.  We could
761   dnl automatically disable support if zlib isn't found, but overall that
762   dnl probably does more harm than good - it's most likely that someone just
763   dnl forgot to install the -dev package for zlib.
764   dnl
765   dnl Similarly for uuid support.
767   dnl Check for zlib.h.
768   AC_CHECK_HEADERS([zlib.h], [], [
769     AC_MSG_ERROR([zlib.h not found - required for glass (you may need to install the zlib1g-dev or zlib-devel package)])
770     ], [ ])
772   dnl Check for zlibVersion in -lz.
773   SAVE_LIBS=$LIBS
774   dnl mingw build needs -lzlib or -lzdll.
775   AC_SEARCH_LIBS([zlibVersion], [z zlib zdll], [], [
776     AC_MSG_ERROR([zlibVersion() not found in -lz, -lzlib, or -lzdll - required for glass (you may need to install the zlib1g-dev or zlib-devel package)])
777     ])
778   if test x != x"$LIBS" ; then
779     XAPIAN_LIBS="$XAPIAN_LIBS $LIBS"
780   fi
781   LIBS=$SAVE_LIBS
783   dnl Find the UUID library (from e2fsprogs/util-linux-ng, not the OSSP one).
785   case $host_os in
786     *mingw* | *cygwin*) dnl Use built-in API.
787       use_win32_uuid_api=1
788       ;;
789     *)
790       dnl Check for uuid/uuid.h (e2fsprogs/util-linux-ng) or uuid.h
791       dnl (FreeBSD/NetBSD).
792       AC_CHECK_HEADERS([uuid/uuid.h], [
793         dnl util-linux-ng's uuid/uuid.h found - check for uuid_generate in
794         dnl -luuid.
795         SAVE_LIBS=$LIBS
796         AC_SEARCH_LIBS([uuid_generate], [uuid], [], [
797           AC_MSG_ERROR([uuid_generate() not found in -luuid - required for glass (you may need to install the uuid-dev, libuuid-devel or e2fsprogs-devel package)])
798           ])
799         if test x != x"$LIBS" ; then
800           XAPIAN_LIBS="$XAPIAN_LIBS $LIBS"
801         fi
802       ], [
803         dnl Try uuid.h as found on FreeBSD/NetBSD, with associated code in libc.
804         AC_CHECK_HEADERS([uuid.h], [
805           dnl Check for uuid_create with no extra libraries required.
806           AC_CHECK_FUNC([uuid_create], [], [
807             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)])
808           ])
809         ], [
810           dnl Especially useful for Android.
811           AC_MSG_CHECKING([if host platform supports /proc/sys/kernel/random/uuid])
812           case $host_os in
813             linux*)
814               use_proc_for_uuid=1
815               AC_DEFINE([USE_PROC_FOR_UUID], [1],
816                         [Define to 1 to read UUID from '/proc/sys/kernel/random/uuid'])
817               AC_MSG_RESULT([yes])
818               ;;
819             *)
820               AC_MSG_RESULT([no])
821               AC_MSG_ERROR([Failed to find a way to generate UUIDs, required for glass backends (you may need to install the uuid-dev, libuuid-devel or e2fsprogs-devel package)])
822               ;;
823           esac
824         ], [ ])
825       ], [ ])
826       ;;
827   esac
829   dnl Older versions of libuuid (such as that on CentOS 4.7) don't have
830   dnl uuid_unparse_lower(), only uuid_unparse().
831   AC_LINK_IFELSE([AC_LANG_CALL([], [uuid_unparse_lower])],
832     [
833     AC_DEFINE([HAVE_UUID_UNPARSE_LOWER], [1],
834               [Define to 1 if you have the 'uuid_unparse_lower' function.])
835     ])
836   LIBS=$SAVE_LIBS
837   ;;
838 esac
839 AM_CONDITIONAL([USE_PROC_FOR_UUID], [test "$use_proc_for_uuid" = 1])
840 AM_CONDITIONAL([USE_WIN32_UUID_API], [test "$use_win32_uuid_api" = 1])
842 REMOTE_LIBS=
843 if test "$enable_backend_remote" = yes ; then
844   AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
845 #ifdef __WIN32__
846 #error WIN32
847 #endif
848   ]])], [win32=no], [win32=yes])
850   case $host_os-$win32 in
851     *-yes )
852       dnl For mingw and msvc we have an alternative implementation which
853       dnl doesn't need fork() or socketpair().
854       dnl
855       dnl We need -lws2_32 for getaddrinfo(), etc.
856       REMOTE_LIBS=-lws2_32
857       dnl Vista is needed for the AI_ADDRCONFIG flag to getaddrinfo().
858       AC_DEFINE([WINVER], [0x600],
859                 [Version of Windows to assume (0x600 => Vista).])
860       AC_DEFINE([_WIN32_WINNT], [WINVER],
861                 [Version of Windows to assume.])
862       ;;
863     *djgpp* | *msdos* )
864       dnl DJGPP has a dummy implementation of fork which always fails.
865       dnl
866       dnl For disk-based backend, use flock() for locking, which doesn't need
867       dnl fork() or socketpair().
868       AC_DEFINE([FLINTLOCK_USE_FLOCK], 1, [Define to use flock() for flint-compatible locking])
869       dnl If someone actually wanted remote backend support, then DJGPP has a
870       dnl pthreads port, so using threads like we do on Windows would make more
871       dnl sense.
872       enable_backend_remote=no
873       ;;
874     *)
875       dnl On Unix, we need fork and socketpair for the remotebackend.
876       SAVE_LIBS=$LIBS
877       AC_CHECK_FUNCS([fork], [], [
878         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.)])
879       ])
880       dnl Check if -lsocket is required for socketpair (Solaris needs it).
881       dnl And on Haiku it's in -lnetwork.
882       AC_SEARCH_LIBS([socketpair], [socket network], [], [
883         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.)])
884       ])
885       AC_DEFINE([HAVE_SOCKETPAIR], [1],
886                 [Define to 1 if you have the 'socketpair' function.])
887       dnl Check if extra libraries are needed for getaddrinfo or inet_ntop()
888       dnl (e.g. on Solaris).
889       dnl
890       dnl We're currently assuming that any system that is worth trying to
891       dnl support has getaddrinfo() and inet_ntop(), since these are the
892       dnl standard route for supporting IPv6, and that's pretty much essential
893       dnl for platforms to support now.
894       AC_SEARCH_LIBS([getaddrinfo], [nsl socket], [], [
895         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.)])
896       ])
897       AC_SEARCH_LIBS([inet_ntop], [nsl socket], [], [
898         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.)])
899       ])
900       REMOTE_LIBS=$LIBS
901       LIBS=$SAVE_LIBS
902       ;;
903   esac
905   if test "$enable_backend_remote" = yes ; then
906     TYPE_SOCKLEN_T
907     XAPIAN_LIBS="$XAPIAN_LIBS $REMOTE_LIBS"
908   fi
911 AC_ARG_ENABLE([visibility],
912   [AS_HELP_STRING([--disable-visibility], [disable use of GCC visibility])],
913   [case ${enableval} in
914     yes|no) ;;
915     *) AC_MSG_ERROR([bad value ${enableval} for --disable-visibility]) ;;
916   esac])
918 vpath_build=no
919 if test "`pwd`" != "`cd $srcdir;pwd`" ; then
920   vpath_build=yes
922 AM_CONDITIONAL([VPATH_BUILD], [test yes = "$vpath_build"])
924 dnl Turn off compilation of anything that we don't have the requirements for
926 dnl Set conditionals to specify what we compile
928 AM_CONDITIONAL([BUILD_BACKEND_GLASS], [test yes = "$enable_backend_glass"])
929 AM_CONDITIONAL([BUILD_BACKEND_INMEMORY], [test yes = "$enable_backend_inmemory"])
930 AM_CONDITIONAL([BUILD_BACKEND_REMOTE], [test yes = "$enable_backend_remote"])
931 AM_CONDITIONAL([BUILD_BACKEND_TOOLS],
932   [test no != "$enable_backend_glass"])
934 dnl Used to decide if we should use the zlib-vg.so LD_PRELOAD hack.
935 use_zlib_vg=no
936 if test -n "$VALGRIND" ; then
937   case $host_os in
938     linux*) use_zlib_vg=yes ;;
939   esac
941 AM_CONDITIONAL([USE_ZLIB_VG], [test yes = "$use_zlib_vg"])
943 dnl See if we have fdatasync, and what libraries are needed for it.
944 dnl We need to actually check for a declaration as OS X has a dummy
945 dnl implementation in the library which is not prototyped in any header.
946 AC_CHECK_DECL([fdatasync(int)], [
947   SAVE_LIBS=$LIBS
948   AC_SEARCH_LIBS([fdatasync], [rt], [XAPIAN_LIBS="$LIBS $XAPIAN_LIBS"])
949   LIBS=$SAVE_LIBS
950   AC_CHECK_FUNCS([fdatasync])
951   ],
952   [ac_cv_func_fdatasync=no],
953   [#include <unistd.h>]
956 AC_CHECK_FUNCS([fsync])
957 AC_CHECK_FUNCS([posix_fadvise])
958 AC_CHECK_FUNCS([ftruncate])
960 dnl HP-UX has pread and pwrite, but they don't work!  Apparently this problem
961 dnl manifests when largefile support is enabled, and we definitely want that
962 dnl so don't use pread or pwrite on HP-UX.
963 case $host_os in
964   hpux*)
965     AC_MSG_CHECKING([for pread])
966     AC_MSG_RESULT([present but broken on $host_os])
967     AC_MSG_CHECKING([for pwrite])
968     AC_MSG_RESULT([present but broken on $host_os])
969     ;;
970   *)
971     AC_CHECK_FUNC([pread],
972        [AC_DEFINE([HAVE_PREAD], [1],
973             [Define if pread is available on this system])
974         AC_MSG_CHECKING([for any prototype needed for pread])
975         AC_CACHE_VAL([xo_cv_pread_prototype],
976           [
977             for p in ' ' \
978               'extern "C" ssize_t pread(int, void *, size_t, off_t) throw ();' \
979               'extern "C" ssize_t pread(int, void *, size_t, off_t);' ; do
980               AC_TRY_COMPILE([
981 #include <sys/types.h>
982 #include <unistd.h>
984               ],[
985                 char b[256];
986                 pread(1, b, 256, 20);
987               ],[
988                 xo_cv_pread_prototype="$p"
989                 break
990               ])
991             done
992             if test -z "$xo_cv_pread_prototype"; then
993               AC_MSG_RESULT([not found])
994               AC_MSG_ERROR([Failed to find working prototype for pread])
995             fi
996           ])
997           if test " " = "$xo_cv_pread_prototype" ; then
998             AC_MSG_RESULT([none required])
999           else
1000             AC_MSG_RESULT([$xo_cv_pread_prototype])
1001             AC_DEFINE_UNQUOTED([PREAD_PROTOTYPE], [$xo_cv_pread_prototype],
1002                                [explicit prototype needed for pread (if any)])
1003           fi
1004         ])
1005     AC_CHECK_FUNC([pwrite],
1006        [AC_DEFINE([HAVE_PWRITE], [1],
1007             [Define if pwrite is available on this system])
1008         AC_MSG_CHECKING([for any prototype needed for pwrite])
1009         AC_CACHE_VAL([xo_cv_pwrite_prototype],
1010           [
1011             for p in ' ' \
1012               'extern "C" ssize_t pwrite(int, const void *, size_t, off_t) throw ();' \
1013               'extern "C" ssize_t pwrite(int, const void *, size_t, off_t);' ; do
1014               AC_TRY_COMPILE([
1015 #include <sys/types.h>
1016 #include <unistd.h>
1018               ],[
1019                 const char *p = "hello";
1020                 pwrite(1, p, 5, 20);
1021               ],[
1022                 xo_cv_pwrite_prototype="$p"
1023                 break
1024               ])
1025             done
1026             if test -z "$xo_cv_pwrite_prototype"; then
1027               AC_MSG_RESULT([not found])
1028               AC_MSG_ERROR([Failed to find working prototype for pwrite])
1029             fi
1030           ])
1031           if test " " = "$xo_cv_pwrite_prototype" ; then
1032             AC_MSG_RESULT([none required])
1033           else
1034             AC_MSG_RESULT([$xo_cv_pwrite_prototype])
1035             AC_DEFINE_UNQUOTED([PWRITE_PROTOTYPE], [$xo_cv_pwrite_prototype],
1036                                [explicit prototype needed for pwrite (if any)])
1037           fi
1038         ])
1039     ;;
1040 esac
1042 AC_CHECK_FUNCS([link])
1044 dnl *************************
1045 dnl * Set debugging options *
1046 dnl *************************
1048 dnl Which assertion types to enable in the code.
1050 AC_ARG_ENABLE([assertions],
1051   [AS_HELP_STRING([--enable-assertions], [enable debug assertions (no|partial|yes) [default=no]])],
1052   [case $enableval in
1053     yes|partial|no) ;;
1054     *)
1055       AC_MSG_ERROR([Invalid option: '--enable-assertions=$enableval']) ;;
1056   esac])
1058 AC_ARG_ENABLE([log],
1059   [AS_HELP_STRING([--enable-log], [generate a log of methods called, etc (no|yes|profile) [default=no]])],
1060   [case $enableval in
1061     yes|no) ;;
1062     profile)
1063       AC_MSG_ERROR(['--enable-log=profile' is no longer supported - see https://trac.xapian.org/wiki/ProfilingXapian for alternatives.]) ;;
1064     *)
1065       AC_MSG_ERROR([Invalid option: '--enable-log=$enableval']) ;;
1066   esac])
1068 dnl Set defines according to the --enable-assertions and --enable-log options
1069 dnl given.
1071 if test yes = "$enable_assertions" || test partial = "$enable_assertions" ; then
1072   AC_DEFINE([XAPIAN_ASSERTIONS],,
1073     [Define if you want assertions (causes some slow-down)])
1076 if test yes = "$enable_assertions"; then
1077   AC_DEFINE([XAPIAN_ASSERTIONS_PARANOID],,
1078     [Define if you want paranoid assertions (causes significant slow-down)])
1081 if test yes = "$enable_log"; then
1082   AC_DEFINE([XAPIAN_DEBUG_LOG],,
1083     [Define if you want a log of methods called and other debug messages])
1086 dnl ******************************
1087 dnl * Set special compiler flags *
1088 dnl ******************************
1090 dnl Set flags to control warnings (enable more, or disable annoying ones).
1091 dash_d_visibility=
1092 if test yes = "$GXX"; then
1093   dnl Intel's C++ compiler and clang both lie and define __GNUC__, so check which
1094   dnl we actually have, as neither is really 100% compatible.
1095   case `echo __INTEL_COMPILER __clang__|$CXX -E - 2>&AS_MESSAGE_LOG_FD|grep -v '^#'` in
1096     *__INTEL_COMPILER*__clang__*)
1097       dnl GCC (since neither substituted):
1099       dnl The exact format of g++ --version seems to change with almost every
1100       dnl minor release so use the preprocessor macros which should be more
1101       dnl robust.
1102       AC_MSG_CHECKING([for version of $CXX])
1103       gxx_version=`echo __GNUC__.__GNUC_MINOR__.__GNUC_PATCHLEVEL__|$CXX -E -|sed '/^#/d;s/ //g'`
1104       AC_MSG_RESULT([GCC $gxx_version])
1106       case $gxx_version in
1107       [[0123]].*|4.[[0-7]].*)
1108         AC_MSG_ERROR([Xapian requires GCC 4.8 or later])
1109         ;;
1110       esac
1112       dnl -Wundef was supported by g++ 3.0.
1113       dnl
1114       dnl -Wlogical-op and -Wmissing-declarations (for C++) were added in
1115       dnl GCC 4.3.
1116       dnl
1117       dnl -Wdouble-promotion was added in GCC 4.6.
1118       dnl
1119       dnl -Winit-self was added in GCC 3.4, but for GCC < 4.7 g++ always
1120       dnl warns for this case with -Wuninitialized (implied by -W).  We
1121       dnl don't intend to use this idiom, so any instances are bugs we'd
1122       dnl like to know about.
1123       dnl
1124       dnl All the other options were supported by g++ 2.95.
1125       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"
1127       dnl FIXME:
1128       dnl -Wconversion in older GCC versions is intended to help migration
1129       dnl from K&R to ISO C, and isn't useful for us.  In 4.3 it was renamed
1130       dnl to -Wtraditional-conversion and a new -Wconversion added which
1131       dnl sounds useful but is a bit buggy currently.  So we should consider
1132       dnl enabling -Wconversion once it is stabilised (GCC 4.4 or ...)
1133       dnl
1134       dnl -Wold-style-cast is interesting, but triggers for macros from
1135       dnl system headers (e.g. FD_SET).  GCC 4.8 improved this by making
1136       dnl -ftrack-macro-expansion=2 the default, but we still see such
1137       dnl warnings on some platforms for some reason (e.g. Cygwin with GCC
1138       dnl 5.4.0 warns about FD_SET, and on Debian with GCC 4.9.2 we see
1139       dnl warnings from zlib.h).
1141       dnl Automatically add -Werror if maintainer mode is enabled.
1142       if test x$USE_MAINTAINER_MODE = xyes; then
1143         AM_CXXFLAGS="$AM_CXXFLAGS -Werror"
1144       fi
1145       ;;
1146     *__clang__*)
1147       dnl Intel's compiler (since __clang__ not substituted):
1148       dnl
1149       dnl -w1 stops the avalanche of uninteresting "remark" messages.
1150       dnl -wd... disables warnings which don't have good code workarounds.
1151       AM_CXXFLAGS="$AM_CXXFLAGS -Wall -w1 -wd177,1572"
1153       dnl Automatically add -Werror if maintainer mode is enabled.
1154       if test x$USE_MAINTAINER_MODE = xyes; then
1155         AM_CXXFLAGS="$AM_CXXFLAGS -Werror"
1156       fi
1157       ;;
1158     *__INTEL_COMPILER*)
1159       dnl clang (since __INTEL_COMPILER not substituted):
1161       dnl These options all work at least as far back as clang++ 3.0:
1162       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"
1164       dnl Automatically add -Werror if maintainer mode is enabled.
1165       if test x$USE_MAINTAINER_MODE = xyes; then
1166         AM_CXXFLAGS="$AM_CXXFLAGS -Werror"
1167       fi
1168       ;;
1169   esac
1171   if test no != "$enable_visibility"; then
1172     dnl GCC doesn't support symbol visibility on all platforms (e.g. it isn't
1173     dnl on mingw).
1174     AC_MSG_CHECKING([if $CXX -fvisibility=hidden works])
1175     if echo 'int bar() __attribute__((visibility("default"))); int foo() {return 42;}'|$CXX -Werror -fvisibility=hidden -c -oconftest.o -xc++ - >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD ; then
1176       AC_MSG_RESULT([yes])
1177       AM_CXXFLAGS="$AM_CXXFLAGS -fvisibility=hidden"
1178       dash_d_visibility=-DXAPIAN_ENABLE_VISIBILITY
1179     else
1180       AC_MSG_RESULT([no])
1181     fi
1182   fi
1183 else
1184   dnl Not GCC, nor a compiler masquerading as GCC.
1185   case /$CXX in
1186   */aCC)
1187     dnl +w turns on more warnings.
1188     dnl +wlint turns on "lint-like" warnings.
1189     dnl +W<n1>,<n2>,... suppresses warnings n1, n2, ...
1190     dnl 2340 (remark) "value copied to temporary, reference to temporary
1191     dnl use", in: throw Xapian::UnimplementedError("...");
1192     dnl 2401 "destructor for base class ... is non-virtual" (we don't need a
1193     dnl virtual destructor for intrusive_base, since we never delete
1194     dnl       its subclasses by a intrusive_base *).
1195     dnl 3348 "declaration hides constant ..." which seems to misfire!
1196     dnl 4255 (remark) "padding size of struct "..." with ... bytes to
1197     dnl alignment boundary".
1198     dnl 4273 "floating-point equality and inequality comparisons may be
1199     dnl inappropriate due to roundoff common in floating-point computation"
1200     dnl No obvious workaround for when you really do want == or !=.
1201     dnl 4285 "operator= does not have a check for the source and destination
1202     dnl addresses being non-identical" - fires for AutoPtr which
1203     dnl includes such a check indirectly (internaltest's autoptr1 check this).
1204     dnl 20201 "Memory leak is detected" which triggers for "return new Foo;"!
1205     AM_CXXFLAGS="$AM_CXXFLAGS +w +wlint +W2340,2401,3348,4255,4273,4285,20201" ;;
1206   */sunCC|*/CC)
1207     dnl Sun's C++ compiler warns about functions failing to return a value even
1208     dnl when the function ends with a "throw" statement.  That's just unhelpful
1209     dnl noise, and adding a dummy "return" after "throw" seems a worse solution
1210     dnl than simply disabling this warning - any genuinely missing return
1211     dnl statements will get reported by compilers with superior warning
1212     dnl machinery.
1213     XAPIAN_TEST_CXXFLAGS([-erroff=voidretw], [AM_CXXFLAGS])
1214     ;;
1215   esac
1218 XAPIAN_TEST_LINKER_FLAG([-Bsymbolic-functions], [symbolic_functions],
1219   [XAPIAN_LDFLAGS="$XAPIAN_LDFLAGS $flag"])
1221 FP_EXCESS_PRECISION=no
1222 AC_MSG_CHECKING([whether to use SSE instructions on x86])
1223 case $host_cpu in
1224   i*86)
1225     if test "$enable_sse" = no ; then
1226       AC_MSG_RESULT([no])
1227       FP_EXCESS_PRECISION=yes
1228     else
1229       dnl Default to sse2.
1230       test "$enable_sse" != yes || enable_sse=sse2
1231       if test yes = "$GXX"; then
1232         AC_MSG_RESULT([yes (configure with --disable-sse to disable)])
1233         dnl We can unconditionally use -mtune=generic as it was added in GCC
1234         dnl 4.2, and supported at least as far back as clang 3.0.
1235         AM_CXXFLAGS="$AM_CXXFLAGS -mfpmath=sse -m$enable_sse -mtune=generic"
1236       else
1237         AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
1238 [[#ifndef __SUNPRO_CC
1239 #error Not Sun compiler
1240 #endif]])],
1241           [AC_MSG_RESULT([yes (configure with --disable-sse to disable)])
1242           AM_CXXFLAGS="$AM_CXXFLAGS -xarch=$enable_sse"]
1243           ,
1244           [AC_MSG_RESULT([don't know how to for compiler $CXX])
1245           FP_EXCESS_PRECISION=yes]
1246         )
1247       fi
1248     fi
1249     ;;
1250   *)
1251     AC_MSG_RESULT([non-x86 arch ($host_cpu)]) ;;
1252 esac
1253 AC_SUBST([FP_EXCESS_PRECISION])
1255 AH_BOTTOM(
1256 [/* Disable stupid MSVC "performance" warning for converting int to bool. */
1257 #ifdef _MSC_VER
1258 # pragma warning(disable:4800)
1259 #endif
1261 /* _FORTIFY_SOURCE is only supported by GCC >= 4.1 and glibc >= 2.3.4, but it
1262  * shouldn't cause a problem to define it where it's not supported and some
1263  * distros may have backported support, so hardcoding version checks is
1264  * counter-productive.
1266  * Check if _FORTIFY_SOURCE is already defined to allow the user to override
1267  * our choice with "./configure CPPFLAGS=-D_FORTIFY_SOURCE=0" or "...=1".
1268  */
1269 #if defined __GNUC__ && !defined _FORTIFY_SOURCE
1270 # define _FORTIFY_SOURCE 2
1271 #endif
1273 /* For compilers which support it (such as GCC, clang, Intel's C++ compiler)
1274  * we can use __builtin_expect to give the compiler hints about branch
1275  * prediction.  See HACKING for how to use these.
1276  */
1277 #if HAVE_DECL___BUILTIN_EXPECT
1278 /* The arguments of __builtin_expect() are both long, so use !! to ensure that
1279  * the first argument is always an integer expression, and always 0 or 1, but
1280  * still has the same truth value for the if or while it is used in.
1281  */
1282 # define rare(COND) __builtin_expect(!!(COND), 0)
1283 # define usual(COND) __builtin_expect(!!(COND), 1)
1284 #else
1285 # define rare(COND) (COND)
1286 # define usual(COND) (COND)
1287 #endif
1289 /* Signal we're building the library so it's OK to include headers such as
1290  * xapian/query.h directly.
1291  */
1292 #define XAPIAN_LIB_BUILD 1
1294 /* With Sun CC 5.13 (Studio 12.4) on Solaris 11.2, <math.h> seems to get
1295  * implicitly included somehow before <cmath>, and compilation fails due
1296  * to 'std::exception' colliding with 'struct exception'.  It's not clear
1297  * how to avoid this, so just define the making macro which <cmath> does
1298  * before it includes <math.h>.
1299  */
1300 #ifdef __SUNPRO_CC
1301 # define __MATHERR_RENAME_EXCEPTION
1302 #endif
1305 AC_SUBST([AM_CXXFLAGS])
1307 dnl Restore CXXFLAGS to those the user specified or autoconf defaulted to.
1308 CXXFLAGS=$save_CXXFLAGS
1310 dnl Required for auto regeneration to work in a combined maintainer-mode tree.
1311 : ${AUTOM4TE=autom4te}
1312 AC_SUBST([AUTOM4TE])
1314 dnl Libtool sets this (to yes|no|unknown) and we use it in xapian-config.
1315 AC_SUBST([link_all_deplibs_CXX])
1317 dnl Shared library extension.
1318 module=no
1319 eval "SHLIBEXT=$shrext_cmds"
1320 AC_SUBST([SHLIBEXT])
1322 dnl We want to be able to use GNU make % pattern rules in maintainer targets
1323 dnl but automake warns these aren't portable, so we substitute the % to avoid
1324 dnl this warning.
1325 PERCENT='%'
1326 AC_SUBST([PERCENT])
1328 dnl Split up the version number into "MAJOR.MINOR.REVISION".
1329 MAJOR_VERSION=`echo "$VERSION"|sed 's/\..*//'`
1330 [MINOR_VERSION=`echo "$VERSION"|sed 's/[^.]*\.//;s/\..*//'`]
1331 [REVISION=`echo "$VERSION"|sed 's/.*\.//;s/_.*$//'`]
1333 dnl **************************
1334 dnl * Build the output files *
1335 dnl **************************
1337 AC_CONFIG_FILES([
1338  Makefile
1339  tests/Makefile
1340  docs/Makefile
1341  docs/doxygen_api.conf
1342  docs/doxygen_source.conf
1343  xapian-core.spec
1344  cmake/xapian-config.cmake
1345  cmake/xapian-config-version.cmake
1346  pkgconfig/xapian-core"$LIBRARY_VERSION_SUFFIX".pc:pkgconfig/xapian-core.pc.in
1347  ])
1348 AC_CONFIG_FILES([tests/runtest], [chmod +x tests/runtest])
1349 AC_CONFIG_FILES([tests/runsrv], [chmod +x tests/runsrv])
1350 AC_CONFIG_FILES([tests/submitperftest], [chmod +x tests/submitperftest])
1351 AC_CONFIG_FILES([tests/perftest/get_machine_info], [chmod +x tests/perftest/get_machine_info])
1352 AC_CONFIG_FILES([xapian-config], [chmod +x xapian-config])
1353 AC_CONFIG_FILES([makemanpage], [chmod +x makemanpage])
1354 AC_OUTPUT
1356 dnl There are no files generated by AC_OUTPUT in the following directories
1357 dnl and we need to ensure they exist so that the rest of configure or make
1358 dnl won't fail because they don't exist when srcdir != builddir.
1359 if test yes = "$vpath_build" ; then
1360   for dir in include/xapian languages queryparser ; do
1361     AS_MKDIR_P(["$dir"])
1362   done
1365 dnl Generate include/xapian/version.h:
1367 dnl MAIN_VERSION is VERSION without any _git123 suffix.
1368 MAIN_VERSION="$MAJOR_VERSION.$MINOR_VERSION.$REVISION"
1369 cxxcpp_flags=-I.
1370 for backend in GLASS INMEMORY REMOTE ; do
1371   val=`eval echo "\\\$BUILD_BACKEND_${backend}_TRUE"`
1372   if test -z "$val" ; then
1373     cxxcpp_flags="$cxxcpp_flags -DXAPIAN_HAS_${backend}_BACKEND"
1374   fi
1375 done
1377 if test yes = "$enable_64bit_docid" ; then
1378   cxxcpp_flags="$cxxcpp_flags -DXAPIAN_DOCID_BASE_TYPE="`echo "$INT64_T"|sed 's/ /____/g'`
1379 else
1380   cxxcpp_flags="$cxxcpp_flags -DXAPIAN_DOCID_BASE_TYPE="`echo "$INT32_T"|sed 's/ /____/g'`
1383 if test yes = "$enable_64bit_termcount" ; then
1384   cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TERMCOUNT_BASE_TYPE="`echo "$INT64_T"|sed 's/ /____/g'`
1385 else
1386   cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TERMCOUNT_BASE_TYPE="`echo "$INT32_T"|sed 's/ /____/g'`
1389 dnl Make revision numbers in the API 64 bit for future-proofing.
1390 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_REVISION_TYPE="`echo "unsigned $INT64_T"|sed 's/ /____/g'`
1392 dnl For GCC (and compilers which pretend to be GCC) and MSVC, we create some
1393 dnl ABI checks in the generated version.h, and $CXXFLAGS may contain options
1394 dnl which affect the ABI (e.g. -fabi-version for GCC) so we want to use these
1395 dnl options when generating version.h.  For these compilers, CXXCPP="$CXX -E"
1396 dnl so it should understand all compiler options.
1398 dnl For other compilers, we only pass $CPPFLAGS to $CXXCPP in case it's an
1399 dnl external cpp which doesn't understand flags which might be in $CXXFLAGS.
1400 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[#ifndef __GNUC__
1401 #ifndef _MSC_VER
1402        choke me
1403 #endif
1404 #endif
1405 ]])],
1406         [cxxcpp_flags="$cxxcpp_flags $CPPFLAGS $CXXFLAGS"],
1407         [cxxcpp_flags="$cxxcpp_flags $CPPFLAGS"])
1408 rm -f include/xapian/version.h.tmp
1409 dnl "\r" in sed is a GNUism, but we only need to remove it on MS Windows
1410 dnl where we'll always have GNU sed, and other sed's will just interpret
1411 dnl it as "r" (Solaris sed) or maybe literal "\r" which won't match.
1413 dnl Use @@ around $MAIN_VERSION so we get " in the final output.
1414 $CXXCPP $cxxcpp_flags\
1415         -DSTRING_VERSION="\"@@$MAIN_VERSION@@\""\
1416         -DMAJOR_VERSION="\"$MAJOR_VERSION\""\
1417         -DMINOR_VERSION="\"$MINOR_VERSION\""\
1418         -DREVISION="\"$REVISION\""\
1419         $dash_d_visibility\
1420         $srcdir/include/xapian/version_h.cc|\
1421         ${SED-sed} '/"/!d;s/^ *//;/^#/d;s/ *$//;s/" *,//;s/"//g;s/@@/"/g;s/  */ /g;s/ *,\r$//;s/ *,$//;s/____/ /g;s/\\\\$/\\/'\
1422         > include/xapian/version.h.tmp
1423 dnl Only update the file if it has changed, so we don't alter the timestamp
1424 dnl and cause lots of rebuilding needlessly.  However, the build system
1425 dnl needs a timestamp to know when to regenerate version.h because version_h.cc
1426 dnl has changed so we use a separate timestamp file.
1427 touch include/xapian/version.h.timestamp
1428 if cmp include/xapian/version.h.tmp include/xapian/version.h >/dev/null 2>&1
1429 then
1430   rm include/xapian/version.h.tmp
1431 else
1432   mv include/xapian/version.h.tmp include/xapian/version.h