1 ## this one is commonly used with AM_PATH_PYTHONDIR ...
2 dnl AM_CHECK_PYMOD(MODNAME [,SYMBOL [,ACTION-IF-FOUND [,ACTION-IF-NOT-FOUND]]])
3 dnl Check if a module containing a given symbol is visible to python.
4 AC_DEFUN([AM_CHECK_PYMOD],
5 [AC_REQUIRE([AM_PATH_PYTHON])
6 py_mod_var=`echo $1['_']$2 | sed 'y%./+-%__p_%'`
7 AC_MSG_CHECKING(for ifelse([$2],[],,[$2 in ])python module $1)
8 AC_CACHE_VAL(py_cv_mod_$py_mod_var, [
9 ifelse([$2],[], [prog="
17 sys.exit(0)"], [prog="
20 if $PYTHON -c "$prog" 1>&AC_FD_CC 2>&AC_FD_CC
22 eval "py_cv_mod_$py_mod_var=yes"
24 eval "py_cv_mod_$py_mod_var=no"
27 py_val=`eval "echo \`echo '$py_cv_mod_'$py_mod_var\`"`
28 if test "x$py_val" != xno; then
39 dnl a macro to check for ability to create python extensions
40 dnl AM_CHECK_PYTHON_HEADERS([ACTION-IF-POSSIBLE], [ACTION-IF-NOT-POSSIBLE])
41 dnl function also defines PYTHON_INCLUDES
42 AC_DEFUN([AM_CHECK_PYTHON_HEADERS],
43 [AC_REQUIRE([AM_PATH_PYTHON])
44 AC_MSG_CHECKING(for headers required to compile python extensions)
45 dnl deduce PYTHON_INCLUDES
46 py_prefix=`$PYTHON -c "import sys; sys.stdout.write(sys.prefix)"`
47 py_exec_prefix=`$PYTHON -c "import sys; sys.stdout.write(sys.exec_prefix)"`
48 PYTHON_CONFIG=`which $PYTHON`-config
49 if test -x "$PYTHON_CONFIG"; then
50 PYTHON_INCLUDES=`$PYTHON_CONFIG --includes 2>/dev/null`
52 PYTHON_INCLUDES="-I${py_prefix}/include/python${PYTHON_VERSION}"
53 if test "$py_prefix" != "$py_exec_prefix"; then
54 PYTHON_INCLUDES="$PYTHON_INCLUDES -I${py_exec_prefix}/include/python${PYTHON_VERSION}"
57 AC_SUBST(PYTHON_INCLUDES)
58 dnl check if the headers exist:
59 save_CPPFLAGS="$CPPFLAGS"
60 CPPFLAGS="$CPPFLAGS $PYTHON_INCLUDES"
61 AC_TRY_CPP([#include <Python.h>],dnl
64 [AC_MSG_RESULT(not found)
66 CPPFLAGS="$save_CPPFLAGS"
69 # JD_PYTHON_CHECK_VERSION(PROG, VERSION, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
70 # ---------------------------------------------------------------------------
71 # Run ACTION-IF-TRUE if the Python interpreter PROG has version >= VERSION.
72 # Run ACTION-IF-FALSE otherwise.
73 # This test uses sys.hexversion instead of the string equivalent.
74 # This is similar to AM_PYTHON_CHECK_VERSION, but without python 1.5.x support
75 # and with python 3.0 support.
76 AC_DEFUN([JD_PYTHON_CHECK_VERSION],
78 # split strings by '.' and convert to numeric. Append some zeros
79 # because we need at least 4 digits for the hex conversion.
80 # map returns an iterator in Python 3.0 and a list in 2.x
81 minver = list(map(int, '$2'.split('.'))) + [[0, 0, 0]]
83 # xrange is not present in Python 3.0 and range returns an iterator
84 for i in list(range(0, 4)): minverhex = (minverhex << 8) + minver[[i]]
85 sys.exit(sys.hexversion < minverhex)"
86 AS_IF([AM_RUN_LOG([$1 -c "$prog"])], [$3], [$4])])
88 # Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005
89 # Free Software Foundation, Inc.
91 # This file is free software; the Free Software Foundation
92 # gives unlimited permission to copy and/or distribute it,
93 # with or without modifications, as long as this notice is preserved.
95 # JD_PATH_PYTHON([MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
96 # ---------------------------------------------------------------------------
97 # Adds support for distributing Python modules and packages. To
98 # install modules, copy them to $(pythondir), using the python_PYTHON
99 # automake variable. To install a package with the same name as the
100 # automake package, install to $(pkgpythondir), or use the
101 # pkgpython_PYTHON automake variable.
103 # The variables $(pyexecdir) and $(pkgpyexecdir) are provided as
104 # locations to install python extension modules (shared libraries).
105 # Another macro is required to find the appropriate flags to compile
108 # If your package is configured with a different prefix to python,
109 # users will have to add the install directory to the PYTHONPATH
110 # environment variable, or create a .pth file (see the python
111 # documentation for details).
113 # If the MINIMUM-VERSION argument is passed, AM_PATH_PYTHON will
114 # cause an error if the version of python installed on the system
115 # doesn't meet the requirement. MINIMUM-VERSION should consist of
116 # numbers and dots only.
117 AC_DEFUN([JD_PATH_PYTHON],
119 dnl Find a Python interpreter. Python versions prior to 2.0 are not
121 m4_define_default([_AM_PYTHON_INTERPRETER_LIST],
122 [python python2 python3 python3.0 python2.5 python2.4 python2.3 python2.2 dnl
123 python2.1 python2.0])
126 dnl No version check is needed.
127 # Find any Python interpreter.
128 if test -z "$PYTHON"; then
129 AC_PATH_PROGS([PYTHON], _AM_PYTHON_INTERPRETER_LIST, :)
131 am_display_PYTHON=python
133 dnl A version check is needed.
134 if test -n "$PYTHON"; then
135 # If the user set $PYTHON, use it and don't search something else.
136 AC_MSG_CHECKING([whether $PYTHON version >= $1])
137 JD_PYTHON_CHECK_VERSION([$PYTHON], [$1],
138 [AC_MSG_RESULT(yes)],
139 [AC_MSG_ERROR(too old)])
140 am_display_PYTHON=$PYTHON
142 # Otherwise, try each interpreter until we find one that satisfies
144 AC_CACHE_CHECK([for a Python interpreter with version >= $1],
145 [am_cv_pathless_PYTHON],[
146 for am_cv_pathless_PYTHON in _AM_PYTHON_INTERPRETER_LIST none; do
147 test "$am_cv_pathless_PYTHON" = none && break
148 JD_PYTHON_CHECK_VERSION([$am_cv_pathless_PYTHON], [$1], [break])
150 # Set $PYTHON to the absolute path of $am_cv_pathless_PYTHON.
151 if test "$am_cv_pathless_PYTHON" = none; then
154 AC_PATH_PROG([PYTHON], [$am_cv_pathless_PYTHON])
156 am_display_PYTHON=$am_cv_pathless_PYTHON
160 if test "$PYTHON" = :; then
161 dnl Run any user-specified action, or abort.
162 m4_default([$3], [AC_MSG_ERROR([no suitable Python interpreter found])])
165 dnl Query Python for its version number. Getting [:3] seems to be
166 dnl the best way to do this; it's what "site.py" does in the standard
169 AC_CACHE_CHECK([for $am_display_PYTHON version], [am_cv_python_version],
170 [am_cv_python_version=`$PYTHON -c "import sys; sys.stdout.write(sys.version[[:3]])"`])
171 AC_SUBST([PYTHON_VERSION], [$am_cv_python_version])
173 dnl Use the values of $prefix and $exec_prefix for the corresponding
174 dnl values of PYTHON_PREFIX and PYTHON_EXEC_PREFIX. These are made
175 dnl distinct variables so they can be overridden if need be. However,
176 dnl general consensus is that you shouldn't need this ability.
178 AC_SUBST([PYTHON_PREFIX], ['${prefix}'])
179 AC_SUBST([PYTHON_EXEC_PREFIX], ['${exec_prefix}'])
181 dnl At times (like when building shared libraries) you may want
182 dnl to know which OS platform Python thinks this is.
184 AC_CACHE_CHECK([for $am_display_PYTHON platform], [am_cv_python_platform],
185 [am_cv_python_platform=`$PYTHON -c "import sys; sys.stdout.write(sys.platform)"`])
186 AC_SUBST([PYTHON_PLATFORM], [$am_cv_python_platform])
189 dnl Set up 4 directories:
191 dnl pythondir -- where to install python scripts. This is the
192 dnl site-packages directory, not the python standard library
193 dnl directory like in previous automake betas. This behavior
194 dnl is more consistent with lispdir.m4 for example.
195 dnl Query distutils for this directory. distutils does not exist in
196 dnl Python 1.5, so we fall back to the hardcoded directory if it
198 AC_CACHE_CHECK([for $am_display_PYTHON script directory],
199 [am_cv_python_pythondir],
200 [am_cv_python_pythondir=`$PYTHON -c "from distutils import sysconfig; print(sysconfig.get_python_lib(0,0,prefix='$PYTHON_PREFIX'))" 2>/dev/null ||
201 echo "$PYTHON_PREFIX/lib/python$PYTHON_VERSION/site-packages"`])
202 AC_SUBST([pythondir], [$am_cv_python_pythondir])
204 dnl pkgpythondir -- $PACKAGE directory under pythondir. Was
205 dnl PYTHON_SITE_PACKAGE in previous betas, but this naming is
206 dnl more consistent with the rest of automake.
208 AC_SUBST([pkgpythondir], [\${pythondir}/$PACKAGE])
210 dnl pyexecdir -- directory for installing python extension modules
211 dnl (shared libraries)
212 dnl Query distutils for this directory. distutils does not exist in
213 dnl Python 1.5, so we fall back to the hardcoded directory if it
215 AC_CACHE_CHECK([for $am_display_PYTHON extension module directory],
216 [am_cv_python_pyexecdir],
217 [am_cv_python_pyexecdir=`$PYTHON -c "from distutils import sysconfig; print(sysconfig.get_python_lib(1,0,prefix='$PYTHON_EXEC_PREFIX'))" 2>/dev/null ||
218 echo "${PYTHON_EXEC_PREFIX}/lib/python${PYTHON_VERSION}/site-packages"`])
219 AC_SUBST([pyexecdir], [$am_cv_python_pyexecdir])
221 dnl pkgpyexecdir -- $(pyexecdir)/$(PACKAGE)
223 AC_SUBST([pkgpyexecdir], [\${pyexecdir}/$PACKAGE])
225 dnl Run any user-specified action.