]> git.lyx.org Git - lyx.git/commitdiff
Autotools: check for python >= 2.7.0 or >= 3.3.0
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 23 Mar 2015 21:35:52 +0000 (22:35 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 24 Mar 2015 09:34:08 +0000 (10:34 +0100)
A new macro adapted from AM_PROG_PYTHON is defined. It does the dual version testing for python 2 and python 3. The rest of the functionnality of AM_PROG_PYTHON has been stripped off.

Once our special macro has been invoked, we use the usual AM_PROG_PYTHON.

config/Makefile.am
config/lyxpython.m4 [new file with mode: 0644]
configure.ac

index d91a889d38fef587b94a634d6ee4f7e310a53d76..2f099eaa8dbac2c3d7f3bac4e0809179d8d8d665 100644 (file)
@@ -3,6 +3,7 @@ include $(top_srcdir)/config/common.am
 EXTRA_DIST = \
        common.am \
        lyxinclude.m4 \
+       lyxpython.m4 \
        pkg.m4 \
        qt4.m4 \
        spell.m4
diff --git a/config/lyxpython.m4 b/config/lyxpython.m4
new file mode 100644 (file)
index 0000000..ff92740
--- /dev/null
@@ -0,0 +1,69 @@
+## ------------------------                                 -*- Autoconf -*-
+# adapted for LyX from the automake python support.
+## Python file handling
+## From Andrew Dalke
+## Updated by James Henstridge
+## ------------------------
+# Copyright (C) 1999-2015 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+dnl The minimum version for a python2 interpreter
+m4_define(py2_ver, 2.7.0)
+dnl The minimum version for a python3 interpreter
+m4_define(py3_ver, 3.3.0)
+
+dnl Usage: LYX_PATH_PYTHON
+dnl Find a suitable Python interpreter, that is either python2 >= py2_ver
+dnl or python3 >= py3_ver. Stop with an error message if it has not been found.
+AC_DEFUN([LYX_PATH_PYTHON],
+ [
+  m4_define_default([_AM_PYTHON_INTERPRETER_LIST],
+[python python2 python3 python3.3 python3.2 python3.1 python3.0 python2.7 dnl
+ python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 python2.0])
+
+    if test -n "$PYTHON"; then
+      # If the user set $PYTHON, use it and don't search something else.
+      AC_MSG_CHECKING([whether $PYTHON version is >= py2_ver or py3_ver])
+      LYX_PYTHON_CHECK_VERSION([$PYTHON],
+                             [AC_MSG_RESULT([yes])],
+                             [AC_MSG_RESULT([no])
+                              AC_MSG_ERROR([Python interpreter is not suitable])])
+      am_display_PYTHON=$PYTHON
+    else
+      # Otherwise, try each interpreter until we find one that satisfies
+      # LYX_PYTHON_CHECK_VERSION.
+      AC_CACHE_CHECK([for a Python interpreter with version >= py2_ver or py3_ver],
+       [am_cv_pathless_PYTHON],[
+       for am_cv_pathless_PYTHON in _AM_PYTHON_INTERPRETER_LIST none; do
+         test "$am_cv_pathless_PYTHON" = none && break
+         LYX_PYTHON_CHECK_VERSION([$am_cv_pathless_PYTHON], [break])
+       done])
+      # Set $PYTHON to the absolute path of $am_cv_pathless_PYTHON.
+      if test "$am_cv_pathless_PYTHON" = none; then
+       PYTHON=:
+      else
+        AC_PATH_PROG([PYTHON], [$am_cv_pathless_PYTHON])
+      fi
+      am_display_PYTHON=$am_cv_pathless_PYTHON
+    fi
+
+    if test "$PYTHON" = : ; then
+      AC_MSG_ERROR([no suitable Python interpreter found])
+    fi
+])
+
+m4_define(py2_ver_list, [patsubst(py2_ver,[\.],[,])])
+m4_define(py3_ver_list, [patsubst(py3_ver,[\.],[,])])
+
+# LYX_PYTHON_CHECK_VERSION(PROG, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
+# ---------------------------------------------------------------------------
+# Run ACTION-IF-TRUE if the Python interpreter PROG has version >= py2_ver or py3_ver.
+# Run ACTION-IF-FALSE otherwise.
+AC_DEFUN([LYX_PYTHON_CHECK_VERSION],
+ [prog="import sys
+version = sys.version_info@<:@:3@:>@
+sys.exit(not ((py2_ver_list) <= version < (3,0,0) or version >= (py3_ver_list)))"
+  AS_IF([AM_RUN_LOG([$1 -c "$prog"])], [$2], [$3])])
index 43bfb597c443f10a17766233707bc84f98e377d5..9a5267b9ff4819b76eea34b4485c587bdcfbc6be 100644 (file)
@@ -63,7 +63,10 @@ for file in config/install-sh ; do
   chmod 755 ${srcdir}/${file}
 done
 
-AM_PATH_PYTHON(2.7.0,, :)
+# Find a suitable python interpreter
+LYX_PATH_PYTHON
+# do the usual python setup stuff
+AM_PATH_PYTHON
 AC_PROG_RANLIB
 
 ### Check for a C++ compiler