[scriptindex] Add new "split" action
[xapian.git] / xapian-bindings / configure.ac
blob1ef4ed6638ad1980a9312364ce1a02b9e70e03aa
1 dnl Process this file with autoconf to produce a configure script.
3 dnl See xapian-core's HACKING document for details of the reasons for required
4 dnl versions.
5 AC_PREREQ([2.63])
7 m4_define([project_version], [1.4.7])
8 AC_INIT([xapian-bindings], project_version, [https://xapian.org/bugs])
10 dnl See xapian-core's HACKING document for details of the reasons for required
11 dnl versions.
12 AM_INIT_AUTOMAKE([1.12.2 parallel-tests -Wportability subdir-objects tar-ustar no-dist-gzip dist-xz])
13 AC_CONFIG_SRCDIR([xapian-headers.i])
15 AC_CONFIG_HEADERS([config.h])
17 AC_CONFIG_MACRO_DIR([m4])
19 dnl Mac OS X needs MACOSX_DEPLOYMENT_TARGET set to 10.3 (or higher) to
20 dnl successfully link the SWIG generated modules.  The link always fails on
21 dnl earlier versions of Mac OS X (10.1.4 and 10.2.8 tested), and these versions
22 dnl are long obsolete now, so we just ensure that MACOSX_DEPLOYMENT_TARGET is
23 dnl set to at least 10.3.
24 dnl
25 dnl NB we must do this *BEFORE* LT_INIT since that is what checks
26 dnl MACOSX_DEPLOYMENT_TARGET.
27 AC_CANONICAL_HOST
28 OVERRIDE_MACOSX_DEPLOYMENT_TARGET=
29 case $host in
30 *86*-darwin8*|*-darwin[[91]]*)
31   dnl On 10.5 or later, and 10.4 on x86, the deployment target defaults to the
32   dnl OS version, so we don't need to override on these.
33   ;;
34 *-darwin*)
35   case $MACOSX_DEPLOYMENT_TARGET in
36   "")
37     OVERRIDE_MACOSX_DEPLOYMENT_TARGET=10.3 ;;
38   10.[[012]])
39     AC_MSG_WARN([Overriding MACOSX_DEPLOYMENT_TARGET from $MACOSX_DEPLOYMENT_TARGET to 10.3])
40     OVERRIDE_MACOSX_DEPLOYMENT_TARGET=10.3 ;;
41   esac
42   ;;
43 esac
44 AM_CONDITIONAL(OVERRIDE_MACOSX_DEPLOYMENT_TARGET, test -n "$OVERRIDE_MACOSX_DEPLOYMENT_TARGET")
45 AC_SUBST(OVERRIDE_MACOSX_DEPLOYMENT_TARGET)
46 if test -n "$OVERRIDE_MACOSX_DEPLOYMENT_TARGET" ; then
47   MACOSX_DEPLOYMENT_TARGET=$OVERRIDE_MACOSX_DEPLOYMENT_TARGET
50 dnl Use libtool to manage our libraries, but don't build static libraries as
51 dnl the bindings only have a use for dynamic ones.
52 LT_PREREQ([2.2.6])
53 LT_INIT([disable-static])
55 dnl -no-undefined causes problems on Mac OS X with at least some
56 dnl MACOSX_DEPLOYMENT_TARGET settings, so only pass -no-undefined on
57 dnl platforms where it is required in order to link a shared library at
58 dnl all (Windows is the main one).
59 NO_UNDEFINED=
60 if test unsupported = "$allow_undefined_flag" ; then
61   NO_UNDEFINED=-no-undefined
63 AC_SUBST(NO_UNDEFINED)
65 dnl Checks for programs.
66 AC_PROG_CXX
68 # Checked: freebsd8.0 openbsd4.6 solaris2.9 solaris2.10
69 case $host_os in
70   linux* | k*bsd*-gnu | freebsd* | openbsd* | solaris*)
71     dnl Vanilla libtool sets this to "unknown" which it then handles as "yes".
72     link_all_deplibs_CXX=no
73     ;;
74 esac
76 case $host_os in
77   linux*)
78     dnl Extract search path from ldconfig which is more reliable than the way
79     dnl vanilla libtool extracts them from ld.so.conf.
80     d=`/sbin/ldconfig -N -X -v 2>&AS_MESSAGE_LOG_FD|$SED 's,^\(/.*\):\( (.*)\)\?$,\1,p;d'|tr '\n' ' '`
81     test -z "$d" || sys_lib_dlsearch_path_spec=$d
82     ;;
83 esac
85 dnl Run tests using the C++ compiler.
86 AC_LANG_CPLUSPLUS
88 dnl Probe for any options needed to enable C++11 support.
89 AX_CXX_COMPILE_STDCXX_11
91 dnl Check for xapian-core.
92 XO_LIB_XAPIAN([], [],
93     [xapian-config]regexp(project_version,
94                           [^\([0-9]*\.[0-9]*[13579]\)\..*$], [-\1]))
95 XO_REQUIRE([1.4.0])
97 NEED_JNILIB_EXT=no
98 NEED_INTREE_DYLD=no
99 INTREE_DYLD_PATH=
100 case $host_os in
101 darwin*)
102   NEED_JNILIB_EXT=yes
103   dnl If we're building against an uninstalled xapian-core, xapian-config
104   dnl --libs will give an error.
105   if $XAPIAN_CONFIG --libs >/dev/null 2>/dev/null ; then
106     :
107   else
108     NEED_INTREE_DYLD=yes
109     dnl $XAPIAN_LIBS may have some options first, so grab the last argument,
110     dnl which should be the .la file.
111     set x $XAPIAN_LIBS
112     as_fn_arith $# - 1
113     shift $as_val
114     INTREE_DYLD_PATH=$1
115     dnl Make sure the path is absolute.
116     case $INTREE_DYLD_PATH in
117       /*) ;;
118       *) INTREE_DYLD_PATH=`pwd`/$INTREE_DYLD_PATH ;;
119     esac
120     dnl Add .libs or equivalent.
121     INTREE_DYLD_PATH=`echo "$INTREE_DYLD_PATH"|sed 's,\(.*/\).*,\1,'`$lt_cv_objdir
122     AC_SUBST([INTREE_DYLD_PATH])
123   fi
124   ;;
125 esac
126 AM_CONDITIONAL(NEED_JNILIB_EXT, test yes = "$NEED_JNILIB_EXT")
127 AM_CONDITIONAL(NEED_INTREE_DYLD, test yes = "$NEED_INTREE_DYLD")
129 dnl We want XAPIAN_CXXFLAGS to be used for configure tests, so add it to
130 dnl CXXFLAGS for the duration of configure.
131 save_CXXFLAGS=$CXXFLAGS
132 CXXFLAGS="$CXXFLAGS $XAPIAN_CXXFLAGS"
134 dnl COMPAT_VERSION is the version of xapian-core that "matches" our version.
135 dnl We allow for bindings being version 0.8.5.1 while xapian-core is 0.8.5.
136 dnl COMPAT_VERSION also ignores any _git123 suffix which snapshots will have.
137 COMPAT_VERSION=[`echo "$PACKAGE_VERSION"|sed 's/^\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/'`]
138 AC_SUBST(COMPAT_VERSION)
140 dnl VERSION_NO_SNAPSHOT simply has any _git123 suffix removed.
141 VERSION_NO_SNAPSHOT=[`echo "$PACKAGE_VERSION"|sed 's/_.*$//'`]
142 AC_SUBST(VERSION_NO_SNAPSHOT)
144 dnl We only need to set docdir for compatibility with autoconf < 2.60 - this
145 dnl code can be removed once we move to requiring autoconf 2.60 or newer.
146 test -n "$docdir" || docdir='${datadir}/doc/${PACKAGE_TARNAME}'
147 AC_SUBST(docdir)
149 AC_ARG_ENABLE(visibility,
150   [AS_HELP_STRING([--disable-visibility], [disable use of GCC visibility])],
151   [case ${enableval} in
152     yes|no) ;;
153     *) AC_MSG_ERROR([bad value ${enableval} for --disable-visibility]) ;;
154   esac])
156 dnl Only probe for SWIG and enable SWIG rules in makefiles if
157 dnl configure --enable-maintainer-mode is used.
158 AM_MAINTAINER_MODE
160 AC_ARG_ENABLE(documentation,
161   [AS_HELP_STRING([--enable-documentation], [enable make rules to rebuild shipped documentation [default=maintainer-mode]])],
162   [case ${enableval} in
163     yes|no) ;;
164     *) AC_MSG_ERROR([bad value ${enableval} for --enable-documentation]) ;;
165   esac])
166 test -z "$enable_documentation" && enable_documentation=$USE_MAINTAINER_MODE
167 AM_CONDITIONAL(DOCUMENTATION_RULES, test x"$enable_documentation" = xyes)
168 AM_CONDITIONAL(MAINTAINER_NO_DOCS, test x"$USE_MAINTAINER_MODE$enable_documentation" = xyesno)
170 if test yes = "$enable_documentation" ; then
171   dnl Check for rst2html. (Needed to make HTML from reStructuredText format)
172   dnl Also look for rst2html.py, which archlinux reportedly installs it as.
173   AC_PATH_PROGS(RST2HTML, [rst2html rst2html.py], [])
174   test -z "$RST2HTML" && AC_MSG_ERROR([rst2html is required to build documentation (try package python-docutils)])
177 if test x$USE_MAINTAINER_MODE = xyes; then
178   dnl Check for swig - this does most of the work for the bindings.
179   dnl AC_PATH_PROGS only honours an already set SWIG if it's a full
180   dnl path.  Listing it in the "to be searched" list like this allows
181   dnl ./configure SWIG=myswig to work.
182   swigoverridden=${SWIG+yes}
183   AC_PATH_PROGS(SWIG, ["${SWIG-swig}"], [])
184   AC_ARG_VAR(SWIG, [SWIG interface generator (only needed by Xapian developers)])
185   if test -z "$SWIG" ; then
186     AC_MSG_ERROR([Can't find SWIG utility])
187   fi
188   dnl Check for new enough SWIG.
189   dnl
190   dnl 3.0.6 fixes compiling the Perl bindings under C++11 ("seed" macro issue).
191   dnl 3.0.8 fixes conversion of integers large than an int in Python 3.
192   dnl 3.0.9 fixes generation of unnecessary _swigconstant helpers for Python.
193   dnl 3.0.12 fixes segfault on unload with PHP 7.1
194   v=`$SWIG -version 2>&1|sed 's/^SWIG Version \([[0-9\.]]*\).*/\1/p;d'`
195   case $v in
196     [[012].*|3.0.?|3.0.1[01]|""])
197       msg="SWIG >= 3.0.12 required (you have ${v:-an unknown version})"
198       if test -n "$swigoverridden" ; then
199         dnl If SWIG was explicitly set, make this a warning only.
200         AC_MSG_WARN([$msg])
201       else
202         AC_MSG_ERROR([$msg])
203       fi ;;
204   esac
205   SWIG_FLAGS=`$XAPIAN_CONFIG --swigflags`
206   AC_SUBST(SWIG_FLAGS)
207   XAPIAN_HEADER_DIRS=
208   XAPIAN_HEADERS=
209   for a in $SWIG_FLAGS ; do
210     case $a in
211     -I*)
212       d=`echo "x$a"|sed 's/^x-I//'`
213       dnl Quote each entry in XAPIAN_HEADER_DIRS with "".
214       XAPIAN_HEADER_DIRS=$XAPIAN_HEADER_DIRS' "'$d'"'
215       for f in "$d/"*.h "$d/xapian/*.h" ; do
216         if test -f "$f" ; then
217           XAPIAN_HEADERS="$XAPIAN_HEADERS $f"
218         fi
219       done
220       ;;
221     esac
222   done
223   AC_SUBST([XAPIAN_HEADER_DIRS])
224   AC_SUBST([XAPIAN_HEADERS])
226   dnl Need perl in maintainer mode to generate the except.i file for python.
227   AC_PATH_PROGS(PERL, ["${PERL-perl}"], [])
228   test -z "$PERL" && AC_MSG_ERROR([perl is required in maintainer mode])
229   dnl Need doxygen in maintainer mode to convert C++ doxygen comments to Python
230   dnl docstrings.
231   AC_PATH_PROG(DOXYGEN, doxygen, [])
232   test -z "$DOXYGEN" && AC_MSG_ERROR([doxygen is required to build documentation])
235 AC_ARG_WITH(python,
236   AC_HELP_STRING([--with-python], [enable Python 2 bindings]),
237   [],
238   [with_python=])
240 AC_ARG_WITH(python3,
241   AC_HELP_STRING([--with-python3], [enable Python 3 bindings]),
242   [],
243   [with_python3=])
245 AC_ARG_WITH(php,
246   AC_HELP_STRING([--with-php], [enable PHP 5 bindings]),
247   [],
248   [with_php=])
250 AC_ARG_WITH(php7,
251   AC_HELP_STRING([--with-php7], [enable PHP 7 bindings]),
252   [],
253   [with_php7=])
255 AC_ARG_WITH(ruby,
256   AC_HELP_STRING([--with-ruby], [enable Ruby bindings]),
257   [],
258   [with_ruby=])
260 AC_ARG_WITH(tcl,
261   AC_HELP_STRING([--with-tcl], [enable Tcl bindings]),
262   [],
263   [with_tcl=])
265 AC_ARG_WITH(csharp,
266   AC_HELP_STRING([--with-csharp], [enable CSharp bindings]),
267   [],
268   [with_csharp=])
270 AC_ARG_WITH(java,
271   AC_HELP_STRING([--with-java], [enable Java bindings]),
272   [],
273   [with_java=])
275 AC_ARG_WITH(perl,
276   AC_HELP_STRING([--with-perl], [enable Perl bindings]),
277   [],
278   [with_perl=])
280 AC_ARG_WITH(lua,
281   AC_HELP_STRING([--with-lua], [enable Lua bindings]),
282   [],
283   [with_lua=])
285 case $with_python$with_python3$with_php$with_php7$with_ruby$with_tcl$with_csharp$with_java$with_perl$with_lua in
286 *yes*)
287   dnl Default unspecified values to no.
288   test -z "$with_python" && with_python=no
289   test -z "$with_python3" && with_python3=no
290   test -z "$with_php" && with_php=no
291   test -z "$with_php7" && with_php7=no
292   test -z "$with_tcl" && with_tcl=no
293   test -z "$with_csharp" && with_csharp=no
294   test -z "$with_java" && with_java=no
295   test -z "$with_ruby" && with_ruby=no
296   test -z "$with_perl" && with_perl=no
297   test -z "$with_lua" && with_lua=no
298   ;;
299 esac
301 BINDINGS=
303 if test no != "$with_python" ; then
304   dnl For backward compatibility:
305   : ${PYTHON2="$PYTHON"}
306   : ${PYTHON2_INC="$PYTHON_INC"}
307   : ${PYTHON2_LIB="$PYTHON_LIB"}
308   : ${PYTHON2_LIBS="$PYTHON_LIBS"}
309   : ${PYTHON2_SO="$PYTHON_SO"}
310   dnl See comment for AC_PATH_PROGS(SWIG, ...).
311   if test -n "$PYTHON2" ; then
312     AC_PATH_PROGS(PYTHON2, ["$PYTHON2"], [])
313   else
314     AC_PATH_PROGS(PYTHON2, [python2 python], [])
315   fi
316   AC_ARG_VAR(PYTHON2, [Python 2 interpreter])
317   if test -n "$PYTHON2" ; then
318     dnl Require Python 2.6 or newer.  Older versions are essentially
319     dnl unsupported upstream.
320     AC_MSG_CHECKING([$PYTHON2 version])
321     version=`$PYTHON2 -c 'import sys;print("%d.%d" % sys.version_info[[:2]])' 2>/dev/null`
322     case $version in
323     [2.[6-9]*|2.[1-5][0-9]*])
324       AC_MSG_RESULT([$version])
325       ;;
326     [[3-9].*])
327       AC_MSG_RESULT([$version (too new - use --with-python3 for Python 3 support)])
328       if test yes = "$with_python" ; then
329         AC_MSG_ERROR([Use --with-python3 for Python 3 support ($PYTHON2 is $version)])
330       fi
331       PYTHON2=
332       ;;
333     *)
334       AC_MSG_RESULT([$version (too old)])
335       if test yes = "$with_python" ; then
336         AC_MSG_ERROR([Only Python 2.6 or newer is supported ($PYTHON2 is $version)])
337       fi
338       PYTHON2=
339       ;;
340     esac
341     if test -n "$PYTHON2" ; then
342       if $PYTHON2 -c 'import distutils.sysconfig' 2>/dev/null ; then
343         PYTHON2_INC=`$PYTHON2 -c 'import os,distutils.sysconfig;print(distutils.sysconfig.get_python_inc().replace(os.sep,"/"))'`
344         AC_SUBST(PYTHON2_INC)
345       else
346         if test yes = "$with_python" ; then
347           AC_MSG_ERROR([Couldn't import Python module distutils.sysconfig - you probably need to install a python-dev or python-devel package])
348         else
349           AC_MSG_WARN([Couldn't import Python module distutils.sysconfig - you probably don't have a python-dev or python-devel package installed])
350           PYTHON2=
351         fi
352       fi
353     fi
354     AC_MSG_CHECKING([for python2 sphinx module])
355     if $PYTHON2 -c 'import sphinx;print(repr(sphinx.main))' >&5 2>&5 ; then
356       AC_MSG_RESULT([yes])
357     else
358       AC_MSG_RESULT([no])
359       if test yes = "$with_python" ; then
360         AC_MSG_ERROR([Couldn't import sphinx module and call sphinx.main() for Python2 - try package python-sphinx])
361       fi
362       PYTHON2=
363     fi
364     if test -n "$PYTHON2" ; then
365       dnl Check that Python.h is there, which is a good way to check that
366       dnl the appropriate python-dev package has been installed.
367       AC_MSG_CHECKING([for $PYTHON2_INC/Python.h])
368       if test -f "$PYTHON2_INC/Python.h" ; then
369         AC_MSG_RESULT(yes)
370         AC_MSG_CHECKING([for directory to install python2 bindings in])
371         if test -z "$PYTHON2_LIB" ; then
372           PYTHON2_LIB=`$PYTHON2 -c 'import os,distutils.sysconfig;print(distutils.sysconfig.get_python_lib(1).replace(os.sep,"/"))'`
373         fi
374         AC_MSG_RESULT([$PYTHON2_LIB])
375         AC_ARG_VAR(PYTHON2_LIB, [Directory to install python2 bindings in])
377         AC_MSG_CHECKING([for python2 libraries to link against])
378         case $host_os in
379         mingw* | pw32*)
380           PYTHON2_LIBS=`$PYTHON2 -c 'import os,sys;print("-L"+os.path.join(sys.prefix,"libs").replace(os.sep,"/")+" -lpython"+sys.version[[:3]].replace(".",""))'` ;;
381         cygwin*)
382           PYTHON2_LIBS=`$PYTHON2 -c 'import os,sys;print("-L"+os.path.join(sys.path[[3]],"config")+" -lpython"+sys.version[[:3]])'` ;;
383         *)
384           PYTHON2_LIBS= ;;
385         esac
386         AC_SUBST(PYTHON2_LIBS)
387         AC_MSG_RESULT([$PYTHON2_LIBS])
389         AC_MSG_CHECKING([for python2 module extension])
390         dnl Usually ".so", but for example, Mac OS X uses ".dylib".
391         PYTHON2_SO=`$PYTHON2 -c 'import distutils.sysconfig;print(distutils.sysconfig.get_config_vars("SO")[[0]])'`
392         AC_SUBST(PYTHON2_SO)
393         AC_MSG_RESULT([$PYTHON2_SO])
394         BINDINGS="$BINDINGS python"
395       else
396         AC_MSG_RESULT([no (install python-dev or python-devel package or similar)])
397         if test yes = "$with_python" ; then
398           AC_MSG_ERROR([Python.h not found])
399         fi
400       fi
401     fi
402   fi
405 if test no != "$with_python3" ; then
406   dnl See comment for AC_PATH_PROGS(SWIG, ...).
407   if test -n "$PYTHON3" ; then
408     AC_PATH_PROGS(PYTHON3, ["$PYTHON3"], [])
409   else
410     AC_PATH_PROGS(PYTHON3, [python3 python], [])
411   fi
412   AC_ARG_VAR(PYTHON3, [Python 3 interpreter])
413   if test -n "$PYTHON3" ; then
414     dnl Require Python 3.2 or newer, as that's the oldest version we can
415     dnl easily test with.  If anyone's keen to support older versions, please
416     dnl test and send in any patches needed to get it to work.
417     AC_MSG_CHECKING([$PYTHON3 version])
418     version=`$PYTHON3 -c 'import sys;print("%d.%d" % sys.version_info[[:2]])' 2>/dev/null`
419     case $version in
420     [3.[2-9]*|3.1[0-9]*|[4-9].*])
421       AC_MSG_RESULT([$version])
422       ;;
423     *)
424       AC_MSG_RESULT([$version (too old)])
425       if test yes = "$with_python3" ; then
426         AC_MSG_ERROR([Only Python 3.2 or newer is supported ($python3 is $version)])
427       fi
428       PYTHON3=
429       ;;
430     esac
431     if test -n "$PYTHON3" ; then
432       if $PYTHON3 -c 'import distutils.sysconfig' 2>/dev/null ; then
433         PYTHON3_INC=`$PYTHON3 -c 'import os,distutils.sysconfig;print(distutils.sysconfig.get_python_inc().replace(os.sep,"/"))'`
434         AC_SUBST(PYTHON3_INC)
435       else
436         if test yes = "$with_python3" ; then
437           AC_MSG_ERROR([Couldn't import Python module distutils.sysconfig - you probably need to install a python3-dev or python3-devel package])
438         else
439           AC_MSG_WARN([Couldn't import Python module distutils.sysconfig - you probably don't have a python3-dev or python3-devel package installed])
440           PYTHON3=
441         fi
442       fi
443     fi
444     AC_MSG_CHECKING([for python3 sphinx module])
445     if $PYTHON3 -c 'import sphinx;print(repr(sphinx.main))' >&5 2>&5 ; then
446       AC_MSG_RESULT([yes])
447     else
448       AC_MSG_RESULT([no])
449       if test yes = "$with_python3" ; then
450         AC_MSG_ERROR([Couldn't import sphinx module and call sphinx.main() for Python3 - try package python3-sphinx])
451       fi
452       PYTHON3=
453     fi
454     if test -n "$PYTHON3" ; then
455       dnl Check that Python.h is there, which is a good way to check that
456       dnl the appropriate python3-dev package has been installed.
457       AC_MSG_CHECKING([for $PYTHON3_INC/Python.h])
458       if test -f "$PYTHON3_INC/Python.h" ; then
459         AC_MSG_RESULT(yes)
460         AC_MSG_CHECKING([for directory to install python3 bindings in])
461         if test -z "$PYTHON3_LIB" ; then
462           PYTHON3_LIB=`$PYTHON3 -c 'import os,distutils.sysconfig;print(distutils.sysconfig.get_python_lib(1).replace(os.sep,"/"))'`
463         fi
464         AC_MSG_RESULT([$PYTHON3_LIB])
465         AC_ARG_VAR(PYTHON3_LIB, [Directory to install python3 bindings in])
467         AC_MSG_CHECKING([for python3 libraries to link against])
468         case $host_os in
469         mingw* | pw32*)
470           PYTHON3_LIBS=`$PYTHON3 -c 'import os,sys;print("-L"+os.path.join(sys.prefix,"libs").replace(os.sep,"/")+" -lpython"+sys.version[[:3]].replace(".",""))'` ;;
471         cygwin*)
472           PYTHON3_LIBS=`$PYTHON3 -c 'import os,sys;print("-L"+os.path.join(sys.path[[3]],"config")+" -lpython"+sys.version[[:3]])'` ;;
473         *)
474           PYTHON3_LIBS= ;;
475         esac
476         AC_SUBST(PYTHON3_LIBS)
477         AC_MSG_RESULT([$PYTHON3_LIBS])
479         AC_MSG_CHECKING([for python3 module extension])
480         dnl Usually ".so", but for example, Mac OS X uses ".dylib".
481         PYTHON3_SO=`$PYTHON3 -c 'import distutils.sysconfig;print(distutils.sysconfig.get_config_vars("SO")[[0]])'`
482         AC_SUBST(PYTHON3_SO)
483         AC_MSG_RESULT([$PYTHON3_SO])
485         AC_MSG_CHECKING([for tag for cached compiled scripts])
486         PYTHON3_CACHE_TAG=`$PYTHON3 -c 'import imp;print(imp.get_tag())'`
487         AC_SUBST(PYTHON3_CACHE_TAG)
488         AC_MSG_RESULT([$PYTHON3_CACHE_TAG])
490         AC_MSG_CHECKING([for extension of cached and optimized python3 bytecode])
491         PYTHON3_CACHE_OPT1_EXT=`$PYTHON3 -c 'import imp,sys;print("%s.pyo"%imp.get_tag()) if sys.version_info.minor<5 else print("{1}{2}".format(*imp.util.cache_from_source("",optimization=1).rpartition(imp.get_tag())))'`
492         AC_SUBST(PYTHON3_CACHE_OPT1_EXT)
493         AC_MSG_RESULT([$PYTHON3_CACHE_OPT1_EXT])
495         BINDINGS="$BINDINGS python3"
496       else
497         AC_MSG_RESULT([no (install python3-dev or python3-devel package or similar)])
498         if test yes = "$with_python3" ; then
499           AC_MSG_ERROR([Python.h not found])
500         fi
501       fi
502     fi
503   fi
506 if test x$USE_MAINTAINER_MODE = xyes; then
507   dnl Need python in maintainer mode to run doxy2swig.py.
508   dnl Either Python 2 or 3 is OK for this.
509   if test -n "$PYTHON2" ; then
510     PYTHON=$PYTHON2
511   elif test -n "$PYTHON3" ; then
512     PYTHON=$PYTHON3
513   else
514     AC_PATH_PROGS(PYTHON, [python2 python python3], [])
515   fi
516   test -z "$PYTHON" && AC_MSG_ERROR([python is required in maintainer mode])
519 if test no != "$with_php" ; then
520   dnl See comment for AC_PATH_PROGS(SWIG, ...).
521   if test -n "$PHP_CONFIG" ; then
522     AC_PATH_PROGS(PHP_CONFIG, ["$PHP_CONFIG"], [])
523   fi
524   if test -z "$PHP_CONFIG" ; then
525     AC_PATH_PROGS(PHP_CONFIG, [php-config5 php-config], [])
526   fi
527   AC_ARG_VAR(PHP_CONFIG, [php-config utility for PHP5])
528   AC_ARG_VAR(PHP, [PHP5 interpreter (optional - only needed to run PHP5 testsuite with)])
529   if test -n "$PHP_CONFIG" ; then
530     AC_MSG_CHECKING([$PHP_CONFIG version])
531     version=`$PHP_CONFIG --version 2>/dev/null`
532     case $version in
533     [[01234].*|5.[01234].*|[6789].*])
534       AC_MSG_RESULT([$version (not supported, PHP5 bindings need PHP 5.x where x >= 5)])
535       if test yes = "$with_php" ; then
536         AC_MSG_ERROR([$PHP_CONFIG reports version $version - PHP5 bindings need PHP 5.x where x >= 5])
537       fi
538       with_php=no
539       ;;
540     *)
541       AC_MSG_RESULT([$version])
542       PHP_MAJOR_VERSION=`echo "$version"|cut -d. -f1`
543       ;;
544     esac
545     AC_SUBST(PHP_MAJOR_VERSION)
547     if test no != "$with_php" ; then
548       AC_MSG_CHECKING([for PHP5 extension directory])
549       if test -z "$PHP_EXTENSION_DIR" ; then
550         PHP_EXTENSION_DIR=`$PHP_CONFIG --extension-dir`
551       fi
552       AC_MSG_RESULT([$PHP_EXTENSION_DIR])
553       AC_ARG_VAR(PHP_EXTENSION_DIR, [Directory to install PHP5 extensions in])
554     fi
556     if test no != "$with_php" ; then
557       PHP_INC=`$PHP_CONFIG --includes`
558       AC_SUBST(PHP_INC)
559       save_CPPFLAGS=$CPPFLAGS
560       CPPFLAGS="$CPPFLAGS $PHP_INC"
561       dnl One of SGI's SuSE boxes has php-config but no headers.
562       AC_CHECK_HEADER(zend.h, [], [
563         if test yes = "$with_php" ; then
564           AC_MSG_ERROR(['$PHP_CONFIG --includes' reports '$PHP_INC' but zend.h can't be included from there])
565         fi
566         with_php=no], [ ])
567       CPPFLAGS=$save_CPPFLAGS
568     fi
570     if test no != "$with_php" ; then
571       if test x"$PHP" = x ; then
572         AC_MSG_CHECKING([for PHP5 interpreter])
573         dnl PHP5's php-config supports --php-binary, so just use that.
574         PHP=`$PHP_CONFIG --php-binary 2>/dev/null`
575         if test x"$PHP" != x ; then
576           if $PHP -r 'exit(0);' 2> /dev/null ; then
577             if $PHP -r 'exit(PHP_MAJOR_VERSION==5?0:1);' 2> /dev/null ; then
578               AC_MSG_RESULT([$PHP])
579             else
580               dnl We get /usr/bin/php on Debian, which might be PHP7:
581               dnl https://bugs.debian.org/819139
582               if ${PHP}5 -r 'exit(PHP_MAJOR_VERSION==5?0:1);' 2> /dev/null ; then
583                 PHP=${PHP}5
584                 AC_MSG_RESULT([$PHP])
585               else
586                 AC_MSG_RESULT([no ($PHP isn't PHP5)])
587                 PHP=
588               fi
589             fi
590           else
591             AC_MSG_RESULT([no ($PHP does not work)])
592             PHP=
593           fi
594         else
595           AC_MSG_RESULT([not found])
596         fi
597       else
598         AC_PATH_PROGS(PHP, ["$PHP"], [])
599       fi
600       if test x"$PHP" = x ; then
601         AC_MSG_WARN([No PHP5 interpreter found - PHP5 bindings tests will be skipped])
602         dnl The skiptest script just returns exit code 77.
603         PHP='$(top_srcdir)/skiptest'
604       else
605         AC_MSG_CHECKING([for PHP5 path separator])
606         PHP_PATH_SEPARATOR=`$PHP -r 'echo PATH_SEPARATOR;'`
607         AC_SUBST([PHP_PATH_SEPARATOR])
608         AC_MSG_RESULT([$PHP_PATH_SEPARATOR])
609       fi
611       case $host_os in
612       mingw* | pw32*)
613         dnl This is a bit of an informed guess, pending more information from
614         dnl someone who actually has mingw and wants to build the PHP bindings
615         dnl there.  FIXME.
616         PHP_LIBS="-L`$PHP_CONFIG --prefix` -lphp${PHP_MAJOR_VERSION}ts" ;;
617       cygwin*)
618         PHP_LIBS="-lphp${PHP_MAJOR_VERSION}lib" ;;
619       *)
620         PHP_LIBS= ;;
621       esac
622       AC_SUBST(PHP_LIBS)
623       BINDINGS="$BINDINGS php"
624     fi
625   fi
628 if test no != "$with_php7" ; then
629   dnl See comment for AC_PATH_PROGS(SWIG, ...).
630   if test -n "$PHP_CONFIG7" ; then
631     AC_PATH_PROGS(PHP_CONFIG7, ["$PHP_CONFIG7"], [])
632   fi
633   if test -z "$PHP_CONFIG7" ; then
634     AC_PATH_PROGS(PHP_CONFIG7, [php-config7.1 php-config7.0 php-config], [])
635   fi
636   AC_ARG_VAR(PHP_CONFIG7, [php-config utility for PHP7])
637   AC_ARG_VAR(PHP7, [PHP7 interpreter (optional - only needed to run PHP7 testsuite with)])
638   if test -n "$PHP_CONFIG7" ; then
639     AC_MSG_CHECKING([$PHP_CONFIG7 version])
640     version=`$PHP_CONFIG7 --version 2>/dev/null`
641     case $version in
642     [[0123456].*])
643       AC_MSG_RESULT([$version (not supported, PHP7 bindings need PHP >= 7.0)])
644       if test yes = "$with_php7" ; then
645         AC_MSG_ERROR([$PHP_CONFIG7 reports version $version - PHP7 bindings need >= 7.0])
646       fi
647       with_php7=no
648       ;;
649     *)
650       AC_MSG_RESULT([$version])
651       PHP7_MAJOR_VERSION=`echo "$version"|cut -d. -f1`
652       ;;
653     esac
654     AC_SUBST(PHP7_MAJOR_VERSION)
656     if test no != "$with_php7" ; then
657       AC_MSG_CHECKING([for PHP7 extension directory])
658       if test -z "$PHP7_EXTENSION_DIR" ; then
659         PHP7_EXTENSION_DIR=`$PHP_CONFIG7 --extension-dir`
660       fi
661       AC_MSG_RESULT([$PHP7_EXTENSION_DIR])
662       AC_ARG_VAR(PHP7_EXTENSION_DIR, [Directory to install PHP7 extensions in])
663     fi
665     if test no != "$with_php7" ; then
666       PHP7_INC=`$PHP_CONFIG7 --includes`
667       AC_SUBST(PHP7_INC)
668     fi
670     if test no != "$with_php7" ; then
671       if test x"$PHP7" = x ; then
672         AC_MSG_CHECKING([for PHP7 interpreter])
673         dnl PHP7's php-config supports --php-binary, so just use that.
674         PHP7=`$PHP_CONFIG7 --php-binary 2>/dev/null`
675         if test x"$PHP7" != x ; then
676           if $PHP7 -r 'exit(0);' 2> /dev/null ; then
677             if $PHP7 -r 'exit(PHP_MAJOR_VERSION==7?0:1);' 2> /dev/null ; then
678               AC_MSG_RESULT([$PHP7])
679             else
680               AC_MSG_RESULT([no ($PHP7 isn't PHP7)])
681               PHP7=
682             fi
683           else
684             AC_MSG_RESULT([no ($PHP7 does not work)])
685             PHP7=
686           fi
687         else
688           AC_MSG_RESULT([not found])
689         fi
690       else
691         AC_PATH_PROGS(PHP7, ["$PHP7"], [])
692       fi
693       if test x"$PHP7" = x ; then
694         AC_MSG_WARN([No PHP7 interpreter found - PHP7 bindings tests will be skipped])
695         dnl The skiptest script just returns exit code 77.
696         PHP7='$(top_srcdir)/skiptest'
697       else
698         AC_MSG_CHECKING([for PHP7 path separator])
699         PHP7_PATH_SEPARATOR=`$PHP7 -r 'echo PATH_SEPARATOR;'`
700         AC_SUBST([PHP7_PATH_SEPARATOR])
701         AC_MSG_RESULT([$PHP7_PATH_SEPARATOR])
702       fi
704       case $host_os in
705       mingw* | pw32*)
706         dnl This is a bit of an informed guess, pending more information from
707         dnl someone who actually has mingw and wants to build the PHP bindings
708         dnl there.  FIXME.
709         PHP7_LIBS="-L`$PHP_CONFIG7 --prefix` -lphp${PHP7_MAJOR_VERSION}ts" ;;
710       cygwin*)
711         PHP7_LIBS="-lphp${PHP7_MAJOR_VERSION}lib" ;;
712       *)
713         PHP7_LIBS= ;;
714       esac
715       AC_SUBST(PHP7_LIBS)
716       BINDINGS="$BINDINGS php7"
717     fi
718   fi
721 if test no != "$with_tcl" ; then
722   dnl The documented minimum requirement is Tcl 8.5.  Older versions may work,
723   dnl but we don't test with them regularly, and they are no longer supported
724   dnl upstream.  Also ::tcl::pckconfig was added in Tcl 8.5, which makes the
725   dnl tests below simpler and more reliable.
726   dnl
727   dnl If you really want to build with an older version, run configure with
728   dnl a lower tcl_min and specify at least TCL_INC explicitly:
729   dnl
730   dnl ./configure tcl_min=8.4 TCL_INC=/usr/include/tcl8.4
731   dnl
732   dnl We definitely need at least Tcl 8.1 for TCL_STUBS.
733   : ${tcl_min=8.5}
734   AC_PATH_PROGS(TCLSH, ["${TCLSH-tclsh}"], [])
735   AC_ARG_VAR(TCLSH, [Tcl interpreter])
736   if test -n "$TCLSH" ; then
737     AC_MSG_CHECKING([$TCLSH version])
738     if echo 'if {$tcl_version < '"$tcl_min"' } { exit 1 }'|$TCLSH 2> /dev/null ; then
739       tcl_version=`echo 'puts "$tcl_version"'|$TCLSH`
740       AC_MSG_RESULT([$tcl_version])
742       AC_ARG_VAR(TCL_LIB, [Directory to install Tcl files into])
743       if test -z "$TCL_LIB" ; then
744         [TCL_LIB=`echo 'foreach d $tcl_pkgPath {if {![regexp {/share(/|$)} $d]} {break}};puts $d'|$TCLSH`]
745       fi
746       AC_SUBST(TCL_LIB)
748       AC_ARG_VAR([TCL_INC], [Directory to include for Tcl headers])
749       if test -z "$TCL_INC" ; then
750         dnl ::tcl::pkgconfig was added in Tcl 8.5.
751         [TCL_INC=`echo 'puts [::tcl::pkgconfig get includedir,runtime]'|$TCLSH 2> /dev/null`]
752       fi
754       dnl Check that the headers are there (the tcl8.N-dev package
755       dnl may not be installed).
756       TCL_CPPFLAGS=
757       AC_MSG_CHECKING([for tcl.h from Tcl $tcl_version])
758       if test x"$TCL_INC" != x && test -f "$TCL_INC/tcl.h" ; then
759         tcl_hdr_version=`awk '($1 == "#define" && $2 == "TCL_VERSION") {print $3}' "$TCL_INC/tcl.h"|sed 's/"//g'`
760         if test x"$tcl_hdr_version" = x"$tcl_version" ; then
761           AC_MSG_RESULT([$TCL_INC/tcl.h])
762           BINDINGS="$BINDINGS tcl8"
763           if test x"$TCL_INC" != x"/usr/include" ; then
764             TCL_CPPFLAGS="-I$TCL_INC"
765           fi
766         else
767           AC_MSG_RESULT([not found])
768           if test yes = "$with_tcl" ; then
769             AC_MSG_ERROR([Found tcl.h from version $tcl_hdr_version, not $tcl_version - specify TCL_INC on configure command line])
770           fi
771           TCLSH=
772         fi
773       else
774         AC_MSG_RESULT([not found])
775         if test yes = "$with_tcl" ; then
776           AC_MSG_ERROR([Can't find tcl.h])
777         fi
778         TCLSH=
779       fi
781       if test -n "$TCLSH" ; then
782         dnl Cygwin needs to link with -ltcl8.5 or similar.
783         TCL_LIBS=
784         case $host_os in
785         cygwin*)
786           AC_CHECK_LIB([tcl$tcl_version], [Tcl_Init],
787                        [TCL_LIBS="-ltcl$tcl_version"],
788                        [AC_MSG_ERROR([libtcl$tcl_version not found])])
789           ;;
790         *)
791           dnl ::tcl::pkgconfig was added in Tcl 8.5, but prior to 8.6 it isn't
792           dnl necessary to link against -ltclstub anyway.
793           [tcl_libdir_runtime=`echo 'puts [::tcl::pkgconfig get libdir,runtime]'|$TCLSH 2> /dev/null`]
794           if test -n "$tcl_libdir_runtime" ; then
795             for x in "/tcl$tcl_version" "" ; do
796               TCLCONFIG_SH=$tcl_libdir_runtime$x/tclConfig.sh
797               if test -r "$TCLCONFIG_SH" ; then
798                 eval "`sed 's/^TCL_STUB_LIB_SPEC=/TCL_LIBS=/p;d' $TCLCONFIG_SH`"
799                 break
800               fi
801             done
802           fi
803           TCL_CPPFLAGS="$TCL_CPPFLAGS -DUSE_TCL_STUBS" ;;
804         esac
805       fi
807       AC_SUBST(TCL_CPPFLAGS)
808       AC_SUBST(TCL_LIBS)
809     else
810       AC_MSG_RESULT([< $tcl_min (too old)])
811       if test yes = "$with_tcl" ; then
812         AC_MSG_ERROR([$TCLSH too old (Tcl $tcl_min or newer required)])
813       fi
814     fi
815   else
816     if test yes = "$with_tcl" ; then
817       AC_MSG_ERROR([tclsh not found])
818     fi
819   fi
822 if test no != "$with_csharp" ; then
823   csc_note=
824   AC_ARG_VAR(CSC, [CSharp compiler command])
825   if test -n "$CSC" ; then
826     AC_PATH_PROGS(CSC, ["$CSC"], [])
827   fi
828   if test -z "$CSC" ; then
829     dnl First we try cli-csc and mono-csc, which are used by Debian and Ubuntu
830     dnl as "alternatives" which can be mapped to the CSharp compiler the admin
831     dnl favours.
832     AC_PATH_PROGS(CSC, [cli-csc mono-csc], [])
833     if test -z "$CSC" ; then
834       dnl mcs is the Mono CSharp compiler, which is a unified compiler
835       dnl available from Mono 2.11 (and also the compiler in Mono 1.0, but
836       dnl that's no longer relevant).
837       AC_PATH_PROGS(CSC, [mcs], [])
838       if test -n "$CSC" ; then
839         dnl There are other tools called mcs (such as /usr/bin/mcs on Tru64),
840         dnl so we check that the mcs we found understands --version which is
841         dnl sufficient to distinguish mono's mcs from the Tru64 one.
842         AC_MSG_CHECKING([whether $CSC is from GNU Mono])
843         if (exec >&5 2>&5;$CSC --version </dev/null;exit $?) ; then
844           AC_MSG_RESULT(yes)
845         else
846           AC_MSG_RESULT(no)
847           CSC=
848           csc_note="$csc_note (found different mcs program)"
849         fi
850       fi
851     fi
852     if test -z "$CSC" ; then
853       dnl csc is the Microsoft CSharp compiler.
854       AC_PATH_PROGS(CSC, [csc], [])
855       if test -n "$CSC" ; then
856         dnl Chicken (the Scheme-to-C compiler) includes a tool called csc so we
857         dnl check if the output from "csc -version" includes the word chicken
858         dnl which is sufficient to distinguish Chicken's csc from Microsoft's
859         dnl csc.exe.
860         AC_MSG_CHECKING([whether $CSC is for CSharp])
861         if $CSC -version 2>/dev/null|grep chicken > /dev/null ; then
862           AC_MSG_RESULT(no)
863           CSC=
864           csc_note="$csc_note (found Chicken csc program)"
865         else
866           AC_MSG_RESULT(yes)
867         fi
868       fi
869     fi
870   fi
872   if test -n "$CSC" ; then
873     AC_ARG_VAR(GACUTIL, [gacutil utility to use for CSharp bindings])
874     if test -n "$GACUTIL" ; then
875       AC_PATH_PROGS(GACUTIL, ["$GACUTIL"], [])
876     fi
877     if test -z "$GACUTIL" ; then
878       AC_PATH_PROGS(GACUTIL, [cli-gacutil gacutil], [])
879     fi
881     AC_ARG_VAR(SN, [sn utility to use for CSharp bindings])
882     if test -n "$SN" ; then
883       AC_PATH_PROGS(SN, ["$SN"], [])
884     fi
885     if test -z "$SN" ; then
886       AC_PATH_PROGS(SN, [cli-sn sn], [])
887     fi
888     if test -n "$GACUTIL" -a -n "$SN" ; then
889       AC_MSG_CHECKING([whether the CSharp compiler works])
890       [echo 'class conftest { public static void Main() { System.Console.WriteLine("OK"); } }' > conftest.cs]
891       if (exec >&5 2>&5;$CSC /out:conftest.exe conftest.cs;exit $?) ; then
892         AC_MSG_RESULT(yes)
893         AC_MSG_CHECKING([whether CSharp programs can just be run])
894         if test OK = "`./conftest.exe 2> /dev/null`" ; then
895           AC_MSG_RESULT(yes)
896           RUN_CSHARP=
897         else
898           AC_MSG_RESULT(no)
899           AC_PATH_PROGS(CLI, ["${CLI-cli}"], [])
900           if test -z "$CLI" ; then
901             AC_PATH_PROGS(CLI, [mono ilrun], [])
902           fi
903           AC_ARG_VAR(CLI, [CSharp bytecode interpreter (optional - only needed to run CSharp testsuite with)])
904           if test -n "$CLI" ; then
905             AC_MSG_CHECKING([whether $CLI can run CSharp programs])
906             if test OK = "`$CLI ./conftest.exe 2> /dev/null`" ; then
907               AC_MSG_RESULT(yes)
908               RUN_CSHARP=$CLI
909             else
910               AC_MSG_RESULT([no - CSharp tests will be skipped])
911               RUN_CSHARP='\$(top_srcdir)/skiptest'
912             fi
913           else
914             AC_MSG_RESULT([not found - CSharp tests will be skipped])
915             RUN_CSHARP='\$(top_srcdir)/skiptest'
916           fi
917         fi
918         AC_SUBST(RUN_CSHARP)
920         AC_MSG_CHECKING([for extra flags for $GACUTIL])
921         GACUTIL_FLAGS='/package $(ASSEMBLY) /gacdir $(libdir) /root $(DESTDIR)$(libdir)'
922         dnl Microsoft's gacutil accepts fewer options than Mono's
923         $GACUTIL /\?|grep '\<Mono\>' >/dev/null || GACUTIL_FLAGS=
924         AC_SUBST([GACUTIL_FLAGS])
925         if test -z "$GACUTIL_FLAGS" ; then
926           AC_MSG_RESULT([no])
927         else
928           AC_MSG_RESULT([$GACUTIL_FLAGS])
929         fi
931         BINDINGS="$BINDINGS csharp"
932       else
933         AC_MSG_RESULT(no)
934         if test yes = "$with_csharp" ; then
935           AC_MSG_ERROR([CSharp compiler $CSC doesn't work])
936         fi
937       fi
938     else
939       if test yes = "$with_csharp" ; then
940         if test -z "$GACUTIL" ; then
941           AC_MSG_ERROR([Mono gacutil not found])
942         elif test -z "$SN" ; then
943           AC_MSG_ERROR([Mono sn not found])
944         fi
945       fi
946     fi
947   else
948     if test yes = "$with_csharp" ; then
949       AC_MSG_ERROR([CSharp compiler not found$csc_note])
950     fi
951   fi
954 JAVA_CPPFLAGS=
955 if test no != "$with_java" ; then
956   AC_PATH_PROGS(JAVA, ["${JAVA-java}"], [],
957         [${JAVA_HOME+$JAVA_HOME/bin:}${JDK_HOME+$JDK_HOME/bin:}$PATH])
958   AC_PATH_PROGS(JAVAC, ["${JAVAC-javac}"], [],
959         [${JAVA_HOME+$JAVA_HOME/bin:}${JDK_HOME+$JDK_HOME/bin:}$PATH])
960   AC_PATH_PROGS(JAR, ["${JAR-jar}"], [],
961         [${JAVA_HOME+$JAVA_HOME/bin:}${JDK_HOME+$JDK_HOME/bin:}$PATH])
962   AC_ARG_VAR(JAVA, [Java interpreter command])
963   AC_ARG_VAR(JAVAC, [Java compiler command])
964   AC_ARG_VAR(JAR, [java jar utility])
965   AC_ARG_VAR(JAVA_HOME, [Pathname of the directory where the JDK is installed])
966   AC_ARG_VAR(JDK_HOME, [Pathname of the directory where the JDK is installed])
967   AC_ARG_VAR(JNI_INCLUDE_DIR, [Pathname of the directory where jni.h is installed])
968   if test -n "$JAVA" -a -n "$JAVAC" -a -n "$JAR" ; then
969     dnl Eric says:
970     dnl  The JNI library *requires* "Java 2", which is 1.2 or better.
971     dnl
972     dnl So checking for jni.h presumably implicitly checks we have "Java 2".
973     dnl Note: jni.h #defines JNI_VERSION_1_[12468] (but not 3, 5 or 7 it seems).
974     dnl So we could check for one of these if we want to check for a particular
975     dnl JDK version...
976     java_ok=no
977     AC_CHECK_HEADER([jni.h], [java_ok=yes], [
978       dnl We need to look for jni.h in /usr/lib/jvm/java-gcj/include on some
979       dnl Debian and Ubuntu boxes at least.  And on Mac OS X, jni.h lives
980       dnl in /System/Library/Frameworks/JavaVM.framework/Headers.
981       SAVE_CPPFLAGS=$CPPFLAGS
982       real_javac=$JAVAC
983       dnl Avoid endlessly traversing if there's a symlink loop.
984       for count in 1 2 3 4 5 6 7 8 9 ; do
985         r=`readlink "$real_javac"`
986         test -n "$r" || break
987         real_javac=$r
988       done
989       dnl Translate ".../bin/javac" to ".../include".
990       [rel_jnidir=`echo "$real_javac"|sed 's!/[^/]*/[^/]*$!/include!'`]
991       for jnidir in \
992           $JNI_INCLUDE_DIR \
993           ${JAVA_HOME+"$JAVA_HOME/include"} \
994           ${JDK_HOME+"$JDK_HOME/include"} \
995           "$rel_jnidir" \
996           /System/Library/Frameworks/JavaVM.framework/Headers ; do
997         CPPFLAGS="$SAVE_CPPFLAGS -I$jnidir"
998         AC_MSG_CHECKING([for jni.h in $jnidir])
999         if test -f "$jnidir/jni.h" ; then
1000           AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <jni.h>]])], [java_ok=yes])
1001           if test yes = $java_ok ; then
1002             AC_MSG_RESULT([yes])
1003             JAVA_CPPFLAGS=-I$jnidir
1004             break
1005           fi
1007           dnl For OpenJDK (and maybe others) we have to specify an extra -I
1008           dnl option for an OS-specific subdirectory containing a "jni_md.h"
1009           dnl header which is included by "jni.h".  Sadly we seem to need to
1010           dnl hardcode a mapping for these platform names - the list below
1011           dnl was determined by inspecting the source code of OpenJDK 8.
1012           jni_host_os=
1013           case $host_os in
1014             linux*)
1015               jni_host_os=linux ;;
1016             solaris*)
1017               jni_host_os=solaris ;;
1018             mingw* | pw32* | cygwin*)
1019               jni_host_os=win32 ;;
1020             darwin*)
1021               jni_host_os=darwin ;;
1022             *bsd*)
1023               jni_host_os=bsd ;;
1024             aix*)
1025               jni_host_os=aix ;;
1026           esac
1027           if test -n "$jni_host_os" ; then
1028             CPPFLAGS="$CPPFLAGS -I$jnidir/$jni_host_os"
1029             AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <jni.h>]])], [java_ok=yes])
1030             if test yes = $java_ok ; then
1031               AC_MSG_RESULT([yes, requires additional -I$jnidir/$jni_host_os])
1032               JAVA_CPPFLAGS="-I$jnidir -I$jnidir/$jni_host_os"
1033               break
1034             fi
1035           fi
1036           AC_MSG_RESULT([found, but not usable])
1038           CPPFLAGS="$SAVE_CPPFLAGS -I$jnidir"
1039         else
1040           AC_MSG_RESULT([no])
1041         fi
1042       done
1043       CPPFLAGS=$SAVE_CPPFLAGS
1044       test noyes = $java_ok$with_java && AC_MSG_ERROR([jni.h not found])
1045       ], [ ])
1046     AC_SUBST(JAVA_CPPFLAGS)
1047     if test yes = $java_ok ; then
1048       AC_MSG_CHECKING([for Java path separator])
1049       [echo 'public class conftest { public static void main(String[] args) { System.out.println(System.getProperty("path.separator")); } }' > conftest.java]
1050       if (exec >&5 2>&5;$JAVAC conftest.java;exit $?) ; then
1051         JAVA_PATHSEP=`$JAVA conftest 2>&5`
1052         AC_SUBST(JAVA_PATHSEP)
1053         if test -n "$JAVA_PATHSEP" ; then
1054           AC_MSG_RESULT($JAVA_PATHSEP)
1055           BINDINGS="$BINDINGS java"
1057           dnl If -Xcheck:jni is supported then run tests with it.
1058           dnl
1059           dnl ... except that with OpenJDK 8 and 9 -Xcheck:jni seems to report
1060           dnl false positives and so can't usefully be turned on in this
1061           dnl situation.  Recheck this with future versions.
1062 dnl       AC_MSG_CHECKING([for $JAVA -Xcheck:jni option])
1063 dnl       JAVA_PATHSEP2=`$JAVA conftest 2>&5`
1064           JAVA_CHECK_JNI_OPTION=
1065 dnl       if test "$JAVA_PATHSEP" = "$JAVA_PATHSEP2" ; then
1066 dnl         JAVA_CHECK_JNI_OPTION=-Xcheck:jni
1067 dnl         AC_MSG_RESULT([yes])
1068 dnl       else
1069 dnl         AC_MSG_RESULT([no])
1070 dnl       fi
1071           AC_SUBST([JAVA_CHECK_JNI_OPTION])
1072         else
1073           AC_MSG_RESULT([failed to run test program])
1074           java_ok=no
1075         fi
1076       else
1077         AC_MSG_RESULT([failed to compile test program])
1078         java_ok=no
1079       fi
1080       if test no = "$java_ok" ; then
1081         test yes = "$with_java" && AC_MSG_ERROR([Couldn't compile and run a simple Java test program])
1082       fi
1083     fi
1084   else
1085     if test yes = "$with_java" ; then
1086       if test -z "$JAVA" ; then
1087         AC_MSG_ERROR([java not found])
1088       elif test -z "$JAVAC" ; then
1089         AC_MSG_ERROR([javac not found])
1090       elif test -z "$JAR" ; then
1091         AC_MSG_ERROR([jar not found])
1092       fi
1093     fi
1094   fi
1097 if test no != "$with_ruby" ; then
1098   dnl See comment for AC_PATH_PROGS(SWIG, ...).
1099   if test -n "$RUBY" ; then
1100     AC_PATH_PROGS(RUBY, ["$RUBY"], [])
1101   else
1102     AC_PATH_PROGS(RUBY, [ruby], [])
1103   fi
1104   AC_ARG_VAR(RUBY, [Ruby interpreter])
1105   if test -n "$RUBY" ; then
1106     dnl Require Ruby 2.1 or newer.
1107     AC_MSG_CHECKING([$RUBY version])
1108     dnl RUBY_VERSION works with 1.6.  Once we've checked we have at least 1.8
1109     dnl we can safely use RbConfig below (RbConfig requires Ruby 1.8).
1110     version=`$RUBY -e 'print RUBY_VERSION' 2>/dev/null`
1111     case $version in
1112     "")
1113       AC_MSG_RESULT([\$RUBY -e 'print RUBY_VERSION' didn't work])
1114       if test yes = "$with_ruby" ; then
1115         AC_MSG_ERROR([Working Ruby interpreter not found])
1116       fi
1117       RUBY=
1118       ;;
1119     [[01].*|2.0.*])
1120       AC_MSG_RESULT([$version (too old)])
1121       if test yes = "$with_ruby" ; then
1122         AC_MSG_ERROR([Only Ruby 2.1 or newer is supported ($RUBY is $version)])
1123       fi
1124       RUBY=
1125       ;;
1126     esac
1127     if test -n "$RUBY" ; then
1128       AC_MSG_RESULT([$version])
1129       AC_ARG_VAR(RUBY_INC, [Directory where ruby.h can be found])
1130       if test -z "$RUBY_INC" ; then
1131         dnl Ruby 1.9 added rubyhdrdir.
1132         [RUBY_INC=`$RUBY -rrbconfig -e 'print RbConfig::CONFIG["rubyhdrdir"]'`]
1133       fi
1134       AC_SUBST(RUBY_INC)
1135       dnl Check that ruby.h is there, which is a good way to check that
1136       dnl the appropriate ruby-dev package has been installed.
1137       AC_MSG_CHECKING([for $RUBY_INC/ruby.h])
1138       if test -f "$RUBY_INC/ruby.h" ; then
1139         AC_MSG_RESULT(yes)
1141         AC_ARG_VAR(RUBY_INC_ARCH, [Directory where ruby/config.h can be found])
1142         if test -z "$RUBY_INC_ARCH" ; then
1143           dnl Ruby 2.0 and later have rubyarchhdrdir.
1144           [RUBY_INC_ARCH=`$RUBY -rrbconfig -e 'print RbConfig::CONFIG["rubyarchhdrdir"]'`]
1145         fi
1146         AC_SUBST(RUBY_INC_ARCH)
1148         AC_ARG_VAR(RUBY_LIB, [Directory to install ruby files into])
1149         if test -z "$RUBY_LIB" ; then
1150           [RUBY_LIB=`$RUBY -rrbconfig -e 'print RbConfig::CONFIG["sitelibdir"]'`]
1151         fi
1152         AC_SUBST(RUBY_LIB)
1154         AC_ARG_VAR(RUBY_LIB_ARCH, [Directory to install ruby binary modules into])
1155         if test -z "$RUBY_LIB_ARCH" ; then
1156           [RUBY_LIB_ARCH=`$RUBY -rrbconfig -e 'print RbConfig::CONFIG["sitearchdir"]'`]
1157         fi
1158         AC_SUBST(RUBY_LIB_ARCH)
1160         RUBY_LIBS=
1161         if test unsupported = "$allow_undefined_flag" ; then
1162           dnl For Microsoft Windows and a few other platforms.
1163           [RUBY_LIBS=`$RUBY -rrbconfig -e 'print RbConfig::CONFIG["LIBRUBYARG"]'`]
1164         fi
1165         AC_SUBST(RUBY_LIBS)
1167         dnl rdoc is included as part of the Ruby core distribution, so run it
1168         dnl at build time rather shipping the rather large generated output in
1169         dnl our source tarball.
1170         if test -n "$RDOC" ; then
1171           AC_PATH_PROGS(RDOC, ["$RDOC"], [])
1172         else
1173           dnl Try replace the *last* 'ruby' with 'rdoc'.
1174           rdoc_best_guess=`echo "$RUBY"|sed 's,\(.*\)ruby,\1rdoc,'`
1175           AC_PATH_PROGS(RDOC, ["$rdoc_best_guess"], [])
1176           if test -z "$RDOC"; then
1177             AC_PATH_PROGS(RDOC, [rdoc], [])
1178           fi
1179         fi
1180         if test -n "$RDOC"; then
1181           BINDINGS="$BINDINGS ruby"
1182         fi
1183       else
1184         AC_MSG_RESULT([no (install ruby-dev or ruby-devel package or similar)])
1185         if test yes = "$with_ruby" ; then
1186           AC_MSG_ERROR([ruby.h not found])
1187         fi
1188       fi
1189       RUBY_DLEXT=`$RUBY -rrbconfig -e 'print RbConfig::CONFIG[["DLEXT"]]'`
1190       AC_SUBST(RUBY_DLEXT)
1191     fi
1192   fi
1195 if test no != "$with_perl" ; then
1196   AC_PATH_PROGS(PERL, ["${PERL-perl}"], [])
1197   AC_ARG_VAR(PERL, [perl interpreter])
1198   if test -n "$PERL" ; then
1199     if test -z "$PERL_INC" ; then
1200       PERL_INC=`$PERL -MConfig -e 'print $Config{archlibexp}, "/CORE"'`
1201     fi
1202     AC_SUBST(PERL_INC)
1204     AC_ARG_VAR(PERL_ARCH, [Directory to install architecture-dependent perl files into])
1205     if test -z "$PERL_ARCH" ; then
1206       PERL_ARCH=`$PERL -MConfig -e 'print $Config{installsitearch}'`
1207     fi
1208     AC_SUBST(PERL_ARCH)
1210     AC_ARG_VAR(PERL_LIB, [Directory to install architecture-independent perl files into])
1211     if test -z "$PERL_LIB" ; then
1212       PERL_LIB=`$PERL -MConfig -e 'print $Config{installsitelib}'`
1213     fi
1214     AC_SUBST(PERL_LIB)
1216     AC_ARG_VAR(PERL_SO, [Extension for compiled Perl modules])
1217     if test -z "$PERL_SO" ; then
1218       PERL_SO=`$PERL -MConfig -e 'print ".", $Config{dlext}'`
1219     fi
1220     AC_SUBST(PERL_SO)
1222     if test -z "$PERL_XAPIAN_VERSION" ; then
1223       dnl snapshot versions look like 1.2.3_git123 or 1.2.3_svn14971
1224       case $PACKAGE_VERSION in
1225       *_git*)
1226         PERL_XAPIAN_VERSION=`echo "$PACKAGE_VERSION"|sed 's/_git/./'` ;;
1227       *_svn*)
1228         PERL_XAPIAN_VERSION=`echo "$PACKAGE_VERSION"|sed 's/_svn/./'` ;;
1229       *)
1230         PERL_XAPIAN_VERSION=$PACKAGE_VERSION.0 ;;
1231       esac
1232     fi
1233     AC_SUBST(PERL_XAPIAN_VERSION)
1235     BINDINGS="$BINDINGS perl"
1236   else
1237     if test yes = "$with_perl" ; then
1238       AC_MSG_ERROR([perl not found])
1239     fi
1240   fi
1243 if test no != "$with_lua" ; then
1244   AC_PATH_PROGS(LUA, ["${LUA-lua}"], [])
1245   AC_ARG_VAR(LUA, [lua interpreter])
1246   if test -n "$LUA" ; then
1247     dnl We need Lua 5.1 or later.
1248     AC_MSG_CHECKING([$LUA version])
1249     lua_version=`$LUA -e 'print(_VERSION)' | cut -f 2 -d ' ' 2>&AS_MESSAGE_LOG_FD`
1251     case $lua_version in
1252     [[01234]].*|5.0|5.0.*)
1253       AC_MSG_RESULT([$lua_version < 5.1 (too old)])
1254       if test yes = "$with_lua" ; then
1255         AC_MSG_ERROR([$LUA too old (Lua 5.1 or newer required)])
1256       fi
1257       LUA=
1258       ;;
1259     "")
1260       AC_MSG_RESULT([\$LUA -e 'print(_VERSION)' | cut -f 2 -d ' ' didn't work])
1262       if test yes = "$with_lua" ; then
1263         AC_MSG_ERROR([Working Lua interpreter not found])
1264       fi
1265       LUA=
1266       ;;
1267     esac
1269     if test -n "$LUA" ; then
1270       AC_MSG_RESULT([$lua_version])
1272       AC_ARG_VAR([LUA_LIB], [Directory to install compiled Lua modules into])
1273       AC_ARG_VAR([LUA_SO], [Extension for compiled Lua modules (e.g. LUA_SO=.so)])
1274       AC_MSG_CHECKING([for directory to install compiled Lua modules into])
1275       if test -z "$LUA_LIB" -o -z "$LUA_SO" ; then
1276         lua_cpath=`$LUA -e 'require("package") print(package.cpath)'`
1277         dnl Look for the first absolute path in lua_cpath which has leaf
1278         dnl "?.<ext>" and put the directory part into lua_lib and <ext> into
1279         dnl lua_so.  If LUA_SO was specified by the user, only consider
1280         dnl entries where <ext> matches LUA_SO.
1281         lua_lib=
1282         lua_so=
1283         case $LUA_SO in
1284           "")
1285            [lua_so_pat='[a-zA-Z][a-zA-Z]*'] ;;
1286           .*)
1287             dnl If LUA_SO has a leading '.', remove it.
1288             lua_so_pat=`AS_ECHO("$LUA_SO")|sed 's/^\.//'` ;;
1289           *)
1290             dnl If LUA_SO was specified without a leading '.', add one to the
1291             dnl value substituted into Makefile.in.
1292             lua_so_pat=$LUA_SO
1293             LUA_SO=.$LUA_SO
1294             ;;
1295         esac
1296         while test x"$lua_cpath" != x ; do
1297           [lua_lib=`expr X"$lua_cpath" : X'\([^;]*\)'`]
1298           lua_so=.`expr X"$lua_lib" : X'/.*/?\.\('"$lua_so_pat"'\)$'`
1299           case $lua_so in
1300             .|.lua)
1301               dnl If someone has foolishly put ?.lua in cpath, ignore them.
1302               lua_lib=
1303               ;;
1304             *)
1305               lua_lib=`expr X"$lua_lib" : X'\(/.*\)/?\.'"$lua_so_pat"'$'`
1306               break ;;
1307           esac
1308           [lua_cpath=`expr X"$lua_cpath" : X'[^;]*;*\(.*\)'`]
1309         done
1310         test -n "$LUA_LIB" || LUA_LIB=$lua_lib
1311         test -n "$LUA_SO" || LUA_SO=$lua_so
1312       fi
1313       if test -z "$LUA_LIB"; then
1314         AC_MSG_RESULT([not found])
1315       else
1316         AC_MSG_RESULT([$LUA_LIB])
1317       fi
1318       AC_SUBST([LUA_LIB])
1320       AC_MSG_CHECKING([for extension to use for compiled Lua modules])
1321       if test -z "$LUA_SO"; then
1322         AC_MSG_RESULT([not found])
1323       else
1324         AC_MSG_RESULT([$LUA_SO])
1325       fi
1326       AC_SUBST([LUA_SO])
1328       AC_MSG_CHECKING([for Lua header files])
1329       AC_ARG_VAR([LUA_INC], [Directory to include for lua headers])
1330       if test -z "$LUA_INC" ; then
1331         dirs="/usr/include/lua$lua_version /usr/local/include/lua$lua_version"
1332         for i in $dirs ; do
1333           if test -r "$i/lua.h"; then
1334             LUA_INC=$i
1335             break
1336           fi
1337         done
1338       fi
1340       if test -z "$LUA_INC" ; then
1341         AC_MSG_RESULT([not found])
1342       else
1343         AC_MSG_RESULT([$LUA_INC])
1344         BINDINGS="$BINDINGS lua"
1345         LUA_CPPFLAGS="-I$LUA_INC"
1346       fi
1347       AC_SUBST([LUA_CPPFLAGS])
1348     fi
1349   else
1350     if test yes = "$with_lua" ; then
1351       AC_MSG_ERROR([lua not found])
1352     fi
1353   fi
1356 AC_SUBST(BINDINGS)
1358 case $BINDINGS in
1359 *python*) dnl Matches python and/or python3
1360   dnl C++11 has thread_local
1361   dnl GCC and some others have __thread
1362   dnl MSVC and some others have __declspec(thread)
1363   AC_MSG_CHECKING([for thread-local storage qualifier])
1364   AC_ARG_VAR([THREAD_LOCAL], [thread-local storage qualifier])
1365   if test -z "$THREAD_LOCAL" ; then
1366     for t in thread_local __thread '__declspec(thread)' ; do
1367       AC_COMPILE_IFELSE([AC_LANG_SOURCE([[static $t void * p;]])],
1368                         [THREAD_LOCAL=$t; break])
1369     done
1370   fi
1371   if test -z "$THREAD_LOCAL" ; then
1372     AC_MSG_RESULT([unknown, disabling thread-local support])
1373   else
1374     AC_MSG_RESULT([$THREAD_LOCAL])
1375     AC_DEFINE_UNQUOTED([THREAD_LOCAL], [$THREAD_LOCAL], [Thread local storage qualifier (undefined if no TLS)])
1376   fi
1377   ;;
1378 esac
1380 dnl Set flags to control warnings (enable more, or disable annoying ones)
1381 dnl and other compiler specific flags.
1382 SWIG_CXXFLAGS=
1383 if test yes = "$GXX" ; then
1384   dnl Python itself is compiled with -fno-strict-aliasing, and it appears
1385   dnl it's safest to follow this lead when compiling the SWIG generated
1386   dnl interface code.  E.g.:
1387   dnl   http://article.gmane.org/gmane.comp.gcc.devel/74692
1388   dnl The code SWIG generates for other languages seems to have similar
1389   dnl issues too, so just turn this on for all of them.
1390   dnl
1391   dnl There's no need to check -fno-strict-aliasing is supported as it works
1392   dnl with GCC 2.95 and we don't support anything older.
1393   SWIG_CXXFLAGS="-fno-strict-aliasing"
1395   dnl We need to explicitly link against -lstdc++ on OpenBSD (discovered
1396   dnl on OpenBSD 3.7 with GCC 3.3.5 but this appears to be due to a
1397   dnl deliberate decision on the part of OpenBSD developers).  Luckily
1398   dnl we can just always specify -lstdc++ explicitly if GCC is the
1399   dnl compiler and libtool will eliminate the duplicate on other
1400   dnl platforms.
1401   XAPIAN_LIBS="$XAPIAN_LIBS -lstdc++"
1403   dnl Intel's C++ compiler is identified as "GXX" by autoconf's test - check
1404   dnl which we actually have.
1405   AC_EGREP_CPP(yes,
1406     [#ifdef __INTEL_COMPILER
1407      yes
1408      #endif
1409     ],
1410     [
1411       dnl Intel's compiler:
1412       dnl
1413       dnl -w1 stops the avalanche of uninteresting "remark" messages.
1414       dnl -wd... disables warnings which don't have good code workarounds.
1415       dnl
1416       dnl Swig generated code gives lots of unused and uninitialized warnings.
1417       dnl They're non-harmful, so suppress them.
1418       SWIG_CXXFLAGS="$SWIG_CXXFLAGS -Wall -w1 -wd177,1572"
1419     ],
1420     [
1421       dnl GCC or clang:
1422       dnl
1423       dnl Swig generated code gives lots of unused and uninitialized warnings.
1424       dnl They're non-harmful, so suppress them.
1425       SWIG_CXXFLAGS="$SWIG_CXXFLAGS -Wall -Wno-unused -Wno-uninitialized"
1426     ])
1428   if test no != "$enable_visibility"; then
1429     dnl GCC doesn't support symbol visibility on all platforms (e.g. it isn't
1430     dnl on mingw).
1431     AC_MSG_CHECKING([if $CXX -fvisibility=hidden works])
1432     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
1433       AC_MSG_RESULT([yes])
1434       SWIG_CXXFLAGS="$SWIG_CXXFLAGS -fvisibility=hidden"
1435     else
1436       AC_MSG_RESULT([no])
1437     fi
1438   fi
1440 AC_SUBST(SWIG_CXXFLAGS)
1442 dnl Restore CXXFLAGS to those the user specified or autoconf defaulted to.
1443 CXXFLAGS=$save_CXXFLAGS
1445 dnl Required for auto regeneration to work in a combined maintainer-mode tree.
1446 : ${AUTOM4TE=autom4te}
1447 AC_SUBST([AUTOM4TE])
1449 AC_CONFIG_FILES([Makefile
1450  doxygen_xml.conf
1451  xapian-version.h
1452  python/Makefile python/docs/conf.py python/version.i
1453  python3/Makefile python3/docs/conf.py python3/version.i
1454  php/Makefile
1455  php7/Makefile
1456  java/Makefile
1457  tcl8/Makefile tcl8/pkgIndex.tcl
1458  csharp/Makefile csharp/AssemblyInfo.cs
1459  ruby/Makefile
1460  perl/Makefile perl/util.i
1461  lua/Makefile
1462  xapian-bindings.spec
1463  ])
1464 AC_OUTPUT
1466 echo ""
1467 if test -z "$BINDINGS" ; then
1468   echo "*** Not found the required tools for building bindings for any"
1469   echo "*** supported language!"
1470   echo "***"
1471   echo "*** You may need to install -dev or -devel packages for the languages"
1472   echo "*** you want to build bindings for."
1473   echo "***"
1474   echo "*** For details of how to point configure at tools not on PATH, see:"
1475   echo "***     ./configure --help"
1476 else
1477   echo "*** Building bindings for languages:" $BINDINGS
1479 echo ""
1480 if test "$COMPAT_VERSION" != "$XAPIAN_VERSION" ; then
1481   release_series=[`echo "$COMPAT_VERSION"|sed 's/[0-9][0-9]*$//'`]
1482   case $XAPIAN_VERSION in
1483   $release_series*) ;;
1484   *)
1485     AC_MSG_ERROR([Xapian library is version ${XAPIAN_VERSION-<0.8.2} which is from a different release series to bindings $PACKAGE_VERSION, so they aren't compatible.])
1486     ;;
1487   esac
1488   dnl 0.8.2 was the first version which set XAPIAN_VERSION
1489   AC_MSG_WARN([Xapian library is version ${XAPIAN_VERSION-<0.8.2} but the bindings are version $PACKAGE_VERSION - we strongly recommend using matching versions.])