Debian Codegraph @

m4/python.m4

raw ◀ ▶
1 Debian patch touch this file
1 ## ------------------------ -*- Autoconf -*-
2 ## Python file handling
3 ## From Andrew Dalke
4 ## Updated by James Henstridge
5 ## ------------------------
6 # Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
7 # Free Software Foundation, Inc.
8 #
9 # This file is free software; the Free Software Foundation
10 # gives unlimited permission to copy and/or distribute it,
11 # with or without modifications, as long as this notice is preserved.
12
13 # AM_PATH_PYTHON([MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
14 # ---------------------------------------------------------------------------
15 # Adds support for distributing Python modules and packages. To
16 # install modules, copy them to $(pythondir), using the python_PYTHON
17 # automake variable. To install a package with the same name as the
18 # automake package, install to $(pkgpythondir), or use the
19 # pkgpython_PYTHON automake variable.
20 #
21 # The variables $(pyexecdir) and $(pkgpyexecdir) are provided as
22 # locations to install python extension modules (shared libraries).
23 # Another macro is required to find the appropriate flags to compile
24 # extension modules.
25 #
26 # If your package is configured with a different prefix to python,
27 # users will have to add the install directory to the PYTHONPATH
28 # environment variable, or create a .pth file (see the python
29 # documentation for details).
30 #
31 # If the MINIMUM-VERSION argument is passed, AM_PATH_PYTHON will
32 # cause an error if the version of python installed on the system
33 # doesn't meet the requirement. MINIMUM-VERSION should consist of
34 # numbers and dots only.
35
36 ############ CHANGES FOR GENGEO (search for GENGEO for details) ############
37 # * updated the search list of Python executables
38 # * added the detection of Python major and minor versions
39 # * added the detection of ABI tags used in Python names from version 3.2
40 # * added a check for the location of the fully named Python executable
41
42 AC_DEFUN([AM_PATH_PYTHON],
43 [
44 dnl Find a Python interpreter. Python versions prior to 2.0 are not
45 dnl supported. (2.0 was released on October 16, 2000).
46 dnl
47 dnl CHANGED FOR GENGEO:
48 dnl * Search list of Python executables updated
49 m4_define_default([_AM_PYTHON_INTERPRETER_LIST],
50 [python python2 python3 python2.0 python2.1 python2.2 dnl
51 python2.3 python2.4 python2.5 python2.6 python2.7 python3.0 python3.1 python3.2 dnl
•52 python3.3 python3.4 python3.5 python3.6 python3.7 python3.8 python3.9 python3.10 python3.11])
53
54 m4_if([$1],[],[
55 dnl No version check is needed.
56 # Find any Python interpreter.
57 if test -z "$PYTHON"; then
58 AC_PATH_PROGS([PYTHON], _AM_PYTHON_INTERPRETER_LIST, :)
59 fi
60 am_display_PYTHON=python
61 ], [
62 dnl A version check is needed.
63 if test -n "$PYTHON"; then
64 # If the user set $PYTHON, use it and don't search something else.
65 AC_MSG_CHECKING([whether $PYTHON version >= $1])
66 AM_PYTHON_CHECK_VERSION([$PYTHON], [$1],
67 [AC_MSG_RESULT(yes)],
68 [AC_MSG_ERROR(too old)])
69 am_display_PYTHON=$PYTHON
70 else
71 # Otherwise, try each interpreter until we find one that satisfies
72 # VERSION.
73 AC_CACHE_CHECK([for a Python interpreter with version >= $1],
74 [am_cv_pathless_PYTHON],[
75 for am_cv_pathless_PYTHON in _AM_PYTHON_INTERPRETER_LIST none; do
76 test "$am_cv_pathless_PYTHON" = none && break
77 AM_PYTHON_CHECK_VERSION([$am_cv_pathless_PYTHON], [$1], [break])
78 done])
79 # Set $PYTHON to the absolute path of $am_cv_pathless_PYTHON.
80 if test "$am_cv_pathless_PYTHON" = none; then
81 PYTHON=:
82 else
83 AC_PATH_PROG([PYTHON], [$am_cv_pathless_PYTHON])
84 fi
85 am_display_PYTHON=$am_cv_pathless_PYTHON
86 fi
87 ])
88
89 if test "$PYTHON" = :; then
90 dnl Run any user-specified action, or abort.
91 m4_default([$3], [AC_MSG_ERROR([no suitable Python interpreter found])])
92 else
93
94 dnl Query Python for its version number. Getting [:3] seems to be
95 dnl the best way to do this; it's what "site.py" does in the standard
96 dnl library.
97 AC_CACHE_CHECK([for $am_display_PYTHON version], [am_cv_python_version],
•98 [am_cv_python_version=`$PYTHON -c "import sys; print(str(sys.version_info.major) + '.' + str(sys.version_info.minor))"`])
99 AC_SUBST([PYTHON_VERSION], [$am_cv_python_version])
100
101 dnl CHANGED FOR GENGEO:
102 dnl * Added the detection of Python major and minor versions
103 dnl * Added the check for Python version 3.2 and higher as the naming convention for
104 dnl libraries changed to allow any combination of the tags `d', `m' and `u'; so this
105 dnl adds the PYTHON_VERSION_SUFFIX variable to be used on any subsequent commands.
106 dnl (The next commented lines are two earlier solutions for handling the new naming convention.)
107 dnl * Added a check for the location of the fully named Python executable
108 am_cv_python_major_version=`$PYTHON -c "import sys;sys.stdout.write(str(sys.version_info[[0]]))"`
109 am_cv_python_minor_version=`$PYTHON -c "import sys;sys.stdout.write(str(sys.version_info[[1]]))"`
110 AC_SUBST([PYTHON_MAJOR_VERSION], [${am_cv_python_major_version}])
111 AC_SUBST([PYTHON_MINOR_VERSION], [${am_cv_python_minor_version}])
112 if [[ $PYTHON_MAJOR_VERSION -ge 4 ]] || ([[ $PYTHON_MAJOR_VERSION -eq 3 ]] && [[ $PYTHON_MINOR_VERSION -ge 2 ]])
113 then
114 #
115 # Current GENGEO solution to Python's new naming convention
116 AC_MSG_CHECKING(for the Python ABI tags)
117 am_cv_python_version_suffix=`$PYTHON -c "import sys,sysconfig;sys.stdout.write(sysconfig.get_config_var('ABIFLAGS'))"`
118 AC_MSG_RESULT([${am_cv_python_version_suffix}])
119 #
120 # Second GENGEO solution to Python's new naming convention
121 #am_cv_pyconfig_h=`$PYTHON -c "import sys,sysconfig;sys.stdout.write(sysconfig.get_config_h_filename())"`
122 #am_cv_python_version_suffix=${am_cv_pyconfig_h#*python${PYTHON_VERSION}}
123 #am_cv_python_version_suffix=${am_cv_python_version_suffix%\/*}
124 #
125 # First GENGEO solution to Python's new naming convention
126 #am_cv_python_pymalloc=m
127 #am_cv_python_wide_unicode=`$PYTHON -c "exec(\"import sys\\nif sys.maxunicode == 1114111 and sys.version_info[[0]] == 3 and sys.version_info[[1]] == 2: sys.stdout.write('u')\")"`
128 #AC_MSG_CHECKING(for Python's Py_DEBUG status)
129 #m4_pattern_allow([^Py_DEBUG$])dnl
130 #AC_EGREP_CPP(yes,
131 # [
132 # #include <${am_cv_pyconfig_h}>
133 # #if Py_DEBUG == 1
134 # python-pydebug-status = yes
135 # #endif
136 # ],
137 # [am_cv_python_pydebug_status=1; am_cv_python_pydebug=d],
138 # [am_cv_python_pydebug_status="0 or undefined"; am_cv_pydebug_info="no tag"; am_cv_python_pydebug=])
139 #AC_MSG_RESULT([${am_cv_python_pydebug_status} => ${am_cv_pydebug_info}${am_cv_python_pydebug}])
140 #AC_MSG_CHECKING(for Python's WITH_PYMALLOC status)
141 #m4_pattern_allow([^WITH_PYMALLOC$])dnl
142 #AC_EGREP_CPP(yes,
143 # [
144 # #include <${am_cv_pyconfig_h}>
145 # #if WITH_PYMALLOC == 1
146 # python-pymalloc-status = yes
147 # #endif
148 # ],
149 # [am_cv_python_pymalloc_status=1; am_cv_python_pymalloc=m],
150 # [am_cv_python_pymalloc_status="0 or undefined"; am_cv_pymalloc_info="no tag"; am_cv_python_pymalloc=])
151 #AC_MSG_RESULT([${am_cv_python_pymalloc_status} => ${am_cv_pymalloc_info}${am_cv_python_pymalloc}])
152 fi
153 #
154 # First GENGEO solution to Python's new naming convention
155 #AC_SUBST([PYTHON_VERSION_SUFFIX], [$am_cv_python_pydebug$am_cv_python_pymalloc$am_cv_python_wide_unicode])
156 AC_SUBST([PYTHON_VERSION_SUFFIX], [${am_cv_python_version_suffix}])
157 AC_MSG_CHECKING([for the location of the Python executable python${PYTHON_VERSION}${PYTHON_VERSION_SUFFIX}])
158 am_cv_python_bin=$(which python${PYTHON_VERSION}${PYTHON_VERSION_SUFFIX})
159 if ! test -z ${am_cv_python_bin}
160 then
161 AC_MSG_RESULT([${am_cv_python_bin}])
162 else
163 AC_MSG_ERROR(
164 [not found: the ABI tag combination "${PYTHON_VERSION_SUFFIX}" calculated for the library name is wrong])
165 fi
166
167 dnl Use the values of $prefix and $exec_prefix for the corresponding
168 dnl values of PYTHON_PREFIX and PYTHON_EXEC_PREFIX. These are made
169 dnl distinct variables so they can be overridden if need be. However,
170 dnl general consensus is that you shouldn't need this ability.
171
172 AC_SUBST([PYTHON_PREFIX], ['${prefix}'])
173 AC_SUBST([PYTHON_EXEC_PREFIX], ['${exec_prefix}'])
174
175 dnl At times (like when building shared libraries) you may want
176 dnl to know which OS platform Python thinks this is.
177
178 AC_CACHE_CHECK([for $am_display_PYTHON platform], [am_cv_python_platform],
179 [am_cv_python_platform=`$PYTHON -c "import sys; sys.stdout.write(sys.platform)"`])
180 AC_SUBST([PYTHON_PLATFORM], [$am_cv_python_platform])
181
182
183 dnl Set up 4 directories:
184
185 dnl pythondir -- where to install python scripts. This is the
186 dnl site-packages directory, not the python standard library
187 dnl directory like in previous automake betas. This behavior
188 dnl is more consistent with lispdir.m4 for example.
189 dnl Query distutils for this directory. distutils does not exist in
190 dnl Python 1.5, so we fall back to the hardcoded directory if it
191 dnl doesn't work.
192 AC_CACHE_CHECK([for $am_display_PYTHON script directory],
193 [am_cv_python_pythondir],
194 [if test "x$prefix" = xNONE
195 then
196 am_py_prefix=$ac_default_prefix
197 else
198 am_py_prefix=$prefix
199 fi
200 am_cv_python_pythondir=`$PYTHON -c "import sys; from distutils import sysconfig; sys.stdout.write(sysconfig.get_python_lib(0,0,prefix='$am_py_prefix'))" 2>/dev/null ||
201 echo "$PYTHON_PREFIX/lib/python$PYTHON_VERSION/site-packages"`
202 case $am_cv_python_pythondir in
203 $am_py_prefix*)
204 am__strip_prefix=`echo "$am_py_prefix" | sed 's|.|.|g'`
205 am_cv_python_pythondir=`echo "$am_cv_python_pythondir" | sed "s,^$am__strip_prefix,$PYTHON_PREFIX,"`
206 ;;
207 esac
208 ])
209 AC_SUBST([pythondir], [$am_cv_python_pythondir])
210
211 dnl pkgpythondir -- $PACKAGE directory under pythondir. Was
212 dnl PYTHON_SITE_PACKAGE in previous betas, but this naming is
213 dnl more consistent with the rest of automake.
214
215 AC_SUBST([pkgpythondir], [\${pythondir}/$PACKAGE])
216
217 dnl pyexecdir -- directory for installing python extension modules
218 dnl (shared libraries)
219 dnl Query distutils for this directory. distutils does not exist in
220 dnl Python 1.5, so we fall back to the hardcoded directory if it
221 dnl doesn't work.
222 AC_CACHE_CHECK([for $am_display_PYTHON extension module directory],
223 [am_cv_python_pyexecdir],
224 [if test "x$exec_prefix" = xNONE
225 then
226 am_py_exec_prefix=$am_py_prefix
227 else
228 am_py_exec_prefix=$exec_prefix
229 fi
230 am_cv_python_pyexecdir=`$PYTHON -c "import sys; from distutils import sysconfig; sys.stdout.write(sysconfig.get_python_lib(1,0,prefix='$am_py_exec_prefix'))" 2>/dev/null ||
231 echo "$PYTHON_EXEC_PREFIX/lib/python$PYTHON_VERSION/site-packages"`
232 case $am_cv_python_pyexecdir in
233 $am_py_exec_prefix*)
234 am__strip_prefix=`echo "$am_py_exec_prefix" | sed 's|.|.|g'`
235 am_cv_python_pyexecdir=`echo "$am_cv_python_pyexecdir" | sed "s,^$am__strip_prefix,$PYTHON_EXEC_PREFIX,"`
236 ;;
237 esac
238 ])
239 AC_SUBST([pyexecdir], [$am_cv_python_pyexecdir])
240
241 dnl pkgpyexecdir -- $(pyexecdir)/$(PACKAGE)
242
243 AC_SUBST([pkgpyexecdir], [\${pyexecdir}/$PACKAGE])
244
245 dnl Run any user-specified action.
246 $2
247 fi
248
249 ])
250
251
252 # AM_PYTHON_CHECK_VERSION(PROG, VERSION, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
253 # ---------------------------------------------------------------------------
254 # Run ACTION-IF-TRUE if the Python interpreter PROG has version >= VERSION.
255 # Run ACTION-IF-FALSE otherwise.
256 # This test uses sys.hexversion instead of the string equivalent (first
257 # word of sys.version), in order to cope with versions such as 2.2c1.
258 # This supports Python 2.0 or higher. (2.0 was released on October 16, 2000).
259 AC_DEFUN([AM_PYTHON_CHECK_VERSION],
260 [prog="import sys
261 # split strings by '.' and convert to numeric. Append some zeros
262 # because we need at least 4 digits for the hex conversion.
263 # map returns an iterator in Python 3.0 and a list in 2.x
264 minver = list(map(int, '$2'.split('.'))) + [[0, 0, 0]]
265 minverhex = 0
266 # xrange is not present in Python 3.0 and range returns an iterator
267 for i in list(range(0, 4)): minverhex = (minverhex << 8) + minver[[i]]
268 sys.exit(sys.hexversion < minverhex)"
269 AS_IF([AM_RUN_LOG([$1 -c "$prog"])], [$3], [$4])])