]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - config/always-pyzfs.m4
Correct a flaw in the Python 3 version checking
[FreeBSD/FreeBSD.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 # Required by ZFS_AC_CONFIG_ALWAYS_PYZFS.
7 dnl #
8 AC_DEFUN([ZFS_AC_PYTHON_MODULE], [
9         PYTHON_NAME=$(basename $PYTHON)
10         AC_MSG_CHECKING([for $PYTHON_NAME module: $1])
11         AS_IF([$PYTHON -c "import $1" 2>/dev/null], [
12                 AC_MSG_RESULT(yes)
13                 m4_ifvaln([$2], [$2])
14         ], [
15                 AC_MSG_RESULT(no)
16                 m4_ifvaln([$3], [$3])
17         ])
18 ])
19
20 dnl #
21 dnl # Determines if pyzfs can be built, requires Python 2.7 or later.
22 dnl #
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],
28                 [enable_pyzfs=check])
29
30         dnl #
31         dnl # Packages for pyzfs specifically enabled/disabled.
32         dnl #
33         AS_IF([test "x$enable_pyzfs" != xcheck], [
34                 AS_IF([test "x$enable_pyzfs" = xyes], [
35                         DEFINE_PYZFS='--with pyzfs'
36                 ], [
37                         DEFINE_PYZFS='--without pyzfs'
38                 ])
39         ], [
40                 AS_IF([test "$PYTHON" != :], [
41                         DEFINE_PYZFS=''
42                 ], [
43                         enable_pyzfs=no
44                         DEFINE_PYZFS='--without pyzfs'
45                 ])
46         ])
47         AC_SUBST(DEFINE_PYZFS)
48
49         dnl #
50         dnl # Python "packaging" (or, failing that, "distlib") module is required to build and install pyzfs
51         dnl #
52         AS_IF([test "x$enable_pyzfs" = xcheck -o "x$enable_pyzfs" = xyes], [
53                 ZFS_AC_PYTHON_MODULE([packaging], [], [
54                         ZFS_AC_PYTHON_MODULE([distlib], [], [
55                                 AS_IF([test "x$enable_pyzfs" = xyes], [
56                                         AC_MSG_ERROR("Python $PYTHON_VERSION packaging and distlib modules are not installed")
57                                 ], [test "x$enable_pyzfs" != xno], [
58                                         enable_pyzfs=no
59                                 ])
60                         ])
61                 ])
62         ])
63
64         dnl #
65         dnl # Require python-devel libraries
66         dnl #
67         AS_IF([test "x$enable_pyzfs" = xcheck  -o "x$enable_pyzfs" = xyes], [
68                 AS_CASE([$PYTHON_VERSION],
69                         [3.*], [PYTHON_REQUIRED_VERSION=">= '3.4.0'"],
70                         [2.*], [PYTHON_REQUIRED_VERSION=">= '2.7.0'"],
71                         [AC_MSG_ERROR("Python $PYTHON_VERSION unknown")]
72                 )
73
74                 AX_PYTHON_DEVEL([$PYTHON_REQUIRED_VERSION], [
75                         AS_IF([test "x$enable_pyzfs" = xyes], [
76                                 AC_MSG_ERROR("Python $PYTHON_REQUIRED_VERSION development library is not installed")
77                         ], [test "x$enable_pyzfs" != xno], [
78                                 enable_pyzfs=no
79                         ])
80                 ])
81         ])
82
83         dnl #
84         dnl # Python "setuptools" module is required to build and install pyzfs
85         dnl #
86         AS_IF([test "x$enable_pyzfs" = xcheck -o "x$enable_pyzfs" = xyes], [
87                 ZFS_AC_PYTHON_MODULE([setuptools], [], [
88                         AS_IF([test "x$enable_pyzfs" = xyes], [
89                                 AC_MSG_ERROR("Python $PYTHON_VERSION setuptools is not installed")
90                         ], [test "x$enable_pyzfs" != xno], [
91                                 enable_pyzfs=no
92                         ])
93                 ])
94         ])
95
96         dnl #
97         dnl # Python "cffi" module is required to run pyzfs
98         dnl #
99         AS_IF([test "x$enable_pyzfs" = xcheck -o "x$enable_pyzfs" = xyes], [
100                 ZFS_AC_PYTHON_MODULE([cffi], [], [
101                         AS_IF([test "x$enable_pyzfs" = xyes], [
102                                 AC_MSG_ERROR("Python $PYTHON_VERSION cffi is not installed")
103                         ], [test "x$enable_pyzfs" != xno], [
104                                 enable_pyzfs=no
105                         ])
106                 ])
107         ])
108
109         dnl #
110         dnl # Set enable_pyzfs to 'yes' if every check passed
111         dnl #
112         AS_IF([test "x$enable_pyzfs" = xcheck], [enable_pyzfs=yes])
113
114         AM_CONDITIONAL([PYZFS_ENABLED], [test "x$enable_pyzfs" = xyes])
115         AC_SUBST([PYZFS_ENABLED], [$enable_pyzfs])
116         AC_SUBST(pythonsitedir, [$PYTHON_SITE_PKG])
117
118         AC_MSG_CHECKING([whether to enable pyzfs: ])
119         AC_MSG_RESULT($enable_pyzfs)
120 ])