1
## ------------------------
2
## Python file handling
4
## Updated by James Henstridge
5
## ------------------------
7
# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004
8
# Free Software Foundation, Inc.
10
# This program is free software; you can redistribute it and/or modify
11
# it under the terms of the GNU General Public License as published by
12
# the Free Software Foundation; either version 2, or (at your option)
15
# This program is distributed in the hope that it will be useful,
16
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
# GNU General Public License for more details.
20
# You should have received a copy of the GNU General Public License
21
# along with this program; if not, write to the Free Software
22
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25
# AM_PATH_PYTHON([MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
27
# Adds support for distributing Python modules and packages. To
28
# install modules, copy them to $(pythondir), using the python_PYTHON
29
# automake variable. To install a package with the same name as the
30
# automake package, install to $(pkgpythondir), or use the
31
# pkgpython_PYTHON automake variable.
33
# The variables $(pyexecdir) and $(pkgpyexecdir) are provided as
34
# locations to install python extension modules (shared libraries).
35
# Another macro is required to find the appropriate flags to compile
38
# If your package is configured with a different prefix to python,
39
# users will have to add the install directory to the PYTHONPATH
40
# environment variable, or create a .pth file (see the python
41
# documentation for details).
43
# If the MINIMUM-VERSION argument is passed, AM_PATH_PYTHON will
44
# cause an error if the version of python installed on the system
45
# doesn't meet the requirement. MINIMUM-VERSION should consist of
46
# numbers and dots only.
48
AC_DEFUN([AM_PATH_PYTHON],
50
dnl Find a Python interpreter. Python versions prior to 1.5 are not
51
dnl supported because the default installation locations changed from
52
dnl $prefix/lib/site-python in 1.4 to $prefix/lib/python1.5/site-packages
54
m4_define([_AM_PYTHON_INTERPRETER_LIST],
55
[python python2 python2.4 python2.3 python2.2 dnl
56
python2.1 python2.0 python1.6 python1.5])
59
dnl No version check is needed.
60
# Find any Python interpreter.
61
if test -z "$PYTHON"; then
63
AC_PATH_PROGS([PYTHON], _AM_PYTHON_INTERPRETER_LIST)
65
am_display_PYTHON=python
67
dnl A version check is needed.
68
if test -n "$PYTHON"; then
69
# If the user set $PYTHON, use it and don't search something else.
70
AC_MSG_CHECKING([whether $PYTHON version >= $1])
71
AM_PYTHON_CHECK_VERSION([$PYTHON], [$1],
73
[AC_MSG_ERROR(too old)])
74
am_display_PYTHON=$PYTHON
76
# Otherwise, try each interpreter until we find one that satisfies
78
AC_CACHE_CHECK([for a Python interpreter with version >= $1],
79
[am_cv_pathless_PYTHON],[
80
for am_cv_pathless_PYTHON in _AM_PYTHON_INTERPRETER_LIST none; do
81
test "$am_cv_pathless_PYTHON" = none && break
82
AM_PYTHON_CHECK_VERSION([$am_cv_pathless_PYTHON], [$1], [break])
84
# Set $PYTHON to the absolute path of $am_cv_pathless_PYTHON.
85
if test "$am_cv_pathless_PYTHON" = none; then
88
AC_PATH_PROG([PYTHON], [$am_cv_pathless_PYTHON])
90
am_display_PYTHON=$am_cv_pathless_PYTHON
94
if test "$PYTHON" = :; then
95
dnl Run any user-specified action, or abort.
96
m4_default([$3], [AC_MSG_ERROR([no suitable Python interpreter found])])
99
dnl Query Python for its version number. Getting [:3] seems to be
100
dnl the best way to do this; it's what "site.py" does in the standard
103
AC_CACHE_CHECK([for $am_display_PYTHON version], [am_cv_python_version],
104
[am_cv_python_version=`$PYTHON -c "import sys; print sys.version[[:3]]"`])
105
AC_SUBST([PYTHON_VERSION], [$am_cv_python_version])
107
dnl Use the values of $prefix and $exec_prefix for the corresponding
108
dnl values of PYTHON_PREFIX and PYTHON_EXEC_PREFIX. These are made
109
dnl distinct variables so they can be overridden if need be. However,
110
dnl general consensus is that you shouldn't need this ability.
112
AC_SUBST([PYTHON_PREFIX], ['${prefix}'])
113
AC_SUBST([PYTHON_EXEC_PREFIX], ['${exec_prefix}'])
115
dnl At times (like when building shared libraries) you may want
116
dnl to know which OS platform Python thinks this is.
118
AC_CACHE_CHECK([for $am_display_PYTHON platform], [am_cv_python_platform],
119
[am_cv_python_platform=`$PYTHON -c "import sys; print sys.platform"`])
120
AC_SUBST([PYTHON_PLATFORM], [$am_cv_python_platform])
123
dnl Set up 4 directories:
125
dnl pythondir -- where to install python scripts. This is the
126
dnl site-packages directory, not the python standard library
127
dnl directory like in previous automake betas. This behavior
128
dnl is more consistent with lispdir.m4 for example.
129
dnl Query distutils for this directory. distutils does not exist in
130
dnl Python 1.5, so we fall back to the hardcoded directory if it
132
AC_CACHE_CHECK([for $am_display_PYTHON script directory],
133
[am_cv_python_pythondir],
134
[am_cv_python_pythondir=`$PYTHON -c "from distutils import sysconfig; print sysconfig.get_python_lib(0,0,prefix='$PYTHON_PREFIX')" 2>/dev/null ||
135
echo "$PYTHON_PREFIX/lib/python$PYTHON_VERSION/site-packages"`])
136
AC_SUBST([pythondir], [$am_cv_python_pythondir])
138
dnl pkgpythondir -- $PACKAGE directory under pythondir. Was
139
dnl PYTHON_SITE_PACKAGE in previous betas, but this naming is
140
dnl more consistent with the rest of automake.
142
AC_SUBST([pkgpythondir], [\${pythondir}/$PACKAGE])
144
dnl pyexecdir -- directory for installing python extension modules
145
dnl (shared libraries)
146
dnl Query distutils for this directory. distutils does not exist in
147
dnl Python 1.5, so we fall back to the hardcoded directory if it
149
AC_CACHE_CHECK([for $am_display_PYTHON extension module directory],
150
[am_cv_python_pyexecdir],
151
[am_cv_python_pyexecdir=`$PYTHON -c "from distutils import sysconfig; print sysconfig.get_python_lib(1,0,prefix='$PYTHON_EXEC_PREFIX')" 2>/dev/null ||
152
echo "${PYTHON_EXEC_PREFIX}/lib/python${PYTHON_VERSION}/site-packages"`])
153
AC_SUBST([pyexecdir], [$am_cv_python_pyexecdir])
155
dnl pkgpyexecdir -- $(pyexecdir)/$(PACKAGE)
157
AC_SUBST([pkgpyexecdir], [\${pyexecdir}/$PACKAGE])
159
dnl Run any user-specified action.
166
# AM_PYTHON_CHECK_VERSION(PROG, VERSION, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
167
# ---------------------------------------------------------------------------
168
# Run ACTION-IF-TRUE if the Python interpreter PROG has version >= VERSION.
169
# Run ACTION-IF-FALSE otherwise.
170
# This test uses sys.hexversion instead of the string equivalent (first
171
# word of sys.version), in order to cope with versions such as 2.2c1.
172
# hexversion has been introduced in Python 1.5.2; it's probably not
173
# worth to support older versions (1.5.1 was released on October 31, 1998).
174
AC_DEFUN([AM_PYTHON_CHECK_VERSION],
175
[prog="import sys, string
176
# split strings by '.' and convert to numeric. Append some zeros
177
# because we need at least 4 digits for the hex conversion.
178
minver = map(int, string.split('$2', '.')) + [[0, 0, 0]]
180
for i in xrange(0, 4): minverhex = (minverhex << 8) + minver[[i]]
181
sys.exit(sys.hexversion < minverhex)"
182
AS_IF([AM_RUN_LOG([$1 -c "$prog"])], [$3], [$4])])
186
## this one is commonly used with AM_PATH_PYTHONDIR ...
187
dnl AM_CHECK_PYMOD(MODNAME [,SYMBOL [,ACTION-IF-FOUND [,ACTION-IF-NOT-FOUND]]])
188
dnl Check if a module containing a given symbol is visible to python.
189
AC_DEFUN([AM_CHECK_PYMOD],
190
[AC_REQUIRE([AM_PATH_PYTHON])
191
py_mod_var=`echo $1['_']$2 | sed 'y%./+-%__p_%'`
192
AC_MSG_CHECKING(for ifelse([$2],[],,[$2 in ])python module $1)
193
AC_CACHE_VAL(py_cv_mod_$py_mod_var, [
194
ifelse([$2],[], [prog="
202
sys.exit(0)"], [prog="
205
if $PYTHON -c "$prog" 1>&AC_FD_CC 2>&AC_FD_CC
207
eval "py_cv_mod_$py_mod_var=yes"
209
eval "py_cv_mod_$py_mod_var=no"
212
py_val=`eval "echo \`echo '$py_cv_mod_'$py_mod_var\`"`
213
if test "x$py_val" != xno; then
215
ifelse([$3], [],, [$3
219
ifelse([$4], [],, [$4
224
dnl a macro to check for ability to create python extensions
225
dnl AM_CHECK_PYTHON_HEADERS([ACTION-IF-POSSIBLE], [ACTION-IF-NOT-POSSIBLE])
226
dnl function also defines PYTHON_INCLUDES
227
AC_DEFUN([AM_CHECK_PYTHON_HEADERS],
228
[AC_REQUIRE([AM_PATH_PYTHON])
229
AC_MSG_CHECKING(for headers required to compile python extensions)
230
dnl deduce PYTHON_INCLUDES
231
py_prefix=`$PYTHON -c "import sys; print sys.prefix"`
232
py_exec_prefix=`$PYTHON -c "import sys; print sys.exec_prefix"`
233
PYTHON_INCLUDES="-I${py_prefix}/include/python${PYTHON_VERSION}"
234
if test "$py_prefix" != "$py_exec_prefix"; then
235
PYTHON_INCLUDES="$PYTHON_INCLUDES -I${py_exec_prefix}/include/python${PYTHON_VERSION}"
237
AC_SUBST(PYTHON_INCLUDES)
238
dnl check if the headers exist:
239
save_CPPFLAGS="$CPPFLAGS"
240
CPPFLAGS="$CPPFLAGS $PYTHON_INCLUDES"
241
AC_TRY_CPP([#include <Python.h>],dnl
242
[AC_MSG_RESULT(found)
244
[AC_MSG_RESULT(not found)
246
CPPFLAGS="$save_CPPFLAGS"