1 ## ------------------------ -*- Autoconf -*-
2 ## Python file handling
4 ## Updated by James Henstridge
5 ## ------------------------
6 # Copyright (C) 1999-2013 Free Software Foundation, Inc.
8 # This file is free software; the Free Software Foundation
9 # gives unlimited permission to copy and/or distribute it,
10 # with or without modifications, as long as this notice is preserved.
12 # This is a modified version of the original python.m4 file which only
13 # tries to use Python 2.x.
16 # AM_PATH_PYTHON([MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
17 # ---------------------------------------------------------------------------
18 # Adds support for distributing Python modules and packages. To
19 # install modules, copy them to $(pythondir), using the python_PYTHON
20 # automake variable. To install a package with the same name as the
21 # automake package, install to $(pkgpythondir), or use the
22 # pkgpython_PYTHON automake variable.
24 # The variables $(pyexecdir) and $(pkgpyexecdir) are provided as
25 # locations to install python extension modules (shared libraries).
26 # Another macro is required to find the appropriate flags to compile
29 # If your package is configured with a different prefix to python,
30 # users will have to add the install directory to the PYTHONPATH
31 # environment variable, or create a .pth file (see the python
32 # documentation for details).
34 # If the MINIMUM-VERSION argument is passed, AM_PATH_PYTHON will
35 # cause an error if the version of python installed on the system
36 # doesn't meet the requirement. MINIMUM-VERSION should consist of
37 # numbers and dots only.
38 AC_DEFUN([AM_PATH_PYTHON],
40 dnl Find a Python interpreter. Python versions prior to 2.0 are not
41 dnl supported. (2.0 was released on October 16, 2000).
42 m4_define_default([_AM_PYTHON_INTERPRETER_LIST],
43 [python2 python2.7 dnl
44 python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 python2.0])
46 AC_ARG_VAR([PYTHON], [the Python interpreter])
49 dnl No version check is needed.
50 # Find any Python interpreter.
51 if test -z "$PYTHON"; then
52 AC_PATH_PROGS([PYTHON], _AM_PYTHON_INTERPRETER_LIST, :)
54 am_display_PYTHON=python
56 dnl A version check is needed.
57 if test -n "$PYTHON"; then
58 # If the user set $PYTHON, use it and don't search something else.
59 AC_MSG_CHECKING([whether $PYTHON version is >= $1])
60 AM_PYTHON_CHECK_VERSION([$PYTHON], [$1],
61 [AC_MSG_RESULT([yes])],
63 AC_MSG_ERROR([Python interpreter is too old])])
64 am_display_PYTHON=$PYTHON
66 # Otherwise, try each interpreter until we find one that satisfies
68 AC_CACHE_CHECK([for a Python interpreter with version >= $1],
69 [am_cv_pathless_PYTHON],[
70 for am_cv_pathless_PYTHON in _AM_PYTHON_INTERPRETER_LIST none; do
71 test "$am_cv_pathless_PYTHON" = none && break
72 AM_PYTHON_CHECK_VERSION([$am_cv_pathless_PYTHON], [$1], [break])
74 # Set $PYTHON to the absolute path of $am_cv_pathless_PYTHON.
75 if test "$am_cv_pathless_PYTHON" = none; then
78 AC_PATH_PROG([PYTHON], [$am_cv_pathless_PYTHON])
80 am_display_PYTHON=$am_cv_pathless_PYTHON
84 if test "$PYTHON" = :; then
85 dnl Run any user-specified action, or abort.
86 m4_default([$3], [AC_MSG_ERROR([no suitable Python interpreter found])])
89 dnl Query Python for its version number. Getting [:3] seems to be
90 dnl the best way to do this; it's what "site.py" does in the standard
93 AC_CACHE_CHECK([for $am_display_PYTHON version], [am_cv_python_version],
94 [am_cv_python_version=`$PYTHON -c "import sys; sys.stdout.write(sys.version[[:3]])"`])
95 AC_SUBST([PYTHON_VERSION], [$am_cv_python_version])
97 dnl Use the values of $prefix and $exec_prefix for the corresponding
98 dnl values of PYTHON_PREFIX and PYTHON_EXEC_PREFIX. These are made
99 dnl distinct variables so they can be overridden if need be. However,
100 dnl general consensus is that you shouldn't need this ability.
102 AC_SUBST([PYTHON_PREFIX], ['${prefix}'])
103 AC_SUBST([PYTHON_EXEC_PREFIX], ['${exec_prefix}'])
105 dnl At times (like when building shared libraries) you may want
106 dnl to know which OS platform Python thinks this is.
108 AC_CACHE_CHECK([for $am_display_PYTHON platform], [am_cv_python_platform],
109 [am_cv_python_platform=`$PYTHON -c "import sys; sys.stdout.write(sys.platform)"`])
110 AC_SUBST([PYTHON_PLATFORM], [$am_cv_python_platform])
112 # Just factor out some code duplication.
113 am_python_setup_sysconfig="\
115 # Prefer sysconfig over distutils.sysconfig, for better compatibility
116 # with python 3.x. See automake bug#10227.
120 can_use_sysconfig = 0
122 can_use_sysconfig = 1
123 # Can't use sysconfig in CPython 2.7, since it's broken in virtualenvs:
124 # <https://github.com/pypa/virtualenv/issues/118>
126 from platform import python_implementation
127 if python_implementation() == 'CPython' and sys.version[[:3]] == '2.7':
128 can_use_sysconfig = 0
132 dnl Set up 4 directories:
134 dnl pythondir -- where to install python scripts. This is the
135 dnl site-packages directory, not the python standard library
136 dnl directory like in previous automake betas. This behavior
137 dnl is more consistent with lispdir.m4 for example.
138 dnl Query distutils for this directory.
139 AC_CACHE_CHECK([for $am_display_PYTHON script directory],
140 [am_cv_python_pythondir],
141 [if test "x$prefix" = xNONE
143 am_py_prefix=$ac_default_prefix
147 am_cv_python_pythondir=`$PYTHON -c "
148 $am_python_setup_sysconfig
149 if can_use_sysconfig:
150 sitedir = sysconfig.get_path('purelib', vars={'base':'$am_py_prefix'})
152 from distutils import sysconfig
153 sitedir = sysconfig.get_python_lib(0, 0, prefix='$am_py_prefix')
154 sys.stdout.write(sitedir)"`
155 case $am_cv_python_pythondir in
157 am__strip_prefix=`echo "$am_py_prefix" | sed 's|.|.|g'`
158 am_cv_python_pythondir=`echo "$am_cv_python_pythondir" | sed "s,^$am__strip_prefix,$PYTHON_PREFIX,"`
161 case $am_py_prefix in
164 am_cv_python_pythondir=$PYTHON_PREFIX/lib/python$PYTHON_VERSION/site-packages
170 AC_SUBST([pythondir], [$am_cv_python_pythondir])
172 dnl pkgpythondir -- $PACKAGE directory under pythondir. Was
173 dnl PYTHON_SITE_PACKAGE in previous betas, but this naming is
174 dnl more consistent with the rest of automake.
176 AC_SUBST([pkgpythondir], [\${pythondir}/$PACKAGE])
178 dnl pyexecdir -- directory for installing python extension modules
179 dnl (shared libraries)
180 dnl Query distutils for this directory.
181 AC_CACHE_CHECK([for $am_display_PYTHON extension module directory],
182 [am_cv_python_pyexecdir],
183 [if test "x$exec_prefix" = xNONE
185 am_py_exec_prefix=$am_py_prefix
187 am_py_exec_prefix=$exec_prefix
189 am_cv_python_pyexecdir=`$PYTHON -c "
190 $am_python_setup_sysconfig
191 if can_use_sysconfig:
192 sitedir = sysconfig.get_path('platlib', vars={'platbase':'$am_py_prefix'})
194 from distutils import sysconfig
195 sitedir = sysconfig.get_python_lib(1, 0, prefix='$am_py_prefix')
196 sys.stdout.write(sitedir)"`
197 case $am_cv_python_pyexecdir in
199 am__strip_prefix=`echo "$am_py_exec_prefix" | sed 's|.|.|g'`
200 am_cv_python_pyexecdir=`echo "$am_cv_python_pyexecdir" | sed "s,^$am__strip_prefix,$PYTHON_EXEC_PREFIX,"`
203 case $am_py_exec_prefix in
206 am_cv_python_pyexecdir=$PYTHON_EXEC_PREFIX/lib/python$PYTHON_VERSION/site-packages
212 AC_SUBST([pyexecdir], [$am_cv_python_pyexecdir])
214 dnl pkgpyexecdir -- $(pyexecdir)/$(PACKAGE)
216 AC_SUBST([pkgpyexecdir], [\${pyexecdir}/$PACKAGE])
218 dnl Run any user-specified action.
225 # AM_PYTHON_CHECK_VERSION(PROG, VERSION, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
226 # ---------------------------------------------------------------------------
227 # Run ACTION-IF-TRUE if the Python interpreter PROG has version >= VERSION.
228 # Run ACTION-IF-FALSE otherwise.
229 # This test uses sys.hexversion instead of the string equivalent (first
230 # word of sys.version), in order to cope with versions such as 2.2c1.
231 # This supports Python 2.0 or higher. (2.0 was released on October 16, 2000).
232 AC_DEFUN([AM_PYTHON_CHECK_VERSION],
234 # split strings by '.' and convert to numeric. Append some zeros
235 # because we need at least 4 digits for the hex conversion.
236 # map returns an iterator in Python 3.0 and a list in 2.x
237 minver = list(map(int, '$2'.split('.'))) + [[0, 0, 0]]
239 # xrange is not present in Python 3.0 and range returns an iterator
240 for i in list(range(0, 4)): minverhex = (minverhex << 8) + minver[[i]]
241 sys.exit(sys.hexversion < minverhex)"
242 AS_IF([AM_RUN_LOG([$1 -c "$prog"])], [$3], [$4])])