Add accept() wrapper
[xapian.git] / xapian-core / configure.ac
blob152ea2981dcd43aea3e06a58de751d5a7b544212
1 dnl Process this file with autoconf to produce a configure script.
3 dnl NB When updating the version for a release, update LIBRARY_VERSION_INFO
4 dnl below too.
5 AC_INIT([xapian-core], [1.4.20], [https://xapian.org/bugs])
6 dnl See HACKING document for details of the reasons for required versions.
7 AC_PREREQ([2.64])
8 dnl Extract from the libtool info manual:
9 dnl
10 dnl Here are a set of rules to help you update your library version information:
11 dnl
12 dnl 1. Start with version information of '0:0:0' for each libtool library.
13 dnl
14 dnl 2. Update the version information only immediately before a public
15 dnl    release of your software.  More frequent updates are unnecessary,
16 dnl    and only guarantee that the current interface number gets larger
17 dnl    faster.
18 dnl
19 dnl 3. If the library source code has changed at all since the last
20 dnl    update, then increment REVISION ('C:R:A' becomes 'C:r+1:A').
21 dnl
22 dnl 4. If any interfaces have been added, removed, or changed since the
23 dnl    last update, increment CURRENT, and set REVISION to 0.
24 dnl
25 dnl 5. If any interfaces have been added since the last public release,
26 dnl    then increment AGE.
27 dnl
28 dnl 6. If any interfaces have been removed since the last public release
29 dnl    then set AGE to 0.
30 dnl
31 dnl LIBRARY_VERSION_INFO for libxapian:
32 dnl 29:1:7 1.2.23 No API changes (except new inline methods)
33 dnl 30:0:0 1.4.0 Extensive API changes
34 dnl 31:0:1 1.4.1 New Weight subclasses, etc
35 dnl 32:0:2 1.4.2 Database::get_document() with flags
36 dnl 33:0:3 1.4.3 Database::locked() method
37 dnl 33:1:3 1.4.4 No API changes
38 dnl 34:0:4 1.4.5 Database::get_total_length() method
39 dnl 35:0:5 1.4.6 C++11 move support added
40 dnl 35:1:5 1.4.7 No API changes
41 dnl 36:0:6 1.4.8 STEM_SOME_FULL_POS added
42 dnl 36:1:6 1.4.9 No API changes
43 dnl 37:0:7 1.4.10 Added DatabaseClosedError, etc
44 dnl 38:0:8 1.4.11 Added SNIPPET_CJK_NGRAM
45 dnl 39:0:9 1.4.12 Database::size() method
46 dnl 39:1:9 1.4.13 No API changes
47 dnl 40:0:10 1.4.14 Xapian::Stem changes
48 dnl 40:1:10 1.4.15 No API changes
49 dnl 40:2:10 1.4.16 No API changes
50 dnl 40:3:10 1.4.17 No API changes (except a new inlined method)
51 dnl 41:0:11 1.4.18 QueryParser::FLAG_ACCUMULATE
52 dnl 42:0:12 1.4.19 QueryParser::FLAG_NO_POSITIONS
53 dnl 42:1:12 1.4.20 No API changes
54 LIBRARY_VERSION_INFO=42:1:12
55 AC_SUBST([LIBRARY_VERSION_INFO])
57 LIBRARY_VERSION_SUFFIX=
58 AC_SUBST([LIBRARY_VERSION_SUFFIX])
60 dnl Disabled for stable release series.
61 test x"$program_suffix" != xNONE || program_suffix=
63 dnl Where xapian.h, etc go.  In development release append "/xapian-1.3".
64 incdir=$includedir
65 AC_SUBST([incdir])
67 dnl Check the build directory doesn't contain a space, so we die early with
68 dnl a helpful error.
69 case `pwd` in
70 *' '*)
71    AC_MSG_ERROR([You can't build in a directory whose path contains a space])
72    ;;
73 esac
75 dnl Check the source directory doesn't contain a space, so we die early with
76 dnl a helpful error.  FIXME: Unfortunately, configure seems to choke before
77 dnl it gets to us so this code doesn't get a chance to fire.
78 case $0 in
79 *' '*)
80    dnl Note: for in-tree builds, the build directory test above will fire
81    dnl before this can.
82    AC_MSG_ERROR([You can't build with sources in a directory whose path contains a space])
83    ;;
84 esac
86 dnl Check the prefix to install in doesn't contain a space, so we die early with
87 dnl a helpful error.
88 case $prefix in
89 *' '*)
90    AC_MSG_ERROR([You can't install in a directory whose path contains a space])
91    ;;
92 esac
94 dnl Note if the user specified a particular C++ compiler so we can give a more
95 dnl appropriate error message if we can't link a simple C++ program.
96 original_CXX=
97 if test -n "$CXX" ; then
98   original_CXX="CXX=$CXX"
99 elif test -n "$CCC" ; then
100   original_CXX="CCC=$CCC"
103 dnl See HACKING document for details of the reasons for required versions.
104 AM_INIT_AUTOMAKE([1.11 -Wportability tar-ustar no-dist-gzip dist-xz std-options])
105 AC_CONFIG_SRCDIR([matcher/multiandpostlist.cc])
107 AC_CONFIG_HEADERS([config.h])
109 AC_CONFIG_MACRO_DIR([m4])
111 AM_PROG_AR
113 dnl Use libtool to manage our libraries.
114 LT_PREREQ([2.2.8])
115 dnl Default to only building shared libraries.
117 dnl Building both shared and static means having to compile the files which
118 dnl make up the library twice on most platforms.  Shared libraries are the
119 dnl better option for most users, and if anyone really wants static libraries,
120 dnl they can configure with --enable-static (or --enable-static=xapian-core if
121 dnl configuring a combined tree with the bindings).
123 dnl We don't export any data items from the library, so it should be safe to
124 dnl enable win32-dll without decorating any declarations specially.
125 LT_INIT([disable-static win32-dll])
127 dnl -no-undefined causes problems on Solaris with Sun CC in C++11 mode, so only
128 dnl pass -no-undefined on platforms where it is required in order to link a
129 dnl shared library at all (Windows is the main one).
130 NO_UNDEFINED=
131 if test unsupported = "$allow_undefined_flag" ; then
132   NO_UNDEFINED=-no-undefined
134 AC_SUBST(NO_UNDEFINED)
136 AM_CXXFLAGS=
138 dnl A standard "gotcha" for mingw and cygwin users is to not set up their
139 dnl PATH correctly, so that MSDOS FIND.EXE is found before Unix find.  Help
140 dnl them out by checking for this condition, rather than letting libtool
141 dnl fail in obscure ways.  NB check the *BUILD* OS, not the host one!
142 case $build_os in
143   *mingw* | *cygwin* | pw32*)
144     find /dirunlikelytoexist >/dev/null 2>&1
145     if test $? = 2 ; then
146         dnl Unix find will return 1 if the directory didn't exist, or 0 if
147         dnl it did.
148         AC_MSG_ERROR([
149 *** You appear to have an MSDOS-like FIND.EXE in your PATH ahead of any
150 *** UNIX-like find.  This misconfiguration will confuse libtool - you'll need
151 *** to make sure you have a UNIX-like find installed and fix your PATH, then
152 *** rerun configure.  For more information, see:
154 ***   https://www.cygwin.com/faq/faq.html#faq.using.find
156     fi
157   ;;
158 esac
160 dnl Add parameters for aclocal
161 dnl (This must come after AM_INIT_AUTOMAKE, since it modifies ACLOCAL)
162 ACLOCAL="$ACLOCAL $ACLOCAL_FLAGS"
164 dnl disable "maintainer only" rules by default
165 AM_MAINTAINER_MODE
167 dnl Checks for programs.
168 AC_PROG_CXX
170 AC_CANONICAL_HOST
172 # Checked: freebsd8.0 openbsd4.6 solaris2.9 solaris2.10
173 case $host_os in
174   linux* | k*bsd*-gnu | freebsd* | openbsd* | solaris*)
175     dnl Vanilla libtool sets this to "unknown" which it then handles as "yes".
176     link_all_deplibs_CXX=no
177     ;;
178 esac
180 case $host_os in
181   linux*)
182     dnl Extract search path from ldconfig which is more reliable than the way
183     dnl vanilla libtool extracts them from ld.so.conf.
184     d=`/sbin/ldconfig -N -X -v 2>&AS_MESSAGE_LOG_FD|$SED 's,^\(/.*\):\( (.*)\)\?$,\1,p;d'|tr '\n' ' '`
185     test -z "$d" || sys_lib_dlsearch_path_spec=$d
186     ;;
187 esac
189 case $host in
190   *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
191     dnl On these platforms, libtool emits a warning if -no-install is passed,
192     dnl and uses -no-fast-install instead - the least ugly way to avoid that
193     dnl warnings seems to be to duplicate the above list of platforms from
194     dnl libtool and use -no-fast-install on them directly.
195     NO_INSTALL=-no-fast-install ;;
196   *)
197     NO_INSTALL=-no-install ;;
198 esac
199 AC_SUBST([NO_INSTALL])
201 dnl For reasons which are beyond me, if autoconf can't find a C++ compiler
202 dnl it will set CXX to g++ (which obviously won't work) rather than actually
203 dnl telling the user that it couldn't find a C++ compiler and telling them
204 dnl to either install one or set CXX if there's one configure failed to find.
205 dnl It's probably worthwhile checking that the C++ compiler actually works
206 dnl anyway!
207 if test -n "$CXX" ; then
208   AC_LANG([C++])
209   AC_MSG_CHECKING([whether $CXX is a working C++ compiler])
210   AC_CACHE_VAL([xo_cv_cxx_works],
211     [
212     AC_RUN_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
213                   [xo_cv_cxx_works=yes],
214                   [xo_cv_cxx_works=no],
215                   [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
216                                   [xo_cv_cxx_works=yes],
217                                   [xo_cv_cxx_works=no])])
218     ])
219   AC_MSG_RESULT([$xo_cv_cxx_works])
220 else
221   xo_cv_cxx_works=no
223 if test no = "$xo_cv_cxx_works" ; then
224   case $original_CXX in
225   CCC=*)
226     dnl CCC is handled in a slightly odd way - if its value isn't an
227     dnl executable (taking PATH into account) then it is ignored!
228     test "$original_CXX" = "CCC=$CXX" || original_CXX=
229     ;;
230   esac
231   if test -z "$original_CXX" ; then
232   AC_MSG_ERROR([
233 *** You need a working C++ compiler to compile Xapian, but configure failed to
234 *** find one.  If you have a working C++ compiler, you can tell configure where
235 *** to find it by invoking it like so:
237 ***   ./configure CXX=/opt/bin/c++
239   else
240   AC_MSG_ERROR([
241 *** You need a working C++ compiler to compile Xapian, but the compiler you
242 *** specified (with '$original_CXX') doesn't appear to be able to successfully
243 *** compile and link a simple program.
245   fi
248 dnl Probe for any options needed to enable C++11 support.
249 AX_CXX_COMPILE_STDCXX([11])
251 dnl We don't use a C compiler to compile Xapian's code, but on some platforms
252 dnl (e.g. mingw) libtool uses $LTCC which defaults to $CC, and it's also use to
253 dnl build auxiliary tools like snowball and lemon.
254 AC_PROG_CC
256 dnl Check endianness.
257 AC_C_BIGENDIAN
259 dnl We want a non-cross-compiling C compiler for building lemon with.
260 if test -z "$CC_FOR_BUILD" ; then
261   if test yes = "$cross_compiling"; then
262     CC_FOR_BUILD=cc
263   else
264     CC_FOR_BUILD="$CC"
265   fi
267 AC_ARG_VAR([CC_FOR_BUILD], [C compiler command for native compilation (needed to compile build tools during cross-builds)])
269 dnl Run tests using the C++ compiler.
270 AC_LANG([C++])
272 dnl Enable large file support if possible.
273 AC_SYS_LARGEFILE
274 dnl With xlC on AIX, -D_LARGE_FILES changes the ABI of std::string, so it
275 dnl also needs to be used when compiling user code.
276 abi_affecting_cxxflags=
277 if $GREP '^#define _LARGE_FILES 1$' confdefs.h > /dev/null 2>&1 ; then
278   abi_affecting_cxxflags=-D_LARGE_FILES
280 AC_SUBST([abi_affecting_cxxflags])
282 AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
283 #if defined __WIN32__ || defined _WIN32
284 #error WIN32
285 #endif
286 ]])], [win32=no], [win32=yes])
288 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
289 #ifdef _MSC_VER
290 #error MSVC
291 #endif
292 ]])], [msvc=no], [msvc=yes])
294 XAPIAN_LDFLAGS=
295 XAPIAN_LIBS=
296 AC_SUBST([XAPIAN_LDFLAGS])
297 AC_SUBST([XAPIAN_LIBS])
299 AC_DEFUN([XAPIAN_TEST_FLAGS_],
300   [
301   m4_define([cachevar],
302             [xo_cv_]m4_tolower(m4_bpatsubst([$1][_$3], [[^A-Za-z0-9]], [_])))
303   AC_CACHE_CHECK([for $CXX with $3 in $1], cachevar,
304     [
305     XTF_save_$1=${$1}
306     $1="${$1} $3"
307     $2([AC_LANG_PROGRAM([], [])],
308       [cachevar=yes
309        $1=$XTF_save_$1
310        $4="${$4} $3"
311        $5],
312       [cachevar=no
313        $1=$XTF_save_$1
314        $6])
315     ])
316   ])
318 dnl Test if compiling works with $1 added to CXXFLAGS; if it does, add $1 to
319 dnl variable $2.  If the test passes, also do $3; if it fails, also do $4.
320 AC_DEFUN([XAPIAN_TEST_CXXFLAGS],
321   [XAPIAN_TEST_FLAGS_([CXXFLAGS], [AC_COMPILE_IFELSE], [$1], [$2], [$3], [$4])])
323 dnl Test if linking works with $1 added to LDFLAGS; if it does, add $1 to
324 dnl variable $2.  If the test passes, also do $3; if it fails, also do $4.
325 AC_DEFUN([XAPIAN_TEST_LDFLAGS],
326   [XAPIAN_TEST_FLAGS_([LDFLAGS], [AC_LINK_IFELSE], [$1], [$2], [$3], [$4])])
328 ldflags=
329 if test yesyes = "$GXX$enable_shared" ; then
330   case $host_os in
331     *mingw* | *cygwin*)
332       XAPIAN_TEST_LDFLAGS(
333         [-Wl,--enable-runtime-pseudo-reloc],
334         [ldflags],
335         [],
336         [
337         dnl Can't use AC_DISABLE_SHARED after AC_PROG_LIBTOOL, but
338         dnl this test needs to be after AC_PROG_LIBTOOL, so we can't
339         dnl just disable the shared build automatically...
340         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])
341         ])
342     ;;
343   esac
345 dnl Only works for ldflags which can be specified anywhere on the link line.
346 AC_SUBST([ldflags])
348 dnl Preserve the default CXXFLAGS.
349 save_CXXFLAGS=$CXXFLAGS
351 dnl x86 has excess precision issues with 387 FP instructions, which are
352 dnl avoided by using SSE instructions instead.  This is also faster (~6% in
353 dnl a CPU bound testcase).
354 AC_ARG_ENABLE([sse],
355 [AS_HELP_STRING([--disable-sse],
356                 [disable use of SSE FP instructions on x86])]
357 [AS_HELP_STRING([[--enable-sse[=sse|sse2]]],
358                 [set which SSE FP instructions to use on x86 (default: sse2)])],
359   [case ${enableval} in
360     sse|sse2|yes|no) ;;
361     *) AC_MSG_ERROR([bad value ${enableval} for --enable-sse or --disable-sse]) ;;
362   esac],
363   [enable_sse=yes])
365 dnl The maths functions we use include: exp log ceil fabs sqrt
366 AC_MSG_CHECKING([if -lm is required for maths functions])
367 dnl Don't use constant arguments as the compiler might simply evaluate the
368 dnl whole expression at compile time, and it might inline certain functions
369 dnl so test several functions.  Also write results using printf() so that
370 dnl the compiler can't optimise away the computations.
371 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <cmath>
372 #include <cstdio>
373 #include <ctime>
374 using namespace std;]], [[
375   double a = log(ceil(time(NULL)/7.0));
376   printf("%f %f %f\n", a, sqrt(a), exp(fabs(a - 12345.6)));
377   ]])], [AC_MSG_RESULT([no])], [
378     LIBS="-lm $LIBS"
379     AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <cmath>
380 #include <cstdio>
381 #include <ctime>
382 using namespace std;]], [[
383   double a = log(ceil(time(NULL)/7.0));
384   printf("%f %f %f\n", a, sqrt(a), exp(fabs(a - 12345.6)));]])],
385         [AC_MSG_RESULT([yes])],
386         [AC_MSG_ERROR([Failed to link a C++ program using <cmath>])
387     ])
390 dnl C++11 should have log2(double), but keep this check for now to allow for
391 dnl compilers with incomplete library support for C++11.
392 AC_CHECK_DECLS([log2(double)], [], [],
393 [#include <cmath>
394 using namespace std;])
396 dnl exp10() is a GNU libc extension.
397 AC_CHECK_DECLS([exp10(double)], [], [],
398 [#include <cmath>
399 using namespace std;])
401 dnl Darwin provides __exp10().
402 AC_CHECK_DECLS([__exp10(double)], [], [],
403 [#include <cmath>
404 using namespace std;])
406 dnl GCC provides __builtin_exp10() (but notably clang doesn't currently).
407 dnl On mingw, __builtin_exp10() causes GCC to generate a call to exp10() which
408 dnl then fails to link, so perform a link check here to catch that.
409 AC_CACHE_CHECK([for __builtin_exp10], xo_cv_link___builtin_exp10, [
410   AC_LINK_IFELSE([AC_LANG_PROGRAM([[
411 #include <cstdio>
412 #include <ctime>
413 using namespace std;]],
414     [[printf("%f", __builtin_exp10(double(time(NULL)*1e-8)));]])],
415     [xo_cv_link___builtin_exp10=yes],
416     [xo_cv_link___builtin_exp10=no])
418 if test $xo_cv_link___builtin_exp10 = yes ; then
419   AC_DEFINE([HAVE___BUILTIN_EXP10], [1], [Define to 1 if you have the '__builtin_exp10' function.])
422 dnl See if <typeinfo> can be used in the testsuite - at least for GCC and xlC,
423 dnl compilation of the test code below fails if RTTI isn't being generated
424 dnl (g++ -fno-rtti, or by default with xlC).
425 AC_MSG_CHECKING([if RTTI is supported])
426 save_CXXFLAGS=$CXXFLAGS
427 dnl xlC issues a warning for typeid() being used without RTTI being enabled,
428 dnl so for this test we pass the xlC option to make that warning into an error.
429 CXXFLAGS="$CXXFLAGS -qhaltonmsg=1540-2412"
430 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
431       [],
432       [CXXFLAGS=$save_CXXFLAGS])
433 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
434 #include <exception>
435 #include <typeinfo>]],
436         [[
437         int f();
438         try {
439             return f();
440         } catch (std::exception & e) {
441             return typeid(e).name()[0];
442         }]])],
443     [AC_MSG_RESULT([yes])
444     AC_DEFINE([USE_RTTI], [1], [Define if the testsuite can use RTTI])],
445     [AC_MSG_RESULT([no])])
446 CXXFLAGS=$save_CXXFLAGS
448 dnl We need to specify the argument types for builtin functions, or else
449 dnl AC_CHECK_DECLS fails to detect them when the compiler is clang.
450 AC_CHECK_DECLS([__builtin_add_overflow(int, int, int*),
451                 __builtin_sub_overflow(int, int, int*),
452                 __builtin_mul_overflow(int, int, int*)], [], [], [ ])
453 AC_CHECK_DECLS([__builtin_bswap16(uint16_t),
454                 __builtin_bswap32(uint32_t),
455                 __builtin_bswap64(uint64_t)], [], [],
456                [#include <stdint.h>])
457 AC_CHECK_DECLS([_byteswap_ushort, _byteswap_ulong, _byteswap_uint64], [], [],
458                [#include <stdlib.h>])
459 AC_CHECK_DECLS([__builtin_clz(unsigned),
460                 __builtin_clzl(unsigned long),
461                 __builtin_clzll(unsigned long long)], [], [], [ ])
462 AC_CHECK_DECLS([__builtin_ctz(unsigned),
463                 __builtin_ctzl(unsigned long),
464                 __builtin_ctzll(unsigned long long)], [], [], [ ])
465 AC_CHECK_DECLS([__builtin_expect(long, long)], [], [], [ ])
466 AC_CHECK_DECLS([__builtin_popcount(unsigned),
467                 __builtin_popcountl(unsigned long),
468                 __builtin_popcountll(unsigned long long)], [], [], [ ])
469 AC_CHECK_DECLS([__popcnt, __popcnt64], [], [], [#include <intrin.h>])
470 AC_CHECK_DECLS([_addcarry_u32(unsigned char, unsigned, unsigned, unsigned*),
471                 _addcarry_u64(unsigned char, unsigned __int64, unsigned __int64, unsigned __int64*),
472                 _subborrow_u32(unsigned char, unsigned, unsigned, unsigned*),
473                 _subborrow_u64(unsigned char, unsigned __int64, unsigned __int64, unsigned __int64*)],
474                [], [], [#include <intrin.h>])
476 dnl Check for poll().
477 AC_CHECK_FUNCS([poll])
479 dnl Check for time functions.
480 AC_CHECK_FUNCS([clock_gettime sleep nanosleep gettimeofday ftime])
482 case $host_os in
483   *mingw*)
484     dnl For _ftime64() on mingw we need to tell it we're happy to require
485     dnl MSVCRT 6.10 or higher, which isn't too onerous a requirement it seems.
486     AC_DEFINE([__MSVCRT_VERSION__], [0x0601], [Define on mingw to the minimum msvcrt version to assume])
487     AC_DEFINE([MINGW_HAS_SECURE_API], [1], [Define on mingw to get _s suffixed "secure" functions declared in headers])
488     ;;
489 esac
491 dnl Used by tests/soaktest/soaktest.cc
492 AC_CHECK_FUNCS([srandom random])
494 dnl Used by tests/harness/testsuite.cc
495 AC_CHECK_FUNCS([sigaction])
496 dnl These can be macros (and sigsetjmp is with glibc at least).
497 AC_CHECK_DECLS([sigsetjmp, siglongjmp], [], [], [#include <setjmp.h>])
499 dnl Used by tests/harness/cputimer.cc:
500 AC_CHECK_FUNCS([getrusage times sysconf])
502 dnl Used by tests/harness/unixcmd.cc
503 AC_CHECK_FUNCS([nftw])
505 dnl POSIX requires setenv().  The final Unix-like platform without it seems
506 dnl to have been Solaris 9, which is now out of support.
508 dnl Microsoft don't provide setenv() and have marked putenv() as deprecated, so
509 dnl we use _putenv_s() to avoid deprecation warnings with MSVC.  It's also a
510 dnl more similar interface to setenv() so easier to implement a setenv() wrapper
511 dnl around.  We probe for both the function and a declaration since mingw
512 dnl doesn't currently (v3.20) declare it but it is present in the C runtime DLL
513 dnl so we can provide our own declaration to access it.
514 AC_CHECK_FUNCS([setenv _putenv_s])
515 AC_CHECK_DECLS([_putenv_s(const char*, const char*)], [], [],
516 [#include <stdlib.h>])
518 dnl See if we have closefrom(), or some functions that are useful to implement
519 dnl closefrom() on platforms which don't provide it.
520 AC_CHECK_FUNCS([closefrom getdirentries getrlimit])
522 if test $ac_cv_func_ftime = yes ; then
523   dnl See if ftime returns void (as it does on mingw)
524   AC_MSG_CHECKING([return type of ftime])
525   AC_COMPILE_IFELSE(
526     [AC_LANG_PROGRAM([[#include <sys/timeb.h>]],
527                      [[struct timeb tp; int i = ftime(&tp);]])],
528     [AC_MSG_RESULT([int])],
529     [AC_MSG_RESULT([void])
530     AC_DEFINE([FTIME_RETURNS_VOID], [1], [Define if ftime returns void])])
533 dnl Check how to find the hostname: uname() in sys/utsname.h, or gethostname()
534 AC_CHECK_HEADERS([sys/utsname.h], [], [], [ ])
535 AC_CHECK_FUNCS([gethostname])
537 dnl mingw (for instance) lacks ssize_t
538 AC_TYPE_SSIZE_T
540 AC_TYPE_PID_T
542 AC_TYPE_MODE_T
544 AC_CHECK_SIZEOF([short])
545 AC_CHECK_SIZEOF([int])
546 AC_CHECK_SIZEOF([long])
547 AC_CHECK_SIZEOF([long long])
549 AC_CHECK_HEADERS([sys/types.h])
551 AC_MSG_CHECKING([for 32 bit integer type])
552 case 4 in
553     "$ac_cv_sizeof_int")   INT32_T=int ;;
554     "$ac_cv_sizeof_long")  INT32_T=long ;;
555     "$ac_cv_sizeof_short") INT32_T=short ;;
556     *)
557       AC_MSG_RESULT([none found])
558       AC_MSG_ERROR([No 32 bit integer type found])
559 esac
560 AC_MSG_RESULT([$INT32_T])
562 AC_MSG_CHECKING([for 64 bit integer type])
563 case 8 in
564     "$ac_cv_sizeof_int")       INT64_T=int ;;
565     "$ac_cv_sizeof_long")      INT64_T=long ;;
566     "$ac_cv_sizeof_long_long") INT64_T='long long' ;;
567     *)
568       AC_MSG_RESULT([none found])
569       AC_MSG_ERROR([No 64 bit integer type found])
570 esac
571 AC_MSG_RESULT([$INT64_T])
573 dnl Check for perl (needed to generate some sources and documentation).
574 AC_PATH_PROG([PERL], [perl], [])
575 AC_ARG_VAR([PERL], [Perl interpreter])
576 if test x$USE_MAINTAINER_MODE = xyes; then
577   test -z "$PERL" && AC_MSG_ERROR([perl is required in maintainer mode])
580 AC_ARG_ENABLE([64bit_docid],
581   [AS_HELP_STRING([--enable-64bit-docid], [enable 64bit docid])],
582   [case ${enableval} in
583     yes|no) ;;
584   *) AC_MSG_ERROR([bad value ${enableval} for --enable-64bit-docid]) ;;
585   esac],
586   [enable_64bit_docid=no])
588 AC_ARG_ENABLE([64bit_termcount],
589   [AS_HELP_STRING([--enable-64bit-termcount], [enable 64bit termcount])],
590   [case ${enableval} in
591     yes|no) ;;
592   *) AC_MSG_ERROR([bad value ${enableval} for --enable-64bit-termcount]) ;;
593   esac],
594   [enable_64bit_termcount=no])
596 AC_ARG_ENABLE([64bit_termpos],
597   [AS_HELP_STRING([--enable-64bit-termpos], [enable 64bit termpos])],
598   [case ${enableval} in
599     yes|no) ;;
600   *) AC_MSG_ERROR([bad value ${enableval} for --enable-64bit-termpos]) ;;
601   esac],
602   [enable_64bit_termpos=no])
604 AC_ARG_ENABLE([documentation],
605   [AS_HELP_STRING([--enable-documentation], [enable make rules to rebuild documentation [default=maintainer-mode]])],
606   [case ${enableval} in
607     yes|no) ;;
608     *) AC_MSG_ERROR([bad value ${enableval} for --enable-documentation]) ;;
609   esac],
610   [enable_documentation=$USE_MAINTAINER_MODE])
611 AM_CONDITIONAL([DOCUMENTATION_RULES], [test x"$enable_documentation" = xyes])
612 AM_CONDITIONAL([MAINTAINER_NO_DOCS], [test x"$USE_MAINTAINER_MODE$enable_documentation" = xyesno])
614 if test x"$enable_documentation" = xyes ; then
615   dnl Checks for dot.  (Diagrams in the documentation)
616   AC_PATH_PROG([DOT], [dot])
617   AC_ARG_VAR([DOT], [dot from graphviz])
618   test -z "$DOT" && AC_MSG_ERROR([dot (part of the graphviz package) is required to build documentation])
619   DOXYGEN_DOT_PATH=`echo "$DOT" | sed 's!/dot$!!'`
620   AC_SUBST([DOXYGEN_DOT_PATH])
622   dnl Check for doxygen. (Needed to make some more of the documentation)
623   AC_PATH_PROG([DOXYGEN], [doxygen], [])
624   AC_ARG_VAR([DOXYGEN], [Doxygen documentation system])
625   test -z "$DOXYGEN" && AC_MSG_ERROR([doxygen is required to build documentation])
627   dnl Check for help2man. (Needed to make man pages from "--help" output).
628   AC_PATH_PROG([HELP2MAN], [help2man], [])
629   AC_ARG_VAR([HELP2MAN], [help2man man page generator])
630   test -z "$HELP2MAN" && AC_MSG_ERROR([help2man is required to build documentation])
632   dnl Check for rst2html. (Needed to make HTML from reStructuredText format)
633   dnl Also look for rst2html.py, which archlinux reportedly installs it as.
634   AC_PATH_PROGS([RST2HTML], [rst2html rst2html.py], [])
635   AC_ARG_VAR([RST2HTML], [reST to HTML convertor])
636   test -z "$RST2HTML" && AC_MSG_ERROR([rst2html is required to build documentation (try package python-docutils)])
638   dnl Check for pngcrush, which we optionally use to reduce the size of the
639   dnl PNG files which doxygen generates.  We can get by without it, so don't
640   dnl fail here if it's not found.
641   AC_PATH_PROG([PNGCRUSH], [pngcrush], [])
642   AC_ARG_VAR([PNGCRUSH], [PNG optimiser])
645 dnl Checks for header files.
646 AC_CHECK_HEADERS([fcntl.h limits.h poll.h sys/select.h],
647                  [], [], [ ])
648 AC_CHECK_HEADERS([sys/resource.h],
649                  [], [], [#include <sys/types.h>])
651 dnl cxxabi.h was added in GCC 3.1, but clang lies and defines __GNUC__ yet
652 dnl doesn't seem to reliably provide this header, so probe for it.
653 AC_CHECK_HEADERS([cxxabi.h], [], [], [ ])
655 dnl If valgrind is installed and new enough, we use it for leak checking in the
656 dnl testsuite.  If VALGRIND is set to an empty value, then skip the check and
657 dnl don't use valgrind.  On macOS only use valgrind if VALGRIND is set to a
658 dnl no empty value, as valgrind on macOS gives a lot of false positives.
659 use_valgrind_if_non_empty=
660 case $host in
661   *-*-darwin*)
662     use_valgrind_if_non_empty=$VALGRIND ;;
663   *)
664     use_valgrind_if_non_empty=${VALGRIND-unset} ;;
665 esac
667 if test -n "$use_valgrind_if_non_empty" ; then
668   AC_PATH_PROG([VALGRIND], [valgrind], [])
669   AC_ARG_VAR([VALGRIND], [debugging tool (optionally used by test harness)])
670   if test -n "$VALGRIND" ; then
671     dnl Check that the installed valgrind version works, and supports the
672     dnl options we use.  This means we won't try to use valgrind < 3.3.0
673     dnl (released 7/12/2007) since before that --log-file didn't expand
674     dnl %p (and appended the process id).
675     dnl
676     dnl No need to check for VALGRIND_COUNT_LEAKS now - that was added before
677     dnl 2.0.0.
678     AC_MSG_CHECKING([if valgrind supports --log-file with %p and --child-silent-after-fork=yes])
679     vglog=config.vglog.%p.tmp
680     vglogwild="config.vglog.*.tmp*"
681     rm -f $vglogwild
682     if $VALGRIND --log-file="$vglog" --child-silent-after-fork=yes -q true 2>&AS_MESSAGE_LOG_FD ; then
683       for f in $vglogwild ; do
684         case $f in
685         $vglog*) VALGRIND= ;;
686         esac
687       done
688       if test x"$VALGRIND" = x ; then
689         AC_MSG_RESULT([no])
690       else
691         AC_MSG_RESULT([yes])
692         AC_CHECK_HEADERS([valgrind/memcheck.h], [], [VALGRIND=], [ ])
693       fi
694     else
695       dnl The valgrind detected doesn't seem to work!  Perhaps this is an
696       dnl x86_64 box with a 32 bit valgrind.
697       AC_MSG_RESULT([$VALGRIND doesn't work])
698       VALGRIND=
699     fi
700     rm -f $vglogwild
701   fi
704 if test -n "$VALGRIND" ; then
705   AC_DEFINE([HAVE_VALGRIND], [1], [Define if a suitable valgrind is installed])
708 dnl If eatmydata is installed, we run the testsuite under it to speed it up.
709 dnl If EATMYDATA is set to an empty value, then skip this check and don't use
710 dnl eatmydata.
711 if test -n "${EATMYDATA-unset}" ; then
712   AC_PATH_PROG([EATMYDATA], [eatmydata], [])
713   AC_ARG_VAR([EATMYDATA], [wrapper to disable fsync (optionally used by test harness)])
716 dnl Checks for library functions.
717 AC_FUNC_STRERROR_R
719 AC_CACHE_CHECK([for sys_errlist and sys_nerr], xo_cv_sys_errlist_and_sys_nerr, [
720   AC_LINK_IFELSE([AC_LANG_PROGRAM(
721 dnl On Linux, sys_errlist and sys_nerr need <stdio.h>, though the man page
722 dnl says <errno.h>.  The man page seems to match other platforms such as
723 dnl NetBSD, so include both headers to ensure we get them.  With mingw and MSVC
724 dnl they're provided by <stdlib.h>.
725 [[#include <errno.h>
726 #include <stdio.h>
727 #include <stdlib.h>]],
728 [[  printf("%s", sys_errlist[sys_nerr - 1]);]])],
729   [ xo_cv_sys_errlist_and_sys_nerr=yes ],
730   [ xo_cv_sys_errlist_and_sys_nerr=no ])
732 if test "x$xo_cv_sys_errlist_and_sys_nerr" = "xyes" ; then
733   AC_DEFINE([HAVE_SYS_ERRLIST_AND_SYS_NERR], [1],[Define if you have 'sys_errlist' and 'sys_nerr'])
736 AC_CACHE_CHECK([for _sys_errlist and _sys_nerr], xo_cv__sys_errlist_and__sys_nerr, [
737   AC_LINK_IFELSE([AC_LANG_PROGRAM(
738 [[#include <errno.h>
739 #include <stdio.h>
740 #include <stdlib.h>]],
741 [[  printf("%s", _sys_errlist[_sys_nerr - 1]);]])],
742   [ xo_cv__sys_errlist_and__sys_nerr=yes ],
743   [ xo_cv__sys_errlist_and__sys_nerr=no
744   ])
746 if test "x$xo_cv__sys_errlist_and__sys_nerr" = "xyes" ; then
747   AC_DEFINE([HAVE__SYS_ERRLIST_AND__SYS_NERR], [1],[Define if you have '_sys_errlist' and '_sys_nerr'])
750 dnl GNU-specific replacement for sys_errlist and sys_nerr.
751 AC_CHECK_FUNCS([strerrordesc_np])
753 dnl mingw has _snprintf so check for that too.
754 AC_MSG_CHECKING([for  snprintf])
755 AC_CACHE_VAL([xo_cv_func_snprintf],
756   [
757   xo_cv_func_snprintf=no
758   for func in snprintf _snprintf ; do
759     AC_COMPILE_IFELSE([
760       AC_LANG_PROGRAM(
761         [[
762 #include <cstdio>
763 using namespace std;
764         ]],
765         [[
766           char buffer[4] = "abc";
767           int res = $func(buffer, 4, "%s", "XYZ");
768           return res;
769         ]]
770       )],
771       [xo_cv_func_snprintf=$func;break],
772       []
773     )
774   done
775   ])
776 AC_MSG_RESULT([$xo_cv_func_snprintf])
777 if test "$xo_cv_func_snprintf" != no ; then
778   AC_DEFINE_UNQUOTED([SNPRINTF], [$xo_cv_func_snprintf],
779      [Define to the name of a function implementing snprintf but not caring about ISO C99 return value semantics (if one exists)])
782 dnl ***************************
783 dnl * Select modules to build *
784 dnl ***************************
786 dnl Check which database backends should be built.
788 AC_DEFUN([_XAPIAN_BACKEND_ENABLE],
789   [AC_ARG_ENABLE([backend_$1],
790     [AS_HELP_STRING([--enable-backend-$1], [build the $1 database backend [default=$3]])],
791     [case $enableval in
792       yes|no) ;;
793       *) AC_MSG_ERROR([Invalid option: '--enable-backend-$1=$enableval']) ;;
794     esac], [enable_backend_$1=$2])
795   ])
797 AC_DEFUN([XAPIAN_BACKEND_ENABLE],
798   [_XAPIAN_BACKEND_ENABLE([$1],
799     m4_default([$2], [yes]),
800     m4_default([$3], [yes]))
801   ])
803 dnl When adding a new backend, update INSTALL too.
804 XAPIAN_BACKEND_ENABLE([chert])
805 XAPIAN_BACKEND_ENABLE([glass])
806 XAPIAN_BACKEND_ENABLE([inmemory])
807 default_enable_backend_remote=yes
808 case $host_os in
809   *djgpp* | *msdos* )
810     dnl We don't currently support the remote backend on this platform so
811     dnl disable it by default.
812     default_enable_backend_remote=no
813     ;;
814 esac
815 XAPIAN_BACKEND_ENABLE([remote], [$default_enable_backend_remote], [yes (except for MSDOS)])
817 dnl Save and empty LIBS while we probe for libraries to link libxapian against
818 dnl so we can just use AC_SEARCH_LIBS then copy LIBS to XAPIAN_LIBS and restore
819 dnl the value saved here.
820 save_LIBS=$LIBS
821 LIBS=
823 dnl See if we have fdatasync, and what libraries are needed for it.
824 dnl We need to actually check for a declaration as OS X has a dummy
825 dnl implementation in the library which is not prototyped in any header.
826 AC_CHECK_DECL([fdatasync(int)], [
827   AC_SEARCH_LIBS([fdatasync], [rt], [])
828   AC_CHECK_FUNCS([fdatasync])
829   ],
830   [ac_cv_func_fdatasync=no],
831   [#include <unistd.h>]
834 dnl We use timer_create() if available to implement a search time limit.
835 AC_SEARCH_LIBS([timer_create], [rt],
836                [
837     AC_MSG_CHECKING([for timer_create() usability])
838     dnl Several platforms have timer_create() but it's non-functional.
839     dnl
840     dnl Some of these (at least those with a stub implementation which always
841     dnl fails with ENOSYS) could be probed for, but we'd have to run code
842     dnl which isn't possible when cross-compiling, so just maintain a list
843     dnl of such platforms for now.
844     AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
845 [[#if defined _AIX
846 #error timer_create always fails with EAGAIN on AIX 7.1
847 #elif defined __GNU__
848 #error timer_create always fails with ENOSYS on GNU Hurd
849 #elif defined __NetBSD__
850 #error timer_create timers never fire on NetBSD 7.1
851 #elif defined __OpenBSD__
852 #error timer_create always fails with ENOSYS on OpenBSD 6.2 (and no prototype)
853 #endif]])],
854         [AC_MSG_RESULT([yes])
855         AC_DEFINE([HAVE_TIMER_CREATE], [1], [Define to 1 if you have the 'timer_create' function.])]
856         ,
857         [AC_MSG_RESULT([no])
858     ])
861 win32_need_lws2_32=0
862 case $enable_backend_chert$enable_backend_glass in
863 *yes*)
864   dnl We use zlib for compressing tags in chert/glass.  We could
865   dnl automatically disable support if zlib isn't found, but overall that
866   dnl probably does more harm than good - it's most likely that someone just
867   dnl forgot to install the -dev package for zlib.
868   dnl
869   dnl Similarly for uuid support.
871   dnl Check for zlib.h.
872   AC_CHECK_HEADERS([zlib.h], [], [
873     AC_MSG_ERROR([zlib.h not found - required for chert and glass (you may need to install the zlib1g-dev or zlib-devel package)])
874     ], [ ])
876   dnl Check for zlibVersion - normally it's in -lz but the mingw build needs -lzlib or -lzdll.
877   AC_SEARCH_LIBS([zlibVersion], [z zlib zdll], [], [
878     AC_MSG_ERROR([zlibVersion() not found in -lz, -lzlib, or -lzdll - required for chert and glass (you may need to install the zlib1g-dev or zlib-devel package)])
879     ])
881   dnl Find the UUID library (from e2fsprogs/util-linux-ng, not the OSSP one).
883   case $host_os-$win32 in
884     *-yes | *cygwin*) dnl Use built-in win32 API.
885       AC_DEFINE([USE_WIN32_UUID_API], [1],
886                 [Define to 1 to use UuidCreate(), etc])
887       if test $win32 = yes ; then
888         dnl We need -lws2_32 for htonl(), etc, but not for Cygwin which
889         dnl provides these functions in its libc.
890         win32_need_lws2_32=1
891       fi
892       LIBS="$LIBS -lrpcrt4"
893       ;;
894     *)
895       dnl Check for uuid/uuid.h (e2fsprogs/util-linux-ng) or uuid.h
896       dnl (FreeBSD/NetBSD/OpenBSD/AIX).
897       AC_CHECK_HEADERS([uuid/uuid.h], [
898         dnl util-linux-ng's uuid/uuid.h found - check for uuid_generate in
899         dnl -luuid.
900         AC_SEARCH_LIBS([uuid_generate], [uuid], [], [
901           AC_MSG_ERROR([uuid_generate() not found in -luuid - required for chert and glass (you may need to install the uuid-dev, libuuid-devel or e2fsprogs-devel package)])
902           ])
903       ], [
904         dnl Try uuid.h as found on FreeBSD/NetBSD/OpenBSD/AIX, with associated
905         dnl code in libc.
906         AC_CHECK_HEADERS([uuid.h], [
907           dnl Check for uuid_create with no extra libraries required.
908           AC_CHECK_FUNC([uuid_create], [], [
909             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)])
910           ])
911         ], [
912           dnl Especially useful for Android.
913           AC_MSG_CHECKING([if host platform supports /proc/sys/kernel/random/uuid])
914           case $host_os in
915             linux*)
916               AC_DEFINE([USE_PROC_FOR_UUID], [1],
917                         [Define to 1 to read UUID from '/proc/sys/kernel/random/uuid'])
918               AC_MSG_RESULT([yes])
919               ;;
920             *)
921               AC_MSG_RESULT([no])
922               AC_MSG_ERROR([Failed to find a way to generate UUIDs, required for chert and glass backends (you may need to install the uuid-dev, libuuid-devel or e2fsprogs-devel package)])
923               ;;
924           esac
925         ], [ ])
926       ], [ ])
927       ;;
928   esac
930   case $host_os in
931     *djgpp* | *msdos* )
932       dnl DJGPP has a dummy implementation of fork which always fails.
933       dnl
934       dnl For disk-based backends, use flock() for locking, which doesn't need
935       dnl fork() or socketpair().
936       AC_DEFINE([FLINTLOCK_USE_FLOCK], 1, [Define to use flock() for flint-compatible locking])
937       ;;
938   esac
939   ;;
940 esac
942 if test "$enable_backend_remote" = yes ; then
943   case $host_os-$win32 in
944     *-yes )
945       dnl For mingw and msvc we have an alternative implementation which
946       dnl doesn't need fork() or socketpair().
947       dnl
948       dnl We need -lws2_32 for getaddrinfo(), etc.
949       win32_need_lws2_32=1
950       dnl Vista is needed for the AI_ADDRCONFIG flag to getaddrinfo().
951       AC_DEFINE([WINVER], [0x600],
952                 [Version of Windows to assume (0x600 => Vista).])
953       AC_DEFINE([_WIN32_WINNT], [WINVER],
954                 [Version of Windows to assume.])
955       ;;
956     *djgpp* | *msdos* )
957       dnl DJGPP has a dummy implementation of fork which always fails.  If
958       dnl someone actually wanted remote backend support, then DJGPP has a
959       dnl pthreads port, so using threads like we do on Windows would make more
960       dnl sense.
961       AC_MSG_ERROR([The remote backend is not currently supported on this platform.])
962       ;;
963     *)
964       dnl On Unix, we need fork and socketpair for the remotebackend.
965       AC_CHECK_FUNCS([fork], [], [
966         AC_MSG_ERROR([fork() required for the remote backend - if an extra library is needed, pass LIBS=-lfoo to configure.  Or --disable-backend-remote to disable it.])
967       ])
968       dnl Check if -lsocket is required for socketpair (Solaris needs it).
969       dnl And on Haiku it's in -lnetwork.
970       AC_SEARCH_LIBS([socketpair], [socket network], [], [
971         AC_MSG_ERROR([socketpair() required for the remote backend - if an extra library is needed, pass LIBS=-lfoo to configure.  Or --disable-backend-remote to disable it.])
972       ])
973       AC_DEFINE([HAVE_SOCKETPAIR], [1],
974                 [Define to 1 if you have the 'socketpair' function.])
975       dnl Check if extra libraries are needed for getaddrinfo or inet_ntop()
976       dnl (e.g. on Solaris).
977       dnl
978       dnl We're currently assuming that any system that is worth trying to
979       dnl support has getaddrinfo() and inet_ntop(), since these are the
980       dnl standard route for supporting IPv6, and that's pretty much essential
981       dnl for platforms to support now.
982       AC_SEARCH_LIBS([getaddrinfo], [nsl socket], [], [
983         AC_MSG_ERROR([getaddrinfo() required for the remote backend - if an extra library is needed, pass LIBS=-lfoo to configure.  Or --disable-backend-remote to disable it.])
984       ])
985       AC_SEARCH_LIBS([inet_ntop], [nsl socket], [], [
986         AC_MSG_ERROR([inet_ntop() required for the remote backend - if an extra library is needed, pass LIBS=-lfoo to configure.  Or --disable-backend-remote to disable it.])
987       ])
988       ;;
989   esac
991   XAPIAN_TYPE_SOCKLEN_T
994 if test "$win32_need_lws2_32" = 1 ; then
995   LIBS="$LIBS -lws2_32"
997 XAPIAN_LIBS=$LIBS
998 LIBS=$save_LIBS
1000 AC_ARG_ENABLE([visibility],
1001   [AS_HELP_STRING([--disable-visibility], [disable use of GCC visibility])],
1002   [case ${enableval} in
1003     yes|no) ;;
1004     *) AC_MSG_ERROR([bad value ${enableval} for --disable-visibility]) ;;
1005   esac])
1007 vpath_build=no
1008 if test "`pwd`" != "`cd $srcdir;pwd`" ; then
1009   vpath_build=yes
1011 AM_CONDITIONAL([VPATH_BUILD], [test yes = "$vpath_build"])
1013 dnl Turn off compilation of anything that we don't have the requirements for
1015 dnl Set conditionals to specify what we compile
1017 AM_CONDITIONAL([BUILD_BACKEND_CHERT], [test yes = "$enable_backend_chert"])
1018 AM_CONDITIONAL([BUILD_BACKEND_GLASS], [test yes = "$enable_backend_glass"])
1019 AM_CONDITIONAL([BUILD_BACKEND_INMEMORY], [test yes = "$enable_backend_inmemory"])
1020 AM_CONDITIONAL([BUILD_BACKEND_REMOTE], [test yes = "$enable_backend_remote"])
1021 AM_CONDITIONAL([BUILD_BACKEND_CHERT_OR_GLASS],
1022   [test nono != "$enable_backend_chert$enable_backend_glass"])
1024 dnl Decide if we should use the zlib-vg.so LD_PRELOAD hack.
1025 use_zlib_vg=no
1026 if test -n "$VALGRIND" ; then
1027   case $host_os in
1028     linux*) use_zlib_vg=yes ;;
1029   esac
1031 AM_CONDITIONAL([USE_ZLIB_VG], [test yes = "$use_zlib_vg"])
1033 AC_CHECK_FUNCS([fsync])
1034 AC_CHECK_FUNCS([posix_fadvise])
1035 if test "$win32" = no ; then
1036   dnl ftruncate() under Wine seems to be buggy and sometimes fails, though
1037   dnl a cut-down reproducer seems fine.  For now just avoid ftruncate()
1038   dnl entirely on this platform - we'll fallback to lseek() + write() of a
1039   dnl single zero byte, which is pretty efficient.
1040   AC_CHECK_FUNCS([ftruncate])
1043 dnl HP-UX has pread and pwrite, but they don't work!  Apparently this problem
1044 dnl manifests when largefile support is enabled, and we definitely want that
1045 dnl so don't use pread or pwrite on HP-UX.
1046 case $host_os in
1047   hpux*)
1048     AC_MSG_CHECKING([for pread])
1049     AC_MSG_RESULT([present but broken on $host_os])
1050     AC_MSG_CHECKING([for pwrite])
1051     AC_MSG_RESULT([present but broken on $host_os])
1052     ;;
1053   *)
1054     AC_CHECK_FUNC([pread],
1055        [AC_DEFINE([HAVE_PREAD], [1],
1056             [Define if pread is available on this system])
1057         AC_MSG_CHECKING([for any prototype needed for pread])
1058         AC_CACHE_VAL([xo_cv_pread_prototype],
1059           [
1060             for p in ' ' \
1061               'extern "C" ssize_t pread(int, void *, size_t, off_t) throw ();' \
1062               'extern "C" ssize_t pread(int, void *, size_t, off_t);' ; do
1063               AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1064 #include <sys/types.h>
1065 #include <unistd.h>
1067               ]],[[
1068                 char b[256];
1069                 pread(1, b, 256, 20);
1070               ]])],[
1071                 xo_cv_pread_prototype="$p"
1072                 break
1073               ], [])
1074             done
1075             if test -z "$xo_cv_pread_prototype"; then
1076               AC_MSG_RESULT([not found])
1077               AC_MSG_ERROR([Failed to find working prototype for pread])
1078             fi
1079           ])
1080           if test " " = "$xo_cv_pread_prototype" ; then
1081             AC_MSG_RESULT([none required])
1082           else
1083             AC_MSG_RESULT([$xo_cv_pread_prototype])
1084             AC_DEFINE_UNQUOTED([PREAD_PROTOTYPE], [$xo_cv_pread_prototype],
1085                                [explicit prototype needed for pread (if any)])
1086           fi
1087         ])
1088     AC_CHECK_FUNC([pwrite],
1089        [AC_DEFINE([HAVE_PWRITE], [1],
1090             [Define if pwrite is available on this system])
1091         AC_MSG_CHECKING([for any prototype needed for pwrite])
1092         AC_CACHE_VAL([xo_cv_pwrite_prototype],
1093           [
1094             for p in ' ' \
1095               'extern "C" ssize_t pwrite(int, const void *, size_t, off_t) throw ();' \
1096               'extern "C" ssize_t pwrite(int, const void *, size_t, off_t);' ; do
1097               AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1098 #include <sys/types.h>
1099 #include <unistd.h>
1101               ]],[[
1102                 const char *p = "hello";
1103                 pwrite(1, p, 5, 20);
1104               ]])],[
1105                 xo_cv_pwrite_prototype="$p"
1106                 break
1107               ], [])
1108             done
1109             if test -z "$xo_cv_pwrite_prototype"; then
1110               AC_MSG_RESULT([not found])
1111               AC_MSG_ERROR([Failed to find working prototype for pwrite])
1112             fi
1113           ])
1114           if test " " = "$xo_cv_pwrite_prototype" ; then
1115             AC_MSG_RESULT([none required])
1116           else
1117             AC_MSG_RESULT([$xo_cv_pwrite_prototype])
1118             AC_DEFINE_UNQUOTED([PWRITE_PROTOTYPE], [$xo_cv_pwrite_prototype],
1119                                [explicit prototype needed for pwrite (if any)])
1120           fi
1121         ])
1122     ;;
1123 esac
1125 AC_MSG_CHECKING([for directory separator(s)])
1126 case $host_os-$win32 in
1127   *-yes | cygwin* | os2* | *djgpp* | *msdos* )
1128     AC_MSG_RESULT([/ and \\])
1129     AC_DEFINE([DIR_SEPS], ["/\\"], [directory separator(s) as a character or string literal])
1130     AC_DEFINE([DIR_SEPS_LIST], [{ '/', '\\' }], [directory separator(s) as an initialiser list])
1131     ;;
1132   *)
1133     AC_MSG_RESULT([/])
1134     AC_DEFINE([DIR_SEPS], ['/'], [directory separator(s) as a character or string literal])
1135     AC_DEFINE([DIR_SEPS_LIST], [{ '/' }], [directory separator(s) as an initialiser list])
1136     ;;
1137 esac
1139 AC_CHECK_FUNCS([link])
1141 dnl *************************
1142 dnl * Set debugging options *
1143 dnl *************************
1145 dnl Which assertion types to enable in the code.
1147 AC_ARG_ENABLE([assertions],
1148   [AS_HELP_STRING([--enable-assertions], [enable debug assertions (no|partial|yes) [default=no]])],
1149   [case $enableval in
1150     yes|partial|no) ;;
1151     *)
1152       AC_MSG_ERROR([Invalid option: '--enable-assertions=$enableval']) ;;
1153   esac])
1155 AC_ARG_ENABLE([log],
1156   [AS_HELP_STRING([--enable-log], [generate a log of methods called, etc (no|yes|profile) [default=no]])],
1157   [case $enableval in
1158     yes|no) ;;
1159     profile)
1160       AC_MSG_ERROR(['--enable-log=profile' is no longer supported - see https://trac.xapian.org/wiki/ProfilingXapian for alternatives.]) ;;
1161     *)
1162       AC_MSG_ERROR([Invalid option: '--enable-log=$enableval']) ;;
1163   esac])
1165 dnl Set defines according to the --enable-assertions and --enable-log options
1166 dnl given.
1168 if test yes = "$enable_assertions" || test partial = "$enable_assertions" ; then
1169   AC_DEFINE([XAPIAN_ASSERTIONS],,
1170     [Define if you want assertions (causes some slow-down)])
1173 if test yes = "$enable_assertions"; then
1174   AC_DEFINE([XAPIAN_ASSERTIONS_PARANOID],,
1175     [Define if you want paranoid assertions (causes significant slow-down)])
1178 if test yes = "$enable_log"; then
1179   AC_DEFINE([XAPIAN_DEBUG_LOG],,
1180     [Define if you want a log of methods called and other debug messages])
1183 dnl ******************************
1184 dnl * Set special compiler flags *
1185 dnl ******************************
1187 dnl Set flags to control warnings (enable more, or disable annoying ones).
1188 dash_d_visibility=
1189 if test yes = "$GXX"; then
1190   dnl Intel's C++ compiler and clang both lie and define __GNUC__, so check which
1191   dnl we actually have, as neither is really 100% compatible.
1192   case `echo __INTEL_COMPILER __clang__|$CXX -E - 2>&AS_MESSAGE_LOG_FD|grep -v '^#'` in
1193     *__INTEL_COMPILER*__clang__*)
1194       dnl GCC (since neither substituted):
1196       dnl The exact format of g++ --version seems to change with almost every
1197       dnl minor release so use the preprocessor macros which should be more
1198       dnl robust.
1199       AC_MSG_CHECKING([for version of $CXX])
1200       gxx_version=`echo __GNUC__.__GNUC_MINOR__.__GNUC_PATCHLEVEL__|$CXX -E -|sed '/^#/d;s/ //g'`
1201       AC_MSG_RESULT([GCC $gxx_version])
1203       dnl -Wundef was supported by g++ 3.0.
1204       dnl
1205       dnl -Wlogical-op and -Wmissing-declarations (for C++) were added in
1206       dnl GCC 4.3.
1207       dnl
1208       dnl -Wdouble-promotion was added in GCC 4.6.
1209       dnl
1210       dnl -Winit-self was added in GCC 3.4, but for GCC < 4.7 g++ always
1211       dnl warns for this case with -Wuninitialized (implied by -W).  We
1212       dnl don't intend to use this idiom, so any instances are bugs we'd
1213       dnl like to know about.
1214       dnl
1215       dnl All the other options were supported by g++ 2.95.
1216       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"
1218       case $gxx_version in
1219       [[0123]].*|4.[[0-6]].*)
1220         AC_MSG_ERROR([Xapian requires GCC 4.7 or later])
1221         ;;
1222       4.*|5.*)
1223         ;;
1224       6.*)
1225         AM_CXXFLAGS="$AM_CXXFLAGS -Wduplicated-cond"
1226         ;;
1227       *)
1228         AM_CXXFLAGS="$AM_CXXFLAGS -Wduplicated-cond -Wduplicated-branches"
1229         ;;
1230       esac
1232       dnl FIXME:
1233       dnl -Wold-style-cast is interesting, but triggers for macros from
1234       dnl system headers (e.g. FD_SET).  GCC 4.8 improved this by making
1235       dnl -ftrack-macro-expansion=2 the default, but we still see such
1236       dnl warnings on some platforms for some reason (e.g. Cygwin with GCC
1237       dnl 5.4.0 warns about FD_SET, and on Debian with GCC 4.9.2 we see
1238       dnl warnings from zlib.h).
1240       dnl Automatically add -Werror if maintainer mode is enabled.
1241       if test x$USE_MAINTAINER_MODE = xyes; then
1242         AM_CXXFLAGS="$AM_CXXFLAGS -Werror"
1243       fi
1244       ;;
1245     *__clang__*)
1246       dnl Intel's compiler (since __clang__ not substituted):
1247       dnl
1248       dnl -w1 stops the avalanche of uninteresting "remark" messages.
1249       dnl -wd... disables warnings which don't have good code workarounds.
1250       AM_CXXFLAGS="$AM_CXXFLAGS -Wall -w1 -wd177,1572"
1252       dnl Automatically add -Werror if maintainer mode is enabled.
1253       if test x$USE_MAINTAINER_MODE = xyes; then
1254         AM_CXXFLAGS="$AM_CXXFLAGS -Werror"
1255       fi
1256       ;;
1257     *__INTEL_COMPILER*)
1258       dnl clang (since __INTEL_COMPILER not substituted):
1260       dnl These options all work at least as far back as clang++ 3.0:
1261       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"
1263       dnl Automatically add -Werror if maintainer mode is enabled.
1264       if test x$USE_MAINTAINER_MODE = xyes; then
1265         AM_CXXFLAGS="$AM_CXXFLAGS -Werror"
1266       fi
1267       ;;
1268   esac
1270   if test no != "$enable_visibility"; then
1271     dnl GCC doesn't support symbol visibility on all platforms (e.g. it isn't
1272     dnl supported on mingw and visibility attributes result in warnings).
1273     AC_MSG_CHECKING([if $CXX -fvisibility=hidden -fvisibility-inlines-hidden works])
1274     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
1275       AC_MSG_RESULT([yes])
1276       AM_CXXFLAGS="$AM_CXXFLAGS -fvisibility=hidden -fvisibility-inlines-hidden"
1277       dash_d_visibility=-DXAPIAN_ENABLE_VISIBILITY
1278     else
1279       AC_MSG_RESULT([no])
1280     fi
1281   fi
1282 else
1283   dnl Not GCC, nor a compiler masquerading as GCC.
1284   case /$CXX in
1285   */aCC)
1286     dnl +w turns on more warnings.
1287     dnl +wlint turns on "lint-like" warnings.
1288     dnl +W<n1>,<n2>,... suppresses warnings n1, n2, ...
1289     dnl 2340 (remark) "value copied to temporary, reference to temporary
1290     dnl use", in: throw Xapian::UnimplementedError("...");
1291     dnl 2401 "destructor for base class ... is non-virtual" (we don't need a
1292     dnl virtual destructor for intrusive_base, since we never delete
1293     dnl       its subclasses by a intrusive_base *).
1294     dnl 3348 "declaration hides constant ..." which seems to misfire!
1295     dnl 4255 (remark) "padding size of struct "..." with ... bytes to
1296     dnl alignment boundary".
1297     dnl 4273 "floating-point equality and inequality comparisons may be
1298     dnl inappropriate due to roundoff common in floating-point computation"
1299     dnl No obvious workaround for when you really do want == or !=.
1300     dnl 4285 "operator= does not have a check for the source and destination
1301     dnl addresses being non-identical" - fires for AutoPtr which
1302     dnl includes such a check indirectly (internaltest's autoptr1 check this).
1303     dnl 20201 "Memory leak is detected" which triggers for "return new Foo;"!
1304     AM_CXXFLAGS="$AM_CXXFLAGS +w +wlint +W2340,2401,3348,4255,4273,4285,20201" ;;
1305   */sunCC|*/CC)
1306     dnl Sun's C++ compiler.
1307     dnl
1308     dnl We use -errtags to report the tag for each warning emitted.
1309     dnl
1310     dnl We use -erroff to suppress some unhelpful warnings:
1311     dnl
1312     dnl oklambdaretmulti warns about a lambda with more than one return
1313     dnl statement even if they all return the same type.
1314     dnl
1315     dnl voidretw warns about functions failing to return a value even when the
1316     dnl function ends with a "throw" statement.  That's just unhelpful noise,
1317     dnl and adding a dummy "return" after "throw" seems a worse solution than
1318     dnl simply disabling this warning - any genuinely missing return statements
1319     dnl will get reported by compilers with superior warning machinery.
1320     XAPIAN_TEST_CXXFLAGS([-errtags -erroff=oklambdaretmulti,voidretw], [AM_CXXFLAGS])
1321     ;;
1322   esac
1325 XAPIAN_TEST_LDFLAGS([-Wl,-Bsymbolic-functions], [XAPIAN_LDFLAGS])
1326 dnl Roughly equivalent Sun C++ option.
1327 XAPIAN_TEST_LDFLAGS([-xldscope=symbolic], [XAPIAN_LDFLAGS])
1329 dnl New in GCC 5.  Sort of like -Bsymbolic-functions, but for the compiler
1330 dnl rather than the linker.
1331 XAPIAN_TEST_LDFLAGS([-fno-semantic-interposition], [XAPIAN_LDFLAGS])
1333 AC_MSG_CHECKING([whether to use SSE instructions on x86])
1334 case $host_cpu in
1335   i*86)
1336     if test "$enable_sse" = no ; then
1337       AC_MSG_RESULT([no])
1338       if test yes = "$msvc"; then
1339         dnl MSVC defaults to SSE2.
1340         AM_CXXFLAGS="$AM_CXXFLAGS -arch:IA32"
1341       fi
1342     else
1343       dnl Default to sse2.
1344       test "$enable_sse" != yes || enable_sse=sse2
1345       if test yes = "$GXX"; then
1346         AC_MSG_RESULT([yes (configure with --disable-sse to disable)])
1347         dnl We can unconditionally use -mtune=generic as it was added in GCC
1348         dnl 4.2, and supported at least as far back as clang 3.0.
1349         AM_CXXFLAGS="$AM_CXXFLAGS -mfpmath=sse -m$enable_sse -mtune=generic"
1350       elif test yes = "$msvc"; then
1351         AC_MSG_RESULT([yes (configure with --disable-sse to disable)])
1352         if test sse = "$enable_sse"; then
1353           dnl MSVC defaults to SSE2.
1354           AM_CXXFLAGS="$AM_CXXFLAGS -arch:SSE"
1355         fi
1356       else
1357         AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
1358 [[#ifndef __SUNPRO_CC
1359 #error Not Sun compiler
1360 #endif]])],
1361           [AC_MSG_RESULT([yes (configure with --disable-sse to disable)])
1362           AM_CXXFLAGS="$AM_CXXFLAGS -xarch=$enable_sse"]
1363           ,
1364           [AC_MSG_RESULT([don't know how to for compiler $CXX])]
1365         )
1366       fi
1367     fi
1368     ;;
1369   *)
1370     AC_MSG_RESULT([non-x86 arch ($host_cpu)]) ;;
1371 esac
1373 AH_BOTTOM(
1374 [/* Disable stupid MSVC warnings. */
1375 #ifdef _MSC_VER
1376 /* Passing an empty parameter to a single parameter macro. */
1377 # pragma warning(disable:4003)
1378 /* A "performance" warning for converting int to bool. */
1379 # pragma warning(disable:4800)
1381 /* POSIX get to deprecate POSIX things, not Microsoft. */
1382 # define _CRT_NONSTDC_NO_WARNINGS
1383 # define _CRT_SECURE_NO_WARNINGS
1385 /* WSAAddressToStringA() is deprecated and we should apparently use
1386  * WSAAddressToStringW(), but we don't want wide character output so
1387  * that would mean we'd have to convert the result back to ASCII
1388  * which is a really stupid idea.
1389  */
1390 # define _WINSOCK_DEPRECATED_NO_WARNINGS
1392 /* Tell MSVC we want M_PI, etc defined. */
1393 # define _USE_MATH_DEFINES
1395 /* Tell MSVC we don't want max() and min() macros defined. */
1396 # define NOMINMAX
1397 #endif
1399 /* Make the POSIX-like functions support large files.  MSVC needs this;
1400  * current mingw32 does too; mingw64 supports _FILE_OFFSET_BITS, which
1401  * AC_SYS_LARGEFILE should discover and enable automatically.
1402  */
1403 #if defined _MSC_VER || \
1404     (defined __MINGW32__ && !defined _FILE_OFFSET_BITS)
1406 # include <sys/stat.h>
1407 # include <sys/types.h>
1408 # include <io.h>
1409 /* zlib.h uses off_t so we need to include it before we redefine off_t. */
1410 # include <zlib.h>
1412 // The default stat() and fstat() use 32-bit filesizes and time_t, so we need
1413 // to arrange to use 64-bit variants instead.
1415 # ifdef stat
1416 // Break #undef lines to stop config.status from commenting them out.
1417 #  undef \
1418         stat
1419 # endif
1421 // This hack is a problem is we ever want a method called "stat".
1422 # ifdef _MSC_VER
1423 // MSVC needs to call _stat64() instead of stat() and the struct which holds
1424 // the information is `struct _stat64` instead of `struct stat` so we just
1425 // use #define to replace both in one go.
1426 #  define stat _stat64
1427 # else
1428 // Mingw32 has _stat64() but unhelpfully for our purposes, the struct is
1429 // called __stat64 (with an extra underscore).  We hack around this by
1430 // defining stat to __stat64 which sorts out the struct, and then using
1431 // a second macro to forward function-like uses of __stat64() to
1432 // _stat64().
1433 #  define stat __stat64
1434 #  define __stat64(PATH, STATBUF) _stat64((PATH), (STATBUF))
1435 # endif
1437 // We also want to use _fstat64() instead of fstat() but in this case we can
1438 // use a function-like macro, so we could have a method called fstat so long
1439 // as it didn't take two parameters.
1441 # ifdef fstat
1442 // Break #undef lines to stop config.status from commenting them out.
1443 #  undef \
1444         fstat
1445 # endif
1447 # define fstat(FD, BUF) _fstat64(FD, BUF)
1449 # ifdef lseek
1450 // Break #undef lines to stop config.status from commenting them out.
1451 #  undef \
1452         lseek
1453 # endif
1455 # ifdef off_t
1456 // Break #undef lines to stop config.status from commenting them out.
1457 #  undef \
1458         off_t
1459 # endif
1461 # define lseek(FD, OFF, WHENCE) _lseeki64(FD, OFF, WHENCE)
1462 /* Redefine via a typedef so C++ code off_t(-1) works - it wouldn't if we did:
1463  * #define off_t long long
1464  */
1465 typedef long long off_t_redefinition_typedef;
1466 # define off_t off_t_redefinition_typedef
1468 #endif
1470 /* MSVC defines _WIN32 but not __WIN32__. */
1471 #if !defined __WIN32__ && defined _WIN32
1472 # define __WIN32__
1473 #endif
1475 /* MSVC defines _WIN64 but not __WIN64__. */
1476 #if !defined __WIN64__ && defined _WIN64
1477 # define __WIN64__
1478 #endif
1480 /* Default to enabling _FORTIFY_SOURCE at level 2.  It shouldn't cause a
1481  * problem to define it where it's not supported.
1483  * Check if _FORTIFY_SOURCE is already defined to allow the user to override
1484  * our choice with "./configure CPPFLAGS=-D_FORTIFY_SOURCE=0" or "...=1".
1485  */
1486 #if defined __GNUC__ && !defined _FORTIFY_SOURCE
1487 # define _FORTIFY_SOURCE 2
1488 # ifdef __MINGW32__
1489 /* Both mingw32 and mingw-w64 define __MINGW32__. */
1490 #  include <stddef.h>
1491 #  ifdef __MINGW64_VERSION_MAJOR
1492 /* Enabling _FORTIFY_SOURCE on newer mingw-w64 requires linking with -lssp so
1493  * we simply don't automatically enable it there.
1494  */
1495 #   undef _FORTIFY_SOURCE
1496 #  endif
1497 # endif
1498 #endif
1500 /* For compilers which support it (such as GCC, clang, Intel's C++ compiler)
1501  * we can use __builtin_expect to give the compiler hints about branch
1502  * prediction.  See HACKING for how to use these.
1503  */
1504 #if HAVE_DECL___BUILTIN_EXPECT
1505 /* The arguments of __builtin_expect() are both long, so use !! to ensure that
1506  * the first argument is always an integer expression, and always 0 or 1, but
1507  * still has the same truth value for the if or while it is used in.
1508  */
1509 # define rare(COND) __builtin_expect(!!(COND), 0)
1510 # define usual(COND) __builtin_expect(!!(COND), 1)
1511 #else
1512 # define rare(COND) (COND)
1513 # define usual(COND) (COND)
1514 #endif
1516 /* Signal we're building the library so it's OK to include headers such as
1517  * xapian/query.h directly.
1518  */
1519 #define XAPIAN_LIB_BUILD 1
1521 /* With Sun CC 5.13 (Studio 12.4) on Solaris 11.2, <math.h> seems to get
1522  * implicitly included somehow before <cmath>, and compilation fails due
1523  * to 'std::exception' colliding with 'struct exception'.  It's not clear
1524  * how to avoid this, so just define the same magic macro which <cmath> does
1525  * before it includes <math.h>.
1526  */
1527 #if defined __SUNPRO_CC && !defined __MATHERR_RENAME_EXCEPTION
1528 # define __MATHERR_RENAME_EXCEPTION
1529 #endif
1532 AC_SUBST([AM_CXXFLAGS])
1534 dnl Restore CXXFLAGS to those the user specified or autoconf defaulted to.
1535 CXXFLAGS=$save_CXXFLAGS
1537 dnl Required for auto regeneration to work in a combined maintainer-mode tree.
1538 : ${AUTOM4TE=autom4te}
1539 AC_SUBST([AUTOM4TE])
1541 dnl Libtool sets this (to yes|no|unknown) and we use it in xapian-config.
1542 AC_SUBST([link_all_deplibs_CXX])
1544 dnl Shared library extension.
1545 module=no
1546 eval "SHLIBEXT=$shrext_cmds"
1547 AC_SUBST([SHLIBEXT])
1549 dnl We want to be able to use GNU make % pattern rules in maintainer targets
1550 dnl but automake warns these aren't portable, so we substitute the % to avoid
1551 dnl this warning.
1552 PERCENT='%'
1553 AC_SUBST([PERCENT])
1555 dnl Split up the version number into "MAJOR.MINOR.REVISION".
1556 MAJOR_VERSION=`echo "$VERSION"|sed 's/\..*//'`
1557 [MINOR_VERSION=`echo "$VERSION"|sed 's/[^.]*\.//;s/\..*//'`]
1558 [REVISION=`echo "$VERSION"|sed 's/.*\.//;s/_.*$//'`]
1560 dnl Convert the libs in $XAPIAN_LIBS to a CMake list.
1561 XAPIAN_CMAKE_LIBS=`echo " $XAPIAN_LIBS" | sed 's/ -l/;/g;s/ //g'`
1562 AC_SUBST([XAPIAN_CMAKE_LIBS])
1564 XAPIAN_CMAKE_SHARED=
1565 if test "$enable_shared" = yes; then
1566   XAPIAN_CMAKE_SHARED=ON
1567 else
1568   XAPIAN_CMAKE_SHARED=OFF
1570 AC_SUBST([XAPIAN_CMAKE_SHARED])
1572 LIBRARY_STATIC_EXT=.$libext
1573 AC_SUBST([LIBRARY_STATIC_EXT])
1575 if test "$win32" = yes; then
1576   LIBRARY_SHARED_IMP_EXT=$LIBRARY_STATIC_EXT
1577 else
1578   LIBRARY_SHARED_IMP_EXT=
1580 AC_SUBST([LIBRARY_SHARED_IMP_EXT])
1582 dnl **************************
1583 dnl * Build the output files *
1584 dnl **************************
1586 AC_CONFIG_FILES([
1587  Makefile
1588  tests/Makefile
1589  docs/Makefile
1590  docs/doxygen_api.conf
1591  docs/doxygen_source.conf
1592  xapian-core.spec
1593  cmake/xapian-config.cmake
1594  cmake/xapian-config-version.cmake
1595  pkgconfig/xapian-core"$LIBRARY_VERSION_SUFFIX".pc:pkgconfig/xapian-core.pc.in
1596  ])
1597 AC_CONFIG_FILES([makemanpage], [chmod +x makemanpage])
1598 AC_CONFIG_FILES([tests/runtest], [chmod +x tests/runtest])
1599 AC_CONFIG_FILES([tests/runsrv], [chmod +x tests/runsrv])
1600 AC_CONFIG_FILES([tests/submitperftest], [chmod +x tests/submitperftest])
1601 AC_CONFIG_FILES([tests/perftest/get_machine_info], [chmod +x tests/perftest/get_machine_info])
1602 AC_CONFIG_FILES([xapian-config], [chmod +x xapian-config])
1603 AC_OUTPUT
1605 dnl There are no files generated by AC_OUTPUT in the following directories
1606 dnl and we need to ensure they exist so that the rest of configure or make
1607 dnl won't fail because they don't exist when srcdir != builddir.
1608 if test yes = "$vpath_build" ; then
1609   for dir in include/xapian languages queryparser ; do
1610     AS_MKDIR_P(["$dir"])
1611   done
1614 dnl Generate include/xapian/version.h:
1616 dnl MAIN_VERSION is VERSION without any _git123 suffix.
1617 MAIN_VERSION="$MAJOR_VERSION.$MINOR_VERSION.$REVISION"
1618 cxxcpp_flags=-I.
1619 for backend in CHERT GLASS INMEMORY REMOTE ; do
1620   val=`eval echo "\\\$BUILD_BACKEND_${backend}_TRUE"`
1621   if test -z "$val" ; then
1622     cxxcpp_flags="$cxxcpp_flags -DXAPIAN_HAS_${backend}_BACKEND"
1623   fi
1624 done
1626 if test yes = "$enable_64bit_docid" ; then
1627   cxxcpp_flags="$cxxcpp_flags -DXAPIAN_DOCID_BASE_TYPE="`echo "$INT64_T"|sed 's/ /____/g'`
1628 else
1629   cxxcpp_flags="$cxxcpp_flags -DXAPIAN_DOCID_BASE_TYPE="`echo "$INT32_T"|sed 's/ /____/g'`
1632 if test yes = "$enable_64bit_termcount" ; then
1633   cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TERMCOUNT_BASE_TYPE="`echo "$INT64_T"|sed 's/ /____/g'`
1634 else
1635   cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TERMCOUNT_BASE_TYPE="`echo "$INT32_T"|sed 's/ /____/g'`
1638 if test yes = "$enable_64bit_termpos" ; then
1639   cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TERMPOS_BASE_TYPE="`echo "$INT64_T"|sed 's/ /____/g'`
1640 else
1641   cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TERMPOS_BASE_TYPE="`echo "$INT32_T"|sed 's/ /____/g'`
1644 dnl Always ought to be 64 bit.
1645 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TOTALLENGTH_TYPE="`echo "unsigned $INT64_T"|sed 's/ /____/g'`
1647 dnl Make revision numbers in the API 64 bit for future-proofing.
1648 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_REVISION_TYPE="`echo "unsigned $INT64_T"|sed 's/ /____/g'`
1650 dnl For GCC (and compilers which pretend to be GCC) and MSVC, we create some
1651 dnl ABI checks in the generated version.h, and $CXXFLAGS may contain options
1652 dnl which affect the ABI (e.g. -fabi-version for GCC) so we want to use these
1653 dnl options when generating version.h.  For these compilers, CXXCPP="$CXX -E"
1654 dnl so it should understand all compiler options.
1656 dnl For other compilers, we only pass $CPPFLAGS to $CXXCPP in case it's an
1657 dnl external cpp which doesn't understand flags which might be in $CXXFLAGS.
1658 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[#ifndef __GNUC__
1659 #ifndef _MSC_VER
1660        choke me
1661 #endif
1662 #endif
1663 ]])],
1664         [cxxcpp_flags="$cxxcpp_flags $CPPFLAGS $CXXFLAGS"],
1665         [cxxcpp_flags="$cxxcpp_flags $CPPFLAGS"])
1666 rm -f include/xapian/version.h.tmp
1667 dnl "\r" in sed is a GNUism, but we only need to remove it on MS Windows
1668 dnl where we'll always have GNU sed, and other sed's will just interpret
1669 dnl it as "r" (Solaris sed) or maybe literal "\r" which won't match.
1671 dnl Use @@ around $MAIN_VERSION so we get " in the final output.
1672 $CXXCPP $cxxcpp_flags\
1673         -DSTRING_VERSION="\"@@$MAIN_VERSION@@\""\
1674         -DMAJOR_VERSION="\"$MAJOR_VERSION\""\
1675         -DMINOR_VERSION="\"$MINOR_VERSION\""\
1676         -DREVISION="\"$REVISION\""\
1677         $dash_d_visibility\
1678         $srcdir/include/xapian/version_h.cc|\
1679         ${SED-sed} '0,/const char \* dummy/d;/"/!d;s/^ *//;/^#/d;s/ *$//;s/" *,//;s/"//g;s/@@/"/g;s/  */ /g;s/ *,\r$//;s/ *,$//;s/____/ /g;s/\\\\$/\\/'\
1680         > include/xapian/version.h.tmp
1681 dnl Only update the file if it has changed, so we don't alter the timestamp
1682 dnl and cause lots of rebuilding needlessly.  However, the build system
1683 dnl needs a timestamp to know when to regenerate version.h because version_h.cc
1684 dnl has changed so we use a separate timestamp file.
1685 touch include/xapian/version.h.timestamp
1686 if cmp include/xapian/version.h.tmp include/xapian/version.h >/dev/null 2>&1
1687 then
1688   rm include/xapian/version.h.tmp
1689 else
1690   mv include/xapian/version.h.tmp include/xapian/version.h