jamie@89: ##### http://autoconf-archive.cryp.to/ac_python_devel.html jamie@89: # jamie@89: # SYNOPSIS jamie@89: # jamie@89: # AC_PYTHON_DEVEL([version]) jamie@89: # jamie@89: # DESCRIPTION jamie@89: # jamie@89: # Note: Defines as a precious variable "PYTHON_VERSION". Don't jamie@89: # override it in your configure.ac. jamie@89: # jamie@89: # This macro checks for Python and tries to get the include path to jamie@89: # 'Python.h'. It provides the $(PYTHON_CPPFLAGS) and jamie@89: # $(PYTHON_LDFLAGS) output variables. It also exports jamie@89: # $(PYTHON_EXTRA_LIBS) and $(PYTHON_EXTRA_LDFLAGS) for embedding jamie@89: # Python in your code. jamie@89: # jamie@89: # You can search for some particular version of Python by passing a jamie@89: # parameter to this macro, for example ">= '2.3.1'", or "== '2.4'". jamie@89: # Please note that you *have* to pass also an operator along with the jamie@89: # version to match, and pay special attention to the single quotes jamie@89: # surrounding the version number. Don't use "PYTHON_VERSION" for jamie@89: # this: that environment variable is declared as precious and thus jamie@89: # reserved for the end-user. jamie@89: # jamie@89: # This macro should work for all versions of Python >= 2.1.0. As an jamie@89: # end user, you can disable the check for the python version by jamie@89: # setting the PYTHON_NOVERSIONCHECK environment variable to something jamie@89: # else than the empty string. jamie@89: # jamie@89: # If you need to use this macro for an older Python version, please jamie@89: # contact the authors. We're always open for feedback. jamie@89: # jamie@89: # LAST MODIFICATION jamie@89: # jamie@89: # 2006-10-22 jamie@89: # jamie@89: # COPYLEFT jamie@89: # jamie@89: # Copyright (c) 2006 Sebastian Huber jamie@89: # Copyright (c) 2006 Alan W. Irwin jamie@89: # Copyright (c) 2006 Rafael Laboissiere jamie@89: # Copyright (c) 2006 Andrew Collier jamie@89: # Copyright (c) 2006 Matteo Settenvini jamie@89: # Copyright (c) 2006 Horst Knorr jamie@89: # jamie@89: # This program is free software; you can redistribute it and/or jamie@89: # modify it under the terms of the GNU General Public License as jamie@89: # published by the Free Software Foundation; either version 2 of the jamie@89: # License, or (at your option) any later version. jamie@89: # jamie@89: # This program is distributed in the hope that it will be useful, but jamie@89: # WITHOUT ANY WARRANTY; without even the implied warranty of jamie@89: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU jamie@89: # General Public License for more details. jamie@89: # jamie@89: # You should have received a copy of the GNU General Public License jamie@89: # along with this program; if not, write to the Free Software jamie@89: # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA jamie@89: # 02111-1307, USA. jamie@89: # jamie@89: # As a special exception, the respective Autoconf Macro's copyright jamie@89: # owner gives unlimited permission to copy, distribute and modify the jamie@89: # configure scripts that are the output of Autoconf when processing jamie@89: # the Macro. You need not follow the terms of the GNU General Public jamie@89: # License when using or distributing such scripts, even though jamie@89: # portions of the text of the Macro appear in them. The GNU General jamie@89: # Public License (GPL) does govern all other use of the material that jamie@89: # constitutes the Autoconf Macro. jamie@89: # jamie@89: # This special exception to the GPL applies to versions of the jamie@89: # Autoconf Macro released by the Autoconf Macro Archive. When you jamie@89: # make and distribute a modified version of the Autoconf Macro, you jamie@89: # may extend this special exception to the GPL to apply to your jamie@89: # modified version as well. jamie@89: jamie@89: AC_DEFUN([AC_PYTHON_DEVEL],[ jamie@89: # jamie@89: # Allow the use of a (user set) custom python version jamie@89: # jamie@89: AC_ARG_VAR([PYTHON_VERSION],[The installed Python jamie@89: version to use, for example '2.3'. This string jamie@89: will be appended to the Python interpreter jamie@89: canonical name.]) jamie@89: jamie@89: AC_PATH_PROG([PYTHON],[python[$PYTHON_VERSION]]) jamie@89: if test -z "$PYTHON"; then jamie@89: AC_MSG_ERROR([Cannot find python$PYTHON_VERSION in your system path]) jamie@89: PYTHON_VERSION="" jamie@89: fi jamie@89: jamie@89: # jamie@89: # Check for a version of Python >= 2.1.0 jamie@89: # jamie@89: AC_MSG_CHECKING([for a version of Python >= '2.1.0']) jamie@89: ac_supports_python_ver=`$PYTHON -c "import sys, string; \ jamie@89: ver = string.split(sys.version)[[0]]; \ jamie@89: print ver >= '2.1.0'"` jamie@89: if test "$ac_supports_python_ver" != "True"; then jamie@89: if test -z "$PYTHON_NOVERSIONCHECK"; then jamie@89: AC_MSG_RESULT([no]) jamie@89: AC_MSG_FAILURE([ jamie@89: This version of the AC@&t@_PYTHON_DEVEL macro jamie@89: doesn't work properly with versions of Python before jamie@89: 2.1.0. You may need to re-run configure, setting the jamie@89: variables PYTHON_CPPFLAGS, PYTHON_LDFLAGS, PYTHON_SITE_PKG, jamie@89: PYTHON_EXTRA_LIBS and PYTHON_EXTRA_LDFLAGS by hand. jamie@89: Moreover, to disable this check, set PYTHON_NOVERSIONCHECK jamie@89: to something else than an empty string. jamie@89: ]) jamie@89: else jamie@89: AC_MSG_RESULT([skip at user request]) jamie@89: fi jamie@89: else jamie@89: AC_MSG_RESULT([yes]) jamie@89: fi jamie@89: jamie@89: # jamie@89: # if the macro parameter ``version'' is set, honour it jamie@89: # jamie@89: if test -n "$1"; then jamie@89: AC_MSG_CHECKING([for a version of Python $1]) jamie@89: ac_supports_python_ver=`$PYTHON -c "import sys, string; \ jamie@89: ver = string.split(sys.version)[[0]]; \ jamie@89: print ver $1"` jamie@89: if test "$ac_supports_python_ver" = "True"; then jamie@89: AC_MSG_RESULT([yes]) jamie@89: else jamie@89: AC_MSG_RESULT([no]) jamie@89: AC_MSG_ERROR([this package requires Python $1. jamie@89: If you have it installed, but it isn't the default Python jamie@89: interpreter in your system path, please pass the PYTHON_VERSION jamie@89: variable to configure. See ``configure --help'' for reference. jamie@89: ]) jamie@89: PYTHON_VERSION="" jamie@89: fi jamie@89: fi jamie@89: jamie@89: # jamie@89: # Check if you have distutils, else fail jamie@89: # jamie@89: AC_MSG_CHECKING([for the distutils Python package]) jamie@89: ac_distutils_result=`$PYTHON -c "import distutils" 2>&1` jamie@89: if test -z "$ac_distutils_result"; then jamie@89: AC_MSG_RESULT([yes]) jamie@89: else jamie@89: AC_MSG_RESULT([no]) jamie@89: AC_MSG_ERROR([cannot import Python module "distutils". jamie@89: Please check your Python installation. The error was: jamie@89: $ac_distutils_result]) jamie@89: PYTHON_VERSION="" jamie@89: fi jamie@89: jamie@89: # jamie@89: # Check for Python include path jamie@89: # jamie@89: AC_MSG_CHECKING([for Python include path]) jamie@89: if test -z "$PYTHON_CPPFLAGS"; then jamie@89: python_path=`$PYTHON -c "import distutils.sysconfig; \ jamie@89: print distutils.sysconfig.get_python_inc();"` jamie@89: if test -n "${python_path}"; then jamie@89: python_path="-I$python_path" jamie@89: fi jamie@89: PYTHON_CPPFLAGS=$python_path jamie@89: fi jamie@89: AC_MSG_RESULT([$PYTHON_CPPFLAGS]) jamie@89: AC_SUBST([PYTHON_CPPFLAGS]) jamie@89: jamie@89: # jamie@89: # Check for Python library path jamie@89: # jamie@89: AC_MSG_CHECKING([for Python library path]) jamie@89: if test -z "$PYTHON_LDFLAGS"; then jamie@89: # (makes two attempts to ensure we've got a version number jamie@89: # from the interpreter) jamie@89: py_version=`$PYTHON -c "from distutils.sysconfig import *; \ jamie@89: from string import join; \ jamie@89: print join(get_config_vars('VERSION'))"` jamie@89: if test "$py_version" == "[None]"; then jamie@89: if test -n "$PYTHON_VERSION"; then jamie@89: py_version=$PYTHON_VERSION jamie@89: else jamie@89: py_version=`$PYTHON -c "import sys; \ jamie@89: print sys.version[[:3]]"` jamie@89: fi jamie@89: fi jamie@89: jamie@89: PYTHON_LDFLAGS=`$PYTHON -c "from distutils.sysconfig import *; \ jamie@89: from string import join; \ jamie@89: print '-L' + get_python_lib(0,1), \ jamie@89: '-lpython';"`$py_version jamie@89: fi jamie@89: AC_MSG_RESULT([$PYTHON_LDFLAGS]) jamie@89: AC_SUBST([PYTHON_LDFLAGS]) jamie@89: jamie@89: # jamie@89: # Check for site packages jamie@89: # jamie@89: AC_MSG_CHECKING([for Python site-packages path]) jamie@89: if test -z "$PYTHON_SITE_PKG"; then jamie@89: PYTHON_SITE_PKG=`$PYTHON -c "import distutils.sysconfig; \ jamie@89: print distutils.sysconfig.get_python_lib(0,0);"` jamie@89: fi jamie@89: AC_MSG_RESULT([$PYTHON_SITE_PKG]) jamie@89: AC_SUBST([PYTHON_SITE_PKG]) jamie@89: jamie@89: # jamie@89: # libraries which must be linked in when embedding jamie@89: # jamie@89: AC_MSG_CHECKING(python extra libraries) jamie@89: if test -z "$PYTHON_EXTRA_LIBS"; then jamie@89: PYTHON_EXTRA_LIBS=`$PYTHON -c "import distutils.sysconfig; \ jamie@89: conf = distutils.sysconfig.get_config_var; \ jamie@89: print conf('LOCALMODLIBS'), conf('LIBS')"` jamie@89: fi jamie@89: AC_MSG_RESULT([$PYTHON_EXTRA_LIBS]) jamie@89: AC_SUBST(PYTHON_EXTRA_LIBS) jamie@89: jamie@89: # jamie@89: # linking flags needed when embedding jamie@89: # jamie@89: AC_MSG_CHECKING(python extra linking flags) jamie@89: if test -z "$PYTHON_EXTRA_LDFLAGS"; then jamie@89: PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "import distutils.sysconfig; \ jamie@89: conf = distutils.sysconfig.get_config_var; \ jamie@89: print conf('LINKFORSHARED')"` jamie@89: fi jamie@89: AC_MSG_RESULT([$PYTHON_EXTRA_LDFLAGS]) jamie@89: AC_SUBST(PYTHON_EXTRA_LDFLAGS) jamie@89: jamie@89: # jamie@89: # final check to see if everything compiles alright jamie@89: # jamie@89: AC_MSG_CHECKING([consistency of all components of python development environment]) jamie@89: AC_LANG_PUSH([C]) jamie@89: # save current global flags jamie@89: LIBS="$ac_save_LIBS $PYTHON_LDFLAGS" jamie@89: CPPFLAGS="$ac_save_CPPFLAGS $PYTHON_CPPFLAGS" jamie@89: AC_TRY_LINK([ jamie@89: #include jamie@89: ],[ jamie@89: Py_Initialize(); jamie@89: ],[pythonexists=yes],[pythonexists=no]) jamie@89: jamie@89: AC_MSG_RESULT([$pythonexists]) jamie@89: jamie@89: if test ! "$pythonexists" = "yes"; then jamie@89: AC_MSG_ERROR([ jamie@89: Could not link test program to Python. Maybe the main Python library has been jamie@89: installed in some non-standard library path. If so, pass it to configure, jamie@89: via the LDFLAGS environment variable. jamie@89: Example: ./configure LDFLAGS="-L/usr/non-standard-path/python/lib" jamie@89: ============================================================================ jamie@89: ERROR! jamie@89: You probably have to install the development version of the Python package jamie@89: for your distribution. The exact name of this package varies among them. jamie@89: ============================================================================ jamie@89: ]) jamie@89: PYTHON_VERSION="" jamie@89: fi jamie@89: AC_LANG_POP jamie@89: # turn back to default flags jamie@89: CPPFLAGS="$ac_save_CPPFLAGS" jamie@89: LIBS="$ac_save_LIBS" jamie@89: jamie@89: # jamie@89: # all done! jamie@89: # jamie@89: ])