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