2 dnl # ZFS_AC_PYTHON_VERSION(version, [action-if-true], [action-if-false])
4 dnl # Verify Python version
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"], [
16 dnl # ZFS_AC_PYTHON_MODULE(module_name, [action-if-true], [action-if-false])
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.
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], [
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.
41 AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_PYTHON], [
43 AC_HELP_STRING([--with-python[=VERSION]],
44 [default system python version @<:@default=check@:>@]),
45 [with_python=$withval],
48 AS_CASE([$with_python],
50 [AS_IF([test -x /usr/bin/python3],
52 [AS_IF([test -x /usr/bin/python2],
57 [2*], [PYTHON="python${with_python}"],
58 [*python2*], [PYTHON="${with_python}"],
59 [3*], [PYTHON="python${with_python}"],
60 [*python3*], [PYTHON="${with_python}"],
62 [AC_MSG_ERROR([Unknown --with-python value '$with_python'])]
65 AS_IF([$PYTHON --version >/dev/null 2>&1], [ /bin/true ], [
66 AC_MSG_ERROR([Cannot find $PYTHON in your system path])
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."])
75 dnl # Minimum supported Python versions for utilities:
76 dnl # Python 2.6.x, or Python 3.4.x
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")])
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")])
89 dnl # Request that packages be built for a specific Python version.
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}'"'
96 DEFINE_PYTHON_VERSION=''
97 DEFINE_PYTHON_PKG_VERSION=''
100 AC_SUBST(DEFINE_PYTHON_VERSION)
101 AC_SUBST(DEFINE_PYTHON_PKG_VERSION)