[chert] Fix potential SEGV with corrupt value stats
[xapian.git] / xapian-letor / configure.ac
blob50c8672e37adc8aacf2a7990918f83934bf63711
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 m4_define([project_version], [1.3.0])
6 AC_INIT([xapian-letor], project_version, [https://xapian.org/bugs])
8 AC_PREREQ([2.64])
9 dnl Extract from the libtool info manual:
10 dnl
11 dnl Here are a set of rules to help you update your library version information:
12 dnl
13 dnl 1. Start with version information of '0:0:0' for each libtool library.
14 dnl
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
18 dnl    faster.
19 dnl
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').
22 dnl
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.
25 dnl
26 dnl 5. If any interfaces have been added since the last public release,
27 dnl    then increment AGE.
28 dnl
29 dnl 6. If any interfaces have been removed since the last public release
30 dnl    then set AGE to 0.
31 dnl
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".
38 dnl incdir=$includedir
39 incdir=$includedir/xapian-1.3
40 AC_SUBST([incdir])
42 AM_INIT_AUTOMAKE([1.10.1 -Wportability tar-ustar])
44 AC_CONFIG_SRCDIR([api/letor.cc])
46 AC_CONFIG_HEADERS([config.h])
48 AC_CONFIG_MACRO_DIR([m4])
50 LT_PREREQ([2.2.8])
51 LT_INIT
53 dnl disable "maintainer only" rules by default
54 AM_MAINTAINER_MODE
56 dnl Checks for programs.
57 AC_PROG_CXX
59 AC_CANONICAL_HOST
61 # Checked: freebsd8.0 openbsd4.6 solaris2.9 solaris2.10
62 case $host_os in
63   linux* | k*bsd*-gnu | freebsd* | openbsd* | solaris*)
64     dnl Vanilla libtool sets this to "unknown" which it then handles as "yes".
65     link_all_deplibs_CXX=no
66     ;;
67 esac
69 case $host_os in
70   linux*)
71     dnl Extract search path from ldconfig which is more reliable than the way
72     dnl vanilla libtool extracts them from ld.so.conf.
73     d=`/sbin/ldconfig -N -X -v 2>&AS_MESSAGE_LOG_FD|$SED 's,^\(/.*\):\( (.*)\)\?$,\1,p;d'|tr '\n' ' '`
74     test -z "$d" || sys_lib_dlsearch_path_spec=$d
75     ;;
76 esac
78 dnl Probe for any options needed to enable C++11 support.
79 AX_CXX_COMPILE_STDCXX_11
81 dnl Run tests using the C++ compiler.
82 AC_LANG_CPLUSPLUS
84 dnl Check for xapian-core.
85 XO_LIB_XAPIAN([], [],
86     [xapian-config]regexp(project_version,
87                           [^\([0-9]*\.[0-9]*[13579]\)\..*$], [-\1]))
89 dnl We want XAPIAN_CXXFLAGS to be used for configure tests.
90 save_CXXFLAGS=$CXXFLAGS
91 CXXFLAGS="$CXXFLAGS $XAPIAN_CXXFLAGS"
92 dnl mingw (for instance) lacks ssize_t
93 AC_TYPE_SSIZE_T
95 AC_TYPE_PID_T
97 AC_TYPE_MODE_T
99 dnl Check for perl (needed to generate some sources and documentation).
100 AC_PATH_PROG([PERL], [perl], [])
101 if test x$USE_MAINTAINER_MODE = xyes; then
102   test -z "$PERL" && AC_MSG_ERROR([perl is required in maintainer mode])
105 AC_ARG_ENABLE([documentation],
106   [AS_HELP_STRING([--enable-documentation], [enable make rules to rebuild documentation [default=maintainer-mode]])],
107   [case ${enableval} in
108     yes|no) ;;
109     *) AC_MSG_ERROR([bad value ${enableval} for --enable-documentation]) ;;
110   esac],
111   [enable_documentation=$USE_MAINTAINER_MODE])
112 AM_CONDITIONAL([DOCUMENTATION_RULES], [test x"$enable_documentation" = xyes])
113 AM_CONDITIONAL([MAINTAINER_NO_DOCS], [test x"$USE_MAINTAINER_MODE$enable_documentation" = xyesno])
115 if test x"$enable_documentation" = xyes ; then
116   dnl Check for help2man. (Needed to make man pages from "--help" output).
117   AC_PATH_PROG([HELP2MAN], [help2man], [])
118   test -z "$HELP2MAN" && AC_MSG_ERROR([help2man is required to build documentation])
120   dnl Check for rst2html. (Needed to make HTML from reStructuredText format)
121   dnl Also look for rst2html.py, which archlinux reportedly installs it as.
122   AC_PATH_PROGS([RST2HTML], [rst2html rst2html.py], [])
123   test -z "$RST2HTML" && AC_MSG_ERROR([rst2html is required to build documentation (try package python-docutils)])
126 dnl Checks for header files.
127 AC_CHECK_HEADERS([fcntl.h limits.h sys/errno.h sys/select.h], [], [], [ ])
129 dnl libsvm is required.
130 AC_CHECK_HEADER([libsvm/svm.h], [], AC_MSG_ERROR([libsvm required but libsvm/svm.h not found]), [ ])
131 save_LIBS=$LIBS
132 LIBS=
133 AC_SEARCH_LIBS([svm_train], [svm], [], AC_MSG_ERROR([libsvm required]))
134 LIBSVM_LIBS=$LIBS
135 LIBS=$save_LIBS
136 AC_SUBST([LIBSVM_LIBS])
138 dnl Check that snprintf actually works as it's meant to.
140 dnl Linux 'man snprintf' warns:
141 dnl  Linux libc4.[45] does not have a snprintf, but provides a libbsd that
142 dnl  contains an snprintf equivalent to sprintf, i.e., one that ignores the
143 dnl  size argument.  Thus, the use of snprintf with early libc4 leads to
144 dnl  serious security problems.
146 dnl It also warns that glibc < 2.0.6 (and presumably other pre-C90
147 dnl implementations) return -1 when truncating so check that we get the
148 dnl ISO C90 semantics for the returned length when truncating.  If we
149 dnl have a working snprintf but with non-ISO return semantics, handle
150 dnl that case separately as it may still be useful in many cases.
152 dnl mingw has _snprintf so check for that too.
153 AC_MSG_CHECKING([for working ISO C90 conforming snprintf])
154 ac_cv_func_snprintf_noniso=no
155 for func in snprintf _snprintf ; do
156   AC_RUN_IFELSE([
157     AC_LANG_PROGRAM(
158       [[
159 #include <cstdio>
160 #include <cstring>
161 using namespace std;
162       ]],
163       dnl Return different exit status for each error so we can see which
164       dnl check failed by consulting config.log.
165       [[
166         char buffer[4] = "abc";
167         int res1 = $func(buffer, 2, "%s", "XYZ");
168         if (memcmp(buffer, "X\0c", 4) != 0) return 2;
169         int res2 = $func(buffer, 2, "%x", 0x12);
170         if (memcmp(buffer, "1\0c", 4) != 0) return 3;
171         if (res1 == -1 && res2 == -1) return 15; /* Pre-ISO semantics. */
172         if (res1 != 3) return 4;
173         if (res2 != 2) return 5;
174       ]]
175     )],
176     [ac_cv_func_snprintf=$func;break],
177     [
178     if test 15no = "$?$ac_cv_func_snprintf_noniso" ; then
179       ac_cv_func_snprintf_noniso=$func
180     fi
181     ac_cv_func_snprintf=no
182     ],
183     [ac_cv_func_snprintf=unknown;break]
184   )
185 done
186 AC_MSG_RESULT([$ac_cv_func_snprintf])
187 case $ac_cv_func_snprintf in
188   no)
189     AC_MSG_CHECKING([for working non-ISO C90 conforming snprintf])
190     AC_MSG_RESULT([$ac_cv_func_snprintf_noniso])
191     if test no != "$ac_cv_func_snprintf_noniso" ; then
192       AC_DEFINE_UNQUOTED([SNPRINTF], [$ac_cv_func_snprintf_noniso],
193         [Define to the name of a function implementing snprintf but not caring about ISO C99 return value semantics (if one exists)])
194     fi
195     ;;
196   unknown)
197     dnl be conservative when crosscompiling
198     ;;
199   *)
200     AC_DEFINE_UNQUOTED([SNPRINTF_ISO], [$ac_cv_func_snprintf],
201        [Define to the name of a function implementing snprintf with ISO C99 semantics (if one exists)])
202     AC_DEFINE_UNQUOTED([SNPRINTF], [$ac_cv_func_snprintf],
203        [Define to the name of a function implementing snprintf but not caring about ISO C99 return value semantics (if one exists)])
204     ;;
205 esac
207 dnl ******************************
208 dnl * Set special compiler flags *
209 dnl ******************************
211 dnl Set flags to control warnings (enable more, or disable annoying ones).
212 dash_d_visibility=
213 if test yes = "$GXX"; then
214   dnl Intel's C++ compiler and clang both lie and define __GNUC__, so check which
215   dnl we actually have, as neither is really 100% compatible.
216   case `echo __INTEL_COMPILER __clang__|$CXX -E - 2>&AS_MESSAGE_LOG_FD|grep -v '^#'` in
217     *__INTEL_COMPILER*__clang__*)
218       dnl GCC (since neither substituted):
219       dnl
220       dnl -Wundef was supported by g++ 3.0.
221       dnl
222       dnl -Wlogical-op and -Wmissing-declarations (for C++) were added in
223       dnl GCC 4.3.
224       dnl
225       dnl All the other options were supported by g++ 2.95.
226       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"
228       dnl The exact format of g++ --version seems to change with almost every
229       dnl minor release so use the preprocessor macros which should be more
230       dnl robust.
231       AC_MSG_CHECKING([for version of $CXX])
232       gxx_version=`echo __GNUC__.__GNUC_MINOR__.__GNUC_PATCHLEVEL__|$CXX -E -|sed '/^#/d;s/ //g'`
233       AC_MSG_RESULT([GCC $gxx_version])
235       case $gxx_version in
236       [[0123]].*|4.[[0123]].*)
237         AC_MSG_ERROR([Xapian requires GCC 4.4 or later])
238         ;;
239       4.[[45]].*) ;;
240       *) dnl GCC >= 4.6
241         dnl -Wdouble-promotion was added in GCC 4.6.
242         dnl
243         dnl -Winit-self was added in GCC 3.4, but for GCC < 4.7 g++ always
244         dnl warns for this case with -Wuninitialized (implied by -W).  We
245         dnl don't intend to use this idiom, so any instances are bugs we'd
246         dnl like to know about.
247         AM_CXXFLAGS="$AM_CXXFLAGS -Wdouble-promotion -Winit-self" ;;
248       esac
250       dnl FIXME:
251       dnl -Wconversion in older GCC versions is intended to help migration
252       dnl from K&R to ISO C, and isn't useful for us.  In 4.3 it was renamed
253       dnl to -Wtraditional-conversion and a new -Wconversion added which
254       dnl sounds useful but is a bit buggy currently.  So we should consider
255       dnl enabling -Wconversion once it is stabilised (GCC 4.4 or ...)
256       dnl
257       dnl -Wold-style-cast is interesting, but triggers for macros from
258       dnl system headers (e.g. FD_SET) (tested with GCC 4.4).
260       dnl Automatically add -Werror if maintainer mode is enabled.
261       if test x$USE_MAINTAINER_MODE = xyes; then
262         AM_CXXFLAGS="$AM_CXXFLAGS -Werror"
263       fi
264       ;;
265     *__clang__*)
266       dnl Intel's compiler (since __clang__ not substituted):
267       dnl
268       dnl -w1 stops the avalanche of uninteresting "remark" messages.
269       dnl -wd... disables warnings which don't have good code workarounds.
270       AM_CXXFLAGS="$AM_CXXFLAGS -Wall -w1 -wd177,1572"
272       dnl Automatically add -Werror if maintainer mode is enabled.
273       if test x$USE_MAINTAINER_MODE = xyes; then
274         AM_CXXFLAGS="$AM_CXXFLAGS -Werror"
275       fi
276       ;;
277     *__INTEL_COMPILER*)
278       dnl clang (since __INTEL_COMPILER not substituted):
279       AM_CXXFLAGS="$AM_CXXFLAGS -Wall -W -Wredundant-decls -Wpointer-arith -Wcast-qual -Wcast-align -Wformat-security -fno-gnu-keywords -Wundef -Woverloaded-virtual"
280       AM_CXXFLAGS="$AM_CXXFLAGS -Wshadow -Wstrict-overflow=1 -Winit-self -Wmissing-declarations"
282       dnl Automatically add -Werror if maintainer mode is enabled.
283       if test x$USE_MAINTAINER_MODE = xyes; then
284         AM_CXXFLAGS="$AM_CXXFLAGS -Werror"
285       fi
286       ;;
287   esac
289   if test no != "$enable_visibility"; then
290     dnl GCC doesn't support symbol visibility on all platforms (e.g. it isn't
291     dnl on mingw).
292     AC_MSG_CHECKING([if $CXX -fvisibility=hidden works])
293     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
294       AC_MSG_RESULT([yes])
295       AM_CXXFLAGS="$AM_CXXFLAGS -fvisibility=hidden"
296       dash_d_visibility=-DXAPIAN_ENABLE_VISIBILITY
297     else
298       AC_MSG_RESULT([no])
299     fi
300   fi
301 else
302   dnl Not GCC, nor a compiler masquerading as GCC.
303   case /$CXX in
304   */aCC)
305     dnl +w turns on more warnings.
306     dnl +wlint turns on "lint-like" warnings.
307     dnl +W<n1>,<n2>,... suppresses warnings n1, n2, ...
308     dnl 2340 (remark) "value copied to temporary, reference to temporary
309     dnl use", in: throw Xapian::UnimplementedError("...");
310     dnl 2401 "destructor for base class ... is non-virtual" (we don't need a
311     dnl virtual destructor for intrusive_base, since we never delete
312     dnl       its subclasses by a intrusive_base *).
313     dnl 3348 "declaration hides constant ..." which seems to misfire!
314     dnl 4255 (remark) "padding size of struct "..." with ... bytes to
315     dnl alignment boundary".
316     dnl 4273 "floating-point equality and inequality comparisons may be
317     dnl inappropriate due to roundoff common in floating-point computation"
318     dnl No obvious workaround for when you really do want == or !=.
319     dnl 4285 "operator= does not have a check for the source and destination
320     dnl addresses being non-identical" - fires for AutoPtr which
321     dnl includes such a check indirectly (internaltest's autoptr1 check this).
322     dnl 20201 "Memory leak is detected" which triggers for "return new Foo;"!
323     AM_CXXFLAGS="$AM_CXXFLAGS +w +wlint +W2340,2401,3348,4255,4273,4285,20201" ;;
324   esac
327 AH_BOTTOM(
328 [/* Disable stupid MSVC "performance" warning for converting int to bool. */
329 #ifdef _MSC_VER
330 # pragma warning(disable:4800)
331 #endif
333 /* _FORTIFY_SOURCE is only supported by GCC >= 4.1 and glibc >= 2.3.4, but it
334  * shouldn't cause a problem to define it where it's not supported and some
335  * distros may have backported support, so hardcoding version checks is
336  * counter-productive.
338  * Check if _FORTIFY_SOURCE is already defined to allow the user to override
339  * our choice with "./configure CPPFLAGS=-D_FORTIFY_SOURCE=0" or "...=1".
340  */
341 #if defined __GNUC__ && !defined _FORTIFY_SOURCE
342 # define _FORTIFY_SOURCE 2
343 #endif
345 /* For GCC >= 3.0 (and Intel's C++ compiler, which also defines __GNUC__),
346  * we can use __builtin_expect to give the compiler hints about branch
347  * prediction.  See HACKING for how to use these.
348  */
349 #if defined __GNUC__
350 /* The arguments of __builtin_expect() are both long, so use !! to ensure that
351  * the first argument is always an integer expression, and always 0 or 1, but
352  * still has the same truth value for the if or while it is used in.
353  */
354 # define rare(COND) __builtin_expect(!!(COND), 0)
355 # define usual(COND) __builtin_expect(!!(COND), 1)
356 #else
357 # define rare(COND) (COND)
358 # define usual(COND) (COND)
359 #endif
362 AC_SUBST([AM_CXXFLAGS])
364 dnl Restore CXXFLAGS to those the user specified or autoconf defaulted to.
365 CXXFLAGS=$save_CXXFLAGS
367 dnl Enable large file support if possible.
368 AC_SYS_LARGEFILE
370 dnl Required for auto regeneration to work in a combined maintainer-mode tree.
371 : ${AUTOM4TE=autom4te}
372 AC_SUBST([AUTOM4TE])
374 dnl We want to be able to use GNU make % pattern rules in maintainer targets
375 dnl but automake warns these aren't portable, so we substitute the % to avoid
376 dnl this warning.
377 PERCENT='%'
378 AC_SUBST([PERCENT])
380 dnl **************************
381 dnl * Build the output files *
382 dnl **************************
384 AC_CONFIG_FILES([
385  Makefile
386  docs/Makefile
387  ])
388 AC_CONFIG_FILES([makemanpage], [chmod +x makemanpage])
389 AC_OUTPUT