1 # ===========================================================================
2 # http://autoconf-archive.cryp.to/ac_python_devel.html
3 # ===========================================================================
7 # AC_PYTHON_DEVEL([version])
11 # Note: Defines as a precious variable "PYTHON_VERSION". Don't override it
12 # in your configure.ac.
14 # This macro checks for Python and tries to get the include path to
15 # 'Python.h'. It provides the $(PYTHON_CPPFLAGS) and $(PYTHON_LDFLAGS)
16 # output variables. It also exports $(PYTHON_EXTRA_LIBS) and
17 # $(PYTHON_EXTRA_LDFLAGS) for embedding Python in your code.
19 # You can search for some particular version of Python by passing a
20 # parameter to this macro, for example ">= '2.3.1'", or "== '2.4'". Please
21 # note that you *have* to pass also an operator along with the version to
22 # match, and pay special attention to the single quotes surrounding the
23 # version number. Don't use "PYTHON_VERSION" for this: that environment
24 # variable is declared as precious and thus reserved for the end-user.
26 # This macro should work for all versions of Python >= 2.1.0. As an end
27 # user, you can disable the check for the python version by setting the
28 # PYTHON_NOVERSIONCHECK environment variable to something else than the
31 # If you need to use this macro for an older Python version, please
32 # contact the authors. We're always open for feedback.
40 # Copyright (c) 2008 Sebastian Huber <sebastian-huber@web.de>
41 # Copyright (c) 2008 Alan W. Irwin <irwin@beluga.phys.uvic.ca>
42 # Copyright (c) 2008 Rafael Laboissiere <rafael@laboissiere.net>
43 # Copyright (c) 2008 Andrew Collier <colliera@ukzn.ac.za>
44 # Copyright (c) 2008 Matteo Settenvini <matteo@member.fsf.org>
45 # Copyright (c) 2008 Horst Knorr <hk_classes@knoda.org>
47 # This program is free software: you can redistribute it and/or modify it
48 # under the terms of the GNU General Public License as published by the
49 # Free Software Foundation, either version 3 of the License, or (at your
50 # option) any later version.
52 # This program is distributed in the hope that it will be useful, but
53 # WITHOUT ANY WARRANTY; without even the implied warranty of
54 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
55 # Public License for more details.
57 # You should have received a copy of the GNU General Public License along
58 # with this program. If not, see <http://www.gnu.org/licenses/>.
60 # As a special exception, the respective Autoconf Macro's copyright owner
61 # gives unlimited permission to copy, distribute and modify the configure
62 # scripts that are the output of Autoconf when processing the Macro. You
63 # need not follow the terms of the GNU General Public License when using
64 # or distributing such scripts, even though portions of the text of the
65 # Macro appear in them. The GNU General Public License (GPL) does govern
66 # all other use of the material that constitutes the Autoconf Macro.
68 # This special exception to the GPL applies to versions of the Autoconf
69 # Macro released by the Autoconf Macro Archive. When you make and
70 # distribute a modified version of the Autoconf Macro, you may extend this
71 # special exception to the GPL to apply to your modified version as well.
73 AC_DEFUN([AC_PYTHON_DEVEL],[
75 # Allow the use of a (user set) custom python version
77 AC_ARG_VAR([PYTHON_VERSION],[The installed Python
78 version to use, for example '2.3'. This string
79 will be appended to the Python interpreter
82 AC_PATH_PROG([PYTHON],[python[$PYTHON_VERSION]])
83 if test -z "$PYTHON"; then
84 AC_MSG_ERROR([Cannot find python$PYTHON_VERSION in your system path])
89 # Check for a version of Python >= 2.1.0
91 AC_MSG_CHECKING([for a version of Python >= '2.1.0'])
92 ac_supports_python_ver=`$PYTHON -c "import sys, string; \
93 ver = string.split(sys.version)[[0]]; \
94 print ver >= '2.1.0'"`
95 if test "$ac_supports_python_ver" != "True"; then
96 if test -z "$PYTHON_NOVERSIONCHECK"; then
99 This version of the AC@&t@_PYTHON_DEVEL macro
100 doesn't work properly with versions of Python before
101 2.1.0. You may need to re-run configure, setting the
102 variables PYTHON_CPPFLAGS, PYTHON_LDFLAGS, PYTHON_SITE_PKG,
103 PYTHON_EXTRA_LIBS and PYTHON_EXTRA_LDFLAGS by hand.
104 Moreover, to disable this check, set PYTHON_NOVERSIONCHECK
105 to something else than an empty string.
108 AC_MSG_RESULT([skip at user request])
115 # if the macro parameter ``version'' is set, honour it
117 if test -n "$1"; then
118 AC_MSG_CHECKING([for a version of Python $1])
119 ac_supports_python_ver=`$PYTHON -c "import sys, string; \
120 ver = string.split(sys.version)[[0]]; \
122 if test "$ac_supports_python_ver" = "True"; then
126 AC_MSG_ERROR([this package requires Python $1.
127 If you have it installed, but it isn't the default Python
128 interpreter in your system path, please pass the PYTHON_VERSION
129 variable to configure. See ``configure --help'' for reference.
136 # Check if you have distutils, else fail
138 AC_MSG_CHECKING([for the distutils Python package])
139 ac_distutils_result=`$PYTHON -c "import distutils" 2>&1`
140 if test -z "$ac_distutils_result"; then
144 AC_MSG_ERROR([cannot import Python module "distutils".
145 Please check your Python installation. The error was:
146 $ac_distutils_result])
151 # Check for Python include path
153 AC_MSG_CHECKING([for Python include path])
154 if test -z "$PYTHON_CPPFLAGS"; then
155 python_path=`$PYTHON -c "import distutils.sysconfig; \
156 print distutils.sysconfig.get_python_inc();"`
157 if test -n "${python_path}"; then
158 python_path="-I$python_path"
160 PYTHON_CPPFLAGS=$python_path
162 AC_MSG_RESULT([$PYTHON_CPPFLAGS])
163 AC_SUBST([PYTHON_CPPFLAGS])
166 # Check for Python library path
168 AC_MSG_CHECKING([for Python library path])
169 if test -z "$PYTHON_LDFLAGS"; then
170 # (makes two attempts to ensure we've got a version number
171 # from the interpreter)
172 py_version=`$PYTHON -c "from distutils.sysconfig import *; \
173 from string import join; \
174 print join(get_config_vars('VERSION'))"`
175 if test "$py_version" == "[None]"; then
176 if test -n "$PYTHON_VERSION"; then
177 py_version=$PYTHON_VERSION
179 py_version=`$PYTHON -c "import sys; \
180 print sys.version[[:3]]"`
184 PYTHON_LDFLAGS=`$PYTHON -c "from distutils.sysconfig import *; \
185 from string import join; \
186 print '-L' + get_python_lib(0,1), \
187 '-lpython';"`$py_version
189 AC_MSG_RESULT([$PYTHON_LDFLAGS])
190 AC_SUBST([PYTHON_LDFLAGS])
193 # Check for site packages
195 AC_MSG_CHECKING([for Python site-packages path])
196 if test -z "$PYTHON_SITE_PKG"; then
197 PYTHON_SITE_PKG=`$PYTHON -c "import distutils.sysconfig; \
198 print distutils.sysconfig.get_python_lib(0,0);"`
200 AC_MSG_RESULT([$PYTHON_SITE_PKG])
201 AC_SUBST([PYTHON_SITE_PKG])
204 # libraries which must be linked in when embedding
206 AC_MSG_CHECKING(python extra libraries)
207 if test -z "$PYTHON_EXTRA_LIBS"; then
208 PYTHON_EXTRA_LIBS=`$PYTHON -c "import distutils.sysconfig; \
209 conf = distutils.sysconfig.get_config_var; \
210 print conf('LOCALMODLIBS'), conf('LIBS')"`
212 AC_MSG_RESULT([$PYTHON_EXTRA_LIBS])
213 AC_SUBST(PYTHON_EXTRA_LIBS)
216 # linking flags needed when embedding
218 AC_MSG_CHECKING(python extra linking flags)
219 if test -z "$PYTHON_EXTRA_LDFLAGS"; then
220 PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "import distutils.sysconfig; \
221 conf = distutils.sysconfig.get_config_var; \
222 print conf('LINKFORSHARED')"`
224 AC_MSG_RESULT([$PYTHON_EXTRA_LDFLAGS])
225 AC_SUBST(PYTHON_EXTRA_LDFLAGS)
228 # final check to see if everything compiles alright
230 AC_MSG_CHECKING([consistency of all components of python development environment])
232 # save current global flags
233 LIBS="$ac_save_LIBS $PYTHON_LDFLAGS"
234 CPPFLAGS="$ac_save_CPPFLAGS $PYTHON_CPPFLAGS"
239 ],[pythonexists=yes],[pythonexists=no])
241 AC_MSG_RESULT([$pythonexists])
243 if test ! "$pythonexists" = "yes"; then
245 Could not link test program to Python. Maybe the main Python library has been
246 installed in some non-standard library path. If so, pass it to configure,
247 via the LDFLAGS environment variable.
248 Example: ./configure LDFLAGS="-L/usr/non-standard-path/python/lib"
249 ============================================================================
251 You probably have to install the development version of the Python package
252 for your distribution. The exact name of this package varies among them.
253 ============================================================================
258 # turn back to default flags
259 CPPFLAGS="$ac_save_CPPFLAGS"
266 # ===========================================================================
267 # http://autoconf-archive.cryp.to/ac_pkg_swig.html
268 # ===========================================================================
272 # AC_PROG_SWIG([major.minor.micro])
276 # This macro searches for a SWIG installation on your system. If found you
277 # should call SWIG via $(SWIG). You can use the optional first argument to
278 # check if the version of the available SWIG is greater than or equal to
279 # the value of the argument. It should have the format: N[.N[.N]] (N is a
280 # number between 0 and 999. Only the first N is mandatory.)
282 # If the version argument is given (e.g. 1.3.17), AC_PROG_SWIG checks that
283 # the swig package is this version number or higher.
285 # In configure.in, use as:
287 # AC_PROG_SWIG(1.3.17)
289 # SWIG_MULTI_MODULE_SUPPORT
298 # Copyright (c) 2008 Sebastian Huber <sebastian-huber@web.de>
299 # Copyright (c) 2008 Alan W. Irwin <irwin@beluga.phys.uvic.ca>
300 # Copyright (c) 2008 Rafael Laboissiere <rafael@laboissiere.net>
301 # Copyright (c) 2008 Andrew Collier <colliera@ukzn.ac.za>
303 # This program is free software; you can redistribute it and/or modify it
304 # under the terms of the GNU General Public License as published by the
305 # Free Software Foundation; either version 2 of the License, or (at your
306 # option) any later version.
308 # This program is distributed in the hope that it will be useful, but
309 # WITHOUT ANY WARRANTY; without even the implied warranty of
310 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
311 # Public License for more details.
313 # You should have received a copy of the GNU General Public License along
314 # with this program. If not, see <http://www.gnu.org/licenses/>.
316 # As a special exception, the respective Autoconf Macro's copyright owner
317 # gives unlimited permission to copy, distribute and modify the configure
318 # scripts that are the output of Autoconf when processing the Macro. You
319 # need not follow the terms of the GNU General Public License when using
320 # or distributing such scripts, even though portions of the text of the
321 # Macro appear in them. The GNU General Public License (GPL) does govern
322 # all other use of the material that constitutes the Autoconf Macro.
324 # This special exception to the GPL applies to versions of the Autoconf
325 # Macro released by the Autoconf Macro Archive. When you make and
326 # distribute a modified version of the Autoconf Macro, you may extend this
327 # special exception to the GPL to apply to your modified version as well.
329 AC_DEFUN([AC_PROG_SWIG],[
330 AC_PATH_PROG([SWIG],[swig])
331 if test -z "$SWIG" ; then
332 AC_MSG_WARN([cannot find 'swig' program. You should look at http://www.swig.org])
333 SWIG='echo "Error: SWIG is not installed. You should look at http://www.swig.org" ; false'
334 elif test -n "$1" ; then
335 AC_MSG_CHECKING([for SWIG version])
336 [swig_version=`$SWIG -version 2>&1 | grep 'SWIG Version' | sed 's/.*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/g'`]
337 AC_MSG_RESULT([$swig_version])
338 if test -n "$swig_version" ; then
339 # Calculate the required version number components
341 [required_major=`echo $required | sed 's/[^0-9].*//'`]
342 if test -z "$required_major" ; then
345 [required=`echo $required | sed 's/[0-9]*[^0-9]//'`]
346 [required_minor=`echo $required | sed 's/[^0-9].*//'`]
347 if test -z "$required_minor" ; then
350 [required=`echo $required | sed 's/[0-9]*[^0-9]//'`]
351 [required_patch=`echo $required | sed 's/[^0-9].*//'`]
352 if test -z "$required_patch" ; then
355 # Calculate the available version number components
356 [available=$swig_version]
357 [available_major=`echo $available | sed 's/[^0-9].*//'`]
358 if test -z "$available_major" ; then
361 [available=`echo $available | sed 's/[0-9]*[^0-9]//'`]
362 [available_minor=`echo $available | sed 's/[^0-9].*//'`]
363 if test -z "$available_minor" ; then
366 [available=`echo $available | sed 's/[0-9]*[^0-9]//'`]
367 [available_patch=`echo $available | sed 's/[^0-9].*//'`]
368 if test -z "$available_patch" ; then
371 if test $available_major -ne $required_major \
372 -o $available_minor -ne $required_minor \
373 -o $available_patch -lt $required_patch ; then
374 AC_MSG_WARN([SWIG version >= $1 is required. You have $swig_version. You should look at http://www.swig.org])
375 SWIG='echo "Error: SWIG version >= $1 is required. You have '"$swig_version"'. You should look at http://www.swig.org" ; false'
377 AC_MSG_NOTICE([SWIG executable is '$SWIG'])
378 SWIG_LIB=`$SWIG -swiglib`
379 AC_MSG_NOTICE([SWIG library directory is '$SWIG_LIB'])
382 AC_MSG_WARN([cannot determine SWIG version])
383 SWIG='echo "Error: Cannot determine SWIG version. You should look at http://www.swig.org" ; false'
388 # ===========================================================================
389 # http://autoconf-archive.cryp.to/swig_python.html
390 # ===========================================================================
394 # SWIG_PYTHON([use-shadow-classes = {no, yes}])
398 # Checks for Python and provides the $(SWIG_PYTHON_CPPFLAGS), and
399 # $(SWIG_PYTHON_OPT) output variables.
401 # $(SWIG_PYTHON_OPT) contains all necessary SWIG options to generate code
402 # for Python. Shadow classes are enabled unless the value of the optional
403 # first argument is exactly 'no'. If you need multi module support
404 # (provided by the SWIG_MULTI_MODULE_SUPPORT macro) use
405 # $(SWIG_PYTHON_LIBS) to link against the appropriate library. It contains
406 # the SWIG Python runtime library that is needed by the type check system
415 # Copyright (c) 2008 Sebastian Huber <sebastian-huber@web.de>
416 # Copyright (c) 2008 Alan W. Irwin <irwin@beluga.phys.uvic.ca>
417 # Copyright (c) 2008 Rafael Laboissiere <rafael@laboissiere.net>
418 # Copyright (c) 2008 Andrew Collier <colliera@ukzn.ac.za>
420 # This program is free software; you can redistribute it and/or modify it
421 # under the terms of the GNU General Public License as published by the
422 # Free Software Foundation; either version 2 of the License, or (at your
423 # option) any later version.
425 # This program is distributed in the hope that it will be useful, but
426 # WITHOUT ANY WARRANTY; without even the implied warranty of
427 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
428 # Public License for more details.
430 # You should have received a copy of the GNU General Public License along
431 # with this program. If not, see <http://www.gnu.org/licenses/>.
433 # As a special exception, the respective Autoconf Macro's copyright owner
434 # gives unlimited permission to copy, distribute and modify the configure
435 # scripts that are the output of Autoconf when processing the Macro. You
436 # need not follow the terms of the GNU General Public License when using
437 # or distributing such scripts, even though portions of the text of the
438 # Macro appear in them. The GNU General Public License (GPL) does govern
439 # all other use of the material that constitutes the Autoconf Macro.
441 # This special exception to the GPL applies to versions of the Autoconf
442 # Macro released by the Autoconf Macro Archive. When you make and
443 # distribute a modified version of the Autoconf Macro, you may extend this
444 # special exception to the GPL to apply to your modified version as well.
446 AC_DEFUN([SWIG_PYTHON],[
447 AC_REQUIRE([AC_PROG_SWIG])
448 AC_REQUIRE([AC_PYTHON_DEVEL])
449 test "x$1" != "xno" || swig_shadow=" -noproxy"
450 AC_SUBST([SWIG_PYTHON_OPT],[-python$swig_shadow])
451 AC_SUBST([SWIG_PYTHON_CPPFLAGS],[$PYTHON_CPPFLAGS])