[python3] Improve configure probe portability
[xapian.git] / xapian-bindings / configure.ac
blobabe7bb4ae86017776419498ab7005ee06cfac6f2
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.19])
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[[912]]*)
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([C++])
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   AC_ARG_VAR([RST2HTML], [reST to HTML convertor])
175   test -z "$RST2HTML" && AC_MSG_ERROR([rst2html is required to build documentation (try package python-docutils)])
178 if test x$USE_MAINTAINER_MODE = xyes; then
179   dnl Check for swig - this does most of the work for the bindings.
180   dnl AC_PATH_PROGS only honours an already set SWIG if it's a full
181   dnl path.  Listing it in the "to be searched" list like this allows
182   dnl ./configure SWIG=myswig to work.
183   swigoverridden=${SWIG+yes}
184   AC_PATH_PROGS(SWIG, ["${SWIG-swig}"], [])
185   AC_ARG_VAR(SWIG, [SWIG interface generator (only needed by Xapian developers)])
186   if test -z "$SWIG" ; then
187     AC_MSG_ERROR([Can't find SWIG utility])
188   fi
189   dnl Check for new enough SWIG.
190   dnl
191   dnl 3.0.6 fixes compiling the Perl bindings under C++11 ("seed" macro issue).
192   dnl 3.0.8 fixes conversion of integers large than an int in Python 3.
193   dnl 3.0.9 fixes generation of unnecessary _swigconstant helpers for Python.
194   dnl 3.0.12 fixes segfault on unload with PHP 7.1
195   v=`$SWIG -version 2>&1|sed 's/^SWIG Version \([[0-9\.]]*\).*/\1/p;d'`
196   case $v in
197     [[012].*|3.0.?|3.0.1[01]|""])
198       msg="SWIG >= 3.0.12 required (you have ${v:-an unknown version})"
199       if test -n "$swigoverridden" ; then
200         dnl If SWIG was explicitly set, make this a warning only.
201         AC_MSG_WARN([$msg])
202       else
203         AC_MSG_ERROR([$msg])
204       fi ;;
205   esac
206   SWIG_FLAGS=`$XAPIAN_CONFIG --swigflags`
207   AC_SUBST(SWIG_FLAGS)
208   XAPIAN_HEADER_DIRS=
209   XAPIAN_HEADERS=
210   for a in $SWIG_FLAGS ; do
211     case $a in
212     -I*)
213       d=`echo "x$a"|sed 's/^x-I//'`
214       dnl Quote each entry in XAPIAN_HEADER_DIRS with "".
215       XAPIAN_HEADER_DIRS=$XAPIAN_HEADER_DIRS' "'$d'"'
216       for f in "$d/"*.h "$d/xapian/*.h" ; do
217         if test -f "$f" ; then
218           XAPIAN_HEADERS="$XAPIAN_HEADERS $f"
219         fi
220       done
221       ;;
222     esac
223   done
224   AC_SUBST([XAPIAN_HEADER_DIRS])
225   AC_SUBST([XAPIAN_HEADERS])
227   dnl Need perl in maintainer mode to generate the except.i file for python.
228   AC_PATH_PROGS(PERL, ["${PERL-perl}"], [])
229   test -z "$PERL" && AC_MSG_ERROR([perl is required in maintainer mode])
230   dnl Need doxygen in maintainer mode to convert C++ doxygen comments to Python
231   dnl docstrings.
232   AC_PATH_PROG(DOXYGEN, doxygen, [])
233   AC_ARG_VAR([DOXYGEN], [Doxygen documentation system])
234   test -z "$DOXYGEN" && AC_MSG_ERROR([doxygen is required to build documentation])
237 AC_ARG_WITH(python,
238   AC_HELP_STRING([--with-python], [enable Python 2 bindings]),
239   [],
240   [with_python=])
242 AC_ARG_WITH(python3,
243   AS_HELP_STRING([--with-python3], [enable Python 3 bindings]),
244   [],
245   [with_python3=])
247 AC_ARG_WITH(php,
248   AC_HELP_STRING([--with-php], [enable PHP 5 bindings]),
249   [],
250   [with_php=])
252 AC_ARG_WITH(php7,
253   AS_HELP_STRING([--with-php7], [enable PHP 7 bindings]),
254   [],
255   [with_php7=])
257 AC_ARG_WITH(ruby,
258   AS_HELP_STRING([--with-ruby], [enable Ruby bindings]),
259   [],
260   [with_ruby=])
262 AC_ARG_WITH(tcl,
263   AS_HELP_STRING([--with-tcl], [enable Tcl bindings]),
264   [],
265   [with_tcl=])
267 AC_ARG_WITH(csharp,
268   AS_HELP_STRING([--with-csharp], [enable CSharp bindings]),
269   [],
270   [with_csharp=])
272 AC_ARG_WITH(java,
273   AS_HELP_STRING([--with-java], [enable Java bindings]),
274   [],
275   [with_java=])
277 AC_ARG_WITH(perl,
278   AS_HELP_STRING([--with-perl], [enable Perl bindings]),
279   [],
280   [with_perl=])
282 AC_ARG_WITH(lua,
283   AS_HELP_STRING([--with-lua], [enable Lua bindings]),
284   [],
285   [with_lua=])
287 case $with_python$with_python3$with_php$with_php7$with_ruby$with_tcl$with_csharp$with_java$with_perl$with_lua in
288 *yes*)
289   dnl Default unspecified values to no.
290   test -z "$with_python" && with_python=no
291   test -z "$with_python3" && with_python3=no
292   test -z "$with_php" && with_php=no
293   test -z "$with_php7" && with_php7=no
294   test -z "$with_tcl" && with_tcl=no
295   test -z "$with_csharp" && with_csharp=no
296   test -z "$with_java" && with_java=no
297   test -z "$with_ruby" && with_ruby=no
298   test -z "$with_perl" && with_perl=no
299   test -z "$with_lua" && with_lua=no
300   ;;
301 esac
303 BINDINGS=
305 if test no != "$with_python" ; then
306   dnl For backward compatibility:
307   : ${PYTHON2="$PYTHON"}
308   : ${PYTHON2_INC="$PYTHON_INC"}
309   : ${PYTHON2_LIB="$PYTHON_LIB"}
310   : ${PYTHON2_LIBS="$PYTHON_LIBS"}
311   : ${PYTHON2_SO="$PYTHON_SO"}
312   dnl See comment for AC_PATH_PROGS(SWIG, ...).
313   if test -n "$PYTHON2" ; then
314     AC_PATH_PROGS(PYTHON2, ["$PYTHON2"], [])
315   else
316     AC_PATH_PROGS(PYTHON2, [python2 python], [])
317   fi
318   AC_ARG_VAR(PYTHON2, [Python 2 interpreter])
319   if test -n "$PYTHON2" ; then
320     dnl Require Python 2.6 or newer.  Older versions are essentially
321     dnl unsupported upstream.
322     AC_MSG_CHECKING([$PYTHON2 version])
323     version=`$PYTHON2 -c 'import sys;print("%d.%d" % sys.version_info[[:2]])' 2>/dev/null`
324     case $version in
325     [2.[6-9]*|2.[1-5][0-9]*])
326       AC_MSG_RESULT([$version])
327       ;;
328     [[3-9].*])
329       AC_MSG_RESULT([$version (too new - use --with-python3 for Python 3 support)])
330       if test yes = "$with_python" ; then
331         AC_MSG_ERROR([Use --with-python3 for Python 3 support ($PYTHON2 is $version)])
332       fi
333       PYTHON2=
334       ;;
335     *)
336       AC_MSG_RESULT([$version (too old)])
337       if test yes = "$with_python" ; then
338         AC_MSG_ERROR([Only Python 2.6 or newer is supported ($PYTHON2 is $version)])
339       fi
340       PYTHON2=
341       ;;
342     esac
343     if test -n "$PYTHON2" ; then
344       if $PYTHON2 -c 'import distutils.sysconfig' 2>/dev/null ; then
345         PYTHON2_INC=`$PYTHON2 -c 'import os,distutils.sysconfig;print(distutils.sysconfig.get_python_inc().replace(os.sep,"/"))'`
346         AC_SUBST(PYTHON2_INC)
347       else
348         if test yes = "$with_python" ; then
349           AC_MSG_ERROR([Couldn't import Python module distutils.sysconfig - you probably need to install a python-dev or python-devel package])
350         else
351           AC_MSG_WARN([Couldn't import Python module distutils.sysconfig - you probably don't have a python-dev or python-devel package installed])
352           PYTHON2=
353         fi
354       fi
355     fi
356     AC_MSG_CHECKING([for python2 sphinx module])
357     if $PYTHON2 -c 'import sphinx;print(repr(sphinx.main))' >&5 2>&5 ; then
358       AC_MSG_RESULT([yes])
359     else
360       AC_MSG_RESULT([no])
361       if test yes = "$with_python" ; then
362         AC_MSG_ERROR([Couldn't import sphinx module and call sphinx.main() for Python2 - try package python-sphinx])
363       fi
364       PYTHON2=
365     fi
366     if test -n "$PYTHON2" ; then
367       dnl Check that Python.h is there, which is a good way to check that
368       dnl the appropriate python-dev package has been installed.
369       AC_MSG_CHECKING([for $PYTHON2_INC/Python.h])
370       if test -f "$PYTHON2_INC/Python.h" ; then
371         AC_MSG_RESULT(yes)
372         AC_MSG_CHECKING([for directory to install python2 bindings in])
373         if test -z "$PYTHON2_LIB" ; then
374           PYTHON2_LIB=`$PYTHON2 -c 'import os,distutils.sysconfig;print(distutils.sysconfig.get_python_lib(1).replace(os.sep,"/"))'`
375         fi
376         AC_MSG_RESULT([$PYTHON2_LIB])
377         AC_ARG_VAR(PYTHON2_LIB, [Directory to install python2 bindings in])
379         AC_MSG_CHECKING([for python2 libraries to link against])
380         case $host_os in
381         mingw* | pw32*)
382           PYTHON2_LIBS=`$PYTHON2 -c 'import os,sys;print("-L"+os.path.join(sys.prefix,"libs").replace(os.sep,"/")+" -lpython"+sys.version[[:3]].replace(".",""))'` ;;
383         cygwin*)
384           PYTHON2_LIBS=`$PYTHON2 -c 'import os,sys;print("-L"+os.path.join(sys.path[[3]],"config")+" -lpython"+sys.version[[:3]])'` ;;
385         *)
386           PYTHON2_LIBS= ;;
387         esac
388         AC_SUBST(PYTHON2_LIBS)
389         AC_MSG_RESULT([$PYTHON2_LIBS])
391         AC_MSG_CHECKING([for python2 module extension])
392         dnl Usually ".so", but for example, Mac OS X uses ".dylib".
393         PYTHON2_SO=`$PYTHON2 -c 'import distutils.sysconfig;print(distutils.sysconfig.get_config_vars("SO")[[0]])'`
394         AC_SUBST(PYTHON2_SO)
395         AC_MSG_RESULT([$PYTHON2_SO])
396         BINDINGS="$BINDINGS python"
397       else
398         AC_MSG_RESULT([no (install python-dev or python-devel package or similar)])
399         if test yes = "$with_python" ; then
400           AC_MSG_ERROR([Python.h not found])
401         fi
402       fi
403     fi
404   fi
407 if test no != "$with_python3" ; then
408   dnl See comment for AC_PATH_PROGS(SWIG, ...).
409   if test -n "$PYTHON3" ; then
410     AC_PATH_PROGS(PYTHON3, ["$PYTHON3"], [])
411   else
412     AC_PATH_PROGS(PYTHON3, [python3 python], [])
413   fi
414   AC_ARG_VAR(PYTHON3, [Python 3 interpreter])
415   if test -n "$PYTHON3" ; then
416     dnl Require Python 3.2 or newer, as that's the oldest version we can
417     dnl easily test with.  If anyone's keen to support older versions, please
418     dnl test and send in any patches needed to get it to work.
419     AC_MSG_CHECKING([$PYTHON3 version])
420     version=`$PYTHON3 -c 'import sys;print("%d.%d" % sys.version_info[[:2]])' 2>/dev/null`
421     case $version in
422     [3.[2-9]*|3.1[0-9]*|[4-9].*])
423       AC_MSG_RESULT([$version])
424       ;;
425     *)
426       AC_MSG_RESULT([$version (too old)])
427       if test yes = "$with_python3" ; then
428         AC_MSG_ERROR([Only Python 3.2 or newer is supported ($python3 is $version)])
429       fi
430       PYTHON3=
431       ;;
432     esac
433     if test -n "$PYTHON3" ; then
434       PYTHON3_INC=`$PYTHON3 -c 'import os,sysconfig;print(sysconfig.get_path("include").replace(os.sep,"/"))' 2>/dev/null`
435       AC_SUBST(PYTHON3_INC)
436     fi
437     AC_MSG_CHECKING([for python3 sphinx module])
438     if $PYTHON3 -c 'import sphinx' >&5 2>&5 ; then
439       AC_MSG_RESULT([yes])
440     else
441       AC_MSG_RESULT([no])
442       if test yes = "$with_python3" ; then
443         AC_MSG_ERROR([Couldn't import sphinx module for Python3 - try package python3-sphinx])
444       fi
445       PYTHON3=
446     fi
447     if test -n "$PYTHON3" ; then
448       dnl Check that Python.h is there, which is a good way to check that
449       dnl the appropriate python3-dev package has been installed.
450       AC_MSG_CHECKING([for $PYTHON3_INC/Python.h])
451       if test -f "$PYTHON3_INC/Python.h" ; then
452         AC_MSG_RESULT(yes)
453         AC_MSG_CHECKING([for directory to install python3 bindings in])
454         if test -z "$PYTHON3_LIB" ; then
455           PYTHON3_LIB=`$PYTHON3 -c 'import os,sysconfig;print(sysconfig.get_path("platlib").replace(os.sep,"/"))'`
456         fi
457         AC_MSG_RESULT([$PYTHON3_LIB])
458         AC_ARG_VAR(PYTHON3_LIB, [Directory to install python3 bindings in])
460         AC_MSG_CHECKING([for python3 libraries to link against])
461         case $host_os in
462         mingw* | pw32*)
463           PYTHON3_LIBS=`$PYTHON3 -c 'import os,sys;print("-L"+os.path.join(sys.prefix,"libs").replace(os.sep,"/")+" -lpython"+sys.version[[:3]].replace(".",""))'` ;;
464         cygwin*)
465           PYTHON3_LIBS=`$PYTHON3 -c 'import os,sys;print("-L"+os.path.join(sys.path[[3]],"config")+" -lpython"+sys.version[[:3]])'` ;;
466         *)
467           PYTHON3_LIBS= ;;
468         esac
469         AC_SUBST(PYTHON3_LIBS)
470         AC_MSG_RESULT([$PYTHON3_LIBS])
472         AC_MSG_CHECKING([for python3 module extension])
473         dnl Encodes the Python version the module is built for, and ends with
474         dnl the platform-dependent shared object extension (which is `.so` on
475         dnl most Unix-like platforms) - e.g. `.cpython-310-x86_64-linux-gnu.so`
476         PYTHON3_EXT_SUFFIX=`$PYTHON3 -c 'import sysconfig;print(sysconfig.get_config_var("EXT_SUFFIX"))'`
477         AC_SUBST(PYTHON3_EXT_SUFFIX)
478         AC_MSG_RESULT([$PYTHON3_EXT_SUFFIX])
480         AC_MSG_CHECKING([for tag for cached compiled scripts])
481         dnl Since Python 3.3 sys.implementation.cache_tag is the preferred option here,
482         dnl and the old approach issues deprecation warnings since Python 3.7.
483         dnl
484         dnl This needs a shell-level || because Python one line program support is poor.
485         PYTHON3_CACHE_TAG=`$PYTHON3 -c 'import sys;print(sys.implementation.cache_tag)' 2>/dev/null || $PYTHON3 -c 'import imp;print(imp.get_tag())'`
486         AC_SUBST(PYTHON3_CACHE_TAG)
487         AC_MSG_RESULT([$PYTHON3_CACHE_TAG])
489         AC_MSG_CHECKING([for extension of cached and optimized python3 bytecode])
490         dnl We use -O instead of cache_from_source()'s optimization parameter
491         dnl as the latter was only added in Python 3.5.  The fallback is needed
492         dnl as cache_from_source() itself is new in Python 3.4.
493         dnl
494         dnl This needs a shell-level || because Python one line program support
495         dnl is poor.
496         PYTHON3_CACHE_OPT1_EXT=`$PYTHON3 -O -c 'import importlib,sys;print("{1}{2}".format(*importlib.util.cache_from_source("").rpartition(sys.implementation.cache_tag)))' 2>/dev/null || $PYTHON3 -c 'import imp;print(imp.get_tag()+".pyo")'`
497         AC_SUBST(PYTHON3_CACHE_OPT1_EXT)
498         AC_MSG_RESULT([$PYTHON3_CACHE_OPT1_EXT])
500         BINDINGS="$BINDINGS python3"
501       else
502         AC_MSG_RESULT([no (install python3-dev or python3-devel package or similar)])
503         if test yes = "$with_python3" ; then
504           AC_MSG_ERROR([Python.h not found])
505         fi
506       fi
507     fi
508   fi
511 if test x$USE_MAINTAINER_MODE = xyes; then
512   dnl Need python in maintainer mode to run doxy2swig.py.
513   dnl Either Python 2 or 3 is OK for this.
514   if test -n "$PYTHON2" ; then
515     PYTHON=$PYTHON2
516   elif test -n "$PYTHON3" ; then
517     PYTHON=$PYTHON3
518   else
519     AC_PATH_PROGS(PYTHON, [python2 python python3], [])
520   fi
521   test -z "$PYTHON" && AC_MSG_ERROR([python is required in maintainer mode])
524 if test no != "$with_php" ; then
525   dnl See comment for AC_PATH_PROGS(SWIG, ...).
526   if test -n "$PHP_CONFIG" ; then
527     AC_PATH_PROGS(PHP_CONFIG, ["$PHP_CONFIG"], [])
528   fi
529   if test -z "$PHP_CONFIG" ; then
530     AC_PATH_PROGS(PHP_CONFIG, [php-config5 php-config5.6 php-config5.5 php-config], [])
531   fi
532   AC_ARG_VAR(PHP_CONFIG, [php-config utility for PHP5])
533   AC_ARG_VAR(PHP, [PHP5 interpreter (optional - only needed to run PHP5 testsuite with)])
534   if test -n "$PHP_CONFIG" ; then
535     AC_MSG_CHECKING([$PHP_CONFIG version])
536     version=`$PHP_CONFIG --version 2>/dev/null`
537     case $version in
538     dnl 5.6 was the final PHP5 release.
539     5.5.*|5.6.*)
540       AC_MSG_RESULT([$version])
541       PHP_MAJOR_VERSION=`echo "$version"|cut -d. -f1`
542       ;;
543     *)
544       AC_MSG_RESULT([$version (not supported, PHP5 bindings need PHP 5.x where x >= 5)])
545       if test yes = "$with_php" ; then
546         AC_MSG_ERROR([$PHP_CONFIG reports version $version - PHP5 bindings need PHP 5.x where x >= 5])
547       fi
548       with_php=no
549       ;;
550     esac
551     AC_SUBST(PHP_MAJOR_VERSION)
553     if test no != "$with_php" ; then
554       AC_MSG_CHECKING([for PHP5 extension directory])
555       if test -z "$PHP_EXTENSION_DIR" ; then
556         PHP_EXTENSION_DIR=`$PHP_CONFIG --extension-dir`
557       fi
558       AC_MSG_RESULT([$PHP_EXTENSION_DIR])
559       AC_ARG_VAR(PHP_EXTENSION_DIR, [Directory to install PHP5 extensions in])
560     fi
562     if test no != "$with_php" ; then
563       PHP_INC=`$PHP_CONFIG --includes`
564       AC_SUBST(PHP_INC)
565       save_CPPFLAGS=$CPPFLAGS
566       CPPFLAGS="$CPPFLAGS $PHP_INC"
567       dnl One of SGI's SuSE boxes has php-config but no headers.
568       AC_CHECK_HEADER(zend.h, [], [
569         if test yes = "$with_php" ; then
570           AC_MSG_ERROR(['$PHP_CONFIG --includes' reports '$PHP_INC' but zend.h can't be included from there])
571         fi
572         with_php=no], [ ])
573       CPPFLAGS=$save_CPPFLAGS
574     fi
576     if test no != "$with_php" ; then
577       if test x"$PHP" = x ; then
578         AC_MSG_CHECKING([for PHP5 interpreter])
579         dnl PHP5's php-config supports --php-binary, so just use that.
580         PHP=`$PHP_CONFIG --php-binary 2>/dev/null`
581         if test x"$PHP" != x ; then
582           if $PHP -r 'exit(0);' 2> /dev/null ; then
583             if $PHP -r 'exit(PHP_MAJOR_VERSION==5?0:1);' 2> /dev/null ; then
584               AC_MSG_RESULT([$PHP])
585             else
586               dnl We get /usr/bin/php on Debian, which might be PHP7:
587               dnl https://bugs.debian.org/819139
588               if ${PHP}5 -r 'exit(PHP_MAJOR_VERSION==5?0:1);' 2> /dev/null ; then
589                 PHP=${PHP}5
590                 AC_MSG_RESULT([$PHP])
591               else
592                 AC_MSG_RESULT([no ($PHP isn't PHP5)])
593                 PHP=
594               fi
595             fi
596           else
597             AC_MSG_RESULT([no ($PHP does not work)])
598             PHP=
599           fi
600         else
601           AC_MSG_RESULT([not found])
602         fi
603       else
604         AC_PATH_PROGS(PHP, ["$PHP"], [])
605       fi
606       if test x"$PHP" = x ; then
607         AC_MSG_WARN([No PHP5 interpreter found - PHP5 bindings tests will be skipped])
608         dnl The skiptest script just returns exit code 77.
609         PHP='$(top_srcdir)/skiptest'
610       else
611         AC_MSG_CHECKING([for PHP5 path separator])
612         PHP_PATH_SEPARATOR=`$PHP -r 'echo PATH_SEPARATOR;'`
613         AC_SUBST([PHP_PATH_SEPARATOR])
614         AC_MSG_RESULT([$PHP_PATH_SEPARATOR])
615       fi
617       case $host_os in
618       mingw* | pw32*)
619         dnl This is a bit of an informed guess, pending more information from
620         dnl someone who actually has mingw and wants to build the PHP bindings
621         dnl there.  FIXME.
622         PHP_LIBS="-L`$PHP_CONFIG --prefix` -lphp${PHP_MAJOR_VERSION}ts" ;;
623       cygwin*)
624         PHP_LIBS="-lphp${PHP_MAJOR_VERSION}lib" ;;
625       *)
626         PHP_LIBS= ;;
627       esac
628       AC_SUBST(PHP_LIBS)
629       BINDINGS="$BINDINGS php"
630     fi
631   fi
634 if test no != "$with_php7" ; then
635   dnl See comment for AC_PATH_PROGS(SWIG, ...).
636   if test -n "$PHP_CONFIG7" ; then
637     AC_PATH_PROGS(PHP_CONFIG7, ["$PHP_CONFIG7"], [])
638   fi
639   if test -z "$PHP_CONFIG7" ; then
640     AC_PATH_PROGS(PHP_CONFIG7, [php-config7.4 php-config7.3 php-config7.2 php-config7.1 php-config7.0 php-config], [])
641   fi
642   AC_ARG_VAR(PHP_CONFIG7, [php-config utility for PHP7])
643   AC_ARG_VAR(PHP7, [PHP7 interpreter (optional - only needed to run PHP7 testsuite with)])
644   if test -n "$PHP_CONFIG7" ; then
645     AC_MSG_CHECKING([$PHP_CONFIG7 version])
646     version=`$PHP_CONFIG7 --version 2>/dev/null`
647     case $version in
648     [[0123456].*])
649       AC_MSG_RESULT([$version (not supported, PHP7 bindings need PHP 7.x)])
650       if test yes = "$with_php7" ; then
651         AC_MSG_ERROR([$PHP_CONFIG7 reports version $version - PHP7 bindings need 7.x])
652       fi
653       with_php7=no
654       ;;
655     7.*)
656       AC_MSG_RESULT([$version])
657       PHP7_MAJOR_VERSION=`echo "$version"|cut -d. -f1`
658       ;;
659     *)
660       AC_MSG_RESULT([$version (PHP >= 8.0 isn't yet supported)])
661       if test yes = "$with_php7" ; then
662         AC_MSG_ERROR([$PHP_CONFIG7 reports version $version - PHP7 bindings need 7.x])
663       fi
664       with_php7=no
665       ;;
666     esac
667     AC_SUBST(PHP7_MAJOR_VERSION)
669     if test no != "$with_php7" ; then
670       AC_MSG_CHECKING([for PHP7 extension directory])
671       if test -z "$PHP7_EXTENSION_DIR" ; then
672         PHP7_EXTENSION_DIR=`$PHP_CONFIG7 --extension-dir`
673       fi
674       AC_MSG_RESULT([$PHP7_EXTENSION_DIR])
675       AC_ARG_VAR(PHP7_EXTENSION_DIR, [Directory to install PHP7 extensions in])
676     fi
678     if test no != "$with_php7" ; then
679       PHP7_INC=`$PHP_CONFIG7 --includes`
680       AC_SUBST(PHP7_INC)
681     fi
683     if test no != "$with_php7" ; then
684       if test x"$PHP7" = x ; then
685         AC_MSG_CHECKING([for PHP7 interpreter])
686         dnl PHP7's php-config supports --php-binary, so just use that.
687         PHP7=`$PHP_CONFIG7 --php-binary 2>/dev/null`
688         if test x"$PHP7" != x ; then
689           if $PHP7 -r 'exit(0);' 2> /dev/null ; then
690             if $PHP7 -r 'exit(PHP_MAJOR_VERSION==7?0:1);' 2> /dev/null ; then
691               AC_MSG_RESULT([$PHP7])
692             else
693               AC_MSG_RESULT([no ($PHP7 isn't PHP7)])
694               PHP7=
695             fi
696           else
697             AC_MSG_RESULT([no ($PHP7 does not work)])
698             PHP7=
699           fi
700         else
701           AC_MSG_RESULT([not found])
702         fi
703       else
704         AC_PATH_PROGS(PHP7, ["$PHP7"], [])
705       fi
706       if test x"$PHP7" = x ; then
707         AC_MSG_WARN([No PHP7 interpreter found - PHP7 bindings tests will be skipped])
708         dnl The skiptest script just returns exit code 77.
709         PHP7='$(top_srcdir)/skiptest'
710       else
711         AC_MSG_CHECKING([for PHP7 path separator])
712         PHP7_PATH_SEPARATOR=`$PHP7 -r 'echo PATH_SEPARATOR;'`
713         AC_SUBST([PHP7_PATH_SEPARATOR])
714         AC_MSG_RESULT([$PHP7_PATH_SEPARATOR])
715       fi
717       case $host_os in
718       mingw* | pw32*)
719         dnl This is a bit of an informed guess, pending more information from
720         dnl someone who actually has mingw and wants to build the PHP bindings
721         dnl there.  FIXME.
722         PHP7_LIBS="-L`$PHP_CONFIG7 --prefix` -lphp${PHP7_MAJOR_VERSION}ts" ;;
723       cygwin*)
724         PHP7_LIBS="-lphp${PHP7_MAJOR_VERSION}lib" ;;
725       *)
726         PHP7_LIBS= ;;
727       esac
728       AC_SUBST(PHP7_LIBS)
729       BINDINGS="$BINDINGS php7"
730     fi
731   fi
734 if test no != "$with_tcl" ; then
735   dnl The documented minimum requirement is Tcl 8.5.  Older versions may work,
736   dnl but we don't test with them regularly, and they are no longer supported
737   dnl upstream.  Also ::tcl::pckconfig was added in Tcl 8.5, which makes the
738   dnl tests below simpler and more reliable.
739   dnl
740   dnl If you really want to build with an older version, run configure with
741   dnl a lower tcl_min and specify at least TCL_INC explicitly:
742   dnl
743   dnl ./configure tcl_min=8.4 TCL_INC=/usr/include/tcl8.4
744   dnl
745   dnl We definitely need at least Tcl 8.1 for TCL_STUBS.
746   : ${tcl_min=8.5}
747   AC_PATH_PROGS(TCLSH, ["${TCLSH-tclsh}"], [])
748   AC_ARG_VAR(TCLSH, [Tcl interpreter])
749   if test -n "$TCLSH" ; then
750     AC_MSG_CHECKING([$TCLSH version])
751     if echo 'if {$tcl_version < '"$tcl_min"' } { exit 1 }'|$TCLSH 2> /dev/null ; then
752       tcl_version=`echo 'puts "$tcl_version"'|$TCLSH`
753       AC_MSG_RESULT([$tcl_version])
755       AC_ARG_VAR(TCL_LIB, [Directory to install Tcl files into])
756       if test -z "$TCL_LIB" ; then
757         [TCL_LIB=`echo 'foreach d $tcl_pkgPath {if {![regexp {/share(/|$)} $d]} {break}};puts $d'|$TCLSH`]
758       fi
759       AC_SUBST(TCL_LIB)
761       AC_ARG_VAR([TCL_INC], [Directory to include for Tcl headers])
762       if test -z "$TCL_INC" ; then
763         dnl ::tcl::pkgconfig was added in Tcl 8.5.
764         [TCL_INC=`echo 'puts [::tcl::pkgconfig get includedir,runtime]'|$TCLSH 2> /dev/null`]
765       fi
767       dnl Check that the headers are there (the tcl8.N-dev package
768       dnl may not be installed).
769       TCL_CPPFLAGS=
770       AC_MSG_CHECKING([for tcl.h from Tcl $tcl_version])
771       if test x"$TCL_INC" != x && test -f "$TCL_INC/tcl.h" ; then
772         tcl_hdr_version=`awk '($1 == "#define" && $2 == "TCL_VERSION") {print $3}' "$TCL_INC/tcl.h"|sed 's/"//g'`
773         if test x"$tcl_hdr_version" = x"$tcl_version" ; then
774           AC_MSG_RESULT([$TCL_INC/tcl.h])
775           BINDINGS="$BINDINGS tcl8"
776           if test x"$TCL_INC" != x"/usr/include" ; then
777             TCL_CPPFLAGS="-I$TCL_INC"
778           fi
779         else
780           AC_MSG_RESULT([not found])
781           if test yes = "$with_tcl" ; then
782             AC_MSG_ERROR([Found tcl.h from version $tcl_hdr_version, not $tcl_version - specify TCL_INC on configure command line])
783           fi
784           TCLSH=
785         fi
786       else
787         AC_MSG_RESULT([not found])
788         if test yes = "$with_tcl" ; then
789           AC_MSG_ERROR([Can't find tcl.h])
790         fi
791         TCLSH=
792       fi
794       if test -n "$TCLSH" ; then
795         dnl Cygwin needs to link with -ltcl8.5 or similar.
796         TCL_LIBS=
797         case $host_os in
798         cygwin*)
799           AC_CHECK_LIB([tcl$tcl_version], [Tcl_Init],
800                        [TCL_LIBS="-ltcl$tcl_version"],
801                        [AC_MSG_ERROR([libtcl$tcl_version not found])])
802           ;;
803         *)
804           dnl ::tcl::pkgconfig was added in Tcl 8.5, but prior to 8.6 it isn't
805           dnl necessary to link against -ltclstub anyway.
806           [tcl_libdir_runtime=`echo 'puts [::tcl::pkgconfig get libdir,runtime]'|$TCLSH 2> /dev/null`]
807           if test -n "$tcl_libdir_runtime" ; then
808             for x in "/tcl$tcl_version" "" ; do
809               TCLCONFIG_SH=$tcl_libdir_runtime$x/tclConfig.sh
810               if test -r "$TCLCONFIG_SH" ; then
811                 eval "`sed 's/^TCL_STUB_LIB_SPEC=/TCL_LIBS=/p;d' $TCLCONFIG_SH`"
812                 break
813               fi
814             done
815           fi
816           TCL_CPPFLAGS="$TCL_CPPFLAGS -DUSE_TCL_STUBS" ;;
817         esac
818       fi
820       AC_SUBST(TCL_CPPFLAGS)
821       AC_SUBST(TCL_LIBS)
822     else
823       AC_MSG_RESULT([< $tcl_min (too old)])
824       if test yes = "$with_tcl" ; then
825         AC_MSG_ERROR([$TCLSH too old (Tcl $tcl_min or newer required)])
826       fi
827     fi
828   else
829     if test yes = "$with_tcl" ; then
830       AC_MSG_ERROR([tclsh not found])
831     fi
832   fi
835 if test no != "$with_csharp" ; then
836   csc_note=
837   AC_ARG_VAR(CSC, [CSharp compiler command])
838   if test -n "$CSC" ; then
839     AC_PATH_PROGS(CSC, ["$CSC"], [])
840   fi
841   if test -z "$CSC" ; then
842     dnl First we try cli-csc and mono-csc, which are used by Debian and Ubuntu
843     dnl as "alternatives" which can be mapped to the CSharp compiler the admin
844     dnl favours.
845     AC_PATH_PROGS(CSC, [cli-csc mono-csc], [])
846     if test -z "$CSC" ; then
847       dnl mcs is the Mono CSharp compiler, which is a unified compiler
848       dnl available from Mono 2.11 (and also the compiler in Mono 1.0, but
849       dnl that's no longer relevant).
850       AC_PATH_PROGS(CSC, [mcs], [])
851       if test -n "$CSC" ; then
852         dnl There are other tools called mcs (such as /usr/bin/mcs on Tru64),
853         dnl so we check that the mcs we found understands --version which is
854         dnl sufficient to distinguish mono's mcs from the Tru64 one.
855         AC_MSG_CHECKING([whether $CSC is from GNU Mono])
856         if (exec >&5 2>&5;$CSC --version </dev/null;exit $?) ; then
857           AC_MSG_RESULT(yes)
858         else
859           AC_MSG_RESULT(no)
860           CSC=
861           csc_note="$csc_note (found different mcs program)"
862         fi
863       fi
864     fi
865     if test -z "$CSC" ; then
866       dnl csc is the Microsoft CSharp compiler.
867       AC_PATH_PROGS(CSC, [csc], [])
868       if test -n "$CSC" ; then
869         dnl Chicken (the Scheme-to-C compiler) includes a tool called csc so we
870         dnl check if the output from "csc -version" includes the word chicken
871         dnl which is sufficient to distinguish Chicken's csc from Microsoft's
872         dnl csc.exe.
873         AC_MSG_CHECKING([whether $CSC is for CSharp])
874         if $CSC -version 2>/dev/null|grep chicken > /dev/null ; then
875           AC_MSG_RESULT(no)
876           CSC=
877           csc_note="$csc_note (found Chicken csc program)"
878         else
879           AC_MSG_RESULT(yes)
880         fi
881       fi
882     fi
883   fi
885   if test -n "$CSC" ; then
886     AC_ARG_VAR(GACUTIL, [gacutil utility to use for CSharp bindings])
887     if test -n "$GACUTIL" ; then
888       AC_PATH_PROGS(GACUTIL, ["$GACUTIL"], [])
889     fi
890     if test -z "$GACUTIL" ; then
891       AC_PATH_PROGS(GACUTIL, [cli-gacutil gacutil], [])
892     fi
894     AC_ARG_VAR(SN, [sn utility to use for CSharp bindings])
895     if test -n "$SN" ; then
896       AC_PATH_PROGS(SN, ["$SN"], [])
897     fi
898     if test -z "$SN" ; then
899       AC_PATH_PROGS(SN, [cli-sn sn], [])
900     fi
901     if test -n "$GACUTIL" -a -n "$SN" ; then
902       AC_MSG_CHECKING([whether the CSharp compiler works])
903       [echo 'class conftest { public static void Main() { System.Console.WriteLine("OK"); } }' > conftest.cs]
904       if (exec >&5 2>&5;$CSC /out:conftest.exe conftest.cs;exit $?) ; then
905         AC_MSG_RESULT(yes)
906         AC_MSG_CHECKING([whether CSharp programs can just be run])
907         if test OK = "`./conftest.exe 2> /dev/null`" ; then
908           AC_MSG_RESULT(yes)
909           RUN_CSHARP=
910         else
911           AC_MSG_RESULT(no)
912           AC_PATH_PROGS(CLI, ["${CLI-cli}"], [])
913           if test -z "$CLI" ; then
914             AC_PATH_PROGS(CLI, [mono ilrun], [])
915           fi
916           AC_ARG_VAR(CLI, [CSharp bytecode interpreter (optional - only needed to run CSharp testsuite with)])
917           if test -n "$CLI" ; then
918             AC_MSG_CHECKING([whether $CLI can run CSharp programs])
919             if test OK = "`$CLI ./conftest.exe 2> /dev/null`" ; then
920               AC_MSG_RESULT(yes)
921               RUN_CSHARP=$CLI
922             else
923               AC_MSG_RESULT([no - CSharp tests will be skipped])
924               RUN_CSHARP='\$(top_srcdir)/skiptest'
925             fi
926           else
927             AC_MSG_RESULT([not found - CSharp tests will be skipped])
928             RUN_CSHARP='\$(top_srcdir)/skiptest'
929           fi
930         fi
931         AC_SUBST(RUN_CSHARP)
933         AC_MSG_CHECKING([for extra flags for $GACUTIL])
934         GACUTIL_FLAGS='/package $(ASSEMBLY) /gacdir $(libdir) /root $(DESTDIR)$(libdir)'
935         dnl Microsoft's gacutil accepts fewer options than Mono's
936         $GACUTIL /\?|grep '\<Mono\>' >/dev/null || GACUTIL_FLAGS=
937         AC_SUBST([GACUTIL_FLAGS])
938         if test -z "$GACUTIL_FLAGS" ; then
939           AC_MSG_RESULT([no])
940         else
941           AC_MSG_RESULT([$GACUTIL_FLAGS])
942         fi
944         BINDINGS="$BINDINGS csharp"
945       else
946         AC_MSG_RESULT(no)
947         if test yes = "$with_csharp" ; then
948           AC_MSG_ERROR([CSharp compiler $CSC doesn't work])
949         fi
950       fi
951     else
952       if test yes = "$with_csharp" ; then
953         if test -z "$GACUTIL" ; then
954           AC_MSG_ERROR([Mono gacutil not found])
955         elif test -z "$SN" ; then
956           AC_MSG_ERROR([Mono sn not found])
957         fi
958       fi
959     fi
960   else
961     if test yes = "$with_csharp" ; then
962       AC_MSG_ERROR([CSharp compiler not found$csc_note])
963     fi
964   fi
967 JAVA_CPPFLAGS=
968 if test no != "$with_java" ; then
969   AC_PATH_PROGS(JAVA, ["${JAVA-java}"], [],
970         [${JAVA_HOME+$JAVA_HOME/bin:}${JDK_HOME+$JDK_HOME/bin:}$PATH])
971   AC_PATH_PROGS(JAVAC, ["${JAVAC-javac}"], [],
972         [${JAVA_HOME+$JAVA_HOME/bin:}${JDK_HOME+$JDK_HOME/bin:}$PATH])
973   AC_PATH_PROGS(JAR, ["${JAR-jar}"], [],
974         [${JAVA_HOME+$JAVA_HOME/bin:}${JDK_HOME+$JDK_HOME/bin:}$PATH])
975   AC_ARG_VAR(JAVA, [Java interpreter command])
976   AC_ARG_VAR(JAVAC, [Java compiler command])
977   AC_ARG_VAR(JAR, [java jar utility])
978   AC_ARG_VAR(JAVA_HOME, [Pathname of the directory where the JDK is installed])
979   AC_ARG_VAR(JDK_HOME, [Pathname of the directory where the JDK is installed])
980   AC_ARG_VAR(JNI_INCLUDE_DIR, [Pathname of the directory where jni.h is installed])
981   if test -n "$JAVA" -a -n "$JAVAC" -a -n "$JAR" ; then
982     dnl Eric says:
983     dnl  The JNI library *requires* "Java 2", which is 1.2 or better.
984     dnl
985     dnl So checking for jni.h presumably implicitly checks we have "Java 2".
986     dnl Note: jni.h #defines JNI_VERSION_1_[12468] (but not 3, 5 or 7 it seems).
987     dnl So we could check for one of these if we want to check for a particular
988     dnl JDK version...
989     java_ok=no
990     AC_CHECK_HEADER([jni.h], [java_ok=yes], [
991       dnl We need to look for jni.h in /usr/lib/jvm/java-gcj/include on some
992       dnl Debian and Ubuntu boxes at least.  And on Mac OS X, jni.h lives
993       dnl in /System/Library/Frameworks/JavaVM.framework/Headers.
994       SAVE_CPPFLAGS=$CPPFLAGS
995       real_javac=$JAVAC
996       dnl Avoid endlessly traversing if there's a symlink loop.
997       for count in 1 2 3 4 5 6 7 8 9 ; do
998         r=`readlink "$real_javac"`
999         test -n "$r" || break
1000         real_javac=$r
1001       done
1002       dnl Translate ".../bin/javac" to ".../include".
1003       [rel_jnidir=`echo "$real_javac"|sed 's!/[^/]*/[^/]*$!/include!'`]
1004       for jnidir in \
1005           $JNI_INCLUDE_DIR \
1006           ${JAVA_HOME+"$JAVA_HOME/include"} \
1007           ${JDK_HOME+"$JDK_HOME/include"} \
1008           "$rel_jnidir" \
1009           /System/Library/Frameworks/JavaVM.framework/Headers ; do
1010         CPPFLAGS="$SAVE_CPPFLAGS -I$jnidir"
1011         AC_MSG_CHECKING([for jni.h in $jnidir])
1012         if test -f "$jnidir/jni.h" ; then
1013           AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <jni.h>]])], [java_ok=yes])
1014           if test yes = $java_ok ; then
1015             AC_MSG_RESULT([yes])
1016             JAVA_CPPFLAGS=-I$jnidir
1017             break
1018           fi
1020           dnl For OpenJDK (and maybe others) we have to specify an extra -I
1021           dnl option for an OS-specific subdirectory containing a "jni_md.h"
1022           dnl header which is included by "jni.h".  Sadly we seem to need to
1023           dnl hardcode a mapping for these platform names - the list below
1024           dnl was determined by inspecting the source code of OpenJDK 8.
1025           jni_host_os=
1026           case $host_os in
1027             linux*)
1028               jni_host_os=linux ;;
1029             solaris*)
1030               jni_host_os=solaris ;;
1031             mingw* | pw32* | cygwin*)
1032               jni_host_os=win32 ;;
1033             darwin*)
1034               jni_host_os=darwin ;;
1035             *bsd*)
1036               jni_host_os=bsd ;;
1037             aix*)
1038               jni_host_os=aix ;;
1039           esac
1040           if test -n "$jni_host_os" ; then
1041             CPPFLAGS="$CPPFLAGS -I$jnidir/$jni_host_os"
1042             AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <jni.h>]])], [java_ok=yes])
1043             if test yes = $java_ok ; then
1044               AC_MSG_RESULT([yes, requires additional -I$jnidir/$jni_host_os])
1045               JAVA_CPPFLAGS="-I$jnidir -I$jnidir/$jni_host_os"
1046               break
1047             fi
1048           fi
1049           AC_MSG_RESULT([found, but not usable])
1051           CPPFLAGS="$SAVE_CPPFLAGS -I$jnidir"
1052         else
1053           AC_MSG_RESULT([no])
1054         fi
1055       done
1056       CPPFLAGS=$SAVE_CPPFLAGS
1057       test noyes = $java_ok$with_java && AC_MSG_ERROR([jni.h not found])
1058       ], [ ])
1059     AC_SUBST(JAVA_CPPFLAGS)
1060     if test yes = $java_ok ; then
1061       AC_MSG_CHECKING([for Java path separator])
1062       [echo 'public class conftest { public static void main(String[] args) { System.out.println(System.getProperty("path.separator")); } }' > conftest.java]
1063       if (exec >&5 2>&5;$JAVAC conftest.java;exit $?) ; then
1064         JAVA_PATHSEP=`$JAVA conftest 2>&5`
1065         AC_SUBST(JAVA_PATHSEP)
1066         if test -n "$JAVA_PATHSEP" ; then
1067           AC_MSG_RESULT($JAVA_PATHSEP)
1068           BINDINGS="$BINDINGS java"
1070           dnl If -Xcheck:jni is supported then run tests with it.
1071           dnl
1072           dnl ... except that with OpenJDK 8 and 9 -Xcheck:jni seems to report
1073           dnl false positives and so can't usefully be turned on in this
1074           dnl situation.  Recheck this with future versions.
1075 dnl       AC_MSG_CHECKING([for $JAVA -Xcheck:jni option])
1076 dnl       JAVA_PATHSEP2=`$JAVA conftest 2>&5`
1077           JAVA_CHECK_JNI_OPTION=
1078 dnl       if test "$JAVA_PATHSEP" = "$JAVA_PATHSEP2" ; then
1079 dnl         JAVA_CHECK_JNI_OPTION=-Xcheck:jni
1080 dnl         AC_MSG_RESULT([yes])
1081 dnl       else
1082 dnl         AC_MSG_RESULT([no])
1083 dnl       fi
1084           AC_SUBST([JAVA_CHECK_JNI_OPTION])
1085         else
1086           AC_MSG_RESULT([failed to run test program])
1087           java_ok=no
1088         fi
1089       else
1090         AC_MSG_RESULT([failed to compile test program])
1091         java_ok=no
1092       fi
1093       if test no = "$java_ok" ; then
1094         test yes = "$with_java" && AC_MSG_ERROR([Couldn't compile and run a simple Java test program])
1095       fi
1096     fi
1097   else
1098     if test yes = "$with_java" ; then
1099       if test -z "$JAVA" ; then
1100         AC_MSG_ERROR([java not found])
1101       elif test -z "$JAVAC" ; then
1102         AC_MSG_ERROR([javac not found])
1103       elif test -z "$JAR" ; then
1104         AC_MSG_ERROR([jar not found])
1105       fi
1106     fi
1107   fi
1110 if test no != "$with_ruby" ; then
1111   dnl See comment for AC_PATH_PROGS(SWIG, ...).
1112   if test -n "$RUBY" ; then
1113     AC_PATH_PROGS(RUBY, ["$RUBY"], [])
1114   else
1115     AC_PATH_PROGS(RUBY, [ruby], [])
1116   fi
1117   AC_ARG_VAR(RUBY, [Ruby interpreter])
1118   if test -n "$RUBY" ; then
1119     dnl Require Ruby 2.1 or newer.
1120     AC_MSG_CHECKING([$RUBY version])
1121     dnl RUBY_VERSION works with 1.6.  Once we've checked we have at least 1.8
1122     dnl we can safely use RbConfig below (RbConfig requires Ruby 1.8).
1123     version=`$RUBY -e 'print RUBY_VERSION' 2>/dev/null`
1124     case $version in
1125     "")
1126       AC_MSG_RESULT([\$RUBY -e 'print RUBY_VERSION' didn't work])
1127       if test yes = "$with_ruby" ; then
1128         AC_MSG_ERROR([Working Ruby interpreter not found])
1129       fi
1130       RUBY=
1131       ;;
1132     [[01].*|2.0.*])
1133       AC_MSG_RESULT([$version (too old)])
1134       if test yes = "$with_ruby" ; then
1135         AC_MSG_ERROR([Only Ruby 2.1 or newer is supported ($RUBY is $version)])
1136       fi
1137       RUBY=
1138       ;;
1139     esac
1140     if test -n "$RUBY" ; then
1141       AC_MSG_RESULT([$version])
1142       AC_ARG_VAR(RUBY_INC, [Directory where ruby.h can be found])
1143       if test -z "$RUBY_INC" ; then
1144         dnl Ruby 1.9 added rubyhdrdir.
1145         [RUBY_INC=`$RUBY -rrbconfig -e 'print RbConfig::CONFIG["rubyhdrdir"]'`]
1146       fi
1147       AC_SUBST(RUBY_INC)
1148       dnl Check that ruby.h is there, which is a good way to check that
1149       dnl the appropriate ruby-dev package has been installed.
1150       AC_MSG_CHECKING([for $RUBY_INC/ruby.h])
1151       if test -f "$RUBY_INC/ruby.h" ; then
1152         AC_MSG_RESULT(yes)
1154         AC_ARG_VAR(RUBY_INC_ARCH, [Directory where ruby/config.h can be found])
1155         if test -z "$RUBY_INC_ARCH" ; then
1156           dnl Ruby 2.0 and later have rubyarchhdrdir.
1157           [RUBY_INC_ARCH=`$RUBY -rrbconfig -e 'print RbConfig::CONFIG["rubyarchhdrdir"]'`]
1158         fi
1159         AC_SUBST(RUBY_INC_ARCH)
1161         AC_ARG_VAR(RUBY_LIB, [Directory to install ruby files into])
1162         if test -z "$RUBY_LIB" ; then
1163           [RUBY_LIB=`$RUBY -rrbconfig -e 'print RbConfig::CONFIG["sitelibdir"]'`]
1164         fi
1165         AC_SUBST(RUBY_LIB)
1167         AC_ARG_VAR(RUBY_LIB_ARCH, [Directory to install ruby binary modules into])
1168         if test -z "$RUBY_LIB_ARCH" ; then
1169           [RUBY_LIB_ARCH=`$RUBY -rrbconfig -e 'print RbConfig::CONFIG["sitearchdir"]'`]
1170         fi
1171         AC_SUBST(RUBY_LIB_ARCH)
1173         RUBY_LIBS=
1174         if test unsupported = "$allow_undefined_flag" ; then
1175           dnl For Microsoft Windows and a few other platforms.
1176           [RUBY_LIBS=`$RUBY -rrbconfig -e 'print RbConfig::CONFIG["LIBRUBYARG"]'`]
1177         fi
1178         AC_SUBST(RUBY_LIBS)
1180         dnl rdoc is included as part of the Ruby core distribution, so run it
1181         dnl at build time rather shipping the rather large generated output in
1182         dnl our source tarball.
1183         if test -n "$RDOC" ; then
1184           AC_PATH_PROGS(RDOC, ["$RDOC"], [])
1185         else
1186           dnl Try replace the *last* 'ruby' with 'rdoc'.
1187           rdoc_best_guess=`echo "$RUBY"|sed 's,\(.*\)ruby,\1rdoc,'`
1188           AC_PATH_PROGS(RDOC, ["$rdoc_best_guess"], [])
1189           if test -z "$RDOC"; then
1190             AC_PATH_PROGS(RDOC, [rdoc], [])
1191           fi
1192         fi
1193         if test -n "$RDOC"; then
1194           BINDINGS="$BINDINGS ruby"
1195         fi
1196         AC_ARG_VAR([RDOC], [Ruby documentation generator])
1197       else
1198         AC_MSG_RESULT([no (install ruby-dev or ruby-devel package or similar)])
1199         if test yes = "$with_ruby" ; then
1200           AC_MSG_ERROR([ruby.h not found])
1201         fi
1202       fi
1203       RUBY_DLEXT=`$RUBY -rrbconfig -e 'print RbConfig::CONFIG[["DLEXT"]]'`
1204       AC_SUBST(RUBY_DLEXT)
1205     fi
1206   fi
1209 if test no != "$with_perl" ; then
1210   AC_PATH_PROGS(PERL, ["${PERL-perl}"], [])
1211   AC_ARG_VAR(PERL, [Perl interpreter])
1212   if test -n "$PERL" ; then
1213     if test -z "$PERL_INC" ; then
1214       PERL_INC=`$PERL -MConfig -e 'print $Config{archlibexp}, "/CORE"'`
1215     fi
1216     AC_SUBST(PERL_INC)
1218     AC_ARG_VAR(PERL_ARCH, [Directory to install architecture-dependent perl files into])
1219     if test -z "$PERL_ARCH" ; then
1220       PERL_ARCH=`$PERL -MConfig -e 'print $Config{installsitearch}'`
1221     fi
1222     AC_SUBST(PERL_ARCH)
1224     AC_ARG_VAR(PERL_LIB, [Directory to install architecture-independent perl files into])
1225     if test -z "$PERL_LIB" ; then
1226       PERL_LIB=`$PERL -MConfig -e 'print $Config{installsitelib}'`
1227     fi
1228     AC_SUBST(PERL_LIB)
1230     AC_ARG_VAR(PERL_SO, [Extension for compiled Perl modules])
1231     if test -z "$PERL_SO" ; then
1232       PERL_SO=`$PERL -MConfig -e 'print ".", $Config{dlext}'`
1233     fi
1234     AC_SUBST(PERL_SO)
1236     if test -z "$PERL_XAPIAN_VERSION" ; then
1237       dnl snapshot versions look like 1.2.3_git123
1238       case $PACKAGE_VERSION in
1239       *_git*)
1240         PERL_XAPIAN_VERSION=`echo "$PACKAGE_VERSION"|sed 's/_git/./'` ;;
1241       *)
1242         PERL_XAPIAN_VERSION=$PACKAGE_VERSION.0 ;;
1243       esac
1244     fi
1245     AC_SUBST(PERL_XAPIAN_VERSION)
1247     BINDINGS="$BINDINGS perl"
1248   else
1249     if test yes = "$with_perl" ; then
1250       AC_MSG_ERROR([perl not found])
1251     fi
1252   fi
1255 if test no != "$with_lua" ; then
1256   AC_PATH_PROGS(LUA, ["${LUA-lua}"], [])
1257   AC_ARG_VAR(LUA, [lua interpreter])
1258   if test -n "$LUA" ; then
1259     dnl We need Lua 5.1 or later.
1260     AC_MSG_CHECKING([$LUA version])
1261     lua_version=`$LUA -e 'print(_VERSION)' | cut -f 2 -d ' ' 2>&AS_MESSAGE_LOG_FD`
1263     case $lua_version in
1264     [[01234]].*|5.0|5.0.*)
1265       AC_MSG_RESULT([$lua_version < 5.1 (too old)])
1266       if test yes = "$with_lua" ; then
1267         AC_MSG_ERROR([$LUA too old (Lua 5.1 or newer required)])
1268       fi
1269       LUA=
1270       ;;
1271     "")
1272       AC_MSG_RESULT([\$LUA -e 'print(_VERSION)' | cut -f 2 -d ' ' didn't work])
1274       if test yes = "$with_lua" ; then
1275         AC_MSG_ERROR([Working Lua interpreter not found])
1276       fi
1277       LUA=
1278       ;;
1279     esac
1281     if test -n "$LUA" ; then
1282       AC_MSG_RESULT([$lua_version])
1284       AC_ARG_VAR([LUA_LIB], [Directory to install compiled Lua modules into])
1285       AC_ARG_VAR([LUA_SO], [Extension for compiled Lua modules (e.g. LUA_SO=.so)])
1286       AC_MSG_CHECKING([for directory to install compiled Lua modules into])
1287       if test -z "$LUA_LIB" -o -z "$LUA_SO" ; then
1288         lua_cpath=`$LUA -e 'require("package") print(package.cpath)'`
1289         dnl Look for the first absolute path in lua_cpath which has leaf
1290         dnl "?.<ext>" and put the directory part into lua_lib and <ext> into
1291         dnl lua_so.  If LUA_SO was specified by the user, only consider
1292         dnl entries where <ext> matches LUA_SO.
1293         lua_lib=
1294         lua_so=
1295         case $LUA_SO in
1296           "")
1297            [lua_so_pat='[a-zA-Z][a-zA-Z]*'] ;;
1298           .*)
1299             dnl If LUA_SO has a leading '.', remove it.
1300             lua_so_pat=`AS_ECHO("$LUA_SO")|sed 's/^\.//'` ;;
1301           *)
1302             dnl If LUA_SO was specified without a leading '.', add one to the
1303             dnl value substituted into Makefile.in.
1304             lua_so_pat=$LUA_SO
1305             LUA_SO=.$LUA_SO
1306             ;;
1307         esac
1308         while test x"$lua_cpath" != x ; do
1309           [lua_lib=`expr X"$lua_cpath" : X'\([^;]*\)'`]
1310           lua_so=.`expr X"$lua_lib" : X'/.*/?\.\('"$lua_so_pat"'\)$'`
1311           case $lua_so in
1312             .|.lua)
1313               dnl If someone has foolishly put ?.lua in cpath, ignore them.
1314               lua_lib=
1315               ;;
1316             *)
1317               lua_lib=`expr X"$lua_lib" : X'\(/.*\)/?\.'"$lua_so_pat"'$'`
1318               break ;;
1319           esac
1320           [lua_cpath=`expr X"$lua_cpath" : X'[^;]*;*\(.*\)'`]
1321         done
1322         test -n "$LUA_LIB" || LUA_LIB=$lua_lib
1323         test -n "$LUA_SO" || LUA_SO=$lua_so
1324       fi
1325       if test -z "$LUA_LIB"; then
1326         AC_MSG_RESULT([not found])
1327       else
1328         AC_MSG_RESULT([$LUA_LIB])
1329       fi
1330       AC_SUBST([LUA_LIB])
1332       AC_MSG_CHECKING([for extension to use for compiled Lua modules])
1333       if test -z "$LUA_SO"; then
1334         AC_MSG_RESULT([not found])
1335       else
1336         AC_MSG_RESULT([$LUA_SO])
1337       fi
1338       AC_SUBST([LUA_SO])
1340       AC_MSG_CHECKING([for Lua header files])
1341       AC_ARG_VAR([LUA_INC], [Directory to include for lua headers])
1342       if test -z "$LUA_INC" ; then
1343         dirs="/usr/include/lua$lua_version /usr/local/include/lua$lua_version"
1344         for i in $dirs ; do
1345           if test -r "$i/lua.h"; then
1346             LUA_INC=$i
1347             break
1348           fi
1349         done
1350       fi
1352       if test -z "$LUA_INC" ; then
1353         AC_MSG_RESULT([not found])
1354       else
1355         AC_MSG_RESULT([$LUA_INC])
1356         BINDINGS="$BINDINGS lua"
1357         LUA_CPPFLAGS="-I$LUA_INC"
1358       fi
1359       AC_SUBST([LUA_CPPFLAGS])
1360     fi
1361   else
1362     if test yes = "$with_lua" ; then
1363       AC_MSG_ERROR([lua not found])
1364     fi
1365   fi
1368 AC_SUBST(BINDINGS)
1370 case $BINDINGS in
1371 *python*) dnl Matches python and/or python3
1372   dnl C++11 has thread_local
1373   dnl GCC and some others have __thread
1374   dnl MSVC and some others have __declspec(thread)
1375   AC_MSG_CHECKING([for thread-local storage qualifier])
1376   AC_ARG_VAR([THREAD_LOCAL], [thread-local storage qualifier])
1377   if test -z "$THREAD_LOCAL" ; then
1378     for t in thread_local __thread '__declspec(thread)' ; do
1379       AC_COMPILE_IFELSE([AC_LANG_SOURCE([[static $t void * p;]])],
1380                         [THREAD_LOCAL=$t; break])
1381     done
1382   fi
1383   if test -z "$THREAD_LOCAL" ; then
1384     AC_MSG_RESULT([unknown, disabling thread-local support])
1385   else
1386     AC_MSG_RESULT([$THREAD_LOCAL])
1387     AC_DEFINE_UNQUOTED([THREAD_LOCAL], [$THREAD_LOCAL], [Thread local storage qualifier (undefined if no TLS)])
1388   fi
1389   ;;
1390 esac
1392 dnl Set flags to control warnings (enable more, or disable annoying ones)
1393 dnl and other compiler specific flags.
1394 SWIG_CXXFLAGS=
1395 if test yes = "$GXX" ; then
1396   dnl Python itself is compiled with -fno-strict-aliasing, and it appears
1397   dnl it's safest to follow this lead when compiling the SWIG generated
1398   dnl interface code.  E.g.:
1399   dnl   https://article.gmane.org/gmane.comp.gcc.devel/74692
1400   dnl The code SWIG generates for other languages seems to have similar
1401   dnl issues too, so just turn this on for all of them.
1402   dnl
1403   dnl There's no need to check -fno-strict-aliasing is supported as it works
1404   dnl with GCC 2.95 and we don't support anything older.
1405   SWIG_CXXFLAGS="-fno-strict-aliasing"
1407   dnl We need to explicitly link against -lstdc++ on OpenBSD (discovered
1408   dnl on OpenBSD 3.7 with GCC 3.3.5 but this appears to be due to a
1409   dnl deliberate decision on the part of OpenBSD developers).  Luckily
1410   dnl we can just always specify -lstdc++ explicitly if GCC is the
1411   dnl compiler and libtool will eliminate the duplicate on other
1412   dnl platforms.
1413   XAPIAN_LIBS="$XAPIAN_LIBS -lstdc++"
1415   dnl Intel's C++ compiler is identified as "GXX" by autoconf's test - check
1416   dnl which we actually have.
1417   AC_EGREP_CPP(yes,
1418     [#ifdef __INTEL_COMPILER
1419      yes
1420      #endif
1421     ],
1422     [
1423       dnl Intel's compiler:
1424       dnl
1425       dnl -w1 stops the avalanche of uninteresting "remark" messages.
1426       dnl -wd... disables warnings which don't have good code workarounds.
1427       dnl
1428       dnl Swig generated code gives lots of unused and uninitialized warnings.
1429       dnl They're non-harmful, so suppress them.
1430       SWIG_CXXFLAGS="$SWIG_CXXFLAGS -Wall -w1 -wd177,1572"
1431     ],
1432     [
1433       dnl GCC or clang:
1434       dnl
1435       dnl Swig generated code gives lots of unused and uninitialized warnings.
1436       dnl They're non-harmful, so suppress them.
1437       SWIG_CXXFLAGS="$SWIG_CXXFLAGS -Wall -Wno-unused -Wno-uninitialized"
1438     ])
1440   if test no != "$enable_visibility"; then
1441     dnl GCC doesn't support symbol visibility on all platforms (e.g. it isn't
1442     dnl supported on mingw and visibility attributes result in warnings).
1443     AC_MSG_CHECKING([if $CXX -fvisibility=hidden -fvisibility-inlines-hidden works])
1444     if echo 'int bar() __attribute__((visibility("default"))); int baz() __attribute__((visibility("internal"))); int bar() { return 6; } int baz() { return 7; } int foo() {return 42;}'|$CXX -Werror -fvisibility=hidden -fvisibility-inlines-hidden -c -oconftest.o -xc++ - >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD ; then
1445       AC_MSG_RESULT([yes])
1446       SWIG_CXXFLAGS="$SWIG_CXXFLAGS -fvisibility=hidden -fvisibility-inlines-hidden"
1447     else
1448       AC_MSG_RESULT([no])
1449     fi
1450   fi
1452 AC_SUBST(SWIG_CXXFLAGS)
1454 dnl Restore CXXFLAGS to those the user specified or autoconf defaulted to.
1455 CXXFLAGS=$save_CXXFLAGS
1457 dnl Required for auto regeneration to work in a combined maintainer-mode tree.
1458 : ${AUTOM4TE=autom4te}
1459 AC_SUBST([AUTOM4TE])
1461 AC_CONFIG_FILES([Makefile
1462  doxygen_xml.conf
1463  xapian-version.h
1464  python/Makefile python/docs/conf.py python/version.i
1465  python3/Makefile python3/docs/conf.py python3/version.i
1466  php/Makefile
1467  php7/Makefile
1468  java/Makefile
1469  tcl8/Makefile tcl8/pkgIndex.tcl
1470  csharp/Makefile csharp/AssemblyInfo.cs
1471  ruby/Makefile
1472  perl/Makefile
1473  lua/Makefile
1474  xapian-bindings.spec
1475  ])
1476 AC_OUTPUT
1478 echo ""
1479 if test -z "$BINDINGS" ; then
1480   echo "*** Not found the required tools for building bindings for any"
1481   echo "*** supported language!"
1482   echo "***"
1483   echo "*** You may need to install -dev or -devel packages for the languages"
1484   echo "*** you want to build bindings for."
1485   echo "***"
1486   echo "*** For details of how to point configure at tools not on PATH, see:"
1487   echo "***     ./configure --help"
1488 else
1489   echo "*** Building bindings for languages:" $BINDINGS
1491 echo ""
1492 if test "$COMPAT_VERSION" != "$XAPIAN_VERSION" ; then
1493   release_series=[`echo "$COMPAT_VERSION"|sed 's/[0-9][0-9]*$//'`]
1494   case $XAPIAN_VERSION in
1495   $release_series*) ;;
1496   *)
1497     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.])
1498     ;;
1499   esac
1500   dnl 0.8.2 was the first version which set XAPIAN_VERSION
1501   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.])