2 dnl # ZFS_AC_PYTHON_MODULE(module_name, [action-if-true], [action-if-false])
4 dnl # Checks for Python module. Freely inspired by AX_PYTHON_MODULE
5 dnl # https://www.gnu.org/software/autoconf-archive/ax_python_module.html
6 dnl # Required by ZFS_AC_CONFIG_ALWAYS_PYZFS.
8 AC_DEFUN([ZFS_AC_PYTHON_MODULE], [
9 PYTHON_NAME=${PYTHON##*/}
10 AC_MSG_CHECKING([for $PYTHON_NAME module: $1])
11 AS_IF([$PYTHON -c "import $1" 2>/dev/null], [
21 dnl # Determines if pyzfs can be built, requires Python 3.6 or later.
23 AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_PYZFS], [
24 AC_ARG_ENABLE([pyzfs],
25 AS_HELP_STRING([--enable-pyzfs],
26 [install libzfs_core python bindings @<:@default=check@:>@]),
27 [enable_pyzfs=$enableval],
31 dnl # Packages for pyzfs specifically enabled/disabled.
33 AS_IF([test "x$enable_pyzfs" != xcheck], [
34 AS_IF([test "x$enable_pyzfs" = xyes], [
35 DEFINE_PYZFS='--with pyzfs'
37 DEFINE_PYZFS='--without pyzfs'
40 AS_IF([test "$PYTHON" != :], [
44 DEFINE_PYZFS='--without pyzfs'
47 AC_SUBST(DEFINE_PYZFS)
50 dnl # Autodetection disables pyzfs if kernel or srpm config
52 AS_IF([test "x$enable_pyzfs" = xcheck], [
53 AS_IF([test "x$ZFS_CONFIG" = xkernel -o "x$ZFS_CONFIG" = xsrpm ], [
55 AC_MSG_NOTICE([Disabling pyzfs for kernel/srpm config])
60 dnl # Python "packaging" (or, failing that, "distlib") module is required to build and install pyzfs
62 AS_IF([test "x$enable_pyzfs" = xcheck -o "x$enable_pyzfs" = xyes], [
63 ZFS_AC_PYTHON_MODULE([packaging], [], [
64 ZFS_AC_PYTHON_MODULE([distlib], [], [
65 AS_IF([test "x$enable_pyzfs" = xyes], [
66 AC_MSG_ERROR("Python $PYTHON_VERSION packaging and distlib modules are not installed")
67 ], [test "x$enable_pyzfs" != xno], [
75 dnl # Require python3-devel libraries
77 AS_IF([test "x$enable_pyzfs" = xcheck -o "x$enable_pyzfs" = xyes], [
78 AS_CASE([$PYTHON_VERSION],
79 [3.*], [PYTHON_REQUIRED_VERSION=">= '3.6.0'"],
80 [AC_MSG_ERROR("Python $PYTHON_VERSION unknown")]
83 AX_PYTHON_DEVEL([$PYTHON_REQUIRED_VERSION], [
84 AS_IF([test "x$enable_pyzfs" = xyes], [
85 AC_MSG_ERROR("Python $PYTHON_REQUIRED_VERSION development library is not installed")
86 ], [test "x$enable_pyzfs" != xno], [
93 dnl # Python "setuptools" module is required to build and install pyzfs
95 AS_IF([test "x$enable_pyzfs" = xcheck -o "x$enable_pyzfs" = xyes], [
96 ZFS_AC_PYTHON_MODULE([setuptools], [], [
97 AS_IF([test "x$enable_pyzfs" = xyes], [
98 AC_MSG_ERROR("Python $PYTHON_VERSION setuptools is not installed")
99 ], [test "x$enable_pyzfs" != xno], [
106 dnl # Python "cffi" module is required to run pyzfs
108 AS_IF([test "x$enable_pyzfs" = xcheck -o "x$enable_pyzfs" = xyes], [
109 ZFS_AC_PYTHON_MODULE([cffi], [], [
110 AS_IF([test "x$enable_pyzfs" = xyes], [
111 AC_MSG_ERROR("Python $PYTHON_VERSION cffi is not installed")
112 ], [test "x$enable_pyzfs" != xno], [
119 dnl # Set enable_pyzfs to 'yes' if every check passed
121 AS_IF([test "x$enable_pyzfs" = xcheck], [enable_pyzfs=yes])
123 AM_CONDITIONAL([PYZFS_ENABLED], [test "x$enable_pyzfs" = xyes])
124 AC_SUBST([PYZFS_ENABLED], [$enable_pyzfs])
125 AC_SUBST(pythonsitedir, [$PYTHON_SITE_PKG])
127 AC_MSG_CHECKING([whether to enable pyzfs: ])
128 AC_MSG_RESULT($enable_pyzfs)