blob: 62a4869c95580efa9ae3195316dc952aa0be983a [file] [log] [blame]
Andrew Geisslerc5535c92023-01-27 16:10:19 -06001From f1418e1b46cb1cbd130935b76f5c78c577d1ad28 Mon Sep 17 00:00:00 2001
2From: Matthew Newton <matthew-git@newtoncomputing.co.uk>
3Date: Wed, 28 Sep 2022 23:49:32 +0100
4Subject: [PATCH] add python.m4 for detecting python > 3.10
5
6Upstream-Status: Backport
7[https://github.com/FreeRADIUS/freeradius-server/commit/86584d2753829756cc73aadce5d48f703af472b1]
8
9Signed-off-by: Yi Zhao <yi.zhao@windriver.com>
10---
11 src/modules/rlm_python3/configure.ac | 4 +
12 src/modules/rlm_python3/m4/python.m4 | 363 +++++++++++++++++++++++++++
13 src/modules/rlm_python3/m4/runlog.m4 | 17 ++
14 3 files changed, 384 insertions(+)
15 create mode 100644 src/modules/rlm_python3/m4/python.m4
16 create mode 100644 src/modules/rlm_python3/m4/runlog.m4
17
18diff --git a/src/modules/rlm_python3/configure.ac b/src/modules/rlm_python3/configure.ac
19index bc0e97f9ba..90f2116e73 100644
20--- a/src/modules/rlm_python3/configure.ac
21+++ b/src/modules/rlm_python3/configure.ac
22@@ -3,6 +3,10 @@ AC_INIT(rlm_python3.c)
23 AC_REVISION($Revision$)
24 AC_DEFUN(modname,[rlm_python3])
25
26+m4_include([ax_compare_version.m4])
27+m4_include([runlog.m4])
28+m4_include([python.m4])
29+
30 AC_ARG_WITH([]modname,
31 [ --with-[]modname build []modname. (default=yes)])
32
33diff --git a/src/modules/rlm_python3/m4/python.m4 b/src/modules/rlm_python3/m4/python.m4
34new file mode 100644
35index 0000000000..78ca7635ab
36--- /dev/null
37+++ b/src/modules/rlm_python3/m4/python.m4
38@@ -0,0 +1,363 @@
39+## ------------------------ -*- Autoconf -*-
40+## Python file handling
41+## From Andrew Dalke
42+## Updated by James Henstridge and other contributors.
43+## ------------------------
44+# Copyright (C) 1999-2021 Free Software Foundation, Inc.
45+#
46+# This file is free software; the Free Software Foundation
47+# gives unlimited permission to copy and/or distribute it,
48+# with or without modifications, as long as this notice is preserved.
49+
50+
51+# AM_PATH_PYTHON([MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
52+# ---------------------------------------------------------------------------
53+# Adds support for distributing Python modules and packages. To
54+# install modules, copy them to $(pythondir), using the python_PYTHON
55+# automake variable. To install a package with the same name as the
56+# automake package, install to $(pkgpythondir), or use the
57+# pkgpython_PYTHON automake variable.
58+#
59+# The variables $(pyexecdir) and $(pkgpyexecdir) are provided as
60+# locations to install python extension modules (shared libraries).
61+# Another macro is required to find the appropriate flags to compile
62+# extension modules.
63+#
64+# If your package is configured with a different prefix to python,
65+# users will have to add the install directory to the PYTHONPATH
66+# environment variable, or create a .pth file (see the python
67+# documentation for details).
68+#
69+# If the MINIMUM-VERSION argument is passed, AM_PATH_PYTHON will
70+# cause an error if the version of python installed on the system
71+# doesn't meet the requirement. MINIMUM-VERSION should consist of
72+# numbers and dots only.
73+AC_DEFUN([AM_PATH_PYTHON],
74+ [
75+ dnl Find a Python interpreter. Python versions prior to 2.0 are not
76+ dnl supported. (2.0 was released on October 16, 2000).
77+ m4_define_default([_AM_PYTHON_INTERPRETER_LIST],
78+[python python2 python3 dnl
79+ python3.11 python3.10 dnl
80+ python3.9 python3.8 python3.7 python3.6 python3.5 python3.4 python3.3 dnl
81+ python3.2 python3.1 python3.0 dnl
82+ python2.7 python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 dnl
83+ python2.0])
84+
85+ AC_ARG_VAR([PYTHON], [the Python interpreter])
86+
87+ m4_if([$1],[],[
88+ dnl No version check is needed.
89+ # Find any Python interpreter.
90+ if test -z "$PYTHON"; then
91+ AC_PATH_PROGS([PYTHON], _AM_PYTHON_INTERPRETER_LIST, :)
92+ fi
93+ am_display_PYTHON=python
94+ ], [
95+ dnl A version check is needed.
96+ if test -n "$PYTHON"; then
97+ # If the user set $PYTHON, use it and don't search something else.
98+ AC_MSG_CHECKING([whether $PYTHON version is >= $1])
99+ AM_PYTHON_CHECK_VERSION([$PYTHON], [$1],
100+ [AC_MSG_RESULT([yes])],
101+ [AC_MSG_RESULT([no])
102+ AC_MSG_ERROR([Python interpreter is too old])])
103+ am_display_PYTHON=$PYTHON
104+ else
105+ # Otherwise, try each interpreter until we find one that satisfies
106+ # VERSION.
107+ AC_CACHE_CHECK([for a Python interpreter with version >= $1],
108+ [am_cv_pathless_PYTHON],[
109+ for am_cv_pathless_PYTHON in _AM_PYTHON_INTERPRETER_LIST none; do
110+ test "$am_cv_pathless_PYTHON" = none && break
111+ AM_PYTHON_CHECK_VERSION([$am_cv_pathless_PYTHON], [$1], [break])
112+ done])
113+ # Set $PYTHON to the absolute path of $am_cv_pathless_PYTHON.
114+ if test "$am_cv_pathless_PYTHON" = none; then
115+ PYTHON=:
116+ else
117+ AC_PATH_PROG([PYTHON], [$am_cv_pathless_PYTHON])
118+ fi
119+ am_display_PYTHON=$am_cv_pathless_PYTHON
120+ fi
121+ ])
122+
123+ if test "$PYTHON" = :; then
124+ dnl Run any user-specified action, or abort.
125+ m4_default([$3], [AC_MSG_ERROR([no suitable Python interpreter found])])
126+ else
127+
128+ dnl Query Python for its version number. Although site.py simply uses
129+ dnl sys.version[:3], printing that failed with Python 3.10, since the
130+ dnl trailing zero was eliminated. So now we output just the major
131+ dnl and minor version numbers, as numbers. Apparently the tertiary
132+ dnl version is not of interest.
133+ dnl
134+ AC_CACHE_CHECK([for $am_display_PYTHON version], [am_cv_python_version],
135+ [am_cv_python_version=`$PYTHON -c "import sys; print ('%u.%u' % sys.version_info[[:2]])"`])
136+ AC_SUBST([PYTHON_VERSION], [$am_cv_python_version])
137+
138+ dnl At times, e.g., when building shared libraries, you may want
139+ dnl to know which OS platform Python thinks this is.
140+ dnl
141+ AC_CACHE_CHECK([for $am_display_PYTHON platform], [am_cv_python_platform],
142+ [am_cv_python_platform=`$PYTHON -c "import sys; sys.stdout.write(sys.platform)"`])
143+ AC_SUBST([PYTHON_PLATFORM], [$am_cv_python_platform])
144+
145+ dnl emacs-page
146+ dnl If --with-python-sys-prefix is given, use the values of sys.prefix
147+ dnl and sys.exec_prefix for the corresponding values of PYTHON_PREFIX
148+ dnl and PYTHON_EXEC_PREFIX. Otherwise, use the GNU ${prefix} and
149+ dnl ${exec_prefix} variables.
150+ dnl
151+ dnl The two are made distinct variables so they can be overridden if
152+ dnl need be, although general consensus is that you shouldn't need
153+ dnl this separation.
154+ dnl
155+ dnl Also allow directly setting the prefixes via configure options,
156+ dnl overriding any default.
157+ dnl
158+ if test "x$prefix" = xNONE; then
159+ am__usable_prefix=$ac_default_prefix
160+ else
161+ am__usable_prefix=$prefix
162+ fi
163+
164+ # Allow user to request using sys.* values from Python,
165+ # instead of the GNU $prefix values.
166+ AC_ARG_WITH([python-sys-prefix],
167+ [AS_HELP_STRING([--with-python-sys-prefix],
168+ [use Python's sys.prefix and sys.exec_prefix values])],
169+ [am_use_python_sys=:],
170+ [am_use_python_sys=false])
171+
172+ # Allow user to override whatever the default Python prefix is.
173+ AC_ARG_WITH([python_prefix],
174+ [AS_HELP_STRING([--with-python_prefix],
175+ [override the default PYTHON_PREFIX])],
176+ [am_python_prefix_subst=$withval
177+ am_cv_python_prefix=$withval
178+ AC_MSG_CHECKING([for explicit $am_display_PYTHON prefix])
179+ AC_MSG_RESULT([$am_cv_python_prefix])],
180+ [
181+ if $am_use_python_sys; then
182+ # using python sys.prefix value, not GNU
183+ AC_CACHE_CHECK([for python default $am_display_PYTHON prefix],
184+ [am_cv_python_prefix],
185+ [am_cv_python_prefix=`$PYTHON -c "import sys; sys.stdout.write(sys.prefix)"`])
186+
187+ dnl If sys.prefix is a subdir of $prefix, replace the literal value of
188+ dnl $prefix with a variable reference so it can be overridden.
189+ case $am_cv_python_prefix in
190+ $am__usable_prefix*)
191+ am__strip_prefix=`echo "$am__usable_prefix" | sed 's|.|.|g'`
192+ am_python_prefix_subst=`echo "$am_cv_python_prefix" | sed "s,^$am__strip_prefix,\\${prefix},"`
193+ ;;
194+ *)
195+ am_python_prefix_subst=$am_cv_python_prefix
196+ ;;
197+ esac
198+ else # using GNU prefix value, not python sys.prefix
199+ am_python_prefix_subst='${prefix}'
200+ am_python_prefix=$am_python_prefix_subst
201+ AC_MSG_CHECKING([for GNU default $am_display_PYTHON prefix])
202+ AC_MSG_RESULT([$am_python_prefix])
203+ fi])
204+ # Substituting python_prefix_subst value.
205+ AC_SUBST([PYTHON_PREFIX], [$am_python_prefix_subst])
206+
207+ # emacs-page Now do it all over again for Python exec_prefix, but with yet
208+ # another conditional: fall back to regular prefix if that was specified.
209+ AC_ARG_WITH([python_exec_prefix],
210+ [AS_HELP_STRING([--with-python_exec_prefix],
211+ [override the default PYTHON_EXEC_PREFIX])],
212+ [am_python_exec_prefix_subst=$withval
213+ am_cv_python_exec_prefix=$withval
214+ AC_MSG_CHECKING([for explicit $am_display_PYTHON exec_prefix])
215+ AC_MSG_RESULT([$am_cv_python_exec_prefix])],
216+ [
217+ # no explicit --with-python_exec_prefix, but if
218+ # --with-python_prefix was given, use its value for python_exec_prefix too.
219+ AS_IF([test -n "$with_python_prefix"],
220+ [am_python_exec_prefix_subst=$with_python_prefix
221+ am_cv_python_exec_prefix=$with_python_prefix
222+ AC_MSG_CHECKING([for python_prefix-given $am_display_PYTHON exec_prefix])
223+ AC_MSG_RESULT([$am_cv_python_exec_prefix])],
224+ [
225+ # Set am__usable_exec_prefix whether using GNU or Python values,
226+ # since we use that variable for pyexecdir.
227+ if test "x$exec_prefix" = xNONE; then
228+ am__usable_exec_prefix=$am__usable_prefix
229+ else
230+ am__usable_exec_prefix=$exec_prefix
231+ fi
232+ #
233+ if $am_use_python_sys; then # using python sys.exec_prefix, not GNU
234+ AC_CACHE_CHECK([for python default $am_display_PYTHON exec_prefix],
235+ [am_cv_python_exec_prefix],
236+ [am_cv_python_exec_prefix=`$PYTHON -c "import sys; sys.stdout.write(sys.exec_prefix)"`])
237+ dnl If sys.exec_prefix is a subdir of $exec_prefix, replace the
238+ dnl literal value of $exec_prefix with a variable reference so it can
239+ dnl be overridden.
240+ case $am_cv_python_exec_prefix in
241+ $am__usable_exec_prefix*)
242+ am__strip_prefix=`echo "$am__usable_exec_prefix" | sed 's|.|.|g'`
243+ am_python_exec_prefix_subst=`echo "$am_cv_python_exec_prefix" | sed "s,^$am__strip_prefix,\\${exec_prefix},"`
244+ ;;
245+ *)
246+ am_python_exec_prefix_subst=$am_cv_python_exec_prefix
247+ ;;
248+ esac
249+ else # using GNU $exec_prefix, not python sys.exec_prefix
250+ am_python_exec_prefix_subst='${exec_prefix}'
251+ am_python_exec_prefix=$am_python_exec_prefix_subst
252+ AC_MSG_CHECKING([for GNU default $am_display_PYTHON exec_prefix])
253+ AC_MSG_RESULT([$am_python_exec_prefix])
254+ fi])])
255+ # Substituting python_exec_prefix_subst.
256+ AC_SUBST([PYTHON_EXEC_PREFIX], [$am_python_exec_prefix_subst])
257+
258+ # Factor out some code duplication into this shell variable.
259+ am_python_setup_sysconfig="\
260+import sys
261+# Prefer sysconfig over distutils.sysconfig, for better compatibility
262+# with python 3.x. See automake bug#10227.
263+try:
264+ import sysconfig
265+except ImportError:
266+ can_use_sysconfig = 0
267+else:
268+ can_use_sysconfig = 1
269+# Can't use sysconfig in CPython 2.7, since it's broken in virtualenvs:
270+# <https://github.com/pypa/virtualenv/issues/118>
271+try:
272+ from platform import python_implementation
273+ if python_implementation() == 'CPython' and sys.version[[:3]] == '2.7':
274+ can_use_sysconfig = 0
275+except ImportError:
276+ pass"
277+
278+ dnl emacs-page Set up 4 directories:
279+
280+ dnl 1. pythondir: where to install python scripts. This is the
281+ dnl site-packages directory, not the python standard library
282+ dnl directory like in previous automake betas. This behavior
283+ dnl is more consistent with lispdir.m4 for example.
284+ dnl Query distutils for this directory.
285+ dnl
286+ AC_CACHE_CHECK([for $am_display_PYTHON script directory (pythondir)],
287+ [am_cv_python_pythondir],
288+ [if test "x$am_cv_python_prefix" = x; then
289+ am_py_prefix=$am__usable_prefix
290+ else
291+ am_py_prefix=$am_cv_python_prefix
292+ fi
293+ am_cv_python_pythondir=`$PYTHON -c "
294+$am_python_setup_sysconfig
295+if can_use_sysconfig:
296+ if hasattr(sysconfig, 'get_default_scheme'):
297+ scheme = sysconfig.get_default_scheme()
298+ else:
299+ scheme = sysconfig._get_default_scheme()
300+ if scheme == 'posix_local':
301+ # Debian's default scheme installs to /usr/local/ but we want to find headers in /usr/
302+ scheme = 'posix_prefix'
303+ sitedir = sysconfig.get_path('purelib', scheme, vars={'base':'$am_py_prefix'})
304+else:
305+ from distutils import sysconfig
306+ sitedir = sysconfig.get_python_lib(0, 0, prefix='$am_py_prefix')
307+sys.stdout.write(sitedir)"`
308+ #
309+ case $am_cv_python_pythondir in
310+ $am_py_prefix*)
311+ am__strip_prefix=`echo "$am_py_prefix" | sed 's|.|.|g'`
312+ am_cv_python_pythondir=`echo "$am_cv_python_pythondir" | sed "s,^$am__strip_prefix,\\${PYTHON_PREFIX},"`
313+ ;;
314+ *)
315+ case $am_py_prefix in
316+ /usr|/System*) ;;
317+ *) am_cv_python_pythondir="\${PYTHON_PREFIX}/lib/python$PYTHON_VERSION/site-packages"
318+ ;;
319+ esac
320+ ;;
321+ esac
322+ ])
323+ AC_SUBST([pythondir], [$am_cv_python_pythondir])
324+
325+ dnl 2. pkgpythondir: $PACKAGE directory under pythondir. Was
326+ dnl PYTHON_SITE_PACKAGE in previous betas, but this naming is
327+ dnl more consistent with the rest of automake.
328+ dnl
329+ AC_SUBST([pkgpythondir], [\${pythondir}/$PACKAGE])
330+
331+ dnl 3. pyexecdir: directory for installing python extension modules
332+ dnl (shared libraries).
333+ dnl Query distutils for this directory.
334+ dnl
335+ AC_CACHE_CHECK([for $am_display_PYTHON extension module directory (pyexecdir)],
336+ [am_cv_python_pyexecdir],
337+ [if test "x$am_cv_python_exec_prefix" = x; then
338+ am_py_exec_prefix=$am__usable_exec_prefix
339+ else
340+ am_py_exec_prefix=$am_cv_python_exec_prefix
341+ fi
342+ am_cv_python_pyexecdir=`$PYTHON -c "
343+$am_python_setup_sysconfig
344+if can_use_sysconfig:
345+ if hasattr(sysconfig, 'get_default_scheme'):
346+ scheme = sysconfig.get_default_scheme()
347+ else:
348+ scheme = sysconfig._get_default_scheme()
349+ if scheme == 'posix_local':
350+ # Debian's default scheme installs to /usr/local/ but we want to find headers in /usr/
351+ scheme = 'posix_prefix'
352+ sitedir = sysconfig.get_path('platlib', scheme, vars={'platbase':'$am_py_exec_prefix'})
353+else:
354+ from distutils import sysconfig
355+ sitedir = sysconfig.get_python_lib(1, 0, prefix='$am_py_exec_prefix')
356+sys.stdout.write(sitedir)"`
357+ #
358+ case $am_cv_python_pyexecdir in
359+ $am_py_exec_prefix*)
360+ am__strip_prefix=`echo "$am_py_exec_prefix" | sed 's|.|.|g'`
361+ am_cv_python_pyexecdir=`echo "$am_cv_python_pyexecdir" | sed "s,^$am__strip_prefix,\\${PYTHON_EXEC_PREFIX},"`
362+ ;;
363+ *)
364+ case $am_py_exec_prefix in
365+ /usr|/System*) ;;
366+ *) am_cv_python_pyexecdir="\${PYTHON_EXEC_PREFIX}/lib/python$PYTHON_VERSION/site-packages"
367+ ;;
368+ esac
369+ ;;
370+ esac
371+ ])
372+ AC_SUBST([pyexecdir], [$am_cv_python_pyexecdir])
373+
374+ dnl 4. pkgpyexecdir: $(pyexecdir)/$(PACKAGE)
375+ dnl
376+ AC_SUBST([pkgpyexecdir], [\${pyexecdir}/$PACKAGE])
377+
378+ dnl Run any user-specified action.
379+ $2
380+ fi
381+])
382+
383+
384+# AM_PYTHON_CHECK_VERSION(PROG, VERSION, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
385+# ---------------------------------------------------------------------------
386+# Run ACTION-IF-TRUE if the Python interpreter PROG has version >= VERSION.
387+# Run ACTION-IF-FALSE otherwise.
388+# This test uses sys.hexversion instead of the string equivalent (first
389+# word of sys.version), in order to cope with versions such as 2.2c1.
390+# This supports Python 2.0 or higher. (2.0 was released on October 16, 2000).
391+AC_DEFUN([AM_PYTHON_CHECK_VERSION],
392+ [prog="import sys
393+# split strings by '.' and convert to numeric. Append some zeros
394+# because we need at least 4 digits for the hex conversion.
395+# map returns an iterator in Python 3.0 and a list in 2.x
396+minver = list(map(int, '$2'.split('.'))) + [[0, 0, 0]]
397+minverhex = 0
398+# xrange is not present in Python 3.0 and range returns an iterator
399+for i in list(range(0, 4)): minverhex = (minverhex << 8) + minver[[i]]
400+sys.exit(sys.hexversion < minverhex)"
401+ AS_IF([AM_RUN_LOG([$1 -c "$prog"])], [$3], [$4])])
402diff --git a/src/modules/rlm_python3/m4/runlog.m4 b/src/modules/rlm_python3/m4/runlog.m4
403new file mode 100644
404index 0000000000..690efc3258
405--- /dev/null
406+++ b/src/modules/rlm_python3/m4/runlog.m4
407@@ -0,0 +1,17 @@
408+## -*- Autoconf -*-
409+# Copyright (C) 2001-2018 Free Software Foundation, Inc.
410+#
411+# This file is free software; the Free Software Foundation
412+# gives unlimited permission to copy and/or distribute it,
413+# with or without modifications, as long as this notice is preserved.
414+
415+# AM_RUN_LOG(COMMAND)
416+# -------------------
417+# Run COMMAND, save the exit status in ac_status, and log it.
418+# (This has been adapted from Autoconf's _AC_RUN_LOG macro.)
419+AC_DEFUN([AM_RUN_LOG],
420+[{ echo "$as_me:$LINENO: $1" >&AS_MESSAGE_LOG_FD
421+ ($1) >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD
422+ ac_status=$?
423+ echo "$as_me:$LINENO: \$? = $ac_status" >&AS_MESSAGE_LOG_FD
424+ (exit $ac_status); }])
425--
4262.25.1
427