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 PYTHON_INCLUDES=`$PYTHON -c "import distutils.sysconfig, sys; sys.stdout.write(distutils.sysconfig.get_python_inc(True))"`
52 PYTHON_INCLUDES="-I$PYTHON_INCLUDES"
55 AC_SUBST(PYTHON_INCLUDES)
56 dnl check if the headers exist:
57 save_CPPFLAGS="$CPPFLAGS"
58 CPPFLAGS="$CPPFLAGS $PYTHON_INCLUDES"
59 AC_TRY_CPP([#include <Python.h>],dnl
62 [AC_MSG_RESULT(not found)
64 CPPFLAGS="$save_CPPFLAGS"
67 dnl a macro to check for ability to embed python
68 dnl AM_CHECK_PYTHON_LIBS([ACTION-IF-POSSIBLE], [ACTION-IF-NOT-POSSIBLE])
69 dnl function also defines PYTHON_LIBS
70 AC_DEFUN([AM_CHECK_PYTHON_LIBS],
71 [AC_REQUIRE([AM_PATH_PYTHON])
72 AC_MSG_CHECKING(for libraries required to embed python)
73 dnl deduce PYTHON_LIBS
74 py_prefix=`$PYTHON -c "import sys; sys.stdout.write(sys.prefix)"`
75 if test "x$PYTHON_LIBS" = x; then
76 PYTHON_LIBS="-L${py_prefix}/lib -lpython${PYTHON_VERSION}"
78 if test "x$PYTHON_LIB_LOC" = x; then
79 PYTHON_LIB_LOC="${py_prefix}/lib"
82 AC_SUBST(PYTHON_LIB_LOC)
83 dnl check if the headers exist:
85 LIBS="$LIBS $PYTHON_LIBS"
86 AC_TRY_LINK_FUNC(Py_Initialize, dnl
87 [LIBS="$save_LIBS"; AC_MSG_RESULT(yes); $1], dnl
88 [LIBS="$save_LIBS"; AC_MSG_RESULT(no); $2])
92 # Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005
93 # Free Software Foundation, Inc.
95 # This file is free software; the Free Software Foundation
96 # gives unlimited permission to copy and/or distribute it,
97 # with or without modifications, as long as this notice is preserved.
99 # JD_PATH_PYTHON([MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
100 # ---------------------------------------------------------------------------
101 # Adds support for distributing Python modules and packages. To
102 # install modules, copy them to $(pythondir), using the python_PYTHON
103 # automake variable. To install a package with the same name as the
104 # automake package, install to $(pkgpythondir), or use the
105 # pkgpython_PYTHON automake variable.
107 # The variables $(pyexecdir) and $(pkgpyexecdir) are provided as
108 # locations to install python extension modules (shared libraries).
109 # Another macro is required to find the appropriate flags to compile
112 # If your package is configured with a different prefix to python,
113 # users will have to add the install directory to the PYTHONPATH
114 # environment variable, or create a .pth file (see the python
115 # documentation for details).
117 # If the MINIMUM-VERSION argument is passed, AM_PATH_PYTHON will
118 # cause an error if the version of python installed on the system
119 # doesn't meet the requirement. MINIMUM-VERSION should consist of
120 # numbers and dots only.
121 AC_DEFUN([JD_PATH_PYTHON],
123 dnl Find a Python interpreter. Python versions prior to 2.0 are not
125 m4_define_default([_AM_PYTHON_INTERPRETER_LIST],
126 [python3 python3.3 python3.2 python3.1 python2 python2.7 python])
129 dnl No version check is needed.
130 # Find any Python interpreter.
131 if test -z "$PYTHON"; then
132 AC_PATH_PROGS([PYTHON], _AM_PYTHON_INTERPRETER_LIST, :)
134 am_display_PYTHON=python
136 dnl A version check is needed.
137 if test -n "$PYTHON"; then
138 # If the user set $PYTHON, use it and don't search something else.
139 AC_MSG_CHECKING([whether $PYTHON version >= $1])
140 AM_PYTHON_CHECK_VERSION([$PYTHON], [$1],
141 [AC_MSG_RESULT(yes)],
142 [AC_MSG_ERROR(too old)])
143 am_display_PYTHON=$PYTHON
145 # Otherwise, try each interpreter until we find one that satisfies
147 AC_CACHE_CHECK([for a Python interpreter with version >= $1],
148 [am_cv_pathless_PYTHON],[
149 for am_cv_pathless_PYTHON in _AM_PYTHON_INTERPRETER_LIST none; do
150 test "$am_cv_pathless_PYTHON" = none && break
151 AM_PYTHON_CHECK_VERSION([$am_cv_pathless_PYTHON], [$1], [break])
153 # Set $PYTHON to the absolute path of $am_cv_pathless_PYTHON.
154 if test "$am_cv_pathless_PYTHON" = none; then
157 AC_PATH_PROG([PYTHON], [$am_cv_pathless_PYTHON])
159 am_display_PYTHON=$am_cv_pathless_PYTHON
163 if test "$PYTHON" = :; then
164 dnl Run any user-specified action, or abort.
165 m4_default([$3], [AC_MSG_ERROR([no suitable Python interpreter found])])
168 dnl Query Python for its version number. Getting [:3] seems to be
169 dnl the best way to do this; it's what "site.py" does in the standard
172 AC_CACHE_CHECK([for $am_display_PYTHON version], [am_cv_python_version],
173 [am_cv_python_version=`$PYTHON -c "import sys; sys.stdout.write(sys.version[[:3]])"`])
174 AC_SUBST([PYTHON_VERSION], [$am_cv_python_version])
176 dnl Use the values of $prefix and $exec_prefix for the corresponding
177 dnl values of PYTHON_PREFIX and PYTHON_EXEC_PREFIX. These are made
178 dnl distinct variables so they can be overridden if need be. However,
179 dnl general consensus is that you shouldn't need this ability.
181 AC_SUBST([PYTHON_PREFIX], ['${prefix}'])
182 AC_SUBST([PYTHON_EXEC_PREFIX], ['${exec_prefix}'])
184 dnl At times (like when building shared libraries) you may want
185 dnl to know which OS platform Python thinks this is.
187 AC_CACHE_CHECK([for $am_display_PYTHON platform], [am_cv_python_platform],
188 [am_cv_python_platform=`$PYTHON -c "import sys; sys.stdout.write(sys.platform)"`])
189 AC_SUBST([PYTHON_PLATFORM], [$am_cv_python_platform])
192 dnl Set up 4 directories:
194 dnl pythondir -- where to install python scripts. This is the
195 dnl site-packages directory, not the python standard library
196 dnl directory like in previous automake betas. This behavior
197 dnl is more consistent with lispdir.m4 for example.
198 dnl Query distutils for this directory. distutils does not exist in
199 dnl Python 1.5, so we fall back to the hardcoded directory if it
201 AC_CACHE_CHECK([for $am_display_PYTHON script directory],
202 [am_cv_python_pythondir],
203 [am_cv_python_pythondir=`$PYTHON -c "from distutils import sysconfig; print(sysconfig.get_python_lib(0,0,prefix='$PYTHON_PREFIX'))" 2>/dev/null ||
204 echo "$PYTHON_PREFIX/lib/python$PYTHON_VERSION/site-packages"`])
205 AC_SUBST([pythondir], [$am_cv_python_pythondir])
207 dnl pkgpythondir -- $PACKAGE directory under pythondir. Was
208 dnl PYTHON_SITE_PACKAGE in previous betas, but this naming is
209 dnl more consistent with the rest of automake.
211 AC_SUBST([pkgpythondir], [\${pythondir}/$PACKAGE])
213 dnl pyexecdir -- directory for installing python extension modules
214 dnl (shared libraries)
215 dnl Query distutils for this directory. distutils does not exist in
216 dnl Python 1.5, so we fall back to the hardcoded directory if it
218 AC_CACHE_CHECK([for $am_display_PYTHON extension module directory],
219 [am_cv_python_pyexecdir],
220 [am_cv_python_pyexecdir=`$PYTHON -c "from distutils import sysconfig; print(sysconfig.get_python_lib(1,0,prefix='$PYTHON_EXEC_PREFIX'))" 2>/dev/null ||
221 echo "${PYTHON_EXEC_PREFIX}/lib/python${PYTHON_VERSION}/site-packages"`])
222 AC_SUBST([pyexecdir], [$am_cv_python_pyexecdir])
224 dnl pkgpyexecdir -- $(pyexecdir)/$(PACKAGE)
226 AC_SUBST([pkgpyexecdir], [\${pyexecdir}/$PACKAGE])
228 dnl Run any user-specified action.