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