1 ## ------------------------
2 ## Python file handling
4 ## Updated by James Henstridge
5 ## ------------------------
7 # Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2, or (at your option)
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24 # AM_PATH_PYTHON([MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
26 # Adds support for distributing Python modules and packages. To
27 # install modules, copy them to $(pythondir), using the python_PYTHON
28 # automake variable. To install a package with the same name as the
29 # automake package, install to $(pkgpythondir), or use the
30 # pkgpython_PYTHON automake variable.
32 # The variables $(pyexecdir) and $(pkgpyexecdir) are provided as
33 # locations to install python extension modules (shared libraries).
34 # Another macro is required to find the appropriate flags to compile
37 # If your package is configured with a different prefix to python,
38 # users will have to add the install directory to the PYTHONPATH
39 # environment variable, or create a .pth file (see the python
40 # documentation for details).
42 # If the MINIMUM-VERSION argument is passed, AM_PATH_PYTHON will
43 # cause an error if the version of python installed on the system
44 # doesn't meet the requirement. MINIMUM-VERSION should consist of
45 # numbers and dots only.
47 AC_DEFUN([AM_PATH_PYTHON],
49 dnl Find a Python interpreter. Python versions prior to 1.5 are not
50 dnl supported because the default installation locations changed from
51 dnl $prefix/lib/site-python in 1.4 to $prefix/lib/python1.5/site-packages
53 m4_define([_AM_PYTHON_INTERPRETER_LIST],
54 [python python2 python2.3 python2.2 python2.1 python2.0 python1.6 python1.5])
57 dnl No version check is needed.
58 # Find any Python interpreter.
59 if test -z "$PYTHON"; then
61 AC_PATH_PROGS([PYTHON], _AM_PYTHON_INTERPRETER_LIST)
63 am_display_PYTHON=python
65 dnl A version check is needed.
66 if test -n "$PYTHON"; then
67 # If the user set $PYTHON, use it and don't search something else.
68 AC_MSG_CHECKING([whether $PYTHON version >= $1])
69 AM_PYTHON_CHECK_VERSION([$PYTHON], [$1],
71 [AC_MSG_ERROR(too old)])
73 # Otherwise, try each interpreter until we find one that satisfies
75 AC_CACHE_CHECK([for a Python interpreter with version >= $1],
76 [am_cv_pathless_PYTHON],[
77 for am_cv_pathless_PYTHON in _AM_PYTHON_INTERPRETER_LIST none; do
78 test "$am_cv_pathless_PYTHON" = none && break
79 AM_PYTHON_CHECK_VERSION([$am_cv_pathless_PYTHON], [$1], [break])
81 # Set $PYTHON to the absolute path of $am_cv_pathless_PYTHON.
82 if test "$am_cv_pathless_PYTHON" = none; then
85 AC_PATH_PROG([PYTHON], [$am_cv_pathless_PYTHON])
87 am_display_PYTHON=$am_cv_pathless_PYTHON
91 if test "$PYTHON" = :; then
92 dnl Run any user-specified action, or abort.
93 m4_default([$3], [AC_MSG_ERROR([no suitable Python interpreter found])])
96 dnl Query Python for its version number. Getting [:3] seems to be
97 dnl the best way to do this; it's what "site.py" does in the standard
100 AC_CACHE_CHECK([for $am_display_PYTHON version], [am_cv_python_version],
101 [am_cv_python_version=`$PYTHON -c "import sys; print sys.version[[:3]]"`])
102 AC_SUBST([PYTHON_VERSION], [$am_cv_python_version])
104 dnl Use the values of $prefix and $exec_prefix for the corresponding
105 dnl values of PYTHON_PREFIX and PYTHON_EXEC_PREFIX. These are made
106 dnl distinct variables so they can be overridden if need be. However,
107 dnl general consensus is that you shouldn't need this ability.
109 AC_SUBST([PYTHON_PREFIX], ['${prefix}'])
110 AC_SUBST([PYTHON_EXEC_PREFIX], ['${exec_prefix}'])
112 dnl At times (like when building shared libraries) you may want
113 dnl to know which OS platform Python thinks this is.
115 AC_CACHE_CHECK([for $am_display_PYTHON platform], [am_cv_python_platform],
116 [am_cv_python_platform=`$PYTHON -c "import sys; print sys.platform"`])
117 AC_SUBST([PYTHON_PLATFORM], [$am_cv_python_platform])
120 dnl Set up 4 directories:
122 dnl pythondir -- where to install python scripts. This is the
123 dnl site-packages directory, not the python standard library
124 dnl directory like in previous automake betas. This behavior
125 dnl is more consistent with lispdir.m4 for example.
126 dnl Query distutils for this directory. distutils does not exist in
127 dnl Python 1.5, so we fall back to the hardcoded directory if it
129 AC_CACHE_CHECK([for $am_display_PYTHON script directory],
130 [am_cv_python_pythondir],
131 [am_cv_python_pythondir=`$PYTHON -c "from distutils import sysconfig; print sysconfig.get_python_lib(0,0,prefix='$PYTHON_PREFIX')" 2>/dev/null ||
132 echo "$PYTHON_PREFIX/lib/python$PYTHON_VERSION/site-packages"`])
133 AC_SUBST([pythondir], [$am_cv_python_pythondir])
135 dnl pkgpythondir -- $PACKAGE directory under pythondir. Was
136 dnl PYTHON_SITE_PACKAGE in previous betas, but this naming is
137 dnl more consistent with the rest of automake.
139 AC_SUBST([pkgpythondir], [\${pythondir}/$PACKAGE])
141 dnl pyexecdir -- directory for installing python extension modules
142 dnl (shared libraries)
143 dnl Query distutils for this directory. distutils does not exist in
144 dnl Python 1.5, so we fall back to the hardcoded directory if it
146 AC_CACHE_CHECK([for $am_display_PYTHON extension module directory],
147 [am_cv_python_pyexecdir],
148 [am_cv_python_pyexecdir=`$PYTHON -c "from distutils import sysconfig; print sysconfig.get_python_lib(1,0,prefix='$PYTHON_EXEC_PREFIX')" 2>/dev/null ||
149 echo "${PYTHON_EXEC_PREFIX}/lib/python${PYTHON_VERSION}/site-packages"`])
150 AC_SUBST([pyexecdir], [$am_cv_python_pyexecdir])
152 dnl pkgpyexecdir -- $(pyexecdir)/$(PACKAGE)
154 AC_SUBST([pkgpyexecdir], [\${pyexecdir}/$PACKAGE])
156 dnl Run any user-specified action.
163 # AM_PYTHON_CHECK_VERSION(PROG, VERSION, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
164 # ---------------------------------------------------------------------------
165 # Run ACTION-IF-TRUE if the Python interpreter PROG has version >= VERSION.
166 # Run ACTION-IF-FALSE otherwise.
167 # This test uses sys.hexversion instead of the string equivalent (first
168 # word of sys.version), in order to cope with versions such as 2.2c1.
169 # hexversion has been introduced in Python 1.5.2; it's probably not
170 # worth to support older versions (1.5.1 was released on October 31, 1998).
171 AC_DEFUN([AM_PYTHON_CHECK_VERSION],
172 [prog="import sys, string
173 # split strings by '.' and convert to numeric. Append some zeros
174 # because we need at least 4 digits for the hex conversion.
175 minver = map(int, string.split('$2', '.')) + [[0, 0, 0]]
177 for i in xrange(0, 4): minverhex = (minverhex << 8) + minver[[i]]
178 sys.exit(sys.hexversion < minverhex)"
179 AS_IF([AM_RUN_LOG([$1 -c "$prog"])], [$3], [$4])])