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 if test "x$PYTHON_INCLUDES" = x; then
47 PYTHON_CONFIG=`which $PYTHON`-config
48 if test -x "$PYTHON_CONFIG"; then
49 PYTHON_INCLUDES=`$PYTHON_CONFIG --includes 2>/dev/null`
51 py_prefix=`$PYTHON -c "import sys; sys.stdout.write(sys.prefix)"`
52 py_exec_prefix=`$PYTHON -c "import sys; sys.stdout.write(sys.exec_prefix)"`
53 PYTHON_INCLUDES="-I${py_prefix}/include/python${PYTHON_VERSION}"
54 if test "$py_prefix" != "$py_exec_prefix"; then
55 PYTHON_INCLUDES="$PYTHON_INCLUDES -I${py_exec_prefix}/include/python${PYTHON_VERSION}"
59 AC_SUBST(PYTHON_INCLUDES)
60 dnl check if the headers exist:
61 save_CPPFLAGS="$CPPFLAGS"
62 CPPFLAGS="$CPPFLAGS $PYTHON_INCLUDES"
63 AC_TRY_CPP([#include <Python.h>],dnl
66 [AC_MSG_RESULT(not found)
68 CPPFLAGS="$save_CPPFLAGS"
71 dnl a macro to check for ability to embed python
72 dnl AM_CHECK_PYTHON_LIBS([ACTION-IF-POSSIBLE], [ACTION-IF-NOT-POSSIBLE])
73 dnl function also defines PYTHON_LIBS
74 AC_DEFUN([AM_CHECK_PYTHON_LIBS],
75 [AC_REQUIRE([AM_CHECK_PYTHON_HEADERS])
76 AC_MSG_CHECKING(for libraries required to embed python)
77 dnl deduce PYTHON_LIBS
78 py_exec_prefix=`$PYTHON -c "import sys; print(sys.exec_prefix)"`
79 if test "x$PYTHON_LIBS" = x; then
80 PYTHON_LIBS="-L${py_prefix}/lib -lpython${PYTHON_VERSION}"
82 if test "x$PYTHON_LIB_LOC" = x; then
83 PYTHON_LIB_LOC="${py_prefix}/lib"
86 AC_SUBST(PYTHON_LIB_LOC)
87 dnl check if the headers exist:
89 LIBS="$LIBS $PYTHON_LIBS"
90 AC_TRY_LINK_FUNC(Py_Initialize, dnl
91 [LIBS="$save_LIBS"; AC_MSG_RESULT(yes); $1], dnl
92 [LIBS="$save_LIBS"; AC_MSG_RESULT(no); $2])
96 # JD_PYTHON_CHECK_VERSION(PROG, VERSION, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
97 # ---------------------------------------------------------------------------
98 # Run ACTION-IF-TRUE if the Python interpreter PROG has version >= VERSION.
99 # Run ACTION-IF-FALSE otherwise.
100 # This test uses sys.hexversion instead of the string equivalent.
101 # This is similar to AM_PYTHON_CHECK_VERSION, but without python 1.5.x support
102 # and with python 3.0 support.
103 AC_DEFUN([JD_PYTHON_CHECK_VERSION],
105 # split strings by '.' and convert to numeric. Append some zeros
106 # because we need at least 4 digits for the hex conversion.
107 # map returns an iterator in Python 3.0 and a list in 2.x
108 minver = list(map(int, '$2'.split('.'))) + [[0, 0, 0]]
110 # xrange is not present in Python 3.0 and range returns an iterator
111 for i in list(range(0, 4)): minverhex = (minverhex << 8) + minver[[i]]
112 sys.exit(sys.hexversion < minverhex)"
113 AS_IF([AM_RUN_LOG([$1 -c "$prog"])], [$3], [$4])])
115 # Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005
116 # Free Software Foundation, Inc.
118 # This file is free software; the Free Software Foundation
119 # gives unlimited permission to copy and/or distribute it,
120 # with or without modifications, as long as this notice is preserved.
122 # JD_PATH_PYTHON([MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
123 # ---------------------------------------------------------------------------
124 # Adds support for distributing Python modules and packages. To
125 # install modules, copy them to $(pythondir), using the python_PYTHON
126 # automake variable. To install a package with the same name as the
127 # automake package, install to $(pkgpythondir), or use the
128 # pkgpython_PYTHON automake variable.
130 # The variables $(pyexecdir) and $(pkgpyexecdir) are provided as
131 # locations to install python extension modules (shared libraries).
132 # Another macro is required to find the appropriate flags to compile
135 # If your package is configured with a different prefix to python,
136 # users will have to add the install directory to the PYTHONPATH
137 # environment variable, or create a .pth file (see the python
138 # documentation for details).
140 # If the MINIMUM-VERSION argument is passed, AM_PATH_PYTHON will
141 # cause an error if the version of python installed on the system
142 # doesn't meet the requirement. MINIMUM-VERSION should consist of
143 # numbers and dots only.
144 AC_DEFUN([JD_PATH_PYTHON],
146 dnl Find a Python interpreter. Python versions prior to 2.0 are not
148 m4_define_default([_AM_PYTHON_INTERPRETER_LIST],
149 [python3 python3.3 python3.2 python3.1 python2 python2.7 python2.6 python])
152 dnl No version check is needed.
153 # Find any Python interpreter.
154 if test -z "$PYTHON"; then
155 AC_PATH_PROGS([PYTHON], _AM_PYTHON_INTERPRETER_LIST, :)
157 am_display_PYTHON=python
159 dnl A version check is needed.
160 if test -n "$PYTHON"; then
161 # If the user set $PYTHON, use it and don't search something else.
162 AC_MSG_CHECKING([whether $PYTHON version >= $1])
163 JD_PYTHON_CHECK_VERSION([$PYTHON], [$1],
164 [AC_MSG_RESULT(yes)],
165 [AC_MSG_ERROR(too old)])
166 am_display_PYTHON=$PYTHON
168 # Otherwise, try each interpreter until we find one that satisfies
170 AC_CACHE_CHECK([for a Python interpreter with version >= $1],
171 [am_cv_pathless_PYTHON],[
172 for am_cv_pathless_PYTHON in _AM_PYTHON_INTERPRETER_LIST none; do
173 test "$am_cv_pathless_PYTHON" = none && break
174 JD_PYTHON_CHECK_VERSION([$am_cv_pathless_PYTHON], [$1], [break])
176 # Set $PYTHON to the absolute path of $am_cv_pathless_PYTHON.
177 if test "$am_cv_pathless_PYTHON" = none; then
180 AC_PATH_PROG([PYTHON], [$am_cv_pathless_PYTHON])
182 am_display_PYTHON=$am_cv_pathless_PYTHON
186 if test "$PYTHON" = :; then
187 dnl Run any user-specified action, or abort.
188 m4_default([$3], [AC_MSG_ERROR([no suitable Python interpreter found])])
191 dnl Query Python for its version number. Getting [:3] seems to be
192 dnl the best way to do this; it's what "site.py" does in the standard
195 AC_CACHE_CHECK([for $am_display_PYTHON version], [am_cv_python_version],
196 [am_cv_python_version=`$PYTHON -c "import sys; sys.stdout.write(sys.version[[:3]])"`])
197 AC_SUBST([PYTHON_VERSION], [$am_cv_python_version])
199 dnl Use the values of $prefix and $exec_prefix for the corresponding
200 dnl values of PYTHON_PREFIX and PYTHON_EXEC_PREFIX. These are made
201 dnl distinct variables so they can be overridden if need be. However,
202 dnl general consensus is that you shouldn't need this ability.
204 AC_SUBST([PYTHON_PREFIX], ['${prefix}'])
205 AC_SUBST([PYTHON_EXEC_PREFIX], ['${exec_prefix}'])
207 dnl At times (like when building shared libraries) you may want
208 dnl to know which OS platform Python thinks this is.
210 AC_CACHE_CHECK([for $am_display_PYTHON platform], [am_cv_python_platform],
211 [am_cv_python_platform=`$PYTHON -c "import sys; sys.stdout.write(sys.platform)"`])
212 AC_SUBST([PYTHON_PLATFORM], [$am_cv_python_platform])
215 dnl Set up 4 directories:
217 dnl pythondir -- where to install python scripts. This is the
218 dnl site-packages directory, not the python standard library
219 dnl directory like in previous automake betas. This behavior
220 dnl is more consistent with lispdir.m4 for example.
221 dnl Query distutils for this directory. distutils does not exist in
222 dnl Python 1.5, so we fall back to the hardcoded directory if it
224 AC_CACHE_CHECK([for $am_display_PYTHON script directory],
225 [am_cv_python_pythondir],
226 [am_cv_python_pythondir=`$PYTHON -c "from distutils import sysconfig; print(sysconfig.get_python_lib(0,0,prefix='$PYTHON_PREFIX'))" 2>/dev/null ||
227 echo "$PYTHON_PREFIX/lib/python$PYTHON_VERSION/site-packages"`])
228 AC_SUBST([pythondir], [$am_cv_python_pythondir])
230 dnl pkgpythondir -- $PACKAGE directory under pythondir. Was
231 dnl PYTHON_SITE_PACKAGE in previous betas, but this naming is
232 dnl more consistent with the rest of automake.
234 AC_SUBST([pkgpythondir], [\${pythondir}/$PACKAGE])
236 dnl pyexecdir -- directory for installing python extension modules
237 dnl (shared libraries)
238 dnl Query distutils for this directory. distutils does not exist in
239 dnl Python 1.5, so we fall back to the hardcoded directory if it
241 AC_CACHE_CHECK([for $am_display_PYTHON extension module directory],
242 [am_cv_python_pyexecdir],
243 [am_cv_python_pyexecdir=`$PYTHON -c "from distutils import sysconfig; print(sysconfig.get_python_lib(1,0,prefix='$PYTHON_EXEC_PREFIX'))" 2>/dev/null ||
244 echo "${PYTHON_EXEC_PREFIX}/lib/python${PYTHON_VERSION}/site-packages"`])
245 AC_SUBST([pyexecdir], [$am_cv_python_pyexecdir])
247 dnl pkgpyexecdir -- $(pyexecdir)/$(PACKAGE)
249 AC_SUBST([pkgpyexecdir], [\${pyexecdir}/$PACKAGE])
251 dnl Run any user-specified action.