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
7 AC_DEFUN([ZFS_AC_PYTHON_MODULE],[
8 PYTHON_NAME=`basename $PYTHON`
9 AC_MSG_CHECKING([for $PYTHON_NAME module: $1])
10 $PYTHON -c "import $1" 2>/dev/null
22 dnl # ZFS_AC_PYTHON_VERSION(version, [action-if-true], [action-if-false])
24 dnl # Verify Python version
26 AC_DEFUN([ZFS_AC_PYTHON_VERSION], [
27 AC_MSG_CHECKING([for a version of Python $1])
28 version_check=`$PYTHON -c "import sys; print (sys.version.split()[[0]] $1)"`
29 if test "$version_check" = "True";
40 AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_PYZFS], [
41 PYTHON_REQUIRED_VERSION="<= '2.7.x'"
43 AC_ARG_ENABLE([pyzfs],
44 AC_HELP_STRING([--enable-pyzfs],
45 [install libzfs_core python bindings @<:@default=check@:>@]),
46 [enable_pyzfs=$enableval],
49 AM_PATH_PYTHON([2.7], [], [
50 AS_IF([test ! "x$enable_pyzfs" = xyes], [
51 AC_MSG_ERROR("python >= 2.7 is not installed")
52 ], [test ! "x$enable_pyzfs" = xno], [
56 AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != :])
59 dnl # Python 2.7.x is supported, other versions (3.5) are not yet
61 AS_IF([test "x$enable_pyzfs" = xcheck], [
62 ZFS_AC_PYTHON_VERSION([$PYTHON_REQUIRED_VERSION], [], [
63 AS_IF([test "x$enable_pyzfs" = xyes], [
64 AC_MSG_ERROR("Python $PYTHON_REQUIRED_VERSION is not available")
65 ], [test ! "x$enable_pyzfs" = xno], [
72 dnl # Require python-devel libraries
74 AS_IF([test "x$enable_pyzfs" = xcheck], [
75 AX_PYTHON_DEVEL([$PYTHON_REQUIRED_VERSION], [
76 AS_IF([test "x$enable_pyzfs" = xyes], [
77 AC_MSG_ERROR("Python development library is not available")
78 ], [test ! "x$enable_pyzfs" = xno], [
85 dnl # Python "setuptools" module is required to build and install pyzfs
87 AS_IF([test "x$enable_pyzfs" = xcheck], [
88 ZFS_AC_PYTHON_MODULE([setuptools], [], [
89 AS_IF([test "x$enable_pyzfs" = xyes], [
90 AC_MSG_ERROR("python-setuptools is not installed")
91 ], [test ! "x$enable_pyzfs" = xno], [
98 dnl # Python "cffi" module is required to run pyzfs
100 AS_IF([test "x$enable_pyzfs" = xcheck], [
101 ZFS_AC_PYTHON_MODULE([cffi], [], [
102 AS_IF([test "x$enable_pyzfs" = xyes], [
103 AC_MSG_ERROR("python-cffi is not installed")
104 ], [test ! "x$enable_pyzfs" = xno], [
111 dnl # Set enable_pyzfs to 'yes' if every check passed
113 AS_IF([test "x$enable_pyzfs" = xcheck], [enable_pyzfs=yes])
115 AM_CONDITIONAL([PYZFS_ENABLED], [test x$enable_pyzfs = xyes])
116 AC_SUBST([PYZFS_ENABLED], [$enable_pyzfs])
118 AS_IF([test "x$enable_pyzfs" = xyes], [
119 DEFINE_PYZFS='--define "_pyzfs 1"'
123 AC_SUBST(DEFINE_PYZFS)
124 AC_SUBST(pythonsitedir, [$PYTHON_SITE_PKG])