1 # Ripped from pygobject-2.0
3 # Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004
4 # Free Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 # AM_PATH_PYTHON([MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
23 # Adds support for distributing Python modules and packages. To
24 # install modules, copy them to $(pythondir), using the python_PYTHON
25 # automake variable. To install a package with the same name as the
26 # automake package, install to $(pkgpythondir), or use the
27 # pkgpython_PYTHON automake variable.
29 # The variables $(pyexecdir) and $(pkgpyexecdir) are provided as
30 # locations to install python extension modules (shared libraries).
31 # Another macro is required to find the appropriate flags to compile
34 # If your package is configured with a different prefix to python,
35 # users will have to add the install directory to the PYTHONPATH
36 # environment variable, or create a .pth file (see the python
37 # documentation for details).
39 # If the MINIMUM-VERSION argument is passed, AM_PATH_PYTHON will
40 # cause an error if the version of python installed on the system
41 # doesn't meet the requirement. MINIMUM-VERSION should consist of
42 # numbers and dots only.
44 AC_DEFUN([AM_PATH_PYTHON],
46 dnl Find a Python interpreter. Python versions prior to 1.5 are not
47 dnl supported because the default installation locations changed from
48 dnl $prefix/lib/site-python in 1.4 to $prefix/lib/python1.5/site-packages
50 m4_define([_AM_PYTHON_INTERPRETER_LIST],
51 [python python2 python2.4 python2.3 python2.2 dnl
52 python2.1 python2.0 python1.6 python1.5])
55 dnl No version check is needed.
56 # Find any Python interpreter.
57 if test -z "$PYTHON"; then
59 AC_PATH_PROGS([PYTHON], _AM_PYTHON_INTERPRETER_LIST)
61 am_display_PYTHON=python
63 dnl A version check is needed.
64 if test -n "$PYTHON"; then
65 # If the user set $PYTHON, use it and don't search something else.
66 AC_MSG_CHECKING([whether $PYTHON version >= $1])
67 AM_PYTHON_CHECK_VERSION([$PYTHON], [$1],
69 [AC_MSG_ERROR(too old)])
70 am_display_PYTHON=$PYTHON
72 # Otherwise, try each interpreter until we find one that satisfies
74 AC_CACHE_CHECK([for a Python interpreter with version >= $1],
75 [am_cv_pathless_PYTHON],[
76 for am_cv_pathless_PYTHON in _AM_PYTHON_INTERPRETER_LIST none; do
77 test "$am_cv_pathless_PYTHON" = none && break
78 AM_PYTHON_CHECK_VERSION([$am_cv_pathless_PYTHON], [$1], [break])
80 # Set $PYTHON to the absolute path of $am_cv_pathless_PYTHON.
81 if test "$am_cv_pathless_PYTHON" = none; then
84 AC_PATH_PROG([PYTHON], [$am_cv_pathless_PYTHON])
86 am_display_PYTHON=$am_cv_pathless_PYTHON
90 if test "$PYTHON" = :; then
91 dnl Run any user-specified action, or abort.
92 m4_default([$3], [AC_MSG_ERROR([no suitable Python interpreter found])])
95 dnl Query Python for its version number. Getting [:3] seems to be
96 dnl the best way to do this; it's what "site.py" does in the standard
99 AC_CACHE_CHECK([for $am_display_PYTHON version], [am_cv_python_version],
100 [am_cv_python_version=`$PYTHON -c "import sys; print sys.version[[:3]]"`])
101 AC_SUBST([PYTHON_VERSION], [$am_cv_python_version])
103 dnl Use the values of $prefix and $exec_prefix for the corresponding
104 dnl values of PYTHON_PREFIX and PYTHON_EXEC_PREFIX. These are made
105 dnl distinct variables so they can be overridden if need be. However,
106 dnl general consensus is that you shouldn't need this ability.
108 AC_SUBST([PYTHON_PREFIX], ['${prefix}'])
109 AC_SUBST([PYTHON_EXEC_PREFIX], ['${exec_prefix}'])
111 dnl At times (like when building shared libraries) you may want
112 dnl to know which OS platform Python thinks this is.
114 AC_CACHE_CHECK([for $am_display_PYTHON platform], [am_cv_python_platform],
115 [am_cv_python_platform=`$PYTHON -c "import sys; print sys.platform"`])
116 AC_SUBST([PYTHON_PLATFORM], [$am_cv_python_platform])
119 dnl Set up 4 directories:
121 dnl pythondir -- where to install python scripts. This is the
122 dnl site-packages directory, not the python standard library
123 dnl directory like in previous automake betas. This behavior
124 dnl is more consistent with lispdir.m4 for example.
125 dnl Query distutils for this directory. distutils does not exist in
126 dnl Python 1.5, so we fall back to the hardcoded directory if it
128 AC_CACHE_CHECK([for $am_display_PYTHON script directory],
129 [am_cv_python_pythondir],
130 [am_cv_python_pythondir=`$PYTHON -c "from distutils import sysconfig; print sysconfig.get_python_lib(0,0,prefix='$PYTHON_PREFIX')" 2>/dev/null ||
131 echo "$PYTHON_PREFIX/lib/python$PYTHON_VERSION/site-packages"`])
132 AC_SUBST([pythondir], [$am_cv_python_pythondir])
134 dnl pkgpythondir -- $PACKAGE directory under pythondir. Was
135 dnl PYTHON_SITE_PACKAGE in previous betas, but this naming is
136 dnl more consistent with the rest of automake.
138 AC_SUBST([pkgpythondir], [\${pythondir}/$PACKAGE])
140 dnl pyexecdir -- directory for installing python extension modules
141 dnl (shared libraries)
142 dnl Query distutils for this directory. distutils does not exist in
143 dnl Python 1.5, so we fall back to the hardcoded directory if it
145 AC_CACHE_CHECK([for $am_display_PYTHON extension module directory],
146 [am_cv_python_pyexecdir],
147 [am_cv_python_pyexecdir=`$PYTHON -c "from distutils import sysconfig; print sysconfig.get_python_lib(1,0,prefix='$PYTHON_EXEC_PREFIX')" 2>/dev/null ||
148 echo "${PYTHON_EXEC_PREFIX}/lib/python${PYTHON_VERSION}/site-packages"`])
149 AC_SUBST([pyexecdir], [$am_cv_python_pyexecdir])
151 dnl pkgpyexecdir -- $(pyexecdir)/$(PACKAGE)
153 AC_SUBST([pkgpyexecdir], [\${pyexecdir}/$PACKAGE])
155 dnl Run any user-specified action.
162 # AM_PYTHON_CHECK_VERSION(PROG, VERSION, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
163 # ---------------------------------------------------------------------------
164 # Run ACTION-IF-TRUE if the Python interpreter PROG has version >= VERSION.
165 # Run ACTION-IF-FALSE otherwise.
166 # This test uses sys.hexversion instead of the string equivalent (first
167 # word of sys.version), in order to cope with versions such as 2.2c1.
168 # hexversion has been introduced in Python 1.5.2; it's probably not
169 # worth to support older versions (1.5.1 was released on October 31, 1998).
170 AC_DEFUN([AM_PYTHON_CHECK_VERSION],
171 [prog="import sys, string
172 # split strings by '.' and convert to numeric. Append some zeros
173 # because we need at least 4 digits for the hex conversion.
174 minver = map(int, string.split('$2', '.')) + [[0, 0, 0]]
176 for i in xrange(0, 4): minverhex = (minverhex << 8) + minver[[i]]
177 sys.exit(sys.hexversion < minverhex)"
178 AS_IF([AM_RUN_LOG([$1 -c "$prog"])], [$3], [$4])])
180 dnl a macro to check for ability to create python extensions
181 dnl AM_CHECK_PYTHON_HEADERS([ACTION-IF-POSSIBLE], [ACTION-IF-NOT-POSSIBLE])
182 dnl function also defines PYTHON_INCLUDES
183 AC_DEFUN([AM_CHECK_PYTHON_HEADERS],
184 [AC_REQUIRE([AM_PATH_PYTHON])
185 AC_MSG_CHECKING(for headers required to compile python extensions)
186 dnl deduce PYTHON_INCLUDES
187 py_prefix=`$PYTHON -c "import sys; print sys.prefix"`
188 py_exec_prefix=`$PYTHON -c "import sys; print sys.exec_prefix"`
189 if test -x "$PYTHON-config"; then
190 PYTHON_INCLUDES=`$PYTHON-config --includes 2>/dev/null`
192 PYTHON_INCLUDES="-I${py_prefix}/include/python${PYTHON_VERSION}"
193 if test "$py_prefix" != "$py_exec_prefix"; then
194 PYTHON_INCLUDES="$PYTHON_INCLUDES -I${py_exec_prefix}/include/python${PYTHON_VERSION}"
197 AC_SUBST(PYTHON_INCLUDES)
198 dnl check if the headers exist:
199 save_CPPFLAGS="$CPPFLAGS"
200 CPPFLAGS="$CPPFLAGS $PYTHON_INCLUDES"
201 AC_TRY_CPP([#include <Python.h>],dnl
202 [AC_MSG_RESULT(found)
204 [AC_MSG_RESULT(not found)
206 CPPFLAGS="$save_CPPFLAGS"