annotate m4/ac_python_devel.m4 @ 94:a60dea3e59a9

Minor documentation change
author Jamie Bullock <jamie@postlude.co.uk>
date Mon, 24 Sep 2007 10:26:26 +0000
parents ee7442343cf0
children
rev   line source
jamie@89 1 ##### http://autoconf-archive.cryp.to/ac_python_devel.html
jamie@89 2 #
jamie@89 3 # SYNOPSIS
jamie@89 4 #
jamie@89 5 # AC_PYTHON_DEVEL([version])
jamie@89 6 #
jamie@89 7 # DESCRIPTION
jamie@89 8 #
jamie@89 9 # Note: Defines as a precious variable "PYTHON_VERSION". Don't
jamie@89 10 # override it in your configure.ac.
jamie@89 11 #
jamie@89 12 # This macro checks for Python and tries to get the include path to
jamie@89 13 # 'Python.h'. It provides the $(PYTHON_CPPFLAGS) and
jamie@89 14 # $(PYTHON_LDFLAGS) output variables. It also exports
jamie@89 15 # $(PYTHON_EXTRA_LIBS) and $(PYTHON_EXTRA_LDFLAGS) for embedding
jamie@89 16 # Python in your code.
jamie@89 17 #
jamie@89 18 # You can search for some particular version of Python by passing a
jamie@89 19 # parameter to this macro, for example ">= '2.3.1'", or "== '2.4'".
jamie@89 20 # Please note that you *have* to pass also an operator along with the
jamie@89 21 # version to match, and pay special attention to the single quotes
jamie@89 22 # surrounding the version number. Don't use "PYTHON_VERSION" for
jamie@89 23 # this: that environment variable is declared as precious and thus
jamie@89 24 # reserved for the end-user.
jamie@89 25 #
jamie@89 26 # This macro should work for all versions of Python >= 2.1.0. As an
jamie@89 27 # end user, you can disable the check for the python version by
jamie@89 28 # setting the PYTHON_NOVERSIONCHECK environment variable to something
jamie@89 29 # else than the empty string.
jamie@89 30 #
jamie@89 31 # If you need to use this macro for an older Python version, please
jamie@89 32 # contact the authors. We're always open for feedback.
jamie@89 33 #
jamie@89 34 # LAST MODIFICATION
jamie@89 35 #
jamie@89 36 # 2006-10-22
jamie@89 37 #
jamie@89 38 # COPYLEFT
jamie@89 39 #
jamie@89 40 # Copyright (c) 2006 Sebastian Huber <sebastian-huber@web.de>
jamie@89 41 # Copyright (c) 2006 Alan W. Irwin <irwin@beluga.phys.uvic.ca>
jamie@89 42 # Copyright (c) 2006 Rafael Laboissiere <rafael@laboissiere.net>
jamie@89 43 # Copyright (c) 2006 Andrew Collier <colliera@ukzn.ac.za>
jamie@89 44 # Copyright (c) 2006 Matteo Settenvini <matteo@member.fsf.org>
jamie@89 45 # Copyright (c) 2006 Horst Knorr <hk_classes@knoda.org>
jamie@89 46 #
jamie@89 47 # This program is free software; you can redistribute it and/or
jamie@89 48 # modify it under the terms of the GNU General Public License as
jamie@89 49 # published by the Free Software Foundation; either version 2 of the
jamie@89 50 # License, or (at your option) any later version.
jamie@89 51 #
jamie@89 52 # This program is distributed in the hope that it will be useful, but
jamie@89 53 # WITHOUT ANY WARRANTY; without even the implied warranty of
jamie@89 54 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
jamie@89 55 # General Public License for more details.
jamie@89 56 #
jamie@89 57 # You should have received a copy of the GNU General Public License
jamie@89 58 # along with this program; if not, write to the Free Software
jamie@89 59 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
jamie@89 60 # 02111-1307, USA.
jamie@89 61 #
jamie@89 62 # As a special exception, the respective Autoconf Macro's copyright
jamie@89 63 # owner gives unlimited permission to copy, distribute and modify the
jamie@89 64 # configure scripts that are the output of Autoconf when processing
jamie@89 65 # the Macro. You need not follow the terms of the GNU General Public
jamie@89 66 # License when using or distributing such scripts, even though
jamie@89 67 # portions of the text of the Macro appear in them. The GNU General
jamie@89 68 # Public License (GPL) does govern all other use of the material that
jamie@89 69 # constitutes the Autoconf Macro.
jamie@89 70 #
jamie@89 71 # This special exception to the GPL applies to versions of the
jamie@89 72 # Autoconf Macro released by the Autoconf Macro Archive. When you
jamie@89 73 # make and distribute a modified version of the Autoconf Macro, you
jamie@89 74 # may extend this special exception to the GPL to apply to your
jamie@89 75 # modified version as well.
jamie@89 76
jamie@89 77 AC_DEFUN([AC_PYTHON_DEVEL],[
jamie@89 78 #
jamie@89 79 # Allow the use of a (user set) custom python version
jamie@89 80 #
jamie@89 81 AC_ARG_VAR([PYTHON_VERSION],[The installed Python
jamie@89 82 version to use, for example '2.3'. This string
jamie@89 83 will be appended to the Python interpreter
jamie@89 84 canonical name.])
jamie@89 85
jamie@89 86 AC_PATH_PROG([PYTHON],[python[$PYTHON_VERSION]])
jamie@89 87 if test -z "$PYTHON"; then
jamie@89 88 AC_MSG_ERROR([Cannot find python$PYTHON_VERSION in your system path])
jamie@89 89 PYTHON_VERSION=""
jamie@89 90 fi
jamie@89 91
jamie@89 92 #
jamie@89 93 # Check for a version of Python >= 2.1.0
jamie@89 94 #
jamie@89 95 AC_MSG_CHECKING([for a version of Python >= '2.1.0'])
jamie@89 96 ac_supports_python_ver=`$PYTHON -c "import sys, string; \
jamie@89 97 ver = string.split(sys.version)[[0]]; \
jamie@89 98 print ver >= '2.1.0'"`
jamie@89 99 if test "$ac_supports_python_ver" != "True"; then
jamie@89 100 if test -z "$PYTHON_NOVERSIONCHECK"; then
jamie@89 101 AC_MSG_RESULT([no])
jamie@89 102 AC_MSG_FAILURE([
jamie@89 103 This version of the AC@&t@_PYTHON_DEVEL macro
jamie@89 104 doesn't work properly with versions of Python before
jamie@89 105 2.1.0. You may need to re-run configure, setting the
jamie@89 106 variables PYTHON_CPPFLAGS, PYTHON_LDFLAGS, PYTHON_SITE_PKG,
jamie@89 107 PYTHON_EXTRA_LIBS and PYTHON_EXTRA_LDFLAGS by hand.
jamie@89 108 Moreover, to disable this check, set PYTHON_NOVERSIONCHECK
jamie@89 109 to something else than an empty string.
jamie@89 110 ])
jamie@89 111 else
jamie@89 112 AC_MSG_RESULT([skip at user request])
jamie@89 113 fi
jamie@89 114 else
jamie@89 115 AC_MSG_RESULT([yes])
jamie@89 116 fi
jamie@89 117
jamie@89 118 #
jamie@89 119 # if the macro parameter ``version'' is set, honour it
jamie@89 120 #
jamie@89 121 if test -n "$1"; then
jamie@89 122 AC_MSG_CHECKING([for a version of Python $1])
jamie@89 123 ac_supports_python_ver=`$PYTHON -c "import sys, string; \
jamie@89 124 ver = string.split(sys.version)[[0]]; \
jamie@89 125 print ver $1"`
jamie@89 126 if test "$ac_supports_python_ver" = "True"; then
jamie@89 127 AC_MSG_RESULT([yes])
jamie@89 128 else
jamie@89 129 AC_MSG_RESULT([no])
jamie@89 130 AC_MSG_ERROR([this package requires Python $1.
jamie@89 131 If you have it installed, but it isn't the default Python
jamie@89 132 interpreter in your system path, please pass the PYTHON_VERSION
jamie@89 133 variable to configure. See ``configure --help'' for reference.
jamie@89 134 ])
jamie@89 135 PYTHON_VERSION=""
jamie@89 136 fi
jamie@89 137 fi
jamie@89 138
jamie@89 139 #
jamie@89 140 # Check if you have distutils, else fail
jamie@89 141 #
jamie@89 142 AC_MSG_CHECKING([for the distutils Python package])
jamie@89 143 ac_distutils_result=`$PYTHON -c "import distutils" 2>&1`
jamie@89 144 if test -z "$ac_distutils_result"; then
jamie@89 145 AC_MSG_RESULT([yes])
jamie@89 146 else
jamie@89 147 AC_MSG_RESULT([no])
jamie@89 148 AC_MSG_ERROR([cannot import Python module "distutils".
jamie@89 149 Please check your Python installation. The error was:
jamie@89 150 $ac_distutils_result])
jamie@89 151 PYTHON_VERSION=""
jamie@89 152 fi
jamie@89 153
jamie@89 154 #
jamie@89 155 # Check for Python include path
jamie@89 156 #
jamie@89 157 AC_MSG_CHECKING([for Python include path])
jamie@89 158 if test -z "$PYTHON_CPPFLAGS"; then
jamie@89 159 python_path=`$PYTHON -c "import distutils.sysconfig; \
jamie@89 160 print distutils.sysconfig.get_python_inc();"`
jamie@89 161 if test -n "${python_path}"; then
jamie@89 162 python_path="-I$python_path"
jamie@89 163 fi
jamie@89 164 PYTHON_CPPFLAGS=$python_path
jamie@89 165 fi
jamie@89 166 AC_MSG_RESULT([$PYTHON_CPPFLAGS])
jamie@89 167 AC_SUBST([PYTHON_CPPFLAGS])
jamie@89 168
jamie@89 169 #
jamie@89 170 # Check for Python library path
jamie@89 171 #
jamie@89 172 AC_MSG_CHECKING([for Python library path])
jamie@89 173 if test -z "$PYTHON_LDFLAGS"; then
jamie@89 174 # (makes two attempts to ensure we've got a version number
jamie@89 175 # from the interpreter)
jamie@89 176 py_version=`$PYTHON -c "from distutils.sysconfig import *; \
jamie@89 177 from string import join; \
jamie@89 178 print join(get_config_vars('VERSION'))"`
jamie@89 179 if test "$py_version" == "[None]"; then
jamie@89 180 if test -n "$PYTHON_VERSION"; then
jamie@89 181 py_version=$PYTHON_VERSION
jamie@89 182 else
jamie@89 183 py_version=`$PYTHON -c "import sys; \
jamie@89 184 print sys.version[[:3]]"`
jamie@89 185 fi
jamie@89 186 fi
jamie@89 187
jamie@89 188 PYTHON_LDFLAGS=`$PYTHON -c "from distutils.sysconfig import *; \
jamie@89 189 from string import join; \
jamie@89 190 print '-L' + get_python_lib(0,1), \
jamie@89 191 '-lpython';"`$py_version
jamie@89 192 fi
jamie@89 193 AC_MSG_RESULT([$PYTHON_LDFLAGS])
jamie@89 194 AC_SUBST([PYTHON_LDFLAGS])
jamie@89 195
jamie@89 196 #
jamie@89 197 # Check for site packages
jamie@89 198 #
jamie@89 199 AC_MSG_CHECKING([for Python site-packages path])
jamie@89 200 if test -z "$PYTHON_SITE_PKG"; then
jamie@89 201 PYTHON_SITE_PKG=`$PYTHON -c "import distutils.sysconfig; \
jamie@89 202 print distutils.sysconfig.get_python_lib(0,0);"`
jamie@89 203 fi
jamie@89 204 AC_MSG_RESULT([$PYTHON_SITE_PKG])
jamie@89 205 AC_SUBST([PYTHON_SITE_PKG])
jamie@89 206
jamie@89 207 #
jamie@89 208 # libraries which must be linked in when embedding
jamie@89 209 #
jamie@89 210 AC_MSG_CHECKING(python extra libraries)
jamie@89 211 if test -z "$PYTHON_EXTRA_LIBS"; then
jamie@89 212 PYTHON_EXTRA_LIBS=`$PYTHON -c "import distutils.sysconfig; \
jamie@89 213 conf = distutils.sysconfig.get_config_var; \
jamie@89 214 print conf('LOCALMODLIBS'), conf('LIBS')"`
jamie@89 215 fi
jamie@89 216 AC_MSG_RESULT([$PYTHON_EXTRA_LIBS])
jamie@89 217 AC_SUBST(PYTHON_EXTRA_LIBS)
jamie@89 218
jamie@89 219 #
jamie@89 220 # linking flags needed when embedding
jamie@89 221 #
jamie@89 222 AC_MSG_CHECKING(python extra linking flags)
jamie@89 223 if test -z "$PYTHON_EXTRA_LDFLAGS"; then
jamie@89 224 PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "import distutils.sysconfig; \
jamie@89 225 conf = distutils.sysconfig.get_config_var; \
jamie@89 226 print conf('LINKFORSHARED')"`
jamie@89 227 fi
jamie@89 228 AC_MSG_RESULT([$PYTHON_EXTRA_LDFLAGS])
jamie@89 229 AC_SUBST(PYTHON_EXTRA_LDFLAGS)
jamie@89 230
jamie@89 231 #
jamie@89 232 # final check to see if everything compiles alright
jamie@89 233 #
jamie@89 234 AC_MSG_CHECKING([consistency of all components of python development environment])
jamie@89 235 AC_LANG_PUSH([C])
jamie@89 236 # save current global flags
jamie@89 237 LIBS="$ac_save_LIBS $PYTHON_LDFLAGS"
jamie@89 238 CPPFLAGS="$ac_save_CPPFLAGS $PYTHON_CPPFLAGS"
jamie@89 239 AC_TRY_LINK([
jamie@89 240 #include <Python.h>
jamie@89 241 ],[
jamie@89 242 Py_Initialize();
jamie@89 243 ],[pythonexists=yes],[pythonexists=no])
jamie@89 244
jamie@89 245 AC_MSG_RESULT([$pythonexists])
jamie@89 246
jamie@89 247 if test ! "$pythonexists" = "yes"; then
jamie@89 248 AC_MSG_ERROR([
jamie@89 249 Could not link test program to Python. Maybe the main Python library has been
jamie@89 250 installed in some non-standard library path. If so, pass it to configure,
jamie@89 251 via the LDFLAGS environment variable.
jamie@89 252 Example: ./configure LDFLAGS="-L/usr/non-standard-path/python/lib"
jamie@89 253 ============================================================================
jamie@89 254 ERROR!
jamie@89 255 You probably have to install the development version of the Python package
jamie@89 256 for your distribution. The exact name of this package varies among them.
jamie@89 257 ============================================================================
jamie@89 258 ])
jamie@89 259 PYTHON_VERSION=""
jamie@89 260 fi
jamie@89 261 AC_LANG_POP
jamie@89 262 # turn back to default flags
jamie@89 263 CPPFLAGS="$ac_save_CPPFLAGS"
jamie@89 264 LIBS="$ac_save_LIBS"
jamie@89 265
jamie@89 266 #
jamie@89 267 # all done!
jamie@89 268 #
jamie@89 269 ])