xref: /freebsd/sys/contrib/openzfs/config/always-python.m4 (revision bdd1243df58e60e85101c09001d9812a789b6bc4)
1dnl #
2dnl # The majority of the python scripts are written to be compatible
3dnl # with Python 3.6. This option is intended to
4dnl # to provide a method to specify the default system version, and
5dnl # set the PYTHON environment variable accordingly.
6dnl #
7AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_PYTHON], [
8	AC_ARG_WITH([python],
9		AS_HELP_STRING([--with-python[=VERSION]],
10		[default system python version @<:@default=check@:>@]),
11		[with_python=$withval],
12		[with_python=check])
13
14	AS_CASE([$with_python],
15		[check], [AC_CHECK_PROGS([PYTHON], [python3], [:])],
16		[3*], [PYTHON="python${with_python}"],
17		[*python3*], [PYTHON="${with_python}"],
18		[no], [PYTHON=":"],
19		[AC_MSG_ERROR([Unknown --with-python value '$with_python'])]
20	)
21
22	dnl #
23	dnl # Minimum supported Python versions for utilities: Python 3.6
24	dnl #
25	AM_PATH_PYTHON([], [], [:])
26	AS_IF([test -z "$PYTHON_VERSION"], [
27		PYTHON_VERSION=$(echo ${PYTHON##*/} | tr -cd 0-9.)
28	])
29	PYTHON_MINOR=${PYTHON_VERSION#*\.}
30
31	AS_CASE([$PYTHON_VERSION],
32		[3.*], [
33			AS_IF([test $PYTHON_MINOR -lt 6],
34				[AC_MSG_ERROR("Python >= 3.6 is required")])
35		],
36		[:|2|3], [],
37		[PYTHON_VERSION=3]
38	)
39
40	AM_CONDITIONAL([USING_PYTHON], [test "$PYTHON" != :])
41	AC_SUBST([PYTHON_SHEBANG], [python3])
42
43	dnl #
44	dnl # Request that packages be built for a specific Python version.
45	dnl #
46	AS_IF([test "x$with_python" != xcheck], [
47		PYTHON_PKG_VERSION=$(echo $PYTHON_VERSION | tr -d .)
48		DEFINE_PYTHON_PKG_VERSION='--define "__use_python_pkg_version '${PYTHON_PKG_VERSION}'"'
49		DEFINE_PYTHON_VERSION='--define "__use_python '${PYTHON}'"'
50	], [
51		DEFINE_PYTHON_VERSION=''
52		DEFINE_PYTHON_PKG_VERSION=''
53	])
54
55	AC_SUBST(DEFINE_PYTHON_VERSION)
56	AC_SUBST(DEFINE_PYTHON_PKG_VERSION)
57])
58