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
5 m4_define([project_version], [1.3.0])
6 AC_INIT([xapian-letor], project_version, [https://xapian.org/bugs])
9 dnl Extract from the libtool info manual:
11 dnl Here are a set of rules to help you update your library version information:
13 dnl 1. Start with version information of '0:0:0' for each libtool library.
15 dnl 2. Update the version information only immediately before a public
16 dnl release of your software. More frequent updates are unnecessary,
17 dnl and only guarantee that the current interface number gets larger
20 dnl 3. If the library source code has changed at all since the last
21 dnl update, then increment REVISION ('C:R:A' becomes 'C:r+1:A').
23 dnl 4. If any interfaces have been added, removed, or changed since the
24 dnl last update, increment CURRENT, and set REVISION to 0.
26 dnl 5. If any interfaces have been added since the last public release,
27 dnl then increment AGE.
29 dnl 6. If any interfaces have been removed since the last public release
30 dnl then set AGE to 0.
32 dnl LIBRARY_VERSION_INFO for libxapianletor:
33 dnl 0:0:0 1.3.1 First release with xapian-letor split out from xapian-core
34 LIBRARY_VERSION_INFO=0:0:0
35 AC_SUBST(LIBRARY_VERSION_INFO)
37 dnl Where xapian-letor.h, etc go. In development release append "/xapian-1.3".
41 AM_INIT_AUTOMAKE([1.13 -Wportability tar-ustar])
43 AC_CONFIG_SRCDIR([ranker/ranker.cc])
45 AC_CONFIG_HEADERS([config.h])
47 AC_CONFIG_MACRO_DIRS([m4])
51 dnl -no-undefined causes problems on Solaris with Sun CC in C++11 mode, so only
52 dnl pass -no-undefined on platforms where it is required in order to link a
53 dnl shared library at all (Windows is the main one).
55 if test unsupported = "$allow_undefined_flag" ; then
56 NO_UNDEFINED=-no-undefined
58 AC_SUBST(NO_UNDEFINED)
61 dnl disable "maintainer only" rules by default
64 dnl Checks for programs.
69 # Checked: freebsd8.0 openbsd4.6 solaris2.9 solaris2.10
71 linux* | k*bsd*-gnu | freebsd* | openbsd* | solaris*)
72 dnl Vanilla libtool sets this to "unknown" which it then handles as "yes".
73 link_all_deplibs_CXX=no
79 dnl Extract search path from ldconfig which is more reliable than the way
80 dnl vanilla libtool extracts them from ld.so.conf.
81 d=`/sbin/ldconfig -N -X -v 2>&AS_MESSAGE_LOG_FD|$SED 's,^\(/.*\):\( (.*)\)\?$,\1,p;d'|tr '\n' ' '`
82 test -z "$d" || sys_lib_dlsearch_path_spec=$d
87 *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
88 dnl On these platforms, libtool emits a warning if -no-install is passed,
89 dnl and uses -no-fast-install instead - the least ugly way to avoid that
90 dnl warnings seems to be to duplicate the above list of platforms from
91 dnl libtool and use -no-fast-install on them directly.
92 NO_INSTALL=-no-fast-install ;;
94 NO_INSTALL=-no-install ;;
96 AC_SUBST([NO_INSTALL])
98 dnl Probe for any options needed to enable C++11 support.
99 AX_CXX_COMPILE_STDCXX_11
101 dnl Run tests using the C++ compiler.
104 dnl Check for xapian-core.
105 XO_LIB_XAPIAN([], [],
106 [xapian-config]regexp(project_version,
107 [^\([0-9]*\.[0-9]*[13579]\)\..*$], [-\1]))
110 dnl We want XAPIAN_CXXFLAGS to be used for configure tests.
111 save_CXXFLAGS=$CXXFLAGS
112 CXXFLAGS="$CXXFLAGS $XAPIAN_CXXFLAGS"
113 dnl mingw (for instance) lacks ssize_t
120 dnl Check for perl (needed to generate some sources and documentation).
121 AC_PATH_PROG([PERL], [perl], [])
122 if test x$USE_MAINTAINER_MODE = xyes; then
123 test -z "$PERL" && AC_MSG_ERROR([perl is required in maintainer mode])
126 AC_ARG_ENABLE([documentation],
127 [AS_HELP_STRING([--enable-documentation], [enable make rules to rebuild documentation [default=maintainer-mode]])],
128 [case ${enableval} in
130 *) AC_MSG_ERROR([bad value ${enableval} for --enable-documentation]) ;;
132 [enable_documentation=$USE_MAINTAINER_MODE])
133 AM_CONDITIONAL([DOCUMENTATION_RULES], [test x"$enable_documentation" = xyes])
134 AM_CONDITIONAL([MAINTAINER_NO_DOCS], [test x"$USE_MAINTAINER_MODE$enable_documentation" = xyesno])
136 if test x"$enable_documentation" = xyes ; then
137 dnl Check for help2man. (Needed to make man pages from "--help" output).
138 AC_PATH_PROG([HELP2MAN], [help2man], [])
139 test -z "$HELP2MAN" && AC_MSG_ERROR([help2man is required to build documentation])
141 dnl Check for rst2html. (Needed to make HTML from reStructuredText format)
142 dnl Also look for rst2html.py, which archlinux reportedly installs it as.
143 AC_PATH_PROGS([RST2HTML], [rst2html rst2html.py], [])
144 test -z "$RST2HTML" && AC_MSG_ERROR([rst2html is required to build documentation (try package python-docutils)])
147 dnl Checks for header files.
148 AC_CHECK_HEADERS([fcntl.h limits.h sys/errno.h sys/select.h], [], [], [ ])
150 dnl C++11 should have log2(), but keep this check for now to allow for
151 dnl compilers with incomplete library support for C++11.
152 AC_CHECK_DECLS([log2], [], [], [#include <cmath>])
154 dnl libsvm is required.
155 AC_CHECK_HEADER([libsvm/svm.h], [], AC_MSG_ERROR([libsvm required but libsvm/svm.h not found]), [ ])
158 AC_SEARCH_LIBS([svm_train], [svm], [], AC_MSG_ERROR([libsvm required]))
161 AC_SUBST([LIBSVM_LIBS])
163 dnl Check that snprintf actually works as it's meant to.
165 dnl Linux 'man snprintf' warns:
166 dnl Linux libc4.[45] does not have a snprintf, but provides a libbsd that
167 dnl contains an snprintf equivalent to sprintf, i.e., one that ignores the
168 dnl size argument. Thus, the use of snprintf with early libc4 leads to
169 dnl serious security problems.
171 dnl It also warns that glibc < 2.0.6 (and presumably other pre-C90
172 dnl implementations) return -1 when truncating so check that we get the
173 dnl ISO C90 semantics for the returned length when truncating. If we
174 dnl have a working snprintf but with non-ISO return semantics, handle
175 dnl that case separately as it may still be useful in many cases.
177 dnl mingw has _snprintf so check for that too.
178 AC_MSG_CHECKING([for working ISO C90 conforming snprintf])
179 ac_cv_func_snprintf_noniso=no
180 for func in snprintf _snprintf ; do
188 dnl Return different exit status for each error so we can see which
189 dnl check failed by consulting config.log.
191 char buffer[4] = "abc";
192 int res1 = $func(buffer, 2, "%s", "XYZ");
193 if (memcmp(buffer, "X\0c", 4) != 0) return 2;
194 int res2 = $func(buffer, 2, "%x", 0x12);
195 if (memcmp(buffer, "1\0c", 4) != 0) return 3;
196 if (res1 == -1 && res2 == -1) return 15; /* Pre-ISO semantics. */
197 if (res1 != 3) return 4;
198 if (res2 != 2) return 5;
201 [ac_cv_func_snprintf=$func;break],
203 if test 15no = "$?$ac_cv_func_snprintf_noniso" ; then
204 ac_cv_func_snprintf_noniso=$func
206 ac_cv_func_snprintf=no
208 [ac_cv_func_snprintf=unknown;break]
211 AC_MSG_RESULT([$ac_cv_func_snprintf])
212 case $ac_cv_func_snprintf in
214 AC_MSG_CHECKING([for working non-ISO C90 conforming snprintf])
215 AC_MSG_RESULT([$ac_cv_func_snprintf_noniso])
216 if test no != "$ac_cv_func_snprintf_noniso" ; then
217 AC_DEFINE_UNQUOTED([SNPRINTF], [$ac_cv_func_snprintf_noniso],
218 [Define to the name of a function implementing snprintf but not caring about ISO C99 return value semantics (if one exists)])
222 dnl be conservative when crosscompiling
225 AC_DEFINE_UNQUOTED([SNPRINTF_ISO], [$ac_cv_func_snprintf],
226 [Define to the name of a function implementing snprintf with ISO C99 semantics (if one exists)])
227 AC_DEFINE_UNQUOTED([SNPRINTF], [$ac_cv_func_snprintf],
228 [Define to the name of a function implementing snprintf but not caring about ISO C99 return value semantics (if one exists)])
232 dnl ******************************
233 dnl * Set special compiler flags *
234 dnl ******************************
236 dnl Set flags to control warnings (enable more, or disable annoying ones).
238 if test yes = "$GXX"; then
239 dnl Intel's C++ compiler and clang both lie and define __GNUC__, so check which
240 dnl we actually have, as neither is really 100% compatible.
241 case `echo __INTEL_COMPILER __clang__|$CXX -E - 2>&AS_MESSAGE_LOG_FD|grep -v '^#'` in
242 *__INTEL_COMPILER*__clang__*)
243 dnl GCC (since neither substituted):
245 dnl -Wundef was supported by g++ 3.0.
247 dnl -Wlogical-op and -Wmissing-declarations (for C++) were added in
250 dnl All the other options were supported by g++ 2.95.
251 AM_CXXFLAGS="$AM_CXXFLAGS -Wall -W -Wredundant-decls -Wpointer-arith -Wcast-qual -Wcast-align -Wformat-security -fno-gnu-keywords -Wundef -Woverloaded-virtual -Wstrict-null-sentinel -Wshadow -Wstrict-overflow=1 -Wlogical-op -Wmissing-declarations"
253 dnl The exact format of g++ --version seems to change with almost every
254 dnl minor release so use the preprocessor macros which should be more
256 AC_MSG_CHECKING([for version of $CXX])
257 gxx_version=`echo __GNUC__.__GNUC_MINOR__.__GNUC_PATCHLEVEL__|$CXX -E -|sed '/^#/d;s/ //g'`
258 AC_MSG_RESULT([GCC $gxx_version])
261 [[0123]].*|4.[[0123]].*)
262 AC_MSG_ERROR([Xapian requires GCC 4.4 or later])
266 dnl -Wdouble-promotion was added in GCC 4.6.
268 dnl -Winit-self was added in GCC 3.4, but for GCC < 4.7 g++ always
269 dnl warns for this case with -Wuninitialized (implied by -W). We
270 dnl don't intend to use this idiom, so any instances are bugs we'd
271 dnl like to know about.
272 AM_CXXFLAGS="$AM_CXXFLAGS -Wdouble-promotion -Winit-self" ;;
276 dnl -Wconversion in older GCC versions is intended to help migration
277 dnl from K&R to ISO C, and isn't useful for us. In 4.3 it was renamed
278 dnl to -Wtraditional-conversion and a new -Wconversion added which
279 dnl sounds useful but is a bit buggy currently. So we should consider
280 dnl enabling -Wconversion once it is stabilised (GCC 4.4 or ...)
282 dnl -Wold-style-cast is interesting, but triggers for macros from
283 dnl system headers (e.g. FD_SET) (tested with GCC 4.4).
285 dnl Automatically add -Werror if maintainer mode is enabled.
286 if test x$USE_MAINTAINER_MODE = xyes; then
287 AM_CXXFLAGS="$AM_CXXFLAGS -Werror"
291 dnl Intel's compiler (since __clang__ not substituted):
293 dnl -w1 stops the avalanche of uninteresting "remark" messages.
294 dnl -wd... disables warnings which don't have good code workarounds.
295 AM_CXXFLAGS="$AM_CXXFLAGS -Wall -w1 -wd177,1572"
297 dnl Automatically add -Werror if maintainer mode is enabled.
298 if test x$USE_MAINTAINER_MODE = xyes; then
299 AM_CXXFLAGS="$AM_CXXFLAGS -Werror"
303 dnl clang (since __INTEL_COMPILER not substituted):
304 AM_CXXFLAGS="$AM_CXXFLAGS -Wall -W -Wredundant-decls -Wpointer-arith -Wcast-qual -Wcast-align -Wformat-security -fno-gnu-keywords -Wundef -Woverloaded-virtual"
305 AM_CXXFLAGS="$AM_CXXFLAGS -Wshadow -Wstrict-overflow=1 -Winit-self -Wmissing-declarations"
307 dnl Automatically add -Werror if maintainer mode is enabled.
308 if test x$USE_MAINTAINER_MODE = xyes; then
309 AM_CXXFLAGS="$AM_CXXFLAGS -Werror"
314 if test no != "$enable_visibility"; then
315 dnl GCC doesn't support symbol visibility on all platforms (e.g. it isn't
317 AC_MSG_CHECKING([if $CXX -fvisibility=hidden works])
318 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
320 AM_CXXFLAGS="$AM_CXXFLAGS -fvisibility=hidden"
321 dash_d_visibility=-DXAPIAN_ENABLE_VISIBILITY
327 dnl Not GCC, nor a compiler masquerading as GCC.
330 dnl +w turns on more warnings.
331 dnl +wlint turns on "lint-like" warnings.
332 dnl +W<n1>,<n2>,... suppresses warnings n1, n2, ...
333 dnl 2340 (remark) "value copied to temporary, reference to temporary
334 dnl use", in: throw Xapian::UnimplementedError("...");
335 dnl 2401 "destructor for base class ... is non-virtual" (we don't need a
336 dnl virtual destructor for intrusive_base, since we never delete
337 dnl its subclasses by a intrusive_base *).
338 dnl 3348 "declaration hides constant ..." which seems to misfire!
339 dnl 4255 (remark) "padding size of struct "..." with ... bytes to
340 dnl alignment boundary".
341 dnl 4273 "floating-point equality and inequality comparisons may be
342 dnl inappropriate due to roundoff common in floating-point computation"
343 dnl No obvious workaround for when you really do want == or !=.
344 dnl 20201 "Memory leak is detected" which triggers for "return new Foo;"!
345 AM_CXXFLAGS="$AM_CXXFLAGS +w +wlint +W2340,2401,3348,4255,4273,20201" ;;
350 [/* Disable stupid MSVC "performance" warning for converting int to bool. */
352 # pragma warning(disable:4800)
355 /* _FORTIFY_SOURCE is only supported by GCC >= 4.1 and glibc >= 2.3.4, but it
356 * shouldn't cause a problem to define it where it's not supported and some
357 * distros may have backported support, so hardcoding version checks is
358 * counter-productive.
360 * Check if _FORTIFY_SOURCE is already defined to allow the user to override
361 * our choice with "./configure CPPFLAGS=-D_FORTIFY_SOURCE=0" or "...=1".
363 #if defined __GNUC__ && !defined _FORTIFY_SOURCE
364 # define _FORTIFY_SOURCE 2
367 /* For GCC >= 3.0 (and Intel's C++ compiler, which also defines __GNUC__),
368 * we can use __builtin_expect to give the compiler hints about branch
369 * prediction. See HACKING for how to use these.
372 /* The arguments of __builtin_expect() are both long, so use !! to ensure that
373 * the first argument is always an integer expression, and always 0 or 1, but
374 * still has the same truth value for the if or while it is used in.
376 # define rare(COND) __builtin_expect(!!(COND), 0)
377 # define usual(COND) __builtin_expect(!!(COND), 1)
379 # define rare(COND) (COND)
380 # define usual(COND) (COND)
384 AC_DEFINE([XAPIAN_LIB_BUILD], [1], [Workaround for avoiding sub-header included error])
386 AC_SUBST([AM_CXXFLAGS])
388 dnl Restore CXXFLAGS to those the user specified or autoconf defaulted to.
389 CXXFLAGS=$save_CXXFLAGS
391 dnl Enable large file support if possible.
394 dnl Required for auto regeneration to work in a combined maintainer-mode tree.
395 : ${AUTOM4TE=autom4te}
398 dnl We want to be able to use GNU make % pattern rules in maintainer targets
399 dnl but automake warns these aren't portable, so we substitute the % to avoid
404 dnl If valgrind is installed and new enough, we use it for leak checking in the
405 dnl testsuite. If VALGRIND is set to an empty value, then skip the check and
406 dnl don't use valgrind.
407 if test -n "${VALGRIND-unset}" ; then
408 AC_PATH_PROG([VALGRIND], [valgrind], [])
409 if test -n "$VALGRIND" ; then
410 dnl Check that the installed valgrind version works, and supports the
411 dnl options we use. This means we won't try to use valgrind < 3.3.0
412 dnl (released 7/12/2007) since before that --log-file didn't expand
413 dnl %p (and appended the process id).
415 dnl No need to check for VALGRIND_COUNT_LEAKS now - that was added before
417 AC_MSG_CHECKING([if valgrind supports --log-file with %p])
418 vglog=config.vglog.%p.tmp
419 vglogwild="config.vglog.*.tmp*"
421 if $VALGRIND --log-file="$vglog" -q true 2>&AS_MESSAGE_LOG_FD ; then
422 for f in $vglogwild ; do
424 $vglog*) VALGRIND= ;;
427 if test x"$VALGRIND" = x ; then
431 AC_CHECK_HEADERS([valgrind/memcheck.h], [], [VALGRIND=], [ ])
434 dnl The valgrind detected doesn't seem to work! Perhaps this is an
435 dnl x86_64 box with a 32 bit valgrind.
436 AC_MSG_RESULT([$VALGRIND doesn't work])
443 if test -n "$VALGRIND" ; then
444 AC_DEFINE([HAVE_VALGRIND], [1], [Define if a suitable valgrind is installed])
449 AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
453 ]])], [win32=no], [win32=yes])
455 case $host_os-$win32 in
457 dnl For mingw and msvc we have an alternative implementation which
458 dnl doesn't need fork() or socketpair().
461 dnl DJGPP has a dummy implementation of fork which always fails.
463 dnl If someone actually wanted remote backend support, then DJGPP has a
464 dnl pthreads port, so using threads like we do on Windows would make more
466 enable_backend_remote=no
469 dnl On Unix, we need fork and socketpair for the remotebackend.
471 AC_CHECK_FUNCS([fork], [], [
472 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.)])
474 dnl Check if -lsocket is required for socketpair (Solaris needs it).
475 dnl And on Haiku it's in -lnetwork.
476 AC_SEARCH_LIBS([socketpair], [socket network], [], [
477 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.)])
479 AC_DEFINE([HAVE_SOCKETPAIR], [1],
480 [Define to 1 if you have the 'socketpair' function.])
488 dnl If eatmydata is installed, we run the testsuite under it to speed it up.
489 dnl If EATMYDATA is set to an empty value, then skip this check and don't use
491 if test -n "${EATMYDATA-unset}" ; then
492 AC_PATH_PROG([EATMYDATA], [eatmydata], [])
495 dnl Used by tests/harness/testsuite.cc
496 AC_CHECK_FUNCS([sigaction])
497 AC_MSG_CHECKING([for sigsetjmp and siglongjmp])
498 AC_TRY_COMPILE([#include <setjmp.h>],
499 [sigjmp_buf jb; if (sigsetjmp(jb, 1)) { siglongjmp(jb, 1); }],
500 AC_DEFINE([HAVE_SIGSETJMP], [1], [Define to 1 if you have the 'sigsetjmp' function])
501 AC_MSG_RESULT([yes]),
504 dnl Used by tests/harness/unixcmd.cc
505 AC_CHECK_FUNCS([nftw])
507 AC_ARG_ENABLE([visibility],
508 [AS_HELP_STRING([--disable-visibility], [disable use of GCC visibility])],
509 [case ${enableval} in
511 *) AC_MSG_ERROR([bad value ${enableval} for --disable-visibility]) ;;
515 if test "`pwd`" != "`cd $srcdir;pwd`" ; then
518 AM_CONDITIONAL([VPATH_BUILD], [test yes = "$vpath_build"])
520 dnl Decide if we should use the zlib-vg.so LD_PRELOAD hack.
522 if test -n "$VALGRIND" ; then
524 linux*) use_zlib_vg=yes ;;
527 AM_CONDITIONAL([USE_ZLIB_VG], [test yes = "$use_zlib_vg"])
529 dnl **************************
530 dnl * Build the output files *
531 dnl **************************
538 AC_CONFIG_FILES([makemanpage], [chmod +x makemanpage])
539 AC_CONFIG_FILES([tests/runtest], [chmod +x tests/runtest])