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