Hi,

I added 2 macros (AM_PATH_PYTHON2 and AM_PATH_PYTHON3) to support both
python2 and python3 on the same system.  It works in the same way that
AM_PATH_PYTHON works (just a small wrapper around it).  Please notice that
AM_PATH_PYTHON and AM_PATH_PYTHONx can't be called together.

The motive for doing this is Fedora Packaging Guidelines for Python (
https://fedoraproject.org/wiki/Packaging:Python) which requires a package
to be built for both runtimes.

Thanks,
Yuval.
From ec9b2cb7eaa00cfb84cfe48333c6d85eef17fd08 Mon Sep 17 00:00:00 2001
From: Yuval Turgeman <yturg...@redhat.com>
Date: Tue, 30 Jan 2018 12:03:23 +0200
Subject: [PATCH] python.m4: supporing multiple python runtimes

Fedora systems rely on building python packages for both python2 and
python3.  This patch presents new macros (AM_PATH_PYTHON{2,3}) that wrap
the existing python macro and save its output to a new set of variables.
For further details, see https://fedoraproject.org/wiki/Packaging:Python

Signed-off-by: Yuval Turgeman <yturg...@redhat.com>
---
 m4/python.m4 | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/m4/python.m4 b/m4/python.m4
index 58dd18761..a10ce26b8 100644
--- a/m4/python.m4
+++ b/m4/python.m4
@@ -9,6 +9,58 @@
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 
+# AM_PATH_PYTHON2([MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
+# ---------------------------------------------------------------------------
+# Searches for a minimum version of python2 and sets the variables: PYTHON2,
+# python2dir, py2execdir, pkgpython2dir, pkgpython2dir, pkgpy2execdir
+AC_DEFUN([AM_PATH_PYTHON2],
+ [
+  m4_define([_AM_PYTHON_INTERPRETER_LIST],
+[python2 python2.7 python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 python2.0])
+
+  AM_PYTHON_MAJOR([2], [$1], [$2], [$3])
+])
+
+# AM_PATH_PYTHON3([MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
+# ---------------------------------------------------------------------------
+# Searches for a minimum version of python3 and sets the variables: PYTHON3,
+# python3dir, py3execdir, pkgpython3dir, pkgpython3dir, pkgpy3execdir
+AC_DEFUN([AM_PATH_PYTHON3],
+ [
+  m4_define([_AM_PYTHON_INTERPRETER_LIST],
+[python3 python3.6 python3.5 python3.4 python3.3 python3.2 python3.1 python3.0])
+
+  AM_PYTHON_MAJOR([3], [$1], [$2], [$3])
+])
+
+# AM_PYTHON_MAJOR(MAJOR-VERSION, [MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
+# -------------------------------------------------------------------------------------------
+# A wrapper on AM_PATH_PYTHON that checks for a MAJOR-VERSION if
+# MINIMUM-VERSION is not specified, and sets the following variables:
+# PYTHON$(MAJOR-VERSION) - equivalent to AM_PATH_PYTHON's $PYTHON
+# python$(MAJOR-VERSIONdir - equivalent to AM_PATH_PYTHON's $(pythondir)
+# py$(MAJOR-VERSION)execdir - equivalent to AM_PATH_PYTHON's $(pyexecdir)
+# pkgpython$(MAJOR-VERSION)dir - equivalent to AM_PATH_PYTHON's $(pkgpythondir)
+# pkgpy$(MAJOR-VERSION)execdir - equivalent to AM_PATH_PYTHON's $(pkgpyexecdir)
+AC_DEFUN([AM_PYTHON_MAJOR],
+ [
+  unset PYTHON ac_cv_path_PYTHON am_cv_pathless_PYTHON dnl
+        am_cv_python_version am_cv_python_platform dnl
+        pythondir am_cv_python_pythondir dnl
+        pyexecdir am_cv_python_pyexecdir
+
+  m4_if(m4_version_compare([$1], [$2]), [-1], [
+    AM_PATH_PYTHON([$2], [$3], [$4])
+  ], [
+    AM_PATH_PYTHON([$1], [$3], [$4])
+  ])
+
+  AC_SUBST([PYTHON$1], [$PYTHON])
+  AC_SUBST([python$1dir], [$pythondir])
+  AC_SUBST([py$1execdir], [$pyexecdir])
+  AC_SUBST([pkgpython$1dir], [\${python$1dir}/$PACKAGE])
+  AC_SUBST([pkgpy$1execdir], [\${pkgpy$1execdir}/$PACKAGE])
+])
 
 # AM_PATH_PYTHON([MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
 # ---------------------------------------------------------------------------
-- 
2.14.3

Reply via email to