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