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