]> git.proxmox.com Git - mirror_zfs.git/blob - config/always-pyzfs.m4
Adopt pyzfs from ClusterHQ
[mirror_zfs.git] / config / always-pyzfs.m4
1 dnl #
2 dnl # ZFS_AC_PYTHON_MODULE(module_name, [action-if-true], [action-if-false])
3 dnl #
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 #
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
11 if test $? -eq 0;
12 then
13 AC_MSG_RESULT(yes)
14 m4_ifvaln([$2], [$2])
15 else
16 AC_MSG_RESULT(no)
17 m4_ifvaln([$3], [$3])
18 fi
19 ])
20
21 dnl #
22 dnl # ZFS_AC_PYTHON_VERSION(version, [action-if-true], [action-if-false])
23 dnl #
24 dnl # Verify Python version
25 dnl #
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";
30 then
31 AC_MSG_RESULT(yes)
32 m4_ifvaln([$2], [$2])
33 else
34 AC_MSG_RESULT(no)
35 m4_ifvaln([$3], [$3])
36 fi
37
38 ])
39
40 AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_PYZFS], [
41 PYTHON_REQUIRED_VERSION="<= '2.7.x'"
42
43 AC_ARG_ENABLE([pyzfs],
44 AC_HELP_STRING([--enable-pyzfs],
45 [install libzfs_core python bindings @<:@default=check@:>@]),
46 [enable_pyzfs=$enableval],
47 [enable_pyzfs=check])
48
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], [
53 enable_pyzfs=no
54 ])
55 ])
56 AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != :])
57
58 dnl #
59 dnl # Python 2.7.x is supported, other versions (3.5) are not yet
60 dnl #
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], [
66 enable_pyzfs=no
67 ])
68 ])
69 ])
70
71 dnl #
72 dnl # Require python-devel libraries
73 dnl #
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], [
79 enable_pyzfs=no
80 ])
81 ])
82 ])
83
84 dnl #
85 dnl # Python "setuptools" module is required to build and install pyzfs
86 dnl #
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], [
92 enable_pyzfs=no
93 ])
94 ])
95 ])
96
97 dnl #
98 dnl # Python "cffi" module is required to run pyzfs
99 dnl #
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], [
105 enable_pyzfs=no
106 ])
107 ])
108 ])
109
110 dnl #
111 dnl # Set enable_pyzfs to 'yes' if every check passed
112 dnl #
113 AS_IF([test "x$enable_pyzfs" = xcheck], [enable_pyzfs=yes])
114
115 AM_CONDITIONAL([PYZFS_ENABLED], [test x$enable_pyzfs = xyes])
116 AC_SUBST([PYZFS_ENABLED], [$enable_pyzfs])
117
118 AS_IF([test "x$enable_pyzfs" = xyes], [
119 DEFINE_PYZFS='--define "_pyzfs 1"'
120 ],[
121 DEFINE_PYZFS=''
122 ])
123 AC_SUBST(DEFINE_PYZFS)
124 AC_SUBST(pythonsitedir, [$PYTHON_SITE_PKG])
125 ])