Make TradWeight a simple subclass and deprecate
[xapian.git] / xapian-core / configure.ac
blob04074aa1910711b1f93daab0dc7f33781e2bb73d
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.13 -Wportability tar-ustar no-dist-gzip dist-xz std-options])
95 AC_CONFIG_SRCDIR([matcher/andpostlist.cc])
97 AC_CONFIG_HEADERS([config.h])
99 AC_CONFIG_MACRO_DIRS([m4])
101 AM_PROG_AR
103 dnl Use libtool to manage our libraries.
104 LT_PREREQ([2.2.8])
105 dnl Default to only building shared libraries.
107 dnl Building both shared and static means having to compile the files which
108 dnl make up the library twice on most platforms.  Shared libraries are the
109 dnl better option for most users, and if anyone really wants static libraries,
110 dnl they can configure with --enable-static (or --enable-static=xapian-core if
111 dnl configuring a combined tree with the bindings).
113 dnl We don't export any data items from the library, so it should be safe to
114 dnl enable win32-dll without decorating any declarations specially.
115 LT_INIT([disable-static win32-dll])
117 dnl Only pass -no-undefined on platforms where it is required in order to link
118 dnl a shared library at all (Microsoft Windows is the main one) as it can cause
119 dnl problems on other platforms (e.g. Solaris with Sun CC in C++11 mode, though
120 dnl we don't support that compiler now as it lacks C++17 support).
121 NO_UNDEFINED=
122 if test unsupported = "$allow_undefined_flag" ; then
123   NO_UNDEFINED=-no-undefined
125 AC_SUBST(NO_UNDEFINED)
127 AM_CXXFLAGS=
129 dnl A standard "gotcha" for mingw and cygwin users is to not set up their
130 dnl PATH correctly, so that MSDOS FIND.EXE is found before Unix find.  Help
131 dnl them out by checking for this condition, rather than letting libtool
132 dnl fail in obscure ways.  NB check the *BUILD* OS, not the host one!
133 case $build_os in
134   cygwin* | mingw* | msys* | pw32*)
135     find /dirunlikelytoexist >/dev/null 2>&1
136     if test $? = 2 ; then
137         dnl Unix find will return 1 if the directory didn't exist, or 0 if
138         dnl it did.
139         AC_MSG_ERROR([
140 *** You appear to have an MSDOS-like FIND.EXE in your PATH ahead of any
141 *** UNIX-like find.  This misconfiguration will confuse libtool - you'll need
142 *** to make sure you have a UNIX-like find installed and fix your PATH, then
143 *** rerun configure.  For more information, see:
145 ***   https://www.cygwin.com/faq/faq.html#faq.using.find
147     fi
148   ;;
149 esac
151 dnl Add parameters for aclocal
152 dnl (This must come after AM_INIT_AUTOMAKE, since it modifies ACLOCAL)
153 ACLOCAL="$ACLOCAL $ACLOCAL_FLAGS"
155 dnl disable "maintainer only" rules by default
156 AM_MAINTAINER_MODE
158 dnl Checks for programs.
159 AC_PROG_CXX
161 AC_CANONICAL_HOST
163 # Checked: dragonfly6.4 freebsd8.0 netbsd9.3 openbsd4.6 solaris2.9 solaris2.10
164 case $host_os in
165   linux* | k*bsd*-gnu | dragonfly* | freebsd* | netbsd* | openbsd* | solaris*)
166     dnl Vanilla libtool sets this to "unknown" which it then handles as "yes".
167     link_all_deplibs_CXX=no
168     ;;
169 esac
171 case $host_os in
172   linux*)
173     dnl Extract search path from ldconfig which is more reliable than the way
174     dnl vanilla libtool extracts them from ld.so.conf.
175     d=`/sbin/ldconfig -N -X -v 2>&AS_MESSAGE_LOG_FD|$SED 's,^\(/.*\):\( (.*)\)\?$,\1,p;d'|tr '\n' ' '`
176     test -z "$d" || sys_lib_dlsearch_path_spec=$d
177     ;;
178 esac
180 case $host in
181   *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
182     dnl On these platforms, libtool emits a warning if -no-install is passed,
183     dnl and uses -no-fast-install instead - the least ugly way to avoid that
184     dnl warnings seems to be to duplicate the above list of platforms from
185     dnl libtool and use -no-fast-install on them directly.
186     NO_INSTALL=-no-fast-install ;;
187   *)
188     NO_INSTALL=-no-install ;;
189 esac
190 AC_SUBST([NO_INSTALL])
192 dnl For reasons which are beyond me, if autoconf can't find a C++ compiler
193 dnl it will set CXX to g++ (which obviously won't work) rather than actually
194 dnl telling the user that it couldn't find a C++ compiler and telling them
195 dnl to either install one or set CXX if there's one configure failed to find.
196 dnl It's probably worthwhile checking that the C++ compiler actually works
197 dnl anyway!
198 if test -n "$CXX" ; then
199   AC_LANG([C++])
200   AC_MSG_CHECKING([whether $CXX is a working C++ compiler])
201   AC_CACHE_VAL([xo_cv_cxx_works],
202     [
203     AC_RUN_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
204                   [xo_cv_cxx_works=yes],
205                   [xo_cv_cxx_works=no],
206                   [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
207                                   [xo_cv_cxx_works=yes],
208                                   [xo_cv_cxx_works=no])])
209     ])
210   AC_MSG_RESULT([$xo_cv_cxx_works])
211 else
212   xo_cv_cxx_works=no
214 if test no = "$xo_cv_cxx_works" ; then
215   case $original_CXX in
216   CCC=*)
217     dnl CCC is handled in a slightly odd way - if its value isn't an
218     dnl executable (taking PATH into account) then it is ignored!
219     test "$original_CXX" = "CCC=$CXX" || original_CXX=
220     ;;
221   esac
222   if test -z "$original_CXX" ; then
223   AC_MSG_ERROR([
224 *** You need a working C++ compiler to compile Xapian, but configure failed to
225 *** find one.  If you have a working C++ compiler, you can tell configure where
226 *** to find it by invoking it like so:
228 ***   ./configure CXX=/opt/bin/c++
230   else
231   AC_MSG_ERROR([
232 *** You need a working C++ compiler to compile Xapian, but the compiler you
233 *** specified (with '$original_CXX') doesn't appear to be able to successfully
234 *** compile and link a simple program.
236   fi
239 dnl Probe for C++ standards version selection options.  We need at least C++17
240 dnl support, but enable support for a newer standards version if the compiler
241 dnl supports it since then we can conditionally make use of newer features.
242 AX_CXX_COMPILE_STDCXX([23], [], [optional])
243 if test "$HAVE_CXX23" = 0 ; then
244   AX_CXX_COMPILE_STDCXX([20], [], [optional])
245   if test "$HAVE_CXX20" = 0 ; then
246     AX_CXX_COMPILE_STDCXX([17])
247   fi
250 dnl We don't use a C compiler to compile Xapian's code, but on some platforms
251 dnl (e.g. mingw) libtool uses $LTCC which defaults to $CC, and it's also use to
252 dnl build auxiliary tools like snowball and lemon.
253 AC_PROG_CC
255 dnl Check endianness.
256 AC_C_BIGENDIAN
258 dnl We want a non-cross-compiling C compiler for building lemon with.
259 if test -z "$CC_FOR_BUILD" ; then
260   if test yes = "$cross_compiling"; then
261     CC_FOR_BUILD=cc
262   else
263     CC_FOR_BUILD="$CC"
264   fi
266 AC_ARG_VAR([CC_FOR_BUILD], [C compiler command for native compilation (needed to compile build tools during cross-builds)])
268 dnl Run tests using the C++ compiler.
269 AC_LANG([C++])
271 dnl Enable large file support if possible.
272 AC_SYS_LARGEFILE
273 dnl With xlC on AIX, -D_LARGE_FILES changes the ABI of std::string, so it
274 dnl also needs to be used when compiling user code.
275 abi_affecting_cxxflags=
276 if $GREP '^#define _LARGE_FILES 1$' confdefs.h > /dev/null 2>&1 ; then
277   abi_affecting_cxxflags=-D_LARGE_FILES
279 AC_SUBST([abi_affecting_cxxflags])
281 AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
282 #if defined __WIN32__ || defined _WIN32
283 #error WIN32
284 #endif
285 ]])], [win32=no], [win32=yes])
287 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
288 #ifdef _MSC_VER
289 #error MSVC
290 #endif
291 ]])], [msvc=no], [msvc=yes])
293 XAPIAN_LDFLAGS=
294 XAPIAN_LIBS=
295 AC_SUBST([XAPIAN_LDFLAGS])
296 AC_SUBST([XAPIAN_LIBS])
298 xo_fn_unknown_option_check() {
299   dnl Some compilers don't error out on unknown options which unhelpfully
300   dnl means we would think the option is supported, use it, and end up
301   dnl with a warning or note diagnostic every time we use the option.
302   dnl
303   dnl Check compiler stderr for known strings:
304   dnl * MSVC: Command line warning D9002 : ignoring unknown option '...'
305   dnl * MSVC: LINK : warning LNK4044: unrecognized option '...'; ignored
306   dnl * icc strings cribbed from automake's depend.m4
307   $GREP 'ignoring unknown option' conftest.err >/dev/null 2>&1 ||
308       $GREP 'unrecognized option' conftest.err >/dev/null 2>&1 ||
309       $GREP 'ignoring option' conftest.err >/dev/null 2>&1 ||
310       $GREP 'not supported' conftest.err >/dev/null 2>&1 ||
311       return 1
312   return 0
315 AC_DEFUN([XAPIAN_TEST_FLAGS_],
316   [
317   m4_define([cachevar],
318             [xo_cv_]m4_tolower(m4_bpatsubst([$1][_$3], [[^A-Za-z0-9]], [_])))
319   AC_CACHE_CHECK([for $CXX with $3 in $1], cachevar,
320     [
321     XTF_save_$1=${$1}
322     $1="${$1} $3"
323     $2([AC_LANG_PROGRAM([], [])],
324       [if xo_fn_unknown_option_check ; then
325          cachevar=no
326        else
327          cachevar=yes
328        fi],
329       [cachevar=no])
330     $1=$XTF_save_$1
331     if test "$cachevar" = yes ; then
332       $4="${$4} $3"
333       $5
334     else :
335       $6
336     fi
337     ])
338   ])
340 dnl Test if compiling works with $1 added to CXXFLAGS; if it does, add $1 to
341 dnl variable $2.  If the test passes, also do $3; if it fails, also do $4.
342 AC_DEFUN([XAPIAN_TEST_CXXFLAGS],
343   [XAPIAN_TEST_FLAGS_([CXXFLAGS], [AC_COMPILE_IFELSE], [$1], [$2], [$3], [$4])])
345 dnl Test if linking works with $1 added to LDFLAGS; if it does, add $1 to
346 dnl variable $2.  If the test passes, also do $3; if it fails, also do $4.
347 AC_DEFUN([XAPIAN_TEST_LDFLAGS],
348   [XAPIAN_TEST_FLAGS_([LDFLAGS], [AC_LINK_IFELSE], [$1], [$2], [$3], [$4])])
350 dnl Preserve the default CXXFLAGS.
351 save_CXXFLAGS=$CXXFLAGS
353 dnl x86 has excess precision issues with 387 FP instructions, which are
354 dnl avoided by using SSE instructions instead.  This is also faster (~6% in
355 dnl a CPU bound testcase).
356 AC_ARG_ENABLE([sse],
357 [AS_HELP_STRING([--disable-sse],
358                 [disable use of SSE FP instructions on x86])]
359 [AS_HELP_STRING([[--enable-sse[=sse|sse2]]],
360                 [set which SSE FP instructions to use on x86 (default: sse2)])],
361   [case ${enableval} in
362     sse|sse2|yes|no) ;;
363     *) AC_MSG_ERROR([bad value ${enableval} for --enable-sse or --disable-sse]) ;;
364   esac],
365   [enable_sse=yes])
367 dnl The maths functions we use include: exp log ceil fabs sqrt
368 AC_MSG_CHECKING([if -lm is required for maths functions])
369 dnl Don't use constant arguments as the compiler might simply evaluate the
370 dnl whole expression at compile time, and it might inline certain functions
371 dnl so test several functions.  Also write results using printf() so that
372 dnl the compiler can't optimise away the computations.
373 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <cmath>
374 #include <cstdio>
375 #include <ctime>
376 using namespace std;]], [[
377   double a = log(ceil(time(NULL)/7.0));
378   printf("%f %f %f\n", a, sqrt(a), exp(fabs(a - 12345.6)));
379   ]])], [AC_MSG_RESULT([no])], [
380     LIBS="-lm $LIBS"
381     AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <cmath>
382 #include <cstdio>
383 #include <ctime>
384 using namespace std;]], [[
385   double a = log(ceil(time(NULL)/7.0));
386   printf("%f %f %f\n", a, sqrt(a), exp(fabs(a - 12345.6)));]])],
387         [AC_MSG_RESULT([yes])],
388         [AC_MSG_ERROR([Failed to link a C++ program using <cmath>])
389     ])
392 dnl exp10() is a GNU libc extension.
393 AC_CHECK_DECLS([exp10(double)], [], [],
394 [#include <cmath>
395 using namespace std;])
397 dnl Darwin provides __exp10().
398 AC_CHECK_DECLS([__exp10(double)], [], [],
399 [#include <cmath>
400 using namespace std;])
402 dnl GCC provides __builtin_exp10() (but notably clang doesn't currently).
403 dnl On mingw, __builtin_exp10() causes GCC to generate a call to exp10() which
404 dnl then fails to link, so perform a link check here to catch that.
405 AC_CACHE_CHECK([for __builtin_exp10], xo_cv_link___builtin_exp10, [
406   AC_LINK_IFELSE([AC_LANG_PROGRAM([[
407 #include <cstdio>
408 #include <ctime>
409 using namespace std;]],
410     [[printf("%f", __builtin_exp10(double(time(NULL)*1e-8)));]])],
411     [xo_cv_link___builtin_exp10=yes],
412     [xo_cv_link___builtin_exp10=no])
414 if test $xo_cv_link___builtin_exp10 = yes ; then
415   AC_DEFINE([HAVE___BUILTIN_EXP10], [1], [Define to 1 if you have the '__builtin_exp10' function.])
418 dnl See if <typeinfo> can be used in the testsuite - at least for GCC and xlC,
419 dnl compilation of the test code below fails if RTTI isn't being generated
420 dnl (g++ -fno-rtti, or by default with xlC).
421 AC_MSG_CHECKING([if RTTI is supported])
422 save_CXXFLAGS=$CXXFLAGS
423 dnl xlC issues a warning for typeid() being used without RTTI being enabled,
424 dnl so for this test we pass the xlC option to make that warning into an error.
425 CXXFLAGS="$CXXFLAGS -qhaltonmsg=1540-2412"
426 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
427       [],
428       [CXXFLAGS=$save_CXXFLAGS])
429 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
430 #include <exception>
431 #include <typeinfo>]],
432         [[
433         int f();
434         try {
435             return f();
436         } catch (std::exception & e) {
437             return typeid(e).name()[0];
438         }]])],
439     [AC_MSG_RESULT([yes])
440     AC_DEFINE([USE_RTTI], [1], [Define if the testsuite can use RTTI])],
441     [AC_MSG_RESULT([no])])
442 CXXFLAGS=$save_CXXFLAGS
444 dnl We need to specify the argument types for builtin functions, or else
445 dnl AC_CHECK_DECLS fails to detect them when the compiler is clang.
446 AC_CHECK_DECLS([__builtin_add_overflow(int, int, int*),
447                 __builtin_sub_overflow(int, int, int*),
448                 __builtin_mul_overflow(int, int, int*)], [], [], [ ])
449 AC_CHECK_DECLS([__builtin_bswap16(uint16_t),
450                 __builtin_bswap32(uint32_t),
451                 __builtin_bswap64(uint64_t)], [], [],
452                [#include <stdint.h>])
453 AC_CHECK_DECLS([_byteswap_ushort, _byteswap_ulong, _byteswap_uint64], [], [],
454                [#include <stdlib.h>])
455 AC_CHECK_DECLS([__builtin_clz(unsigned),
456                 __builtin_clzl(unsigned long),
457                 __builtin_clzll(unsigned long long)], [], [], [ ])
458 AC_CHECK_DECLS([__builtin_ctz(unsigned),
459                 __builtin_ctzl(unsigned long),
460                 __builtin_ctzll(unsigned long long)], [], [], [ ])
461 AC_CHECK_DECLS([__builtin_expect(long, long)], [], [], [ ])
462 AC_CHECK_DECLS([__builtin_ffs(int)], [], [], [ ])
463 AC_CHECK_DECLS([__builtin_popcount(unsigned),
464                 __builtin_popcountl(unsigned long),
465                 __builtin_popcountll(unsigned long long)], [], [], [ ])
466 AC_CHECK_DECLS([__popcnt, __popcnt64], [], [], [#include <intrin.h>])
467 AC_CHECK_DECLS([_addcarry_u32(unsigned char, unsigned, unsigned, unsigned*),
468                 _addcarry_u64(unsigned char, unsigned __int64, unsigned __int64, unsigned __int64*),
469                 _subborrow_u32(unsigned char, unsigned, unsigned, unsigned*),
470                 _subborrow_u64(unsigned char, unsigned __int64, unsigned __int64, unsigned __int64*)],
471                [], [], [#include <intrin.h>])
473 dnl Check for poll().
474 AC_CHECK_FUNCS([poll])
476 dnl Check for time functions.
477 AC_CHECK_FUNCS([clock_gettime sleep nanosleep gettimeofday ftime])
479 case $host_os in
480   *mingw*)
481     AC_DEFINE([MINGW_HAS_SECURE_API], [1], [Define on mingw to get _s suffixed "secure" functions declared in headers])
482     ;;
483 esac
485 dnl Used by tests/harness/testsuite.cc
486 AC_CHECK_FUNCS([sigaction])
487 dnl These can be macros (and sigsetjmp is with glibc at least).
488 AC_CHECK_DECLS([sigsetjmp, siglongjmp], [], [], [#include <setjmp.h>])
490 dnl Used by tests/harness/cputimer.cc:
491 AC_CHECK_FUNCS([getrusage times sysconf])
493 dnl Used by tests/harness/unixcmd.cc
494 AC_CHECK_FUNCS([nftw])
496 dnl POSIX requires setenv().  The final Unix-like platform without it seems
497 dnl to have been Solaris 9, which is now out of support.
499 dnl Microsoft don't provide setenv() and have marked putenv() as deprecated, so
500 dnl we use _putenv_s() to avoid deprecation warnings with MSVC.  It's also a
501 dnl more similar interface to setenv() so easier to implement a setenv() wrapper
502 dnl around.  We probe for both the function and a declaration since mingw
503 dnl doesn't currently (v3.20) declare it but it is present in the C runtime DLL
504 dnl so we can provide our own declaration to access it.
505 AC_CHECK_FUNCS([setenv _putenv_s])
506 AC_CHECK_DECLS([_putenv_s(const char*, const char*)], [], [],
507 [#include <stdlib.h>])
509 dnl See if we have closefrom(), or some functions that are useful to implement
510 dnl closefrom() on platforms which don't provide it.
511 AC_CHECK_FUNCS([closefrom getdirentries getrlimit])
513 if test $ac_cv_func_ftime = yes ; then
514   dnl See if ftime returns void (as it does on mingw)
515   AC_MSG_CHECKING([return type of ftime])
516   AC_COMPILE_IFELSE(
517     [AC_LANG_PROGRAM([[#include <sys/timeb.h>]],
518                      [[struct timeb tp; int i = ftime(&tp);]])],
519     [AC_MSG_RESULT([int])],
520     [AC_MSG_RESULT([void])
521     AC_DEFINE([FTIME_RETURNS_VOID], [1], [Define if ftime returns void])])
524 dnl Check how to find the hostname: uname() in sys/utsname.h, or gethostname()
525 AC_CHECK_HEADERS([sys/utsname.h], [], [], [ ])
526 AC_CHECK_FUNCS([gethostname])
528 AC_MSG_CHECKING([whether std::from_chars() works for double])
529 AC_LINK_IFELSE([AC_LANG_PROGRAM(
530 dnl std::from_chars() was added in C++17, but support it with floating point
531 dnl types was slow to get implemented so probe for it.  We can fall back to
532 dnl using strtod() instead (which is affected by the currently set locale and
533 dnl less thread-safe.
534 [[#include <charconv>]],
535 [[  const char* p = "3.14";
536   double v;
537   const auto& r = std::from_chars(p, p + 4, v);
538   if (r.ec != std::errc() || r.ptr != p + 4) return 1;]])],
539   AC_DEFINE([HAVE_STD_FROM_CHARS_DOUBLE], [1], [Define if std::from_chars() works for double])
540   AC_MSG_RESULT([yes]),
541   AC_MSG_RESULT([no])
544 dnl mingw (for instance) lacks ssize_t
545 AC_TYPE_SSIZE_T
547 AC_TYPE_PID_T
549 AC_TYPE_MODE_T
551 AC_CHECK_SIZEOF([short])
552 AC_CHECK_SIZEOF([int])
553 AC_CHECK_SIZEOF([long])
554 AC_CHECK_SIZEOF([long long])
556 AC_CHECK_HEADERS([sys/types.h])
558 AC_MSG_CHECKING([for 32 bit integer type])
559 case 4 in
560     "$ac_cv_sizeof_int")   INT32_T=int ;;
561     "$ac_cv_sizeof_long")  INT32_T=long ;;
562     "$ac_cv_sizeof_short") INT32_T=short ;;
563     *)
564       AC_MSG_RESULT([none found])
565       AC_MSG_ERROR([No 32 bit integer type found])
566 esac
567 AC_MSG_RESULT([$INT32_T])
569 AC_MSG_CHECKING([for 64 bit integer type])
570 case 8 in
571     "$ac_cv_sizeof_int")       INT64_T=int ;;
572     "$ac_cv_sizeof_long")      INT64_T=long ;;
573     "$ac_cv_sizeof_long_long") INT64_T='long long' ;;
574     *)
575       AC_MSG_RESULT([none found])
576       AC_MSG_ERROR([No 64 bit integer type found])
577 esac
578 AC_MSG_RESULT([$INT64_T])
580 dnl Check for perl (needed to generate some sources and documentation).
581 AC_PATH_PROG([PERL], [perl], [])
582 AC_ARG_VAR([PERL], [Perl interpreter])
583 if test x$USE_MAINTAINER_MODE = xyes; then
584   test -z "$PERL" && AC_MSG_ERROR([perl is required in maintainer mode])
587 AC_ARG_ENABLE([64bit_docid],
588   [AS_HELP_STRING([--enable-64bit-docid], [enable 64bit docid])],
589   [case ${enableval} in
590     yes|no) ;;
591   *) AC_MSG_ERROR([bad value ${enableval} for --enable-64bit-docid]) ;;
592   esac],
593   [enable_64bit_docid=no])
595 AC_ARG_ENABLE([64bit_termcount],
596   [AS_HELP_STRING([--enable-64bit-termcount], [enable 64bit termcount])],
597   [case ${enableval} in
598     yes|no) ;;
599   *) AC_MSG_ERROR([bad value ${enableval} for --enable-64bit-termcount]) ;;
600   esac],
601   [enable_64bit_termcount=no])
603 AC_ARG_ENABLE([64bit_termpos],
604   [AS_HELP_STRING([--enable-64bit-termpos], [enable 64bit termpos])],
605   [case ${enableval} in
606     yes|no) ;;
607   *) AC_MSG_ERROR([bad value ${enableval} for --enable-64bit-termpos]) ;;
608   esac],
609   [enable_64bit_termpos=no])
611 AC_ARG_ENABLE([documentation],
612   [AS_HELP_STRING([--enable-documentation], [enable make rules to rebuild documentation [default=maintainer-mode]])],
613   [case ${enableval} in
614     yes|no) ;;
615     *) AC_MSG_ERROR([bad value ${enableval} for --enable-documentation]) ;;
616   esac],
617   [enable_documentation=$USE_MAINTAINER_MODE])
618 AM_CONDITIONAL([DOCUMENTATION_RULES], [test x"$enable_documentation" = xyes])
619 AM_CONDITIONAL([MAINTAINER_NO_DOCS], [test x"$USE_MAINTAINER_MODE$enable_documentation" = xyesno])
621 if test x"$enable_documentation" = xyes ; then
622   dnl Checks for dot.  (Diagrams in the documentation)
623   AC_PATH_PROG([DOT], [dot])
624   AC_ARG_VAR([DOT], [dot from graphviz])
625   test -z "$DOT" && AC_MSG_ERROR([dot (part of the graphviz package) is required to build documentation])
626   DOXYGEN_DOT_PATH=`echo "$DOT" | sed 's!/dot$!!'`
627   AC_SUBST([DOXYGEN_DOT_PATH])
629   dnl Check for doxygen. (Needed to make some more of the documentation)
630   AC_PATH_PROG([DOXYGEN], [doxygen], [])
631   AC_ARG_VAR([DOXYGEN], [Doxygen documentation system])
632   test -z "$DOXYGEN" && AC_MSG_ERROR([doxygen is required to build documentation])
634   dnl Check for help2man. (Needed to make man pages from "--help" output).
635   AC_PATH_PROG([HELP2MAN], [help2man], [])
636   AC_ARG_VAR([HELP2MAN], [help2man man page generator])
637   test -z "$HELP2MAN" && AC_MSG_ERROR([help2man is required to build documentation])
639   dnl Check for rst2html. (Needed to make HTML from reStructuredText format)
640   dnl Also look for rst2html.py, which archlinux reportedly installs it as.
641   AC_PATH_PROGS([RST2HTML], [rst2html rst2html.py], [])
642   AC_ARG_VAR([RST2HTML], [reST to HTML convertor])
643   test -z "$RST2HTML" && AC_MSG_ERROR([rst2html is required to build documentation (try package python-docutils)])
645   dnl Check for pngcrush, which we optionally use to reduce the size of the
646   dnl PNG files which doxygen generates.  We can get by without it, so don't
647   dnl fail here if it's not found.
648   AC_PATH_PROG([PNGCRUSH], [pngcrush], [])
649   AC_ARG_VAR([PNGCRUSH], [PNG optimiser])
652 dnl Checks for header files.
653 AC_CHECK_HEADERS([fcntl.h limits.h poll.h sys/select.h sys/uio.h sysexits.h],
654                  [], [], [ ])
655 AC_CHECK_HEADERS([sys/resource.h],
656                  [], [], [#include <sys/types.h>])
658 dnl cxxabi.h was added in GCC 3.1, but clang lies and defines __GNUC__ yet
659 dnl doesn't seem to reliably provide this header, so probe for it.
660 AC_CHECK_HEADERS([cxxabi.h], [], [], [ ])
662 dnl If valgrind is installed and new enough, we use it for leak checking in the
663 dnl testsuite.  If VALGRIND is set to an empty value, then skip the check and
664 dnl don't use valgrind.  On macOS only use valgrind if VALGRIND is set to a
665 dnl no empty value, as valgrind on macOS gives a lot of false positives.
666 use_valgrind_if_non_empty=
667 case $host in
668   *-*-darwin*)
669     use_valgrind_if_non_empty=$VALGRIND ;;
670   *)
671     use_valgrind_if_non_empty=${VALGRIND-unset} ;;
672 esac
674 if test -n "$use_valgrind_if_non_empty" ; then
675   AC_PATH_PROG([VALGRIND], [valgrind], [])
676   AC_ARG_VAR([VALGRIND], [debugging tool (optionally used by test harness)])
677   if test -n "$VALGRIND" ; then
678     dnl Check that the installed valgrind version works, and supports the
679     dnl options we use.  This means we won't try to use valgrind < 3.3.0
680     dnl (released 7/12/2007) since before that --log-file didn't expand
681     dnl %p (and appended the process id).
682     dnl
683     dnl No need to check for VALGRIND_COUNT_LEAKS now - that was added before
684     dnl 2.0.0.
685     AC_MSG_CHECKING([if valgrind supports --log-file with %p and --child-silent-after-fork=yes])
686     vglog=config.vglog.%p.tmp
687     vglogwild="config.vglog.*.tmp*"
688     rm -f $vglogwild
689     if $VALGRIND --log-file="$vglog" --child-silent-after-fork=yes -q true 2>&AS_MESSAGE_LOG_FD ; then
690       for f in $vglogwild ; do
691         case $f in
692         $vglog*) VALGRIND= ;;
693         esac
694       done
695       if test x"$VALGRIND" = x ; then
696         AC_MSG_RESULT([no])
697       else
698         AC_MSG_RESULT([yes])
699         AC_CHECK_HEADERS([valgrind/memcheck.h], [], [VALGRIND=], [ ])
700       fi
701     else
702       dnl The valgrind detected doesn't seem to work!  Perhaps this is an
703       dnl x86_64 box with a 32 bit valgrind.
704       AC_MSG_RESULT([$VALGRIND doesn't work])
705       VALGRIND=
706     fi
707     rm -f $vglogwild
708   fi
711 if test -n "$VALGRIND" ; then
712   AC_DEFINE([HAVE_VALGRIND], [1], [Define if a suitable valgrind is installed])
715 dnl If eatmydata is installed, we run the testsuite under it to speed it up.
716 dnl If EATMYDATA is set to an empty value, then skip this check and don't use
717 dnl eatmydata.
718 if test -n "${EATMYDATA-unset}" ; then
719   AC_PATH_PROG([EATMYDATA], [eatmydata], [])
720   AC_ARG_VAR([EATMYDATA], [wrapper to disable fsync (optionally used by test harness)])
723 dnl Checks for library functions.
724 AC_FUNC_STRERROR_R
726 AC_CACHE_CHECK([for sys_errlist and sys_nerr], xo_cv_sys_errlist_and_sys_nerr, [
727   AC_LINK_IFELSE([AC_LANG_PROGRAM(
728 dnl On Linux, sys_errlist and sys_nerr need <stdio.h>, though the man page
729 dnl says <errno.h>.  The man page seems to match other platforms such as
730 dnl NetBSD, so include both headers to ensure we get them.  With mingw and MSVC
731 dnl they're provided by <stdlib.h>.
732 [[#include <errno.h>
733 #include <stdio.h>
734 #include <stdlib.h>]],
735 [[  printf("%s", sys_errlist[sys_nerr - 1]);]])],
736   [ xo_cv_sys_errlist_and_sys_nerr=yes ],
737   [ xo_cv_sys_errlist_and_sys_nerr=no ])
739 if test "x$xo_cv_sys_errlist_and_sys_nerr" = "xyes" ; then
740   AC_DEFINE([HAVE_SYS_ERRLIST_AND_SYS_NERR], [1],[Define if you have 'sys_errlist' and 'sys_nerr'])
743 AC_CACHE_CHECK([for _sys_errlist and _sys_nerr], xo_cv__sys_errlist_and__sys_nerr, [
744   AC_LINK_IFELSE([AC_LANG_PROGRAM(
745 [[#include <errno.h>
746 #include <stdio.h>
747 #include <stdlib.h>]],
748 [[  printf("%s", _sys_errlist[_sys_nerr - 1]);]])],
749   [ xo_cv__sys_errlist_and__sys_nerr=yes ],
750   [ xo_cv__sys_errlist_and__sys_nerr=no
751   ])
753 if test "x$xo_cv__sys_errlist_and__sys_nerr" = "xyes" ; then
754   AC_DEFINE([HAVE__SYS_ERRLIST_AND__SYS_NERR], [1],[Define if you have '_sys_errlist' and '_sys_nerr'])
757 dnl GNU-specific replacement for sys_errlist and sys_nerr.
758 AC_CHECK_FUNCS([strerrordesc_np])
760 dnl Check for ICU, which we can optionally use to find word breaks.
761 AC_ARG_VAR([PKG_CONFIG], [Location of pkg-config])
762 AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
763 if test -n "$PKG_CONFIG" ; then
764   dnl ICU's UTF-8 word boundary code was broken before 54.1.
765   m4_define([icu_min], [54.1])
766   m4_define([icu_mod], [icu-uc])
767   AC_MSG_CHECKING([for ICU (icu_mod >= icu_min)])
768   icu_config="$PKG_CONFIG icu_mod"
769   try_libs=`$PKG_CONFIG 'icu_mod >= icu_min' --libs 2>&AS_MESSAGE_LOG_FD`
770   if test $? -eq 0 ; then
771     AC_MSG_RESULT([yes])
772     AC_DEFINE([USE_ICU], [1], [Define to use ICU to find word breaks])
773     dnl The split here isn't perfect - e.g. -DFOO really ought to be in
774     dnl CPPFLAGS, but hopefully this won't be a problem in practice.
775     ICU_CFLAGS=`$icu_config --cflags-only-other`
776     ICU_CPPFLAGS=`$icu_config --cflags-only-I`
777     ICU_LIBS=$try_libs
778   else
779     icu_version=`$icu_config --modversion 2>&AS_MESSAGE_LOG_FD`
780     if test $? -eq 0 ; then
781       AC_MSG_RESULT([no ($icu_version)])
782     else
783       AC_MSG_RESULT([no])
784     fi
785   fi
787 AC_SUBST([ICU_CFLAGS])
788 AC_SUBST([ICU_CPPFLAGS])
789 AC_SUBST([ICU_LIBS])
791 dnl ***************************
792 dnl * Select modules to build *
793 dnl ***************************
795 dnl Check if a non-GPL library build is specified.
797 AC_ARG_ENABLE([gpl-libxapian],
798   [AS_HELP_STRING([--disable-gpl-libxapian], [disable use of GPL code which we won't be able to relicense in libxapian (NB currently the resulting build still contains GPL code, but GPL code which it will be possible to relicense eventually)])],
799   [case ${enableval} in
800     yes) ;;
801     no)
802       AC_DEFINE([DISABLE_GPL_LIBXAPIAN], 1, [Define to error out if we try to include GPL code in libxapian])
803       ;;
804     *) AC_MSG_ERROR([bad value ${enableval} for --disable-gpl-libxapian]) ;;
805   esac],
806   [enable_gpl_libxapian=yes])
808 dnl Check which database backends should be built.
810 AC_DEFUN([_XAPIAN_BACKEND_ENABLE],
811   [AC_ARG_ENABLE([backend_$1],
812     [AS_HELP_STRING([--enable-backend-$1], [build the $1 database backend [default=$3]])],
813     [case $enableval in
814       yes|no) ;;
815       *) AC_MSG_ERROR([Invalid option: '--enable-backend-$1=$enableval']) ;;
816     esac], [enable_backend_$1=$2])
817   ])
819 AC_DEFUN([XAPIAN_BACKEND_ENABLE],
820   [_XAPIAN_BACKEND_ENABLE([$1],
821     m4_default([$2], [yes]),
822     m4_default([$3], [yes]))
823   ])
825 dnl When adding a new backend, update INSTALL too.
826 XAPIAN_BACKEND_ENABLE([glass], [$enable_gpl_libxapian], [yes (unless --disable-gpl-libxapian)])
827 XAPIAN_BACKEND_ENABLE([honey])
828 XAPIAN_BACKEND_ENABLE([inmemory], [$enable_gpl_libxapian], [yes (unless --disable-gpl-libxapian)])
829 default_enable_backend_remote=$enable_gpl_libxapian
830 case $host_os in
831   *djgpp* | *msdos* )
832     dnl We don't currently support the remote backend on this platform so
833     dnl disable it by default.
834     default_enable_backend_remote=no
835     ;;
836 esac
837 XAPIAN_BACKEND_ENABLE([remote], [$default_enable_backend_remote], [yes (except for MSDOS; unless --disable-gpl-libxapian)])
839 dnl Save and empty LIBS while we probe for libraries to link libxapian against
840 dnl so we can just use AC_SEARCH_LIBS then copy LIBS to XAPIAN_LIBS and restore
841 dnl the value saved here.
842 save_LIBS=$LIBS
843 LIBS=
845 dnl See if we have fdatasync, and what libraries are needed for it.
846 dnl We need to actually check for a declaration as macOS has a dummy
847 dnl implementation in the library which is not prototyped in any header.
848 AC_CHECK_DECL([fdatasync(int)], [
849   AC_SEARCH_LIBS([fdatasync], [rt], [])
850   AC_CHECK_FUNCS([fdatasync])
851   ],
852   [ac_cv_func_fdatasync=no],
853   [#include <unistd.h>]
856 dnl We use timer_create() if available to implement a search time limit.
857 AC_SEARCH_LIBS([timer_create], [rt],
858                [
859     AC_MSG_CHECKING([for timer_create() usability])
860     dnl Several platforms have timer_create() but it's non-functional.
861     dnl
862     dnl Some of these (at least those with a stub implementation which always
863     dnl fails with ENOSYS) could be probed for, but we'd have to run code
864     dnl which isn't possible when cross-compiling, so just maintain a list
865     dnl of such platforms for now.
866     AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
867 [[#if defined _AIX
868 #error timer_create always fails with EAGAIN on AIX 7.1
869 #elif defined __NetBSD__
870 #error SIGEV_THREAD not implemented in NetBSD 9.2 (see: man sigevent)
871 #elif defined __OpenBSD__
872 #error timer_create always fails with ENOSYS on OpenBSD 7.3 (and no prototype)
873 #endif]])],
874         [AC_MSG_RESULT([yes])
875         AC_DEFINE([HAVE_TIMER_CREATE], [1], [Define to 1 if you have the 'timer_create' function.])]
876         ,
877         [AC_MSG_RESULT([no])
878     ])
881 win32_need_lws2_32=0
882 case $enable_backend_glass$enable_backend_honey in
883 *yes*)
884   dnl We use zlib for compressing tags in glass and honey.  We could
885   dnl automatically disable support if zlib isn't found, but overall that
886   dnl probably does more harm than good - it's most likely that someone just
887   dnl forgot to install the -dev package for zlib.
888   dnl
889   dnl Similarly for uuid support.
891   dnl Check for zlib.h.
892   AC_CHECK_HEADERS([zlib.h], [], [
893     AC_MSG_ERROR([zlib.h not found - required for glass (you may need to install the zlib1g-dev or zlib-devel package)])
894     ], [ ])
896   dnl Check for zlibVersion - normally it's in -lz but the mingw build needs -lzlib or -lzdll.
897   AC_SEARCH_LIBS([zlibVersion], [z zlib zdll], [], [
898     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)])
899     ])
901   dnl Find a way to generate UUIDs.
903   case $host_os-$win32 in
904     *-yes | cygwin* | msys*) dnl Use built-in win32 API.
905       AC_DEFINE([USE_WIN32_UUID_API], [1],
906                 [Define to 1 to use UuidCreate(), etc])
907       if test $win32 = yes ; then
908         dnl We need -lws2_32 for htonl(), etc, but not for Cygwin which
909         dnl provides these functions in its libc.
910         win32_need_lws2_32=1
911       fi
912       LIBS="$LIBS -lrpcrt4"
913       ;;
914     *)
915       dnl Check for uuid/uuid.h (e2fsprogs/util-linux-ng) or uuid.h
916       dnl (FreeBSD/NetBSD/OpenBSD/AIX).
917       AC_CHECK_HEADERS([uuid/uuid.h], [
918         dnl util-linux-ng's uuid/uuid.h found - check for uuid_generate in
919         dnl -luuid.
920         AC_SEARCH_LIBS([uuid_generate], [uuid], [], [
921           AC_MSG_ERROR([uuid_generate() not found in -luuid - required for glass and honey backends (you may need to install the uuid-dev, libuuid-devel or e2fsprogs-devel package)])
922           ])
923       ], [
924         dnl Try uuid.h as found on FreeBSD/NetBSD/OpenBSD/AIX, with associated
925         dnl code in libc.
926         AC_CHECK_HEADERS([uuid.h], [
927           dnl Check for uuid_create with no extra libraries required.
928           AC_CHECK_FUNC([uuid_create], [], [
929             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)])
930           ])
931         ], [
932           dnl Especially useful for Android.
933           AC_MSG_CHECKING([if host platform supports /proc/sys/kernel/random/uuid])
934           case $host_os in
935             linux*)
936               AC_DEFINE([USE_PROC_FOR_UUID], [1],
937                         [Define to 1 to read UUID from '/proc/sys/kernel/random/uuid'])
938               AC_MSG_RESULT([yes])
939               ;;
940             *)
941               AC_MSG_RESULT([no])
942               AC_MSG_ERROR([Failed to find a way to generate UUIDs, required for glass and honey backends (you may need to install the uuid-dev, libuuid-devel or e2fsprogs-devel package)])
943               ;;
944           esac
945         ], [ ])
946       ], [ ])
947       ;;
948   esac
950   case $host_os in
951     *djgpp* | *msdos* )
952       dnl DJGPP has a dummy implementation of fork which always fails.
953       dnl
954       dnl For disk-based backends, use flock() for locking, which doesn't need
955       dnl fork() or socketpair().
956       AC_DEFINE([FLINTLOCK_USE_FLOCK], 1, [Define to use flock() for flint-compatible locking])
957       ;;
958   esac
959   ;;
960 esac
962 if test "$enable_backend_remote" = yes ; then
963   case $host_os-$win32 in
964     *-yes )
965       dnl For mingw and msvc we have an alternative implementation which
966       dnl doesn't need fork() or socketpair().
967       dnl
968       dnl We need -lws2_32 for getaddrinfo(), etc.
969       win32_need_lws2_32=1
970       dnl Vista is needed for the AI_ADDRCONFIG flag to getaddrinfo().
971       AC_DEFINE([WINVER], [0x600],
972                 [Version of Windows to assume (0x600 => Vista).])
973       AC_DEFINE([_WIN32_WINNT], [WINVER],
974                 [Version of Windows to assume.])
975       ;;
976     *djgpp* | *msdos* )
977       dnl DJGPP has a dummy implementation of fork which always fails.  If
978       dnl someone actually wanted remote backend support, then DJGPP has a
979       dnl pthreads port, so using threads like we do on Windows would make more
980       dnl sense.
981       AC_MSG_ERROR([The remote backend is not currently supported on this platform.])
982       ;;
983     *)
984       dnl On Unix, we need fork and socketpair for the remotebackend.
985       AC_CHECK_FUNCS([fork], [], [
986         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.])
987       ])
988       dnl Check if -lsocket is required for socketpair (Solaris needs it).
989       dnl And on Haiku it's in -lnetwork.
990       AC_SEARCH_LIBS([socketpair], [socket network], [], [
991         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.])
992       ])
993       AC_DEFINE([HAVE_SOCKETPAIR], [1],
994                 [Define to 1 if you have the 'socketpair' function.])
995       dnl Check if extra libraries are needed for getaddrinfo or inet_ntop()
996       dnl (e.g. on Solaris).
997       dnl
998       dnl We're currently assuming that any system that is worth trying to
999       dnl support has getaddrinfo() and inet_ntop(), since these are the
1000       dnl standard route for supporting IPv6, and that's pretty much essential
1001       dnl for platforms to support now.
1002       AC_SEARCH_LIBS([getaddrinfo], [nsl socket], [], [
1003         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.])
1004       ])
1005       AC_SEARCH_LIBS([inet_ntop], [nsl socket], [], [
1006         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.])
1007       ])
1008       ;;
1009   esac
1011   XAPIAN_TYPE_SOCKLEN_T
1014 if test "$win32_need_lws2_32" = 1 ; then
1015   LIBS="$LIBS -lws2_32"
1017 XAPIAN_LIBS=$LIBS
1018 LIBS=$save_LIBS
1020 AC_ARG_ENABLE([visibility],
1021   [AS_HELP_STRING([--disable-visibility], [disable use of GCC visibility])],
1022   [case ${enableval} in
1023     yes|no) ;;
1024     *) AC_MSG_ERROR([bad value ${enableval} for --disable-visibility]) ;;
1025   esac])
1027 vpath_build=no
1028 if test "`pwd`" != "`cd $srcdir;pwd`" ; then
1029   vpath_build=yes
1031 AM_CONDITIONAL([VPATH_BUILD], [test yes = "$vpath_build"])
1033 dnl Turn off compilation of anything that we don't have the requirements for
1035 dnl Set conditionals to specify what we compile
1037 AM_CONDITIONAL([BUILD_BACKEND_GLASS], [test yes = "$enable_backend_glass"])
1038 AM_CONDITIONAL([BUILD_BACKEND_HONEY], [test yes = "$enable_backend_honey"])
1039 AM_CONDITIONAL([BUILD_BACKEND_INMEMORY], [test yes = "$enable_backend_inmemory"])
1040 AM_CONDITIONAL([BUILD_BACKEND_REMOTE], [test yes = "$enable_backend_remote"])
1041 AM_CONDITIONAL([BUILD_BACKEND_TOOLS],
1042   [test nono != "$enable_backend_glass$enable_backend_honey"])
1044 dnl Decide if we should use the zlib-vg.so LD_PRELOAD hack.
1045 use_zlib_vg=no
1046 if test -n "$VALGRIND" ; then
1047   case $host_os in
1048     linux*) use_zlib_vg=yes ;;
1049   esac
1051 AM_CONDITIONAL([USE_ZLIB_VG], [test yes = "$use_zlib_vg"])
1053 AC_CHECK_FUNCS([fsync writev])
1054 AC_CHECK_FUNCS([posix_fadvise])
1055 if test "$win32" = no ; then
1056   dnl ftruncate() under Wine seems to be buggy and sometimes fails, though
1057   dnl a cut-down reproducer seems fine.  For now just avoid ftruncate()
1058   dnl entirely on this platform - we'll fallback to lseek() + write() of a
1059   dnl single zero byte, which is pretty efficient.
1060   AC_CHECK_FUNCS([ftruncate])
1063 dnl HP-UX has pread and pwrite, but they don't work!  Apparently this problem
1064 dnl manifests when largefile support is enabled, and we definitely want that
1065 dnl so don't use pread or pwrite on HP-UX.
1066 case $host_os in
1067   hpux*)
1068     AC_MSG_CHECKING([for pread])
1069     AC_MSG_RESULT([present but broken on $host_os])
1070     AC_MSG_CHECKING([for pwrite])
1071     AC_MSG_RESULT([present but broken on $host_os])
1072     ;;
1073   *)
1074     AC_CHECK_FUNC([pread],
1075        [AC_DEFINE([HAVE_PREAD], [1],
1076             [Define if pread is available on this system])
1077         AC_MSG_CHECKING([for any prototype needed for pread])
1078         AC_CACHE_VAL([xo_cv_pread_prototype],
1079           [
1080             for p in ' ' \
1081               'extern "C" ssize_t pread(int, void *, size_t, off_t) throw ();' \
1082               'extern "C" ssize_t pread(int, void *, size_t, off_t);' ; do
1083               AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1084 #include <sys/types.h>
1085 #include <unistd.h>
1087               ]],[[
1088                 char b[256];
1089                 pread(1, b, 256, 20);
1090               ]])],[
1091                 xo_cv_pread_prototype="$p"
1092                 break
1093               ], [])
1094             done
1095             if test -z "$xo_cv_pread_prototype"; then
1096               AC_MSG_RESULT([not found])
1097               AC_MSG_ERROR([Failed to find working prototype for pread])
1098             fi
1099           ])
1100           if test " " = "$xo_cv_pread_prototype" ; then
1101             AC_MSG_RESULT([none required])
1102           else
1103             AC_MSG_RESULT([$xo_cv_pread_prototype])
1104             AC_DEFINE_UNQUOTED([PREAD_PROTOTYPE], [$xo_cv_pread_prototype],
1105                                [explicit prototype needed for pread (if any)])
1106           fi
1107         ])
1108     AC_CHECK_FUNC([pwrite],
1109        [AC_DEFINE([HAVE_PWRITE], [1],
1110             [Define if pwrite is available on this system])
1111         AC_MSG_CHECKING([for any prototype needed for pwrite])
1112         AC_CACHE_VAL([xo_cv_pwrite_prototype],
1113           [
1114             for p in ' ' \
1115               'extern "C" ssize_t pwrite(int, const void *, size_t, off_t) throw ();' \
1116               'extern "C" ssize_t pwrite(int, const void *, size_t, off_t);' ; do
1117               AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1118 #include <sys/types.h>
1119 #include <unistd.h>
1121               ]],[[
1122                 const char *p = "hello";
1123                 pwrite(1, p, 5, 20);
1124               ]])],[
1125                 xo_cv_pwrite_prototype="$p"
1126                 break
1127               ], [])
1128             done
1129             if test -z "$xo_cv_pwrite_prototype"; then
1130               AC_MSG_RESULT([not found])
1131               AC_MSG_ERROR([Failed to find working prototype for pwrite])
1132             fi
1133           ])
1134           if test " " = "$xo_cv_pwrite_prototype" ; then
1135             AC_MSG_RESULT([none required])
1136           else
1137             AC_MSG_RESULT([$xo_cv_pwrite_prototype])
1138             AC_DEFINE_UNQUOTED([PWRITE_PROTOTYPE], [$xo_cv_pwrite_prototype],
1139                                [explicit prototype needed for pwrite (if any)])
1140           fi
1141         ])
1142     ;;
1143 esac
1145 AC_MSG_CHECKING([for directory separator(s)])
1146 case $host_os-$win32 in
1147   *-yes | cygwin* | msys* | os2* | *djgpp* | *msdos* )
1148     AC_MSG_RESULT([/ and \\])
1149     AC_DEFINE([DIR_SEPS], ["/\\"], [directory separator(s) as a character or string literal])
1150     AC_DEFINE([DIR_SEPS_LIST], [{ '/', '\\' }], [directory separator(s) as an initialiser list])
1151     ;;
1152   *)
1153     AC_MSG_RESULT([/])
1154     AC_DEFINE([DIR_SEPS], ['/'], [directory separator(s) as a character or string literal])
1155     AC_DEFINE([DIR_SEPS_LIST], [{ '/' }], [directory separator(s) as an initialiser list])
1156     ;;
1157 esac
1159 AC_CHECK_FUNCS([link])
1161 dnl *************************
1162 dnl * Set debugging options *
1163 dnl *************************
1165 dnl Which assertion types to enable in the code.
1167 AC_ARG_ENABLE([assertions],
1168   [AS_HELP_STRING([--enable-assertions], [enable debug assertions (no|partial|yes) [default=no]])],
1169   [case $enableval in
1170     yes|partial|no) ;;
1171     *)
1172       AC_MSG_ERROR([Invalid option: '--enable-assertions=$enableval']) ;;
1173   esac])
1175 AC_ARG_ENABLE([log],
1176   [AS_HELP_STRING([--enable-log], [generate a log of methods called, etc (no|yes|profile) [default=no]])],
1177   [case $enableval in
1178     yes|no) ;;
1179     profile)
1180       AC_MSG_ERROR(['--enable-log=profile' is no longer supported - see https://trac.xapian.org/wiki/ProfilingXapian for alternatives.]) ;;
1181     *)
1182       AC_MSG_ERROR([Invalid option: '--enable-log=$enableval']) ;;
1183   esac])
1185 dnl Set defines according to the --enable-assertions and --enable-log options
1186 dnl given.
1188 if test yes = "$enable_assertions" || test partial = "$enable_assertions" ; then
1189   AC_DEFINE([XAPIAN_ASSERTIONS],,
1190     [Define if you want assertions (causes some slow-down)])
1193 if test yes = "$enable_assertions"; then
1194   AC_DEFINE([XAPIAN_ASSERTIONS_PARANOID],,
1195     [Define if you want paranoid assertions (causes significant slow-down)])
1198 if test yes = "$enable_log"; then
1199   AC_DEFINE([XAPIAN_DEBUG_LOG],,
1200     [Define if you want a log of methods called and other debug messages])
1203 dnl Check if IEEE-754 is followed for representing floating point numbers by the platform.
1204 AC_RUN_IFELSE([
1205   AC_LANG_PROGRAM(
1206     [[
1207 #include <cstdint>
1208 #include <cstring>
1209 using namespace std;
1210     ]],
1211     [[
1212       double a = 2353.3523423;
1213       uint64_t bit_pattern = 0x40A262B46635BEFF;
1214       if (memcmp(&bit_pattern, &a, sizeof(double)) == 0) return 0;
1215       return 1;
1216     ]]
1217   )],
1218   [ieee_followed=1],
1219   [ieee_followed=0],
1220   [ieee_followed=0]
1223 if test "$ieee_followed" = 1; then
1224     AC_DEFINE([FOLLOWS_IEEE], [1], [Defined if system uses ieee format to store floating point numbers])
1227 dnl ******************************
1228 dnl * Set special compiler flags *
1229 dnl ******************************
1231 AC_ARG_ENABLE([werror],
1232   [AS_HELP_STRING([--enable-werror], [enable treating compiler warnings as errors [default=maintainer-mode]])],
1233   [case ${enableval} in
1234     yes|no) ;;
1235   *) AC_MSG_ERROR([bad value ${enableval} for --enable-werror]) ;;
1236   esac],
1237   [enable_werror=$USE_MAINTAINER_MODE])
1239 dnl Put -Werror or equivalent in its own make variable so that it can easily
1240 dnl be overridden by `make WERROR=` if needed during development (e.g. if
1241 dnl you want to get a full list of compile warnings to fix rather than
1242 dnl stopping at the first file with warnings).
1243 WERROR=
1244 AC_SUBST([WERROR])
1246 dnl Set flags to control warnings (enable more, or disable annoying ones).
1247 dash_d_visibility=
1248 if test yes = "$GXX"; then
1249   dnl Intel's C++ compiler and clang both lie and define __GNUC__, so check which
1250   dnl we actually have, as neither is really 100% compatible.
1251   echo __INTEL_COMPILER __clang__ > conftest.cc
1252   case `$CXX -E conftest.cc 2>&AS_MESSAGE_LOG_FD|grep -v '^#'` in
1253     *__INTEL_COMPILER*__clang__*)
1254       dnl GCC (since neither substituted):
1256       dnl The exact format of g++ --version seems to change with almost every
1257       dnl minor release so use the preprocessor macros which should be more
1258       dnl robust.  Pass -xc++ to avoid warnings about any command-line options
1259       dnl included in $CXX which aren't valid for C (such as -std=c++17).
1260       AC_MSG_CHECKING([for version of $CXX])
1261       gxx_version=`echo __GNUC__.__GNUC_MINOR__.__GNUC_PATCHLEVEL__|$CXX -xc++ -E -|sed '/^#/d;s/ //g'`
1262       AC_MSG_RESULT([GCC $gxx_version])
1264       dnl -Wundef was supported by g++ 3.0.
1265       dnl
1266       dnl -Wlogical-op and -Wmissing-declarations (for C++) were added in
1267       dnl GCC 4.3.
1268       dnl
1269       dnl -Wdouble-promotion was added in GCC 4.6.
1270       dnl
1271       dnl -Wduplicated-cond was added in GCC 6.
1272       dnl
1273       dnl -Wduplicated-branches was added in GCC 7.
1274       dnl
1275       dnl All the other options were supported by g++ 2.95.
1276       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 -Wduplicated-cond -Wduplicated-branches"
1278       case $gxx_version in
1279       [[0-6]].*)
1280         AC_MSG_ERROR([Xapian requires GCC 7.0 or later])
1281         ;;
1282       esac
1284       dnl FIXME:
1285       dnl -Wold-style-cast is interesting, but triggers for macros from
1286       dnl system headers (e.g. FD_SET).  GCC 4.8 improved this by making
1287       dnl -ftrack-macro-expansion=2 the default, but we still see such
1288       dnl warnings on some platforms for some reason (e.g. Cygwin with GCC
1289       dnl 5.4.0 warns about FD_SET, and on Debian with GCC 4.9.2 we see
1290       dnl warnings from zlib.h).
1292       WERROR=-Werror
1293       ;;
1294     *__clang__*)
1295       dnl Intel's compiler (since __clang__ not substituted):
1296       dnl
1297       dnl -w1 stops the avalanche of uninteresting "remark" messages.
1298       dnl -wd... disables warnings which don't have good code workarounds.
1299       AM_CXXFLAGS="$AM_CXXFLAGS -Wall -w1 -wd177,1572"
1301       WERROR=-Werror
1302       ;;
1303     *__INTEL_COMPILER*)
1304       dnl clang (since __INTEL_COMPILER not substituted):
1306       dnl These options all work at least as far back as clang++ 3.0:
1307       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"
1309       WERROR=-Werror
1310       ;;
1311   esac
1312   rm -f conftest.cc
1314   if test no != "$enable_visibility"; then
1315     dnl GCC doesn't support symbol visibility on all platforms (e.g. it isn't
1316     dnl supported on mingw and visibility attributes result in warnings).
1317     AC_MSG_CHECKING([if $CXX -fvisibility=hidden -fvisibility-inlines-hidden works])
1318     if echo 'int bar() __attribute__((visibility("default"))); int baz() __attribute__((visibility("internal"))); int bar() { return 6; } int baz() { return 7; } int foo() {return 42;}'|$CXX -Werror -fvisibility=hidden -fvisibility-inlines-hidden -c -oconftest.o -xc++ - >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD ; then
1319       AC_MSG_RESULT([yes])
1320       AM_CXXFLAGS="$AM_CXXFLAGS -fvisibility=hidden -fvisibility-inlines-hidden"
1321       dash_d_visibility=-DXAPIAN_ENABLE_VISIBILITY
1322     else
1323       AC_MSG_RESULT([no])
1324     fi
1325   fi
1326 elif test yes = "$msvc"; then
1327   WERROR=-WX
1330 AC_MSG_CHECKING([for option to turn warnings into errors])
1331 if test x$enable_werror != xyes; then
1332   WERROR=
1333   AC_MSG_RESULT([not requested])
1334 elif test -z "$WERROR" ; then
1335   AC_MSG_RESULT([unknown for $CXX])
1336 else
1337   AC_MSG_RESULT([$WERROR])
1340 XAPIAN_TEST_LDFLAGS([-Wl,-Bsymbolic-functions], [XAPIAN_LDFLAGS])
1342 dnl New in GCC 5.  Sort of like -Bsymbolic-functions, but for the compiler
1343 dnl rather than the linker.
1344 XAPIAN_TEST_LDFLAGS([-fno-semantic-interposition], [XAPIAN_LDFLAGS])
1346 AC_MSG_CHECKING([whether to use SSE instructions on x86])
1347 case $host_cpu in
1348   i*86)
1349     if test "$enable_sse" = no ; then
1350       AC_MSG_RESULT([no])
1351       if test yes = "$msvc"; then
1352         dnl MSVC defaults to SSE2.
1353         AM_CXXFLAGS="$AM_CXXFLAGS -arch:IA32"
1354       fi
1355     else
1356       dnl Default to sse2.
1357       test "$enable_sse" != yes || enable_sse=sse2
1358       if test yes = "$GXX"; then
1359         AC_MSG_RESULT([yes (configure with --disable-sse to disable)])
1360         dnl We can unconditionally use -mtune=generic as it was added in GCC
1361         dnl 4.2, and supported at least as far back as clang 3.0.
1362         AM_CXXFLAGS="$AM_CXXFLAGS -mfpmath=sse -m$enable_sse -mtune=generic"
1363       elif test yes = "$msvc"; then
1364         AC_MSG_RESULT([yes (configure with --disable-sse to disable)])
1365         if test sse = "$enable_sse"; then
1366           dnl MSVC defaults to SSE2.
1367           AM_CXXFLAGS="$AM_CXXFLAGS -arch:SSE"
1368         fi
1369       else
1370         AC_MSG_RESULT([don't know how to for compiler $CXX])
1371       fi
1372     fi
1373     ;;
1374   *)
1375     AC_MSG_RESULT([non-x86 arch ($host_cpu)]) ;;
1376 esac
1378 if test "$GXX" = yes; then
1379   dnl Default to enabling _FORTIFY_SOURCE at level 2.  It shouldn't cause a
1380   dnl problem to define it where it's not supported, but we need to check for
1381   dnl an issue on mingw-w64 where some versions required linking with -lssp
1382   dnl (this was fixed in v11.0.0 released 2023-04-28).  We detect this with a
1383   dnl configure-time link test and don't auto-enable _FORTIFY_SOURCE if using
1384   dnl an affected version.
1385   AC_MSG_CHECKING([if _D_FORTIFY_SOURCE=2 links without extra libraries])
1386   save_CPPFLAGS=$CPPFLAGS
1387   CPPFLAGS="$CPPFLAGS -D_FORTIFY_SOURCE=2"
1388   AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1389     #include <string.h>
1390     static char a[20], b[10];]], [[
1391     strcpy(a, b);
1392     ]])],
1393     [AC_MSG_RESULT([yes])
1394     AC_DEFINE([FORTIFY_SOURCE_OK], [1], [Define to 1 if '-D_FORTIFY_SOURCE=2' link test passes])],
1395     [AC_MSG_RESULT([no])])
1396   CPPFLAGS=$save_CPPFLAGS
1399 AH_BOTTOM(
1400 [/* Disable stupid MSVC warnings. */
1401 #ifdef _MSC_VER
1402 /* Passing an empty parameter to a single parameter macro. */
1403 # pragma warning(disable:4003)
1404 /* Assignment in conditional expression; other compilers suppress with extra parentheses but not MSVC. */
1405 # pragma warning(disable:4706)
1406 /* A "performance" warning for converting int to bool. */
1407 # pragma warning(disable:4800)
1408 /* Character in string literal can't be represented in current code page. */
1409 # pragma warning(disable:4566)
1411 /* POSIX get to deprecate POSIX things, not Microsoft. */
1412 # ifndef _CRT_NONSTDC_NO_WARNINGS
1413 #  define _CRT_NONSTDC_NO_WARNINGS
1414 # endif
1415 # ifndef _CRT_SECURE_NO_WARNINGS
1416 #  define _CRT_SECURE_NO_WARNINGS
1417 # endif
1419 /* WSAAddressToStringA() is deprecated and we should apparently use
1420  * WSAAddressToStringW(), but we don't want wide character output so
1421  * that would mean we'd have to convert the result back to ASCII
1422  * which is a really stupid idea.
1423  */
1424 # ifndef _WINSOCK_DEPRECATED_NO_WARNINGS
1425 #  define _WINSOCK_DEPRECATED_NO_WARNINGS
1426 # endif
1428 /* Tell MSVC we want M_PI, etc defined. */
1429 # ifndef _USE_MATH_DEFINES
1430 #  define _USE_MATH_DEFINES
1431 # endif
1433 /* Tell MSVC we don't want max() and min() macros defined. */
1434 # ifndef NOMINMAX
1435 #  define NOMINMAX
1436 # endif
1437 #endif
1439 /* Tell zlib to include const in method signatures.  Define this in config.h
1440  * to ensure it always gets defined before zlib.h is included.
1441  */
1442 #define ZLIB_CONST
1444 /* Make the POSIX-like functions support large files.  MSVC needs this;
1445  * current mingw32 does too; mingw64 supports _FILE_OFFSET_BITS, which
1446  * AC_SYS_LARGEFILE should discover and enable automatically.
1447  */
1448 #if defined _MSC_VER || \
1449     (defined __MINGW32__ && !defined _FILE_OFFSET_BITS)
1451 # include <sys/stat.h>
1452 # include <sys/types.h>
1453 # include <io.h>
1454 /* zlib.h uses off_t so we need to include it before we redefine off_t. */
1455 # include <zlib.h>
1457 // The default stat() and fstat() use 32-bit filesizes and time_t, so we need
1458 // to arrange to use 64-bit variants instead.
1460 # ifdef stat
1461 // Break #undef lines to stop config.status from commenting them out.
1462 #  undef \
1463         stat
1464 # endif
1466 // This hack is a problem is we ever want a method called "stat".
1467 # ifdef _MSC_VER
1468 // MSVC needs to call _stat64() instead of stat() and the struct which holds
1469 // the information is `struct _stat64` instead of `struct stat` so we just
1470 // use #define to replace both in one go.
1471 #  define stat _stat64
1472 # else
1473 // Mingw32 has _stat64() but unhelpfully for our purposes, the struct is
1474 // called __stat64 (with an extra underscore).  We hack around this by
1475 // defining stat to __stat64 which sorts out the struct, and then using
1476 // a second macro to forward function-like uses of __stat64() to
1477 // _stat64().
1478 #  define stat __stat64
1479 #  define __stat64(PATH, STATBUF) _stat64((PATH), (STATBUF))
1480 # endif
1482 // We also want to use _fstat64() instead of fstat() but in this case we can
1483 // use a function-like macro, so we could have a method called fstat so long
1484 // as it didn't take two parameters.
1486 # ifdef fstat
1487 // Break #undef lines to stop config.status from commenting them out.
1488 #  undef \
1489         fstat
1490 # endif
1492 # define fstat(FD, BUF) _fstat64(FD, BUF)
1494 # ifdef lseek
1495 // Break #undef lines to stop config.status from commenting them out.
1496 #  undef \
1497         lseek
1498 # endif
1500 # ifdef off_t
1501 // Break #undef lines to stop config.status from commenting them out.
1502 #  undef \
1503         off_t
1504 # endif
1506 # define lseek(FD, OFF, WHENCE) _lseeki64(FD, OFF, WHENCE)
1507 /* Redefine via a typedef so C++ code off_t(-1) works - it wouldn't if we did:
1508  * #define off_t long long
1509  */
1510 typedef long long off_t_redefinition_typedef;
1511 # define off_t off_t_redefinition_typedef
1513 #endif
1515 /* MSVC defines _WIN32 but not __WIN32__. */
1516 #if !defined __WIN32__ && defined _WIN32
1517 # define __WIN32__
1518 #endif
1520 /* MSVC defines _WIN64 but not __WIN64__. */
1521 #if !defined __WIN64__ && defined _WIN64
1522 # define __WIN64__
1523 #endif
1525 /* Default to enabling _FORTIFY_SOURCE at level 2 for GCC-like compilers.  It
1526  * shouldn't cause a problem to define it where it's not supported.
1528  * The FORTIFY_SOURCE_OK check avoids auto-enabling on some mingw-w64 versions
1529  * which required linking with -lssp too.  This was addressed in v11.0.0
1530  * (released 2023-04-28).
1532  * Check if _FORTIFY_SOURCE is already defined to allow the user to override
1533  * our choice with "./configure CPPFLAGS=-D_FORTIFY_SOURCE=0" or "...=1" or
1534  * "...=3".
1535  */
1536 #if defined FORTIFY_SOURCE_OK && !defined _FORTIFY_SOURCE
1537 # define _FORTIFY_SOURCE 2
1538 #endif
1540 /* For compilers which support it (such as GCC, clang, Intel's C++ compiler)
1541  * we can use __builtin_expect to give the compiler hints about branch
1542  * prediction.  See HACKING for how to use these.
1543  */
1544 #if HAVE_DECL___BUILTIN_EXPECT
1545 /* The arguments of __builtin_expect() are both long, so use !! to ensure that
1546  * the first argument is always an integer expression, and always 0 or 1, but
1547  * still has the same truth value for the if or while it is used in.
1548  */
1549 # define rare(COND) __builtin_expect(!!(COND), 0)
1550 # define usual(COND) __builtin_expect(!!(COND), 1)
1551 #else
1552 # define rare(COND) (COND)
1553 # define usual(COND) (COND)
1554 #endif
1556 /* This macro can be used around expressions which intentionally make use of
1557  * unsigned integer overflow (which is defined behaviour, unlike signed integer
1558  * overflow) so that we can use UBSan's optional unsigned-integer-overflow
1559  * check to find potential bugs where we unintentionally overflow an unsigned
1560  * integer.
1561  */
1562 #ifdef __clang__
1563 #define UNSIGNED_OVERFLOW_OK(X) \
1564     ([&]() __attribute__((no_sanitize("unsigned-integer-overflow"))) {\
1565         return (X);\
1566     }())
1567 #else
1568 # define UNSIGNED_OVERFLOW_OK(X) (X)
1569 #endif
1571 /* Signal we're building the library so it's OK to include headers such as
1572  * xapian/query.h directly.
1573  */
1574 #define XAPIAN_LIB_BUILD 1
1577 AC_SUBST([AM_CXXFLAGS])
1579 dnl Restore CXXFLAGS to those the user specified or autoconf defaulted to.
1580 CXXFLAGS=$save_CXXFLAGS
1582 dnl Required for auto regeneration to work in a combined maintainer-mode tree.
1583 : ${AUTOM4TE=autom4te}
1584 AC_SUBST([AUTOM4TE])
1586 dnl Libtool sets this (to yes|no|unknown) and we use it in xapian-config.
1587 AC_SUBST([link_all_deplibs_CXX])
1589 dnl Shared library extension.
1590 module=no
1591 eval "SHLIBEXT=$shrext_cmds"
1592 AC_SUBST([SHLIBEXT])
1594 dnl We want to be able to use GNU make % pattern rules in maintainer targets
1595 dnl but automake warns these aren't portable, so we substitute the % to avoid
1596 dnl this warning.
1597 PERCENT='%'
1598 AC_SUBST([PERCENT])
1600 dnl Split up the version number into "MAJOR.MINOR.REVISION".
1601 MAJOR_VERSION=`echo "$VERSION"|sed 's/\..*//'`
1602 [MINOR_VERSION=`echo "$VERSION"|sed 's/[^.]*\.//;s/\..*//'`]
1603 [REVISION=`echo "$VERSION"|sed 's/.*\.//;s/_.*$//'`]
1605 dnl Convert the libs in $XAPIAN_LIBS to a CMake list.
1606 XAPIAN_CMAKE_LIBS=`echo " $XAPIAN_LIBS" | sed 's/ -l/;/g;s/ //g'`
1607 AC_SUBST([XAPIAN_CMAKE_LIBS])
1609 XAPIAN_CMAKE_SHARED=
1610 if test "$enable_shared" = yes; then
1611   XAPIAN_CMAKE_SHARED=ON
1612 else
1613   XAPIAN_CMAKE_SHARED=OFF
1615 AC_SUBST([XAPIAN_CMAKE_SHARED])
1617 LIBRARY_STATIC_EXT=.$libext
1618 AC_SUBST([LIBRARY_STATIC_EXT])
1620 if test "$win32" = yes; then
1621   LIBRARY_SHARED_IMP_EXT=$LIBRARY_STATIC_EXT
1622 else
1623   LIBRARY_SHARED_IMP_EXT=
1625 AC_SUBST([LIBRARY_SHARED_IMP_EXT])
1627 dnl We don't make use of maths function setting errno and if we tell the
1628 dnl compiler that it can optimise them better in some cases.  Apparently
1629 dnl most BSD-derived platforms don't set errno in this case anyway.
1630 XAPIAN_TEST_CXXFLAGS([-fno-math-errno], [CXXFLAGS])
1632 dnl **************************
1633 dnl * Build the output files *
1634 dnl **************************
1636 AC_CONFIG_FILES([
1637  Makefile
1638  tests/Makefile
1639  docs/Makefile
1640  docs/doxygen_api.conf
1641  docs/doxygen_source.conf
1642  cmake/xapian-config.cmake
1643  cmake/xapian-config-version.cmake
1644  pkgconfig/xapian-core"$LIBRARY_VERSION_SUFFIX".pc:pkgconfig/xapian-core.pc.in
1645  ])
1646 AC_CONFIG_FILES([makemanpage], [chmod +x makemanpage])
1647 AC_CONFIG_FILES([tests/runtest], [chmod +x tests/runtest])
1648 AC_CONFIG_FILES([tests/runsrv], [chmod +x tests/runsrv])
1649 AC_CONFIG_FILES([tests/submitperftest], [chmod +x tests/submitperftest])
1650 AC_CONFIG_FILES([tests/perftest/get_machine_info], [chmod +x tests/perftest/get_machine_info])
1651 AC_CONFIG_FILES([xapian-config], [chmod +x xapian-config])
1652 AC_OUTPUT
1654 dnl There are no files generated by AC_OUTPUT in the following directories
1655 dnl and we need to ensure they exist so that the rest of configure or make
1656 dnl won't fail because they don't exist when srcdir != builddir.
1657 if test yes = "$vpath_build" ; then
1658   for dir in include/xapian languages queryparser ; do
1659     AS_MKDIR_P(["$dir"])
1660   done
1663 dnl Generate include/xapian/version.h:
1665 dnl MAIN_VERSION is VERSION without any _git123 suffix.
1666 MAIN_VERSION="$MAJOR_VERSION.$MINOR_VERSION.$REVISION"
1667 cxxcpp_flags=-I.
1668 for backend in GLASS HONEY INMEMORY REMOTE ; do
1669   val=`eval echo "\\\$BUILD_BACKEND_${backend}_TRUE"`
1670   if test -z "$val" ; then
1671     cxxcpp_flags="$cxxcpp_flags -DXAPIAN_HAS_${backend}_BACKEND"
1672   fi
1673 done
1675 if test yes = "$enable_64bit_docid" ; then
1676   cxxcpp_flags="$cxxcpp_flags -DXAPIAN_DOCID_BASE_TYPE="`echo "$INT64_T"|sed 's/ /____/g'`
1677 else
1678   cxxcpp_flags="$cxxcpp_flags -DXAPIAN_DOCID_BASE_TYPE="`echo "$INT32_T"|sed 's/ /____/g'`
1681 if test yes = "$enable_64bit_termcount" ; then
1682   cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TERMCOUNT_BASE_TYPE="`echo "$INT64_T"|sed 's/ /____/g'`
1683 else
1684   cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TERMCOUNT_BASE_TYPE="`echo "$INT32_T"|sed 's/ /____/g'`
1687 if test yes = "$enable_64bit_termpos" ; then
1688   cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TERMPOS_BASE_TYPE="`echo "$INT64_T"|sed 's/ /____/g'`
1689 else
1690   cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TERMPOS_BASE_TYPE="`echo "$INT32_T"|sed 's/ /____/g'`
1693 dnl Always ought to be 64 bit.
1694 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TOTALLENGTH_TYPE="`echo "unsigned $INT64_T"|sed 's/ /____/g'`
1696 dnl Make revision numbers in the API 64 bit for future-proofing.
1697 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_REVISION_TYPE="`echo "unsigned $INT64_T"|sed 's/ /____/g'`
1699 dnl For GCC (and compilers which pretend to be GCC) and MSVC, we create checks
1700 dnl for some ABI-incompatible configurations in the generated version.h.
1701 dnl Such configurations may be specified via $CXXFLAGS so we should use this
1702 dnl when generating version.h.  For these compilers, CXXCPP="$CXX -E" so it
1703 dnl should understand all compiler options.
1705 dnl For other compilers, we only pass $CPPFLAGS to $CXXCPP in case it's an
1706 dnl external cpp which doesn't understand all options which might be in
1707 dnl $CXXFLAGS.
1708 case $GXX$msvc in
1709   *yes*)
1710     cxxcpp_flags="$cxxcpp_flags $CPPFLAGS $CXXFLAGS" ;;
1711   *)
1712     cxxcpp_flags="$cxxcpp_flags $CPPFLAGS" ;;
1713 esac
1714 rm -f include/xapian/version.h.tmp
1715 dnl "\r" in sed is a GNUism, but we only need to remove it on MS Windows
1716 dnl where we'll always have GNU sed, and other sed's will just interpret
1717 dnl it as "r" (Solaris sed) or maybe literal "\r" which won't match.
1719 dnl Use @@ around $MAIN_VERSION so we get " in the final output.
1720 $CXXCPP $cxxcpp_flags\
1721         -DSTRING_VERSION="\"@@$MAIN_VERSION@@\""\
1722         -DMAJOR_VERSION="\"$MAJOR_VERSION\""\
1723         -DMINOR_VERSION="\"$MINOR_VERSION\""\
1724         -DREVISION="\"$REVISION\""\
1725         $dash_d_visibility\
1726         $srcdir/include/xapian/version_h.cc|\
1727         ${SED-sed} '0,/const char \* dummy/d;/"/!d;s/^ *//;/^#/d;s/ *$//;s/" *,//;s/"//g;s/@@/"/g;s/  */ /g;s/ *,\r$//;s/ *,$//;s/____/ /g;s/\\\\$/\\/'\
1728         > include/xapian/version.h.tmp
1729 dnl Only update the file if it has changed, so we don't alter the timestamp
1730 dnl and cause lots of rebuilding needlessly.  However, the build system
1731 dnl needs a timestamp to know when to regenerate version.h because version_h.cc
1732 dnl has changed so we use a separate timestamp file.
1733 touch include/xapian/version.h.timestamp
1734 if cmp include/xapian/version.h.tmp include/xapian/version.h >/dev/null 2>&1
1735 then
1736   rm include/xapian/version.h.tmp
1737 else
1738   mv include/xapian/version.h.tmp include/xapian/version.h
1741 if test "$enable_gpl_libxapian" != yes ; then
1742   AC_MSG_WARN([--disable-gpl-libxapian disables use of GPL code which we won't be able to relicense in libxapian - currently the resulting build still contains GPL code, but GPL code which it will be possible to relicense eventually.])