1 ## ------------------------ -*- Autoconf -*-
2 # adapted for LyX from the automake python support.
3 ## Python file handling
5 ## Updated by James Henstridge
6 ## ------------------------
7 # Copyright (C) 1999-2015 Free Software Foundation, Inc.
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.
13 dnl The minimum version for a python2 interpreter
14 m4_define(py2_ver, 2.7.0)
15 dnl The minimum version for a python3 interpreter
16 m4_define(py3_ver, 3.3.0)
18 dnl Usage: LYX_PATH_PYTHON
19 dnl Find a suitable Python interpreter, that is either python2 >= py2_ver
20 dnl or python3 >= py3_ver. Stop with an error message if it has not been found.
21 AC_DEFUN([LYX_PATH_PYTHON],
23 m4_define_default([_AM_PYTHON_INTERPRETER_LIST],
24 [python python2 python3 python3.3 python3.2 python3.1 python3.0 python2.7 dnl
25 python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 python2.0])
27 if test -n "$PYTHON"; then
28 # If the user set $PYTHON, use it and don't search something else.
29 AC_MSG_CHECKING([whether $PYTHON version is >= py2_ver or py3_ver])
30 LYX_PYTHON_CHECK_VERSION([$PYTHON],
31 [AC_MSG_RESULT([yes])],
33 AC_MSG_ERROR([Python interpreter is not suitable])])
34 am_display_PYTHON=$PYTHON
36 # Otherwise, try each interpreter until we find one that satisfies
37 # LYX_PYTHON_CHECK_VERSION.
38 AC_CACHE_CHECK([for a Python interpreter with version >= py2_ver or py3_ver],
39 [am_cv_pathless_PYTHON],[
40 for am_cv_pathless_PYTHON in _AM_PYTHON_INTERPRETER_LIST none; do
41 test "$am_cv_pathless_PYTHON" = none && break
42 LYX_PYTHON_CHECK_VERSION([$am_cv_pathless_PYTHON], [break])
44 # Set $PYTHON to the absolute path of $am_cv_pathless_PYTHON.
45 if test "$am_cv_pathless_PYTHON" = none; then
48 AC_PATH_PROG([PYTHON], [$am_cv_pathless_PYTHON])
50 am_display_PYTHON=$am_cv_pathless_PYTHON
53 if test "$PYTHON" = : ; then
54 AC_MSG_ERROR([no suitable Python interpreter found])
58 m4_define(py2_ver_list, [patsubst(py2_ver,[\.],[,])])
59 m4_define(py3_ver_list, [patsubst(py3_ver,[\.],[,])])
61 # LYX_PYTHON_CHECK_VERSION(PROG, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
62 # ---------------------------------------------------------------------------
63 # Run ACTION-IF-TRUE if the Python interpreter PROG has version >= py2_ver or py3_ver.
64 # Run ACTION-IF-FALSE otherwise.
65 AC_DEFUN([LYX_PYTHON_CHECK_VERSION],
67 version = sys.version_info@<:@:3@:>@
68 sys.exit(not ((py2_ver_list) <= version < (3,0,0) or version >= (py3_ver_list)))"
69 AS_IF([AM_RUN_LOG([$1 -c "$prog"])], [$2], [$3])])