]> git.lyx.org Git - lyx.git/blob - config/lyxpython.m4
Check path of Qt tools if qtchooser is detected
[lyx.git] / config / lyxpython.m4
1 ## ------------------------                                 -*- Autoconf -*-
2 # adapted for LyX from the automake python support.
3 ## Python file handling
4 ## From Andrew Dalke
5 ## Updated by James Henstridge
6 ## ------------------------
7 # Copyright (C) 1999-2015 Free Software Foundation, Inc.
8 #
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.
12
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],
17  [
18   m4_define(py2_ver, [patsubst($1,[\.],[,])])
19   m4_define(py3_ver, [patsubst($2,[\.],[,])])
20
21   m4_define_default([_AM_PYTHON_INTERPRETER_LIST],
22 [python python2 python3 python3.3 python3.2 python3.1 python3.0 python2.7 dnl
23  python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 python2.0])
24
25     if test -n "$PYTHON"; then
26       # If the user set $PYTHON, use it and don't search something else.
27       AC_MSG_CHECKING([whether $PYTHON version is >= $1 or $2])
28       LYX_PYTHON_CHECK_VERSION([$PYTHON],
29                               [AC_MSG_RESULT([yes])],
30                               [AC_MSG_RESULT([no])
31                                AC_MSG_ERROR([Python interpreter is not suitable])])
32       am_display_PYTHON=$PYTHON
33     else
34       # Otherwise, try each interpreter until we find one that satisfies
35       # LYX_PYTHON_CHECK_VERSION.
36       AC_CACHE_CHECK([for a Python interpreter with version >= $1 or $2],
37         [am_cv_pathless_PYTHON],[
38         for am_cv_pathless_PYTHON in _AM_PYTHON_INTERPRETER_LIST none; do
39           test "$am_cv_pathless_PYTHON" = none && break
40           LYX_PYTHON_CHECK_VERSION([$am_cv_pathless_PYTHON], [break])
41         done])
42       # Set $PYTHON to the absolute path of $am_cv_pathless_PYTHON.
43       if test "$am_cv_pathless_PYTHON" = none; then
44         PYTHON=:
45       else
46         AC_PATH_PROG([PYTHON], [$am_cv_pathless_PYTHON])
47       fi
48       am_display_PYTHON=$am_cv_pathless_PYTHON
49     fi
50
51     if test "$PYTHON" = : ; then
52       AC_MSG_ERROR([no suitable Python interpreter found])
53     fi
54 ])
55
56 # LYX_PYTHON_CHECK_VERSION(PROG, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
57 # ---------------------------------------------------------------------------
58 # Run ACTION-IF-TRUE if the Python interpreter PROG has version >= py2_ver or py3_ver.
59 # Run ACTION-IF-FALSE otherwise.
60 AC_DEFUN([LYX_PYTHON_CHECK_VERSION],
61  [prog="import sys
62 version = sys.version_info@<:@:3@:>@
63 sys.exit(not ((py2_ver) <= version < (3,0,0) or version >= (py3_ver)))"
64   AS_IF([AM_RUN_LOG([$1 -c "$prog"])], [$2], [$3])])