]>
Commit | Line | Data |
---|---|---|
6e72a5b9 BB |
1 | dnl # |
2 | dnl # ZFS_AC_PYTHON_VERSION(version, [action-if-true], [action-if-false]) | |
3 | dnl # | |
4 | dnl # Verify Python version | |
5 | dnl # | |
6 | AC_DEFUN([ZFS_AC_PYTHON_VERSION], [ | |
7 | ver_check=`$PYTHON -c "import sys; print (sys.version.split()[[0]] $1)"` | |
8 | AS_IF([test "$ver_check" = "True"], [ | |
9 | m4_ifvaln([$2], [$2]) | |
10 | ], [ | |
11 | m4_ifvaln([$3], [$3]) | |
12 | ]) | |
13 | ]) | |
14 | ||
15 | dnl # | |
16 | dnl # ZFS_AC_PYTHON_MODULE(module_name, [action-if-true], [action-if-false]) | |
17 | dnl # | |
18 | dnl # Checks for Python module. Freely inspired by AX_PYTHON_MODULE | |
19 | dnl # https://www.gnu.org/software/autoconf-archive/ax_python_module.html | |
20 | dnl # Required by ZFS_AC_CONFIG_ALWAYS_PYZFS. | |
21 | dnl # | |
22 | AC_DEFUN([ZFS_AC_PYTHON_MODULE], [ | |
23 | PYTHON_NAME=`basename $PYTHON` | |
24 | AC_MSG_CHECKING([for $PYTHON_NAME module: $1]) | |
25 | AS_IF([$PYTHON -c "import $1" 2>/dev/null], [ | |
26 | AC_MSG_RESULT(yes) | |
27 | m4_ifvaln([$2], [$2]) | |
28 | ], [ | |
29 | AC_MSG_RESULT(no) | |
30 | m4_ifvaln([$3], [$3]) | |
31 | ]) | |
32 | ]) | |
33 | ||
34 | dnl # | |
35 | dnl # The majority of the python scripts are written to be compatible | |
36 | dnl # with Python 2.6 and Python 3.4. Therefore, they may be installed | |
37 | dnl # and used with either interpreter. This option is intended to | |
38 | dnl # to provide a method to specify the default system version, and | |
39 | dnl # set the PYTHON environment variable accordingly. | |
40 | dnl # | |
41 | AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_PYTHON], [ | |
42 | AC_ARG_WITH([python], | |
43 | AC_HELP_STRING([--with-python[=VERSION]], | |
44 | [default system python version @<:@default=check@:>@]), | |
45 | [with_python=$withval], | |
46 | [with_python=check]) | |
47 | ||
48 | AS_CASE([$with_python], | |
49 | [check], | |
50 | [AS_IF([test -x /usr/bin/python3], | |
51 | [PYTHON="python3"], | |
52 | [AS_IF([test -x /usr/bin/python2], | |
53 | [PYTHON="python2"], | |
54 | [PYTHON=""] | |
55 | )] | |
56 | )], | |
57 | [2*], [PYTHON="python${with_python}"], | |
58 | [*python2*], [PYTHON="${with_python}"], | |
59 | [3*], [PYTHON="python${with_python}"], | |
60 | [*python3*], [PYTHON="${with_python}"], | |
61 | [no], [PYTHON=""], | |
62 | [AC_MSG_ERROR([Unknown --with-python value '$with_python'])] | |
63 | ) | |
64 | ||
65 | AS_IF([$PYTHON --version >/dev/null 2>&1], [ /bin/true ], [ | |
66 | AC_MSG_ERROR([Cannot find $PYTHON in your system path]) | |
67 | ]) | |
68 | ||
69 | AM_PATH_PYTHON([2.6], [], [:]) | |
70 | AM_CONDITIONAL([USING_PYTHON], [test "$PYTHON" != :]) | |
71 | AM_CONDITIONAL([USING_PYTHON_2], [test "${PYTHON_VERSION:0:2}" = "2."]) | |
72 | AM_CONDITIONAL([USING_PYTHON_3], [test "${PYTHON_VERSION:0:2}" = "3."]) | |
73 | ||
74 | dnl # | |
75 | dnl # Minimum supported Python versions for utilities: | |
76 | dnl # Python 2.6.x, or Python 3.4.x | |
77 | dnl # | |
78 | AS_IF([test "${PYTHON_VERSION:0:2}" = "2."], [ | |
79 | ZFS_AC_PYTHON_VERSION([>= '2.6'], [ /bin/true ], | |
80 | [AC_MSG_ERROR("Python >= 2.6.x is not available")]) | |
81 | ]) | |
82 | ||
83 | AS_IF([test "${PYTHON_VERSION:0:2}" = "3."], [ | |
84 | ZFS_AC_PYTHON_VERSION([>= '3.4'], [ /bin/true ], | |
85 | [AC_MSG_ERROR("Python >= 3.4.x is not available")]) | |
86 | ]) | |
87 | ||
88 | dnl # | |
89 | dnl # Request that packages be built for a specific Python version. | |
90 | dnl # | |
91 | AS_IF([test $with_python != check], [ | |
92 | PYTHON_PKG_VERSION=`echo ${PYTHON} | tr -d 'a-zA-Z.'` | |
93 | DEFINE_PYTHON_PKG_VERSION='--define "__use_python_pkg_version '${PYTHON_PKG_VERSION}'"' | |
94 | DEFINE_PYTHON_VERSION='--define "__use_python '${PYTHON}'"' | |
95 | ], [ | |
96 | DEFINE_PYTHON_VERSION='' | |
97 | DEFINE_PYTHON_PKG_VERSION='' | |
98 | ]) | |
99 | ||
100 | AC_SUBST(DEFINE_PYTHON_VERSION) | |
101 | AC_SUBST(DEFINE_PYTHON_PKG_VERSION) | |
102 | ]) |