]> git.proxmox.com Git - mirror_zfs.git/blob - config/always-python.m4
Python config cleanup
[mirror_zfs.git] / config / always-python.m4
1 dnl #
2 dnl # The majority of the python scripts are written to be compatible
3 dnl # with Python 2.6 and Python 3.4. Therefore, they may be installed
4 dnl # and used with either interpreter. This option is intended to
5 dnl # to provide a method to specify the default system version, and
6 dnl # set the PYTHON environment variable accordingly.
7 dnl #
8 AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_PYTHON], [
9 AC_ARG_WITH([python],
10 AC_HELP_STRING([--with-python[=VERSION]],
11 [default system python version @<:@default=check@:>@]),
12 [with_python=$withval],
13 [with_python=check])
14
15 AS_CASE([$with_python],
16 [check], [AC_CHECK_PROGS([PYTHON], [python3 python2], [:])],
17 [2*], [PYTHON="python${with_python}"],
18 [*python2*], [PYTHON="${with_python}"],
19 [3*], [PYTHON="python${with_python}"],
20 [*python3*], [PYTHON="${with_python}"],
21 [no], [PYTHON=":"],
22 [AC_MSG_ERROR([Unknown --with-python value '$with_python'])]
23 )
24
25 dnl #
26 dnl # Minimum supported Python versions for utilities:
27 dnl # Python 2.6 or Python 3.4
28 dnl #
29 AM_PATH_PYTHON([], [], [:])
30 AS_IF([test -z "$PYTHON_VERSION"], [
31 PYTHON_VERSION=$(basename $PYTHON | tr -cd 0-9.)
32 ])
33 PYTHON_MINOR=${PYTHON_VERSION#*\.}
34
35 AS_CASE([$PYTHON_VERSION],
36 [2.*], [
37 AS_IF([test $PYTHON_MINOR -lt 6],
38 [AC_MSG_ERROR("Python >= 2.6 is required")])
39 ],
40 [3.*], [
41 AS_IF([test $PYTHON_MINOR -lt 4],
42 [AC_MSG_ERROR("Python >= 3.4 is required")])
43 ],
44 [:|2|3], [],
45 [PYTHON_VERSION=3]
46 )
47
48 AM_CONDITIONAL([USING_PYTHON], [test "$PYTHON" != :])
49 AM_CONDITIONAL([USING_PYTHON_2], [test "x${PYTHON_VERSION%%\.*}" = x2])
50 AM_CONDITIONAL([USING_PYTHON_3], [test "x${PYTHON_VERSION%%\.*}" = x3])
51
52 dnl #
53 dnl # Request that packages be built for a specific Python version.
54 dnl #
55 AS_IF([test "x$with_python" != xcheck], [
56 PYTHON_PKG_VERSION=$(echo $PYTHON_VERSION | tr -d .)
57 DEFINE_PYTHON_PKG_VERSION='--define "__use_python_pkg_version '${PYTHON_PKG_VERSION}'"'
58 DEFINE_PYTHON_VERSION='--define "__use_python '${PYTHON}'"'
59 ], [
60 DEFINE_PYTHON_VERSION=''
61 DEFINE_PYTHON_PKG_VERSION=''
62 ])
63
64 AC_SUBST(DEFINE_PYTHON_VERSION)
65 AC_SUBST(DEFINE_PYTHON_PKG_VERSION)
66 ])