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 Usage: LYX_PATH_PYTHON23(PY2-MIN-VERSION, PYTHON3-MIN-VERSION)
14 dnl Find a suitable Python interpreter, that is either python2 >= $1
15 dnl or python3 >= $2. Stop with an error message if it has not been found.
16 AC_DEFUN([LYX_PATH_PYTHON23],
18 m4_define(py2_ver, [patsubst($1,[\.],[,])])
19 m4_define(py3_ver, [patsubst($2,[\.],[,])])
21 m4_define_default([_AM_PYTHON_INTERPRETER_LIST], [python3 python2 python])
23 if test -n "$PYTHON"; then
24 # If the user set $PYTHON, use it and don't search something else.
25 AC_MSG_CHECKING([whether $PYTHON version is >= $1 or $2])
26 LYX_PYTHON_CHECK_VERSION([$PYTHON],
27 [AC_MSG_RESULT([yes])],
29 AC_MSG_ERROR([Python interpreter is not suitable])])
30 am_display_PYTHON=$PYTHON
32 # Otherwise, try each interpreter until we find one that satisfies
33 # LYX_PYTHON_CHECK_VERSION.
34 AC_CACHE_CHECK([for a Python interpreter with version >= $1 or $2],
35 [am_cv_pathless_PYTHON],[
36 for am_cv_pathless_PYTHON in _AM_PYTHON_INTERPRETER_LIST none; do
37 test "$am_cv_pathless_PYTHON" = none && break
38 LYX_PYTHON_CHECK_VERSION([$am_cv_pathless_PYTHON], [break])
40 # Set $PYTHON to the absolute path of $am_cv_pathless_PYTHON.
41 if test "$am_cv_pathless_PYTHON" = none; then
44 AC_PATH_PROG([PYTHON], [$am_cv_pathless_PYTHON])
46 am_display_PYTHON=$am_cv_pathless_PYTHON
49 if test "$PYTHON" = : ; then
50 AC_MSG_ERROR([no suitable Python interpreter found])
54 # LYX_PYTHON_CHECK_VERSION(PROG, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
55 # ---------------------------------------------------------------------------
56 # Run ACTION-IF-TRUE if the Python interpreter PROG has version >= py2_ver or py3_ver.
57 # Run ACTION-IF-FALSE otherwise.
58 AC_DEFUN([LYX_PYTHON_CHECK_VERSION],
60 version = sys.version_info@<:@:3@:>@
61 sys.exit(not ((py2_ver) <= version < (3,0,0) or version >= (py3_ver)))"
62 AS_IF([AM_RUN_LOG([$1 -c "$prog"])], [$2], [$3])])