Drop special handling for Compaq C++
[xapian.git] / xapian-core / configure.ac
blob9b1fb24d62ab486c74a89a7fed6a8d85709e02a9
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/multiandpostlist.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 -no-undefined causes problems on Solaris with Sun CC in C++11 mode, so only
118 dnl pass -no-undefined on platforms where it is required in order to link a
119 dnl shared library at all (Windows is the main one).
120 NO_UNDEFINED=
121 if test unsupported = "$allow_undefined_flag" ; then
122   NO_UNDEFINED=-no-undefined
124 AC_SUBST(NO_UNDEFINED)
126 AM_CXXFLAGS=
128 dnl A standard "gotcha" for mingw and cygwin users is to not set up their
129 dnl PATH correctly, so that MSDOS FIND.EXE is found before Unix find.  Help
130 dnl them out by checking for this condition, rather than letting libtool
131 dnl fail in obscure ways.  NB check the *BUILD* OS, not the host one!
132 case $build_os in
133   *mingw* | *cygwin* | pw32*)
134     find /dirunlikelytoexist >/dev/null 2>&1
135     if test $? = 2 ; then
136         dnl Unix find will return 1 if the directory didn't exist, or 0 if
137         dnl it did.
138         AC_MSG_ERROR([
139 *** You appear to have an MSDOS-like FIND.EXE in your PATH ahead of any
140 *** UNIX-like find.  This misconfiguration will confuse libtool - you'll need
141 *** to make sure you have a UNIX-like find installed and fix your PATH, then
142 *** rerun configure.  For more information, see:
144 ***   https://www.cygwin.com/faq/faq.html#faq.using.find
146     fi
147   ;;
148 esac
150 dnl Add parameters for aclocal
151 dnl (This must come after AM_INIT_AUTOMAKE, since it modifies ACLOCAL)
152 ACLOCAL="$ACLOCAL $ACLOCAL_FLAGS"
154 dnl disable "maintainer only" rules by default
155 AM_MAINTAINER_MODE
157 dnl Checks for programs.
158 AC_PROG_CXX
160 AC_CANONICAL_HOST
162 # Checked: freebsd8.0 openbsd4.6 solaris2.9 solaris2.10
163 case $host_os in
164   linux* | k*bsd*-gnu | freebsd* | openbsd* | solaris*)
165     dnl Vanilla libtool sets this to "unknown" which it then handles as "yes".
166     link_all_deplibs_CXX=no
167     ;;
168 esac
170 case $host_os in
171   linux*)
172     dnl Extract search path from ldconfig which is more reliable than the way
173     dnl vanilla libtool extracts them from ld.so.conf.
174     d=`/sbin/ldconfig -N -X -v 2>&AS_MESSAGE_LOG_FD|$SED 's,^\(/.*\):\( (.*)\)\?$,\1,p;d'|tr '\n' ' '`
175     test -z "$d" || sys_lib_dlsearch_path_spec=$d
176     ;;
177 esac
179 case $host in
180   *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
181     dnl On these platforms, libtool emits a warning if -no-install is passed,
182     dnl and uses -no-fast-install instead - the least ugly way to avoid that
183     dnl warnings seems to be to duplicate the above list of platforms from
184     dnl libtool and use -no-fast-install on them directly.
185     NO_INSTALL=-no-fast-install ;;
186   *)
187     NO_INSTALL=-no-install ;;
188 esac
189 AC_SUBST([NO_INSTALL])
191 dnl For reasons which are beyond me, if autoconf can't find a C++ compiler
192 dnl it will set CXX to g++ (which obviously won't work) rather than actually
193 dnl telling the user that it couldn't find a C++ compiler and telling them
194 dnl to either install one or set CXX if there's one configure failed to find.
195 dnl It's probably worthwhile checking that the C++ compiler actually works
196 dnl anyway!
197 if test -n "$CXX" ; then
198   AC_LANG_CPLUSPLUS
199   AC_MSG_CHECKING([whether $CXX is a working C++ compiler])
200   AC_CACHE_VAL([xo_cv_cxx_works],
201     [
202     AC_TRY_RUN([int main() {}],
203                xo_cv_cxx_works=yes,
204                xo_cv_cxx_works=no,
205                AC_TRY_LINK([], [], xo_cv_cxx_works=yes, xo_cv_cxx_works=no))
206     ])
207   AC_MSG_RESULT([$xo_cv_cxx_works])
208 else
209   xo_cv_cxx_works=no
211 if test no = "$xo_cv_cxx_works" ; then
212   case $original_CXX in
213   CCC=*)
214     dnl CCC is handled in a slightly odd way - if its value isn't an
215     dnl executable (taking PATH into account) then it is ignored!
216     test "$original_CXX" = "CCC=$CXX" || original_CXX=
217     ;;
218   esac
219   if test -z "$original_CXX" ; then
220   AC_MSG_ERROR([
221 *** You need a working C++ compiler to compile Xapian, but configure failed to
222 *** find one.  If you have a working C++ compiler, you can tell configure where
223 *** to find it by invoking it like so:
225 ***   ./configure CXX=/opt/bin/c++
227   else
228   AC_MSG_ERROR([
229 *** You need a working C++ compiler to compile Xapian, but the compiler you
230 *** specified (with '$original_CXX') doesn't appear to be able to successfully
231 *** compile and link a simple program.
233   fi
236 dnl Probe for any options needed to enable C++11 support.
237 AX_CXX_COMPILE_STDCXX_11
239 dnl We don't use a C compiler to compile Xapian's code, but on some platforms
240 dnl (e.g. mingw) libtool uses $LTCC which defaults to $CC, and it's also use to
241 dnl build auxiliary tools like snowball and lemon.
242 AC_PROG_CC
244 dnl Check endianness.
245 AC_C_BIGENDIAN
247 dnl We want a non-cross-compiling C compiler for building lemon with.
248 if test -z "$CC_FOR_BUILD" ; then
249   if test yes = "$cross_compiling"; then
250     CC_FOR_BUILD=cc
251   else
252     CC_FOR_BUILD="$CC"
253   fi
255 AC_ARG_VAR([CC_FOR_BUILD], [C compiler command for native compilation (needed to compile build tools during cross-builds)])
257 dnl Run tests using the C++ compiler.
258 AC_LANG_CPLUSPLUS
260 dnl Enable large file support if possible.
261 AC_SYS_LARGEFILE
262 dnl With xlC on AIX, -D_LARGE_FILES changes the ABI of std::string, so it
263 dnl also needs to be used when compiling user code.
264 abi_affecting_cxxflags=
265 if $GREP '^#define _LARGE_FILES 1$' confdefs.h > /dev/null 2>&1 ; then
266   abi_affecting_cxxflags=-D_LARGE_FILES
268 AC_SUBST([abi_affecting_cxxflags])
270 AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
271 #if defined __WIN32__ || defined _WIN32
272 #error WIN32
273 #endif
274 ]])], [win32=no], [win32=yes])
276 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
277 #ifdef _MSC_VER
278 #error MSVC
279 #endif
280 ]])], [msvc=no], [msvc=yes])
282 XAPIAN_LDFLAGS=
283 XAPIAN_LIBS=
284 AC_SUBST([XAPIAN_LDFLAGS])
285 AC_SUBST([XAPIAN_LIBS])
287 AC_DEFUN([XAPIAN_TEST_LINKER_FLAG],
288   [
289   AC_MSG_CHECKING([for $CXX -Wl,$1])
290   AC_CACHE_VAL([xo_cv_ldflag_$2],
291     [
292     save_LDFLAGS=$LDFLAGS
293     LDFLAGS="$LDFLAGS -Wl,$1"
294     flag=$1
295     AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
296       [xo_cv_ldflag_$2=yes
297       $3],
298       [xo_cv_ldflag_$2=no
299       $4])
300     LDFLAGS=$save_LDFLAGS
301     ])
302   AC_MSG_RESULT([$xo_cv_ldflag_$2])
303   ])
305 dnl Test if the compiler works with $1 added to CXXFLAGS; if it does, add $1 to
306 dnl variable $2.  If the test passes, also do $3; if it fails, also do $4.
307 AC_DEFUN([XAPIAN_TEST_CXXFLAGS],
308   [
309   XTC_save_CXXFLAGS=$CXXFLAGS
310   CXXFLAGS="$CXXFLAGS $1"
311   AC_TRY_COMPILE([], [],
312                  [CXXFLAGS=$XTC_save_CXXFLAGS
313                   $2="${$2} $1"
314                   $3],
315                  [CXXFLAGS=$XTC_save_CXXFLAGS
316                   $4])
317   ])
319 ldflags=
320 if test yesyes = "$GXX$enable_shared" ; then
321   case $host_os in
322     *mingw* | *cygwin*)
323       XAPIAN_TEST_LINKER_FLAG([--enable-runtime-pseudo-reloc], [enable_runtime_pseudo_reloc],
324         [ldflags="-Wl,$flag"],
325         [
326         dnl Can't use AC_DISABLE_SHARED after AC_PROG_LIBTOOL, but
327         dnl this test needs to be after AC_PROG_LIBTOOL, so we can't
328         dnl just disable the shared build automatically...
329         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])
330         ])
331     ;;
332   esac
334 dnl Only works for ldflags which can be specified anywhere on the link line.
335 AC_SUBST([ldflags])
337 dnl Preserve the default CXXFLAGS.
338 save_CXXFLAGS=$CXXFLAGS
340 dnl x86 has excess precision issues with 387 FP instructions, which are
341 dnl avoided by using SSE instructions instead.  This is also faster (~6% in
342 dnl a CPU bound testcase).
343 AC_ARG_ENABLE([sse],
344 [AS_HELP_STRING([--disable-sse],
345                 [disable use of SSE FP instructions on x86])]
346 [AS_HELP_STRING([[--enable-sse[=sse|sse2]]],
347                 [set which SSE FP instructions to use on x86 (default: sse2)])],
348   [case ${enableval} in
349     sse|sse2|yes|no) ;;
350     *) AC_MSG_ERROR([bad value ${enableval} for --enable-sse or --disable-sse]) ;;
351   esac],
352   [enable_sse=yes])
354 dnl Some versions of Sun's C++ compiler reportedly need an explicit -lm.
355 dnl The maths functions we use include: exp log ceil fabs sqrt
356 AC_MSG_CHECKING([if -lm is required for maths functions])
357 dnl Don't use constant arguments as the compiler might simply evaluate the
358 dnl whole expression at compile time, and it might inline certain functions
359 dnl so test several functions.  Also write results using printf() so that
360 dnl the compiler can't optimise away the computations.
361 AC_TRY_LINK([#ifdef __SUNPRO_CC
362 #error Need -lm for Sun C++ 5.9 under libtool 2.2.10
363 #endif
364 #include <cmath>
365 #include <cstdio>
366 #include <ctime>
367 using namespace std;], [
368   double a = log(ceil(time(NULL)/7.0));
369   printf("%f %f %f\n", a, sqrt(a), exp(fabs(a - 12345.6)));
370   ], [AC_MSG_RESULT([no])], [
371     LIBS="-lm $LIBS"
372     AC_TRY_LINK([#include <cmath>
373 #include <cstdio>
374 #include <ctime>
375 using namespace std;], [
376   double a = log(ceil(time(NULL)/7.0));
377   printf("%f %f %f\n", a, sqrt(a), exp(fabs(a - 12345.6)));],
378         [AC_MSG_RESULT([yes])],
379         [AC_MSG_ERROR([Failed to link a C++ program using <cmath>])
380     ])
383 dnl C++11 should have log2(double), but keep this check for now to allow for
384 dnl compilers with incomplete library support for C++11.
385 AC_CHECK_DECLS([log2(double)], [], [],
386 [#include <cmath>
387 using namespace std;])
389 dnl exp10() is a GNU libc extension.
390 AC_CHECK_DECLS([exp10(double)], [], [],
391 [#include <cmath>
392 using namespace std;])
394 dnl Darwin provides __exp10().
395 AC_CHECK_DECLS([__exp10(double)], [], [],
396 [#include <cmath>
397 using namespace std;])
399 dnl GCC provides __builtin_exp10() (but notably clang doesn't currently).
400 dnl On mingw, __builtin_exp10() causes GCC to generate a call to exp10() which
401 dnl then fails to link, so perform a link check here to catch that.
402 AC_CACHE_CHECK([for __builtin_exp10], ac_cv_link___builtin_exp10, [
403   AC_LINK_IFELSE([AC_LANG_PROGRAM([[
404 #include <cstdio>
405 #include <ctime>
406 using namespace std;]],
407     [[printf("%f", __builtin_exp10(double(time(NULL)*1e-8)));]])],
408     [ac_cv_link___builtin_exp10=yes],
409     [ac_cv_link___builtin_exp10=no])
411 if test $ac_cv_link___builtin_exp10 = yes ; then
412   AC_DEFINE([HAVE___BUILTIN_EXP10], [1], [Define to 1 if you have the '__builtin_exp10' function.])
415 dnl See if <typeinfo> can be used in the testsuite - at least for GCC and xlC,
416 dnl compilation of the test code below fails if RTTI isn't being generated
417 dnl (g++ -fno-rtti, or by default with xlC).
418 AC_MSG_CHECKING([if RTTI is supported])
419 save_CXXFLAGS=$CXXFLAGS
420 dnl xlC issues a warning for typeid() being used without RTTI being enabled,
421 dnl so for this test we pass the xlC option to make that warning into an error.
422 XAPIAN_TEST_CXXFLAGS([-qhaltonmsg=1540-2412], [CXXFLAGS])
423 AC_TRY_COMPILE([
424 #include <exception>
425 #include <typeinfo>],
426         [
427         int f();
428         try {
429             return f();
430         } catch (std::exception & e) {
431             return typeid(e).name()[0];
432         }],
433     AC_MSG_RESULT([yes])
434     AC_DEFINE([USE_RTTI], [1], [Define if the testsuite can use RTTI]),
435     AC_MSG_RESULT([no]))
436 CXXFLAGS=$save_CXXFLAGS
438 AC_MSG_CHECKING([if std::is_trivially_copyable<> is supported])
439 AC_TRY_COMPILE([#include <type_traits>],
440         [return std::is_trivially_copyable<int>::value ? 1 : 0;],
441     AC_MSG_RESULT([yes])
442     AC_DEFINE([HAVE_STD_IS_TRIVIALLY_COPYABLE], [1], [Define to 1 if you have 'std::is_trivially_copyable<>'.]),
443     AC_MSG_RESULT([no]))
445 dnl We need to specify the argument types for builtin functions, or else
446 dnl AC_CHECK_DECLS fails to detect them when the compiler is clang.
447 AC_CHECK_DECLS([__builtin_add_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                [#include <stdint.h>])
452 AC_CHECK_DECLS([_byteswap_ushort, _byteswap_ulong], [], [],
453                [#include <stdlib.h>])
454 AC_CHECK_DECLS([__builtin_clz(unsigned),
455                 __builtin_clzl(unsigned long),
456                 __builtin_clzll(unsigned long long)], [], [], [ ])
457 AC_CHECK_DECLS([__builtin_ctz(unsigned),
458                 __builtin_ctzl(unsigned long),
459                 __builtin_ctzll(unsigned long long)], [], [], [ ])
460 AC_CHECK_DECLS([__builtin_expect(long, long)], [], [], [ ])
461 AC_CHECK_DECLS([__builtin_popcount(unsigned),
462                 __builtin_popcountl(unsigned long),
463                 __builtin_popcountll(unsigned long long)], [], [], [ ])
464 AC_CHECK_DECLS([__popcnt, __popcnt64], [], [], [#include <intrin.h>])
466 dnl Check for time functions.
467 AC_CHECK_FUNCS([clock_gettime sleep nanosleep gettimeofday ftime])
469 case $host_os in
470   *mingw*)
471     dnl For _ftime64() on mingw we need to tell it we're happy to require
472     dnl MSVCRT 6.10 or higher, which isn't too onerous a requirement it seems.
473     AC_DEFINE([__MSVCRT_VERSION__], [0x0601], [Define on mingw to the minimum msvcrt version to assume])
474     AC_DEFINE([MINGW_HAS_SECURE_API], [1], [Define on mingw to get _s suffixed "secure" functions declared in headers])
475     ;;
476 esac
478 dnl We use timer_create() if available to implement a search time limit.
479 SAVE_LIBS=$LIBS
480 AC_SEARCH_LIBS([timer_create], [rt],
481                [
482     AC_MSG_CHECKING([for timer_create() usability])
483     dnl Several platforms have timer_create() but it's non-functional.
484     dnl
485     dnl Some of these (at least those with a stub implementation which always
486     dnl fails with ENOSYS) could be probed for, but we'd have to run code
487     dnl which isn't possible when cross-compiling, so just maintain a list
488     dnl of such platforms for now.
489     AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
490 [[#if defined _AIX
491 #error timer_create always fails with EAGAIN on AIX 7.1
492 #elif defined __GNU__
493 #error timer_create always fails with ENOSYS on GNU Hurd
494 #elif defined __NetBSD__
495 #error timer_create timers never fire on NetBSD 7.1
496 #elif defined __OpenBSD__
497 #error timer_create always fails with ENOSYS on OpenBSD 6.2 (and no prototype)
498 #endif]])],
499         [AC_MSG_RESULT([yes])
500         XAPIAN_LIBS="$LIBS $XAPIAN_LIBS"
501         AC_DEFINE([HAVE_TIMER_CREATE], [1], [Define to 1 if you have the 'timer_create' function.])]
502         ,
503         [AC_MSG_RESULT([no])
504     ])
506 LIBS=$SAVE_LIBS
508 dnl Used by tests/soaktest/soaktest.cc
509 AC_CHECK_FUNCS([srandom random])
511 dnl Used by tests/harness/testsuite.cc
512 AC_CHECK_FUNCS([sigaction])
513 AC_MSG_CHECKING([for sigsetjmp and siglongjmp])
514 AC_TRY_COMPILE([#include <setjmp.h>],
515   [sigjmp_buf jb; if (sigsetjmp(jb, 1)) { siglongjmp(jb, 1);  }],
516   AC_DEFINE([HAVE_SIGSETJMP], [1], [Define to 1 if you have the 'sigsetjmp' function])
517   AC_MSG_RESULT([yes]),
518   AC_MSG_RESULT([no]))
520 dnl Used by tests/harness/cputimer.cc:
521 AC_CHECK_FUNCS([getrusage times sysconf])
523 dnl Used by tests/harness/unixcmd.cc
524 AC_CHECK_FUNCS([nftw])
526 dnl Used by tests/api_replicate.cc.
528 dnl Solaris < 10 only has putenv().
530 dnl Microsoft have marked putenv() as deprecated, so we use _putenv_s() under
531 dnl MSVC to avoid deprecation warnings.  We probe here since mingw doesn't
532 dnl currently (v3.20) provide _putenv_s(), so we can't just use it conditional
533 dnl on __WIN32__ being defined.  We need to check for a declaration rather
534 dnl than just seeing if the symbol exists, as the symbol will exist in the C
535 dnl runtime DLL even if mingw doesn't declare it in its headers.
536 AC_CHECK_FUNCS([setenv])
537 AC_CHECK_DECLS([_putenv_s(const char *,const char *)], [], [],
538 [#include <stdlib.h>])
540 dnl See if we have closefrom(), or some functions that are useful to implement
541 dnl closefrom() on platforms which don't provide it.
542 AC_CHECK_FUNCS([closefrom getdirentries getrlimit])
544 dnl See if ftime returns void (as it does on mingw)
545 AC_MSG_CHECKING([return type of ftime])
546 if test $ac_cv_func_ftime = yes ; then
547   AC_TRY_COMPILE([#include <sys/timeb.h>],
548     [struct timeb tp; int i = ftime(&tp);],
549     AC_MSG_RESULT([int]),
550     AC_MSG_RESULT([void])
551     AC_DEFINE([FTIME_RETURNS_VOID], [1], [Define if ftime returns void]))
554 dnl Check how to find the hostname: uname() in sys/utsname.h, or gethostname()
555 AC_CHECK_HEADERS([sys/utsname.h], [], [], [ ])
556 AC_CHECK_FUNCS([gethostname])
558 dnl mingw (for instance) lacks ssize_t
559 AC_TYPE_SSIZE_T
561 AC_TYPE_PID_T
563 AC_TYPE_MODE_T
565 AC_CHECK_SIZEOF([short])
566 AC_CHECK_SIZEOF([int])
567 AC_CHECK_SIZEOF([long])
568 AC_CHECK_SIZEOF([long long])
570 AC_CHECK_HEADERS([sys/types.h])
572 AC_MSG_CHECKING([for 32 bit integer type])
573 case 4 in
574     "$ac_cv_sizeof_int")   INT32_T=int ;;
575     "$ac_cv_sizeof_long")  INT32_T=long ;;
576     "$ac_cv_sizeof_short") INT32_T=short ;;
577     *)
578       AC_MSG_RESULT([none found])
579       AC_MSG_ERROR([No 32 bit integer type found])
580 esac
581 AC_MSG_RESULT([$INT32_T])
583 AC_MSG_CHECKING([for 64 bit integer type])
584 case 8 in
585     "$ac_cv_sizeof_int")       INT64_T=int ;;
586     "$ac_cv_sizeof_long")      INT64_T=long ;;
587     "$ac_cv_sizeof_long_long") INT64_T='long long' ;;
588     *)
589       AC_MSG_RESULT([none found])
590       AC_MSG_ERROR([No 64 bit integer type found])
591 esac
592 AC_MSG_RESULT([$INT64_T])
594 dnl Check for perl (needed to generate some sources and documentation).
595 AC_PATH_PROG([PERL], [perl], [])
596 if test x$USE_MAINTAINER_MODE = xyes; then
597   test -z "$PERL" && AC_MSG_ERROR([perl is required in maintainer mode])
600 AC_ARG_ENABLE([64bit_docid],
601   [AS_HELP_STRING([--enable-64bit-docid], [enable 64bit docid [default=no]])],
602   [case ${enableval} in
603     yes|no) ;;
604   *) AC_MSG_ERROR([bad value ${enableval} for --enable-64bit-docid]) ;;
605   esac],
606   [enable_64bit_docid=no])
608 AC_ARG_ENABLE([64bit_termcount],
609   [AS_HELP_STRING([--enable-64bit-termcount], [enable 64bit termcount [default=no]])],
610   [case ${enableval} in
611     yes|no) ;;
612   *) AC_MSG_ERROR([bad value ${enableval} for --enable-64bit-termcount]) ;;
613   esac],
614   [enable_64bit_termcount=no])
616 AC_ARG_ENABLE([64bit_termpos],
617   [AS_HELP_STRING([--enable-64bit-termpos], [enable 64bit termpos [default=no]])],
618   [case ${enableval} in
619     yes|no) ;;
620   *) AC_MSG_ERROR([bad value ${enableval} for --enable-64bit-termpos]) ;;
621   esac],
622   [enable_64bit_termpos=no])
624 AC_ARG_ENABLE([documentation],
625   [AS_HELP_STRING([--enable-documentation], [enable make rules to rebuild documentation [default=maintainer-mode]])],
626   [case ${enableval} in
627     yes|no) ;;
628     *) AC_MSG_ERROR([bad value ${enableval} for --enable-documentation]) ;;
629   esac],
630   [enable_documentation=$USE_MAINTAINER_MODE])
631 AM_CONDITIONAL([DOCUMENTATION_RULES], [test x"$enable_documentation" = xyes])
632 AM_CONDITIONAL([MAINTAINER_NO_DOCS], [test x"$USE_MAINTAINER_MODE$enable_documentation" = xyesno])
634 if test x"$enable_documentation" = xyes ; then
635   dnl Checks for dot.  (Diagrams in the documentation)
636   AC_PATH_PROG([DOT], [dot])
637   test -z "$DOT" && AC_MSG_ERROR([dot (part of the graphviz package) is required to build documentation])
638   DOXYGEN_DOT_PATH=`echo "$DOT" | sed 's!/dot$!!'`
639   AC_SUBST([DOXYGEN_DOT_PATH])
641   dnl Check for doxygen. (Needed to make some more of the documentation)
642   AC_PATH_PROG([DOXYGEN], [doxygen], [])
643   test -z "$DOXYGEN" && AC_MSG_ERROR([doxygen is required to build documentation])
645   dnl Check for help2man. (Needed to make man pages from "--help" output).
646   AC_PATH_PROG([HELP2MAN], [help2man], [])
647   test -z "$HELP2MAN" && AC_MSG_ERROR([help2man is required to build documentation])
649   dnl Check for rst2html. (Needed to make HTML from reStructuredText format)
650   dnl Also look for rst2html.py, which archlinux reportedly installs it as.
651   AC_PATH_PROGS([RST2HTML], [rst2html rst2html.py], [])
652   test -z "$RST2HTML" && AC_MSG_ERROR([rst2html is required to build documentation (try package python-docutils)])
654   dnl Check for pngcrush, which we optionally use to reduce the size of the
655   dnl PNG files which doxygen generates.  We can get by without it, so don't
656   dnl fail here if it's not found.
657   AC_PATH_PROG([PNGCRUSH], [pngcrush], [])
660 dnl Checks for header files.
661 AC_CHECK_HEADERS([fcntl.h limits.h sys/errno.h sys/select.h sys/uio.h], [], [], [ ])
662 AC_CHECK_HEADERS([sys/resource.h],
663                  [], [], [#include <sys/types.h>])
665 dnl cxxabi.h was added in GCC 3.1, but clang lies and defines __GNUC__ yet
666 dnl doesn't seem to reliably provide this header, so probe for it.
667 AC_CHECK_HEADERS([cxxabi.h], [], [], [ ])
669 dnl If valgrind is installed and new enough, we use it for leak checking in the
670 dnl testsuite.  If VALGRIND is set to an empty value, then skip the check and
671 dnl don't use valgrind.
672 if test -n "${VALGRIND-unset}" ; then
673   AC_PATH_PROG([VALGRIND], [valgrind], [])
674   if test -n "$VALGRIND" ; then
675     dnl Check that the installed valgrind version works, and supports the
676     dnl options we use.  This means we won't try to use valgrind < 3.3.0
677     dnl (released 7/12/2007) since before that --log-file didn't expand
678     dnl %p (and appended the process id).
679     dnl
680     dnl No need to check for VALGRIND_COUNT_LEAKS now - that was added before
681     dnl 2.0.0.
682     AC_MSG_CHECKING([if valgrind supports --log-file with %p and --child-silent-after-fork=yes])
683     vglog=config.vglog.%p.tmp
684     vglogwild="config.vglog.*.tmp*"
685     rm -f $vglogwild
686     if $VALGRIND --log-file="$vglog" --child-silent-after-fork=yes -q true 2>&AS_MESSAGE_LOG_FD ; then
687       for f in $vglogwild ; do
688         case $f in
689         $vglog*) VALGRIND= ;;
690         esac
691       done
692       if test x"$VALGRIND" = x ; then
693         AC_MSG_RESULT([no])
694       else
695         AC_MSG_RESULT([yes])
696         AC_CHECK_HEADERS([valgrind/memcheck.h], [], [VALGRIND=], [ ])
697       fi
698     else
699       dnl The valgrind detected doesn't seem to work!  Perhaps this is an
700       dnl x86_64 box with a 32 bit valgrind.
701       AC_MSG_RESULT([$VALGRIND doesn't work])
702       VALGRIND=
703     fi
704     rm -f $vglogwild
705   fi
708 if test -n "$VALGRIND" ; then
709   AC_DEFINE([HAVE_VALGRIND], [1], [Define if a suitable valgrind is installed])
712 dnl If eatmydata is installed, we run the testsuite under it to speed it up.
713 dnl If EATMYDATA is set to an empty value, then skip this check and don't use
714 dnl eatmydata.
715 if test -n "${EATMYDATA-unset}" ; then
716   AC_PATH_PROG([EATMYDATA], [eatmydata], [])
719 dnl Checks for library functions.
720 AC_FUNC_MEMCMP
721 AC_FUNC_STRERROR_R
723 AC_CACHE_CHECK([for sys_errlist and sys_nerr], ac_cv_sys_errlist_and_sys_nerr, [
724   AC_LINK_IFELSE([AC_LANG_PROGRAM(
725 dnl On Linux, sys_errlist and sys_nerr need <stdio.h>, though the man page
726 dnl says <errno.h>.  The man page seems to match other platforms such as
727 dnl NetBSD, so include both headers to ensure we get them.
728 [[#include <errno.h>
729 #include <stdio.h>]],
730 [[  printf("%s", sys_errlist[sys_nerr - 1]);]])],
731   [ ac_cv_sys_errlist_and_sys_nerr=yes ],
732   [ ac_cv_sys_errlist_and_sys_nerr=no ])
734 if test "x$ac_cv_sys_errlist_and_sys_nerr" = "xyes" ; then
735   AC_DEFINE([HAVE_SYS_ERRLIST_AND_SYS_NERR], [1],[Define if you have 'sys_errlist' and 'sys_nerr'])
738 AC_CACHE_CHECK([for _sys_errlist and _sys_nerr], ac_cv__sys_errlist_and__sys_nerr, [
739   AC_LINK_IFELSE([AC_LANG_PROGRAM(
740 [[#include <errno.h>
741 #include <stdio.h>]],
742 [[  printf("%s", _sys_errlist[_sys_nerr - 1]);]])],
743   [ ac_cv__sys_errlist_and__sys_nerr=yes ],
744   [ ac_cv__sys_errlist_and__sys_nerr=no
745   ])
747 if test "x$ac_cv__sys_errlist_and__sys_nerr" = "xyes" ; then
748   AC_DEFINE([HAVE__SYS_ERRLIST_AND__SYS_NERR], [1],[Define if you have '_sys_errlist' and '_sys_nerr'])
751 dnl Check that snprintf actually works as it's meant to.
753 dnl Linux 'man snprintf' warns:
754 dnl  Linux libc4.[45] does not have a snprintf, but provides a libbsd that
755 dnl  contains an snprintf equivalent to sprintf, i.e., one that ignores the
756 dnl  size argument.  Thus, the use of snprintf with early libc4 leads to
757 dnl  serious security problems.
759 dnl It also warns that glibc < 2.0.6 (and presumably other pre-C99
760 dnl implementations) return -1 when truncating so check that we get the
761 dnl ISO C99 semantics for the returned length when truncating.  If we
762 dnl have a working snprintf but with non-ISO return semantics, handle
763 dnl that case separately as it may still be useful in many cases.
765 dnl mingw has _snprintf so check for that too.
766 AC_MSG_CHECKING([for working ISO C99 conforming snprintf])
767 ac_cv_func_snprintf_noniso=no
768 for func in snprintf _snprintf ; do
769   AC_RUN_IFELSE([
770     AC_LANG_PROGRAM(
771       [[
772 #include <cstdio>
773 #include <cstring>
774 using namespace std;
775       ]],
776       dnl Return different exit status for each error so we can see which
777       dnl check failed by consulting config.log.
778       [[
779         char buffer[4] = "abc";
780         int res1 = $func(buffer, 2, "%s", "XYZ");
781         if (memcmp(buffer, "X\0c", 4) != 0) return 2;
782         int res2 = $func(buffer, 2, "%x", 0x12);
783         if (memcmp(buffer, "1\0c", 4) != 0) return 3;
784         if (res1 == -1 && res2 == -1) return 15; /* Pre-ISO semantics. */
785         if (res1 != 3) return 4;
786         if (res2 != 2) return 5;
787       ]]
788     )],
789     [ac_cv_func_snprintf=$func;break],
790     [
791     if test 15no = "$?$ac_cv_func_snprintf_noniso" ; then
792       ac_cv_func_snprintf_noniso=$func
793     fi
794     ac_cv_func_snprintf=no
795     ],
796     [ac_cv_func_snprintf=unknown;break]
797   )
798 done
799 AC_MSG_RESULT([$ac_cv_func_snprintf])
800 case $ac_cv_func_snprintf in
801   no)
802     AC_MSG_CHECKING([for working non-ISO C99 conforming snprintf])
803     AC_MSG_RESULT([$ac_cv_func_snprintf_noniso])
804     if test no != "$ac_cv_func_snprintf_noniso" ; then
805       AC_DEFINE_UNQUOTED([SNPRINTF], [$ac_cv_func_snprintf_noniso],
806         [Define to the name of a function implementing snprintf but not caring about ISO C99 return value semantics (if one exists)])
807     fi
808     ;;
809   unknown)
810     dnl be conservative when crosscompiling
811     ;;
812   *)
813     AC_DEFINE_UNQUOTED([SNPRINTF_ISO], [$ac_cv_func_snprintf],
814        [Define to the name of a function implementing snprintf with ISO C99 semantics (if one exists)])
815     AC_DEFINE_UNQUOTED([SNPRINTF], [$ac_cv_func_snprintf],
816        [Define to the name of a function implementing snprintf but not caring about ISO C99 return value semantics (if one exists)])
817     ;;
818 esac
820 dnl ***************************
821 dnl * Select modules to build *
822 dnl ***************************
824 dnl Check if a non-GPL library build is specified.
826 AC_ARG_ENABLE([gpl-libxapian],
827   [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)])],
828   [case ${enableval} in
829     yes) ;;
830     no)
831       AC_DEFINE([DISABLE_GPL_LIBXAPIAN], 1, [Define to error out if we try to include GPL code in libxapian])
832       ;;
833     *) AC_MSG_ERROR([bad value ${enableval} for --disable-gpl-libxapian]) ;;
834   esac],
835   [enable_gpl_libxapian=yes])
837 dnl Check which database backends should be built.
839 AC_DEFUN([_XAPIAN_BACKEND_ENABLE],
840   [AC_ARG_ENABLE([backend_$1],
841     [AS_HELP_STRING([--enable-backend-$1], [build the $1 database backend [default=$3]])],
842     [case $enableval in
843       yes|no) ;;
844       *) AC_MSG_ERROR([Invalid option: '--enable-backend-$1=$enableval']) ;;
845     esac], [enable_backend_$1=$2])
846   ])
848 AC_DEFUN([XAPIAN_BACKEND_ENABLE],
849   [_XAPIAN_BACKEND_ENABLE([$1],
850     m4_default([$2], [yes]),
851     m4_default([$3], [yes]))
852   ])
854 dnl When adding a new backend, update INSTALL too.
855 XAPIAN_BACKEND_ENABLE([glass], [$enable_gpl_libxapian], [yes (unless --disable-gpl-libxapian)])
856 XAPIAN_BACKEND_ENABLE([honey])
857 XAPIAN_BACKEND_ENABLE([inmemory], [$enable_gpl_libxapian], [yes (unless --disable-gpl-libxapian)])
858 default_enable_backend_remote=$enable_gpl_libxapian
859 case $host_os in
860   *djgpp* | *msdos* )
861     dnl We don't currently support the remote backend on this platform so
862     dnl disable it by default.
863     default_enable_backend_remote=no
864     ;;
865 esac
866 XAPIAN_BACKEND_ENABLE([remote], [$default_enable_backend_remote], [yes (except for MSDOS; unless --disable-gpl-libxapian)])
868 win32_need_lws2_32=0
869 case $enable_backend_glass$enable_backend_honey in
870 *yes*)
871   dnl We use zlib for compressing tags in glass and honey.  We could
872   dnl automatically disable support if zlib isn't found, but overall that
873   dnl probably does more harm than good - it's most likely that someone just
874   dnl forgot to install the -dev package for zlib.
875   dnl
876   dnl Similarly for uuid support.
878   dnl Check for zlib.h.
879   AC_CHECK_HEADERS([zlib.h], [], [
880     AC_MSG_ERROR([zlib.h not found - required for glass (you may need to install the zlib1g-dev or zlib-devel package)])
881     ], [ ])
883   dnl Check for zlibVersion in -lz.
884   SAVE_LIBS=$LIBS
885   dnl mingw build needs -lzlib or -lzdll.
886   AC_SEARCH_LIBS([zlibVersion], [z zlib zdll], [], [
887     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)])
888     ])
889   if test x != x"$LIBS" ; then
890     XAPIAN_LIBS="$XAPIAN_LIBS $LIBS"
891   fi
892   LIBS=$SAVE_LIBS
894   dnl Find the UUID library (from e2fsprogs/util-linux-ng, not the OSSP one).
896   case $host_os-$win32 in
897     *-yes | *cygwin*) dnl Use built-in win32 API.
898       AC_DEFINE([USE_WIN32_UUID_API], [1],
899                 [Define to 1 to use UuidCreate(), etc])
900       if test $win32 = yes ; then
901         dnl We need -lws2_32 for htonl(), etc, but not for Cygwin which
902         dnl provides these functions in its libc.
903         win32_need_lws2_32=1
904       fi
905       XAPIAN_LIBS="$XAPIAN_LIBS -lrpcrt4"
906       ;;
907     *)
908       dnl Check for uuid/uuid.h (e2fsprogs/util-linux-ng) or uuid.h
909       dnl (FreeBSD/NetBSD).
910       AC_CHECK_HEADERS([uuid/uuid.h], [
911         dnl util-linux-ng's uuid/uuid.h found - check for uuid_generate in
912         dnl -luuid.
913         SAVE_LIBS=$LIBS
914         AC_SEARCH_LIBS([uuid_generate], [uuid], [], [
915           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)])
916           ])
917         if test x != x"$LIBS" ; then
918           XAPIAN_LIBS="$XAPIAN_LIBS $LIBS"
919         fi
920       ], [
921         dnl Try uuid.h as found on FreeBSD/NetBSD, with associated code in libc.
922         AC_CHECK_HEADERS([uuid.h], [
923           dnl Check for uuid_create with no extra libraries required.
924           AC_CHECK_FUNC([uuid_create], [], [
925             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)])
926           ])
927         ], [
928           dnl Especially useful for Android.
929           AC_MSG_CHECKING([if host platform supports /proc/sys/kernel/random/uuid])
930           case $host_os in
931             linux*)
932               AC_DEFINE([USE_PROC_FOR_UUID], [1],
933                         [Define to 1 to read UUID from '/proc/sys/kernel/random/uuid'])
934               AC_MSG_RESULT([yes])
935               ;;
936             *)
937               AC_MSG_RESULT([no])
938               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)])
939               ;;
940           esac
941         ], [ ])
942       ], [ ])
943       ;;
944   esac
945   LIBS=$SAVE_LIBS
947   case $host_os in
948     *djgpp* | *msdos* )
949       dnl DJGPP has a dummy implementation of fork which always fails.
950       dnl
951       dnl For disk-based backends, use flock() for locking, which doesn't need
952       dnl fork() or socketpair().
953       AC_DEFINE([FLINTLOCK_USE_FLOCK], 1, [Define to use flock() for flint-compatible locking])
954       ;;
955   esac
956   ;;
957 esac
959 if test "$enable_backend_remote" = yes ; then
960   case $host_os-$win32 in
961     *-yes )
962       dnl For mingw and msvc we have an alternative implementation which
963       dnl doesn't need fork() or socketpair().
964       dnl
965       dnl We need -lws2_32 for getaddrinfo(), etc.
966       win32_need_lws2_32=1
967       dnl Vista is needed for the AI_ADDRCONFIG flag to getaddrinfo().
968       AC_DEFINE([WINVER], [0x600],
969                 [Version of Windows to assume (0x600 => Vista).])
970       AC_DEFINE([_WIN32_WINNT], [WINVER],
971                 [Version of Windows to assume.])
972       ;;
973     *djgpp* | *msdos* )
974       dnl DJGPP has a dummy implementation of fork which always fails.  If
975       dnl someone actually wanted remote backend support, then DJGPP has a
976       dnl pthreads port, so using threads like we do on Windows would make more
977       dnl sense.
978       AC_MSG_ERROR([The remote backend is not currently supported on this platform.])
979       ;;
980     *)
981       dnl On Unix, we need fork and socketpair for the remotebackend.
982       SAVE_LIBS=$LIBS
983       AC_CHECK_FUNCS([fork], [], [
984         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.)])
985       ])
986       dnl Check if -lsocket is required for socketpair (Solaris needs it).
987       dnl And on Haiku it's in -lnetwork.
988       AC_SEARCH_LIBS([socketpair], [socket network], [], [
989         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.)])
990       ])
991       AC_DEFINE([HAVE_SOCKETPAIR], [1],
992                 [Define to 1 if you have the 'socketpair' function.])
993       dnl Check if extra libraries are needed for getaddrinfo or inet_ntop()
994       dnl (e.g. on Solaris).
995       dnl
996       dnl We're currently assuming that any system that is worth trying to
997       dnl support has getaddrinfo() and inet_ntop(), since these are the
998       dnl standard route for supporting IPv6, and that's pretty much essential
999       dnl for platforms to support now.
1000       AC_SEARCH_LIBS([getaddrinfo], [nsl socket], [], [
1001         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.)])
1002       ])
1003       AC_SEARCH_LIBS([inet_ntop], [nsl socket], [], [
1004         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.)])
1005       ])
1006       XAPIAN_LIBS="$XAPIAN_LIBS $LIBS"
1007       LIBS=$SAVE_LIBS
1008       ;;
1009   esac
1011   TYPE_SOCKLEN_T
1014 if test "$win32_need_lws2_32" = 1 ; then
1015   XAPIAN_LIBS="$XAPIAN_LIBS -lws2_32"
1018 AC_ARG_ENABLE([visibility],
1019   [AS_HELP_STRING([--disable-visibility], [disable use of GCC visibility])],
1020   [case ${enableval} in
1021     yes|no) ;;
1022     *) AC_MSG_ERROR([bad value ${enableval} for --disable-visibility]) ;;
1023   esac])
1025 vpath_build=no
1026 if test "`pwd`" != "`cd $srcdir;pwd`" ; then
1027   vpath_build=yes
1029 AM_CONDITIONAL([VPATH_BUILD], [test yes = "$vpath_build"])
1031 dnl Turn off compilation of anything that we don't have the requirements for
1033 dnl Set conditionals to specify what we compile
1035 AM_CONDITIONAL([BUILD_BACKEND_GLASS], [test yes = "$enable_backend_glass"])
1036 AM_CONDITIONAL([BUILD_BACKEND_HONEY], [test yes = "$enable_backend_honey"])
1037 AM_CONDITIONAL([BUILD_BACKEND_INMEMORY], [test yes = "$enable_backend_inmemory"])
1038 AM_CONDITIONAL([BUILD_BACKEND_REMOTE], [test yes = "$enable_backend_remote"])
1039 AM_CONDITIONAL([BUILD_BACKEND_TOOLS],
1040   [test nono != "$enable_backend_glass$enable_backend_honey"])
1042 dnl Decide if we should use the zlib-vg.so LD_PRELOAD hack.
1043 use_zlib_vg=no
1044 if test -n "$VALGRIND" ; then
1045   case $host_os in
1046     linux*) use_zlib_vg=yes ;;
1047   esac
1049 AM_CONDITIONAL([USE_ZLIB_VG], [test yes = "$use_zlib_vg"])
1051 dnl See if we have fdatasync, and what libraries are needed for it.
1052 dnl We need to actually check for a declaration as OS X has a dummy
1053 dnl implementation in the library which is not prototyped in any header.
1054 AC_CHECK_DECL([fdatasync(int)], [
1055   SAVE_LIBS=$LIBS
1056   AC_SEARCH_LIBS([fdatasync], [rt], [XAPIAN_LIBS="$LIBS $XAPIAN_LIBS"])
1057   LIBS=$SAVE_LIBS
1058   AC_CHECK_FUNCS([fdatasync])
1059   ],
1060   [ac_cv_func_fdatasync=no],
1061   [#include <unistd.h>]
1064 AC_CHECK_FUNCS([fsync writev])
1065 AC_CHECK_FUNCS([posix_fadvise])
1066 if test "$win32" = no ; then
1067   dnl ftruncate() under Wine seems to be buggy and sometimes fails, though
1068   dnl a cut-down reproducer seems fine.  For now just avoid ftruncate()
1069   dnl entirely on this platform - we'll fallback to lseek() + write() of a
1070   dnl single zero byte, which is pretty efficient.
1071   AC_CHECK_FUNCS([ftruncate])
1074 dnl HP-UX has pread and pwrite, but they don't work!  Apparently this problem
1075 dnl manifests when largefile support is enabled, and we definitely want that
1076 dnl so don't use pread or pwrite on HP-UX.
1077 case $host_os in
1078   hpux*)
1079     AC_MSG_CHECKING([for pread])
1080     AC_MSG_RESULT([present but broken on $host_os])
1081     AC_MSG_CHECKING([for pwrite])
1082     AC_MSG_RESULT([present but broken on $host_os])
1083     ;;
1084   *)
1085     AC_CHECK_FUNC([pread],
1086        [AC_DEFINE([HAVE_PREAD], [1],
1087             [Define if pread is available on this system])
1088         AC_MSG_CHECKING([for any prototype needed for pread])
1089         AC_CACHE_VAL([xo_cv_pread_prototype],
1090           [
1091             for p in ' ' \
1092               'extern "C" ssize_t pread(int, void *, size_t, off_t) throw ();' \
1093               'extern "C" ssize_t pread(int, void *, size_t, off_t);' ; do
1094               AC_TRY_COMPILE([
1095 #include <sys/types.h>
1096 #include <unistd.h>
1098               ],[
1099                 char b[256];
1100                 pread(1, b, 256, 20);
1101               ],[
1102                 xo_cv_pread_prototype="$p"
1103                 break
1104               ])
1105             done
1106             if test -z "$xo_cv_pread_prototype"; then
1107               AC_MSG_RESULT([not found])
1108               AC_MSG_ERROR([Failed to find working prototype for pread])
1109             fi
1110           ])
1111           if test " " = "$xo_cv_pread_prototype" ; then
1112             AC_MSG_RESULT([none required])
1113           else
1114             AC_MSG_RESULT([$xo_cv_pread_prototype])
1115             AC_DEFINE_UNQUOTED([PREAD_PROTOTYPE], [$xo_cv_pread_prototype],
1116                                [explicit prototype needed for pread (if any)])
1117           fi
1118         ])
1119     AC_CHECK_FUNC([pwrite],
1120        [AC_DEFINE([HAVE_PWRITE], [1],
1121             [Define if pwrite is available on this system])
1122         AC_MSG_CHECKING([for any prototype needed for pwrite])
1123         AC_CACHE_VAL([xo_cv_pwrite_prototype],
1124           [
1125             for p in ' ' \
1126               'extern "C" ssize_t pwrite(int, const void *, size_t, off_t) throw ();' \
1127               'extern "C" ssize_t pwrite(int, const void *, size_t, off_t);' ; do
1128               AC_TRY_COMPILE([
1129 #include <sys/types.h>
1130 #include <unistd.h>
1132               ],[
1133                 const char *p = "hello";
1134                 pwrite(1, p, 5, 20);
1135               ],[
1136                 xo_cv_pwrite_prototype="$p"
1137                 break
1138               ])
1139             done
1140             if test -z "$xo_cv_pwrite_prototype"; then
1141               AC_MSG_RESULT([not found])
1142               AC_MSG_ERROR([Failed to find working prototype for pwrite])
1143             fi
1144           ])
1145           if test " " = "$xo_cv_pwrite_prototype" ; then
1146             AC_MSG_RESULT([none required])
1147           else
1148             AC_MSG_RESULT([$xo_cv_pwrite_prototype])
1149             AC_DEFINE_UNQUOTED([PWRITE_PROTOTYPE], [$xo_cv_pwrite_prototype],
1150                                [explicit prototype needed for pwrite (if any)])
1151           fi
1152         ])
1153     ;;
1154 esac
1156 AC_MSG_CHECKING([for directory separator(s)])
1157 case $host_os-$win32 in
1158   *-yes | cygwin* | os2* | *djgpp* | *msdos* )
1159     AC_MSG_RESULT([/ and \\])
1160     AC_DEFINE([DIR_SEPS], ["/\\"], [directory separator(s) as a character or string literal])
1161     AC_DEFINE([DIR_SEPS_LIST], [{ '/', '\\' }], [directory separator(s) as an initialiser list])
1162     ;;
1163   *)
1164     AC_MSG_RESULT([/])
1165     AC_DEFINE([DIR_SEPS], ['/'], [directory separator(s) as a character or string literal])
1166     AC_DEFINE([DIR_SEPS_LIST], [{ '/' }], [directory separator(s) as an initialiser list])
1167     ;;
1168 esac
1170 AC_CHECK_FUNCS([link])
1172 dnl *************************
1173 dnl * Set debugging options *
1174 dnl *************************
1176 dnl Which assertion types to enable in the code.
1178 AC_ARG_ENABLE([assertions],
1179   [AS_HELP_STRING([--enable-assertions], [enable debug assertions (no|partial|yes) [default=no]])],
1180   [case $enableval in
1181     yes|partial|no) ;;
1182     *)
1183       AC_MSG_ERROR([Invalid option: '--enable-assertions=$enableval']) ;;
1184   esac])
1186 AC_ARG_ENABLE([log],
1187   [AS_HELP_STRING([--enable-log], [generate a log of methods called, etc (no|yes|profile) [default=no]])],
1188   [case $enableval in
1189     yes|no) ;;
1190     profile)
1191       AC_MSG_ERROR(['--enable-log=profile' is no longer supported - see https://trac.xapian.org/wiki/ProfilingXapian for alternatives.]) ;;
1192     *)
1193       AC_MSG_ERROR([Invalid option: '--enable-log=$enableval']) ;;
1194   esac])
1196 dnl Set defines according to the --enable-assertions and --enable-log options
1197 dnl given.
1199 if test yes = "$enable_assertions" || test partial = "$enable_assertions" ; then
1200   AC_DEFINE([XAPIAN_ASSERTIONS],,
1201     [Define if you want assertions (causes some slow-down)])
1204 if test yes = "$enable_assertions"; then
1205   AC_DEFINE([XAPIAN_ASSERTIONS_PARANOID],,
1206     [Define if you want paranoid assertions (causes significant slow-down)])
1209 if test yes = "$enable_log"; then
1210   AC_DEFINE([XAPIAN_DEBUG_LOG],,
1211     [Define if you want a log of methods called and other debug messages])
1214 dnl ******************************
1215 dnl * Set special compiler flags *
1216 dnl ******************************
1218 dnl Set flags to control warnings (enable more, or disable annoying ones).
1219 dash_d_visibility=
1220 if test yes = "$GXX"; then
1221   dnl Intel's C++ compiler and clang both lie and define __GNUC__, so check which
1222   dnl we actually have, as neither is really 100% compatible.
1223   case `echo __INTEL_COMPILER __clang__|$CXX -E - 2>&AS_MESSAGE_LOG_FD|grep -v '^#'` in
1224     *__INTEL_COMPILER*__clang__*)
1225       dnl GCC (since neither substituted):
1227       dnl The exact format of g++ --version seems to change with almost every
1228       dnl minor release so use the preprocessor macros which should be more
1229       dnl robust.
1230       AC_MSG_CHECKING([for version of $CXX])
1231       gxx_version=`echo __GNUC__.__GNUC_MINOR__.__GNUC_PATCHLEVEL__|$CXX -E -|sed '/^#/d;s/ //g'`
1232       AC_MSG_RESULT([GCC $gxx_version])
1234       case $gxx_version in
1235       [[0123]].*|4.[[0-7]].*)
1236         AC_MSG_ERROR([Xapian requires GCC 4.8 or later])
1237         ;;
1238       esac
1240       dnl -Wundef was supported by g++ 3.0.
1241       dnl
1242       dnl -Wlogical-op and -Wmissing-declarations (for C++) were added in
1243       dnl GCC 4.3.
1244       dnl
1245       dnl -Wdouble-promotion was added in GCC 4.6.
1246       dnl
1247       dnl -Winit-self was added in GCC 3.4, but for GCC < 4.7 g++ always
1248       dnl warns for this case with -Wuninitialized (implied by -W).  We
1249       dnl don't intend to use this idiom, so any instances are bugs we'd
1250       dnl like to know about.
1251       dnl
1252       dnl All the other options were supported by g++ 2.95.
1253       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"
1255       dnl FIXME:
1256       dnl -Wconversion in older GCC versions is intended to help migration
1257       dnl from K&R to ISO C, and isn't useful for us.  In 4.3 it was renamed
1258       dnl to -Wtraditional-conversion and a new -Wconversion added which
1259       dnl sounds useful but is a bit buggy currently.  So we should consider
1260       dnl enabling -Wconversion once it is stabilised (GCC 4.4 or ...)
1261       dnl
1262       dnl -Wold-style-cast is interesting, but triggers for macros from
1263       dnl system headers (e.g. FD_SET).  GCC 4.8 improved this by making
1264       dnl -ftrack-macro-expansion=2 the default, but we still see such
1265       dnl warnings on some platforms for some reason (e.g. Cygwin with GCC
1266       dnl 5.4.0 warns about FD_SET, and on Debian with GCC 4.9.2 we see
1267       dnl warnings from zlib.h).
1269       dnl Automatically add -Werror if maintainer mode is enabled.
1270       if test x$USE_MAINTAINER_MODE = xyes; then
1271         AM_CXXFLAGS="$AM_CXXFLAGS -Werror"
1272       fi
1273       ;;
1274     *__clang__*)
1275       dnl Intel's compiler (since __clang__ not substituted):
1276       dnl
1277       dnl -w1 stops the avalanche of uninteresting "remark" messages.
1278       dnl -wd... disables warnings which don't have good code workarounds.
1279       AM_CXXFLAGS="$AM_CXXFLAGS -Wall -w1 -wd177,1572"
1281       dnl Automatically add -Werror if maintainer mode is enabled.
1282       if test x$USE_MAINTAINER_MODE = xyes; then
1283         AM_CXXFLAGS="$AM_CXXFLAGS -Werror"
1284       fi
1285       ;;
1286     *__INTEL_COMPILER*)
1287       dnl clang (since __INTEL_COMPILER not substituted):
1289       dnl These options all work at least as far back as clang++ 3.0:
1290       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"
1292       dnl Automatically add -Werror if maintainer mode is enabled.
1293       if test x$USE_MAINTAINER_MODE = xyes; then
1294         AM_CXXFLAGS="$AM_CXXFLAGS -Werror"
1295       fi
1296       ;;
1297   esac
1299   if test no != "$enable_visibility"; then
1300     dnl GCC doesn't support symbol visibility on all platforms (e.g. it isn't
1301     dnl supported on mingw and visibility attributes result in warnings).
1302     AC_MSG_CHECKING([if $CXX -fvisibility=hidden -fvisibility-inlines-hidden works])
1303     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
1304       AC_MSG_RESULT([yes])
1305       AM_CXXFLAGS="$AM_CXXFLAGS -fvisibility=hidden -fvisibility-inlines-hidden"
1306       dash_d_visibility=-DXAPIAN_ENABLE_VISIBILITY
1307     else
1308       AC_MSG_RESULT([no])
1309     fi
1310   fi
1311 else
1312   dnl Not GCC, nor a compiler masquerading as GCC.
1313   case /$CXX in
1314   */aCC)
1315     dnl +w turns on more warnings.
1316     dnl +wlint turns on "lint-like" warnings.
1317     dnl +W<n1>,<n2>,... suppresses warnings n1, n2, ...
1318     dnl 2340 (remark) "value copied to temporary, reference to temporary
1319     dnl use", in: throw Xapian::UnimplementedError("...");
1320     dnl 2401 "destructor for base class ... is non-virtual" (we don't need a
1321     dnl virtual destructor for intrusive_base, since we never delete
1322     dnl       its subclasses by a intrusive_base *).
1323     dnl 3348 "declaration hides constant ..." which seems to misfire!
1324     dnl 4255 (remark) "padding size of struct "..." with ... bytes to
1325     dnl alignment boundary".
1326     dnl 4273 "floating-point equality and inequality comparisons may be
1327     dnl inappropriate due to roundoff common in floating-point computation"
1328     dnl No obvious workaround for when you really do want == or !=.
1329     dnl 20201 "Memory leak is detected" which triggers for "return new Foo;"!
1330     AM_CXXFLAGS="$AM_CXXFLAGS +w +wlint +W2340,2401,3348,4255,4273,20201" ;;
1331   */sunCC|*/CC)
1332     dnl Sun's C++ compiler warns about functions failing to return a value even
1333     dnl when the function ends with a "throw" statement.  That's just unhelpful
1334     dnl noise, and adding a dummy "return" after "throw" seems a worse solution
1335     dnl than simply disabling this warning - any genuinely missing return
1336     dnl statements will get reported by compilers with superior warning
1337     dnl machinery.
1338     XAPIAN_TEST_CXXFLAGS([-erroff=voidretw], [AM_CXXFLAGS])
1339     ;;
1340   esac
1343 XAPIAN_TEST_LINKER_FLAG([-Bsymbolic-functions], [symbolic_functions],
1344   [XAPIAN_LDFLAGS="$XAPIAN_LDFLAGS $flag"])
1346 FP_EXCESS_PRECISION=no
1347 AC_MSG_CHECKING([whether to use SSE instructions on x86])
1348 case $host_cpu in
1349   i*86)
1350     if test "$enable_sse" = no ; then
1351       AC_MSG_RESULT([no])
1352       FP_EXCESS_PRECISION=yes
1353       if test yes = "$msvc"; then
1354         dnl MSVC defaults to SSE2.
1355         AM_CXXFLAGS="$AM_CXXFLAGS -arch:IA32"
1356       fi
1357     else
1358       dnl Default to sse2.
1359       test "$enable_sse" != yes || enable_sse=sse2
1360       if test yes = "$GXX"; then
1361         AC_MSG_RESULT([yes (configure with --disable-sse to disable)])
1362         dnl We can unconditionally use -mtune=generic as it was added in GCC
1363         dnl 4.2, and supported at least as far back as clang 3.0.
1364         AM_CXXFLAGS="$AM_CXXFLAGS -mfpmath=sse -m$enable_sse -mtune=generic"
1365       elif test yes = "$msvc"; then
1366         AC_MSG_RESULT([yes (configure with --disable-sse to disable)])
1367         if test sse = "$enable_sse"; then
1368           dnl MSVC defaults to SSE2.
1369           AM_CXXFLAGS="$AM_CXXFLAGS -arch:SSE"
1370         fi
1371       else
1372         AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
1373 [[#ifndef __SUNPRO_CC
1374 #error Not Sun compiler
1375 #endif]])],
1376           [AC_MSG_RESULT([yes (configure with --disable-sse to disable)])
1377           AM_CXXFLAGS="$AM_CXXFLAGS -xarch=$enable_sse"]
1378           ,
1379           [AC_MSG_RESULT([don't know how to for compiler $CXX])
1380           FP_EXCESS_PRECISION=yes]
1381         )
1382       fi
1383     fi
1384     ;;
1385   *)
1386     AC_MSG_RESULT([non-x86 arch ($host_cpu)]) ;;
1387 esac
1388 AC_SUBST([FP_EXCESS_PRECISION])
1390 AH_BOTTOM(
1391 [/* Disable stupid MSVC warnings. */
1392 #ifdef _MSC_VER
1393 /* Passing an empty parameter to a single parameter macro. */
1394 # pragma warning(disable:4003)
1395 /* A "performance" warning for converting int to bool. */
1396 # pragma warning(disable:4800)
1398 /* Tell MSVC we want M_PI, etc defined. */
1399 # define _USE_MATH_DEFINES
1401 /* Tell MSVC we don't want max() and min() macros defined. */
1402 # define NOMINMAX
1403 #endif
1405 /* Make the POSIX-like functions support large files.  MSVC needs this;
1406  * current mingw32 does too; mingw64 supports _FILE_OFFSET_BITS, which
1407  * AC_SYS_LARGEFILE should discover and enable automatically.
1408  */
1409 #if defined _MSC_VER || \
1410     (defined __MINGW32__ && !defined _FILE_OFFSET_BITS)
1412 # include <sys/stat.h>
1413 # include <sys/types.h>
1414 # include <io.h>
1415 /* zlib.h uses off_t so we need to include it before we redefine off_t. */
1416 # include <zlib.h>
1418 // MSVC needs to call _stat64() instead of stat() and the struct which holds
1419 // the information is "struct _stat64" instead of "struct stat" so we just
1420 // use #define to replace both in one go.  We also want to use _fstat64()
1421 // instead of fstat() but in this case we can use a function-like macro.
1423 // Mingw has _stat64() but unhelpfully for our purposes, it has an extra
1424 // underscore prefix on the struct name ("struct __stat64") so there we
1425 // target _stati64 instead.  This has 64-bit file size but the time_t size
1426 // is switchable.  We don't really care about file timestamps in the
1427 // library, so this should be fine.
1429 // This hack is a problem is we ever want a method called "stat", or one called
1430 // fstat which takes 2 parameters, but we can probably live with these
1431 // limitations.
1433 # ifdef stat
1434 #  undef stat
1435 # endif
1437 # ifdef fstat
1438 #  undef fstat
1439 # endif
1441 # ifdef _MSC_VER
1442 #  define stat _stat64
1443 #  define fstat(FD, BUF) _fstat64(FD, BUF)
1444 # else
1445 #  define stat _stati64
1446 #  define fstat(FD, BUF) _fstati64(FD, BUF)
1447 # endif
1449 # ifdef lseek
1450 #  undef lseek
1451 # endif
1453 # ifdef off_t
1454 #  undef off_t
1455 # endif
1457 # define lseek(FD, OFF, WHENCE) _lseeki64(FD, OFF, WHENCE)
1458 /* Redefine via a typedef so C++ code off_t(-1) works - it wouldn't if we did:
1459  * #define off_t long long
1460  */
1461 typedef long long off_t_redefinition_typedef;
1462 # define off_t off_t_redefinition_typedef
1464 #endif
1466 /* MSVC defines _WIN32 but not __WIN32__. */
1467 #if !defined __WIN32__ && defined _WIN32
1468 # define __WIN32__
1469 #endif
1471 /* MSVC defines _WIN64 but not __WIN64__. */
1472 #if !defined __WIN64__ && defined _WIN64
1473 # define __WIN64__
1474 #endif
1476 /* _FORTIFY_SOURCE is only supported by GCC >= 4.1 and glibc >= 2.3.4, but it
1477  * shouldn't cause a problem to define it where it's not supported and some
1478  * distros may have backported support, so hardcoding version checks is
1479  * counter-productive.
1481  * Check if _FORTIFY_SOURCE is already defined to allow the user to override
1482  * our choice with "./configure CPPFLAGS=-D_FORTIFY_SOURCE=0" or "...=1".
1483  */
1484 #if defined __GNUC__ && !defined _FORTIFY_SOURCE
1485 # define _FORTIFY_SOURCE 2
1486 #endif
1488 /* For compilers which support it (such as GCC, clang, Intel's C++ compiler)
1489  * we can use __builtin_expect to give the compiler hints about branch
1490  * prediction.  See HACKING for how to use these.
1491  */
1492 #if HAVE_DECL___BUILTIN_EXPECT
1493 /* The arguments of __builtin_expect() are both long, so use !! to ensure that
1494  * the first argument is always an integer expression, and always 0 or 1, but
1495  * still has the same truth value for the if or while it is used in.
1496  */
1497 # define rare(COND) __builtin_expect(!!(COND), 0)
1498 # define usual(COND) __builtin_expect(!!(COND), 1)
1499 #else
1500 # define rare(COND) (COND)
1501 # define usual(COND) (COND)
1502 #endif
1504 /* Signal we're building the library so it's OK to include headers such as
1505  * xapian/query.h directly.
1506  */
1507 #define XAPIAN_LIB_BUILD 1
1509 /* With Sun CC 5.13 (Studio 12.4) on Solaris 11.2, <math.h> seems to get
1510  * implicitly included somehow before <cmath>, and compilation fails due
1511  * to 'std::exception' colliding with 'struct exception'.  It's not clear
1512  * how to avoid this, so just define the same magic macro which <cmath> does
1513  * before it includes <math.h>.
1514  */
1515 #ifdef __SUNPRO_CC
1516 # define __MATHERR_RENAME_EXCEPTION
1517 #endif
1520 AC_SUBST([AM_CXXFLAGS])
1522 dnl Restore CXXFLAGS to those the user specified or autoconf defaulted to.
1523 CXXFLAGS=$save_CXXFLAGS
1525 dnl Required for auto regeneration to work in a combined maintainer-mode tree.
1526 : ${AUTOM4TE=autom4te}
1527 AC_SUBST([AUTOM4TE])
1529 dnl Libtool sets this (to yes|no|unknown) and we use it in xapian-config.
1530 AC_SUBST([link_all_deplibs_CXX])
1532 dnl Shared library extension.
1533 module=no
1534 eval "SHLIBEXT=$shrext_cmds"
1535 AC_SUBST([SHLIBEXT])
1537 dnl We want to be able to use GNU make % pattern rules in maintainer targets
1538 dnl but automake warns these aren't portable, so we substitute the % to avoid
1539 dnl this warning.
1540 PERCENT='%'
1541 AC_SUBST([PERCENT])
1543 dnl Split up the version number into "MAJOR.MINOR.REVISION".
1544 MAJOR_VERSION=`echo "$VERSION"|sed 's/\..*//'`
1545 [MINOR_VERSION=`echo "$VERSION"|sed 's/[^.]*\.//;s/\..*//'`]
1546 [REVISION=`echo "$VERSION"|sed 's/.*\.//;s/_.*$//'`]
1548 dnl **************************
1549 dnl * Build the output files *
1550 dnl **************************
1552 AC_CONFIG_FILES([
1553  Makefile
1554  tests/Makefile
1555  docs/Makefile
1556  docs/doxygen_api.conf
1557  docs/doxygen_source.conf
1558  xapian-core.spec
1559  cmake/xapian-config.cmake
1560  cmake/xapian-config-version.cmake
1561  pkgconfig/xapian-core"$LIBRARY_VERSION_SUFFIX".pc:pkgconfig/xapian-core.pc.in
1562  ])
1563 AC_CONFIG_FILES([tests/runtest], [chmod +x tests/runtest])
1564 AC_CONFIG_FILES([tests/runsrv], [chmod +x tests/runsrv])
1565 AC_CONFIG_FILES([tests/submitperftest], [chmod +x tests/submitperftest])
1566 AC_CONFIG_FILES([tests/perftest/get_machine_info], [chmod +x tests/perftest/get_machine_info])
1567 AC_CONFIG_FILES([xapian-config], [chmod +x xapian-config])
1568 AC_CONFIG_FILES([makemanpage], [chmod +x makemanpage])
1569 AC_OUTPUT
1571 dnl There are no files generated by AC_OUTPUT in the following directories
1572 dnl and we need to ensure they exist so that the rest of configure or make
1573 dnl won't fail because they don't exist when srcdir != builddir.
1574 if test yes = "$vpath_build" ; then
1575   for dir in include/xapian languages queryparser ; do
1576     AS_MKDIR_P(["$dir"])
1577   done
1580 dnl Generate include/xapian/version.h:
1582 dnl MAIN_VERSION is VERSION without any _git123 suffix.
1583 MAIN_VERSION="$MAJOR_VERSION.$MINOR_VERSION.$REVISION"
1584 cxxcpp_flags=-I.
1585 for backend in GLASS HONEY INMEMORY REMOTE ; do
1586   val=`eval echo "\\\$BUILD_BACKEND_${backend}_TRUE"`
1587   if test -z "$val" ; then
1588     cxxcpp_flags="$cxxcpp_flags -DXAPIAN_HAS_${backend}_BACKEND"
1589   fi
1590 done
1592 if test yes = "$enable_64bit_docid" ; then
1593   cxxcpp_flags="$cxxcpp_flags -DXAPIAN_DOCID_BASE_TYPE="`echo "$INT64_T"|sed 's/ /____/g'`
1594 else
1595   cxxcpp_flags="$cxxcpp_flags -DXAPIAN_DOCID_BASE_TYPE="`echo "$INT32_T"|sed 's/ /____/g'`
1598 if test yes = "$enable_64bit_termcount" ; then
1599   cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TERMCOUNT_BASE_TYPE="`echo "$INT64_T"|sed 's/ /____/g'`
1600 else
1601   cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TERMCOUNT_BASE_TYPE="`echo "$INT32_T"|sed 's/ /____/g'`
1604 if test yes = "$enable_64bit_termpos" ; then
1605   cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TERMPOS_BASE_TYPE="`echo "$INT64_T"|sed 's/ /____/g'`
1606 else
1607   cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TERMPOS_BASE_TYPE="`echo "$INT32_T"|sed 's/ /____/g'`
1610 dnl Always ought to be 64 bit.
1611 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_TOTALLENGTH_TYPE="`echo "unsigned $INT64_T"|sed 's/ /____/g'`
1613 dnl Make revision numbers in the API 64 bit for future-proofing.
1614 cxxcpp_flags="$cxxcpp_flags -DXAPIAN_REVISION_TYPE="`echo "unsigned $INT64_T"|sed 's/ /____/g'`
1616 dnl For GCC (and compilers which pretend to be GCC) and MSVC, we create some
1617 dnl ABI checks in the generated version.h, and $CXXFLAGS may contain options
1618 dnl which affect the ABI (e.g. -fabi-version for GCC) so we want to use these
1619 dnl options when generating version.h.  For these compilers, CXXCPP="$CXX -E"
1620 dnl so it should understand all compiler options.
1622 dnl For other compilers, we only pass $CPPFLAGS to $CXXCPP in case it's an
1623 dnl external cpp which doesn't understand flags which might be in $CXXFLAGS.
1624 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[#ifndef __GNUC__
1625 #ifndef _MSC_VER
1626        choke me
1627 #endif
1628 #endif
1629 ]])],
1630         [cxxcpp_flags="$cxxcpp_flags $CPPFLAGS $CXXFLAGS"],
1631         [cxxcpp_flags="$cxxcpp_flags $CPPFLAGS"])
1632 rm -f include/xapian/version.h.tmp
1633 dnl "\r" in sed is a GNUism, but we only need to remove it on MS Windows
1634 dnl where we'll always have GNU sed, and other sed's will just interpret
1635 dnl it as "r" (Solaris sed) or maybe literal "\r" which won't match.
1637 dnl Use @@ around $MAIN_VERSION so we get " in the final output.
1638 $CXXCPP $cxxcpp_flags\
1639         -DSTRING_VERSION="\"@@$MAIN_VERSION@@\""\
1640         -DMAJOR_VERSION="\"$MAJOR_VERSION\""\
1641         -DMINOR_VERSION="\"$MINOR_VERSION\""\
1642         -DREVISION="\"$REVISION\""\
1643         $dash_d_visibility\
1644         $srcdir/include/xapian/version_h.cc|\
1645         ${SED-sed} '0,/const char \* dummy/d;/"/!d;s/^ *//;/^#/d;s/ *$//;s/" *,//;s/"//g;s/@@/"/g;s/  */ /g;s/ *,\r$//;s/ *,$//;s/____/ /g;s/\\\\$/\\/'\
1646         > include/xapian/version.h.tmp
1647 dnl Only update the file if it has changed, so we don't alter the timestamp
1648 dnl and cause lots of rebuilding needlessly.  However, the build system
1649 dnl needs a timestamp to know when to regenerate version.h because version_h.cc
1650 dnl has changed so we use a separate timestamp file.
1651 touch include/xapian/version.h.timestamp
1652 if cmp include/xapian/version.h.tmp include/xapian/version.h >/dev/null 2>&1
1653 then
1654   rm include/xapian/version.h.tmp
1655 else
1656   mv include/xapian/version.h.tmp include/xapian/version.h
1659 if test "$enable_gpl_libxapian" != yes ; then
1660   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.])