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