xref: /freebsd/sys/contrib/openzfs/config/always-pyzfs.m4 (revision b985c9cafd2aedac5cf92428c0211485ea4ede24)
1eda14cbcSMatt Macydnl #
2eda14cbcSMatt Macydnl # ZFS_AC_PYTHON_MODULE(module_name, [action-if-true], [action-if-false])
3eda14cbcSMatt Macydnl #
4eda14cbcSMatt Macydnl # Checks for Python module. Freely inspired by AX_PYTHON_MODULE
5eda14cbcSMatt Macydnl # https://www.gnu.org/software/autoconf-archive/ax_python_module.html
6eda14cbcSMatt Macydnl # Required by ZFS_AC_CONFIG_ALWAYS_PYZFS.
7eda14cbcSMatt Macydnl #
8eda14cbcSMatt MacyAC_DEFUN([ZFS_AC_PYTHON_MODULE], [
9dae17134SMartin Matuska	PYTHON_NAME=${PYTHON##*/}
10eda14cbcSMatt Macy	AC_MSG_CHECKING([for $PYTHON_NAME module: $1])
11eda14cbcSMatt Macy	AS_IF([$PYTHON -c "import $1" 2>/dev/null], [
12eda14cbcSMatt Macy		AC_MSG_RESULT(yes)
13eda14cbcSMatt Macy		m4_ifvaln([$2], [$2])
14eda14cbcSMatt Macy	], [
15eda14cbcSMatt Macy		AC_MSG_RESULT(no)
16eda14cbcSMatt Macy		m4_ifvaln([$3], [$3])
17eda14cbcSMatt Macy	])
18eda14cbcSMatt Macy])
19eda14cbcSMatt Macy
20eda14cbcSMatt Macydnl #
21e92ffd9bSMartin Matuskadnl # Determines if pyzfs can be built, requires Python 3.6 or later.
22eda14cbcSMatt Macydnl #
23eda14cbcSMatt MacyAC_DEFUN([ZFS_AC_CONFIG_ALWAYS_PYZFS], [
24eda14cbcSMatt Macy	AC_ARG_ENABLE([pyzfs],
257877fdebSMatt Macy		AS_HELP_STRING([--enable-pyzfs],
26eda14cbcSMatt Macy		[install libzfs_core python bindings @<:@default=check@:>@]),
27eda14cbcSMatt Macy		[enable_pyzfs=$enableval],
28eda14cbcSMatt Macy		[enable_pyzfs=check])
29eda14cbcSMatt Macy
30eda14cbcSMatt Macy	dnl #
31eda14cbcSMatt Macy	dnl # Packages for pyzfs specifically enabled/disabled.
32eda14cbcSMatt Macy	dnl #
33eda14cbcSMatt Macy	AS_IF([test "x$enable_pyzfs" != xcheck], [
34eda14cbcSMatt Macy		AS_IF([test "x$enable_pyzfs" = xyes], [
35eda14cbcSMatt Macy			DEFINE_PYZFS='--with pyzfs'
36eda14cbcSMatt Macy		], [
37eda14cbcSMatt Macy			DEFINE_PYZFS='--without pyzfs'
38eda14cbcSMatt Macy		])
39eda14cbcSMatt Macy	], [
40eda14cbcSMatt Macy		AS_IF([test "$PYTHON" != :], [
41eda14cbcSMatt Macy			DEFINE_PYZFS=''
42eda14cbcSMatt Macy		], [
43eda14cbcSMatt Macy			enable_pyzfs=no
44eda14cbcSMatt Macy			DEFINE_PYZFS='--without pyzfs'
45eda14cbcSMatt Macy		])
46eda14cbcSMatt Macy	])
47eda14cbcSMatt Macy	AC_SUBST(DEFINE_PYZFS)
48eda14cbcSMatt Macy
49eda14cbcSMatt Macy	dnl #
50bb2d13b6SMartin Matuska	dnl # Autodetection disables pyzfs if kernel or srpm config
51bb2d13b6SMartin Matuska	dnl #
52bb2d13b6SMartin Matuska	AS_IF([test "x$enable_pyzfs" = xcheck], [
53bb2d13b6SMartin Matuska		AS_IF([test "x$ZFS_CONFIG" = xkernel -o "x$ZFS_CONFIG" = xsrpm ], [
54bb2d13b6SMartin Matuska				enable_pyzfs=no
55bb2d13b6SMartin Matuska				AC_MSG_NOTICE([Disabling pyzfs for kernel/srpm config])
56bb2d13b6SMartin Matuska		])
57bb2d13b6SMartin Matuska	])
58bb2d13b6SMartin Matuska
59bb2d13b6SMartin Matuska	dnl #
603ff01b23SMartin Matuska	dnl # Python "packaging" (or, failing that, "distlib") module is required to build and install pyzfs
613ff01b23SMartin Matuska	dnl #
623ff01b23SMartin Matuska	AS_IF([test "x$enable_pyzfs" = xcheck -o "x$enable_pyzfs" = xyes], [
633ff01b23SMartin Matuska		ZFS_AC_PYTHON_MODULE([packaging], [], [
643ff01b23SMartin Matuska			ZFS_AC_PYTHON_MODULE([distlib], [], [
653ff01b23SMartin Matuska				AS_IF([test "x$enable_pyzfs" = xyes], [
663ff01b23SMartin Matuska					AC_MSG_ERROR("Python $PYTHON_VERSION packaging and distlib modules are not installed")
673ff01b23SMartin Matuska				], [test "x$enable_pyzfs" != xno], [
683ff01b23SMartin Matuska					enable_pyzfs=no
693ff01b23SMartin Matuska				])
703ff01b23SMartin Matuska			])
713ff01b23SMartin Matuska		])
723ff01b23SMartin Matuska	])
733ff01b23SMartin Matuska
743ff01b23SMartin Matuska	dnl #
75e92ffd9bSMartin Matuska	dnl # Require python3-devel libraries
76eda14cbcSMatt Macy	dnl #
77eda14cbcSMatt Macy	AS_IF([test "x$enable_pyzfs" = xcheck  -o "x$enable_pyzfs" = xyes], [
78eda14cbcSMatt Macy		AS_CASE([$PYTHON_VERSION],
79e92ffd9bSMartin Matuska			[3.*], [PYTHON_REQUIRED_VERSION=">= '3.6.0'"],
80eda14cbcSMatt Macy			[AC_MSG_ERROR("Python $PYTHON_VERSION unknown")]
81eda14cbcSMatt Macy		)
82eda14cbcSMatt Macy
83eda14cbcSMatt Macy		AS_IF([test "x$enable_pyzfs" = xyes], [
84*b985c9caSMartin Matuska			AX_PYTHON_DEVEL([$PYTHON_REQUIRED_VERSION])
85*b985c9caSMartin Matuska		], [
86*b985c9caSMartin Matuska			AX_PYTHON_DEVEL([$PYTHON_REQUIRED_VERSION], [true])
87*b985c9caSMartin Matuska			AS_IF([test "x$ax_python_devel_found" = xno], [
88eda14cbcSMatt Macy				enable_pyzfs=no
89eda14cbcSMatt Macy			])
90eda14cbcSMatt Macy		])
91eda14cbcSMatt Macy	])
92eda14cbcSMatt Macy
93eda14cbcSMatt Macy	dnl #
94eda14cbcSMatt Macy	dnl # Python "setuptools" module is required to build and install pyzfs
95eda14cbcSMatt Macy	dnl #
96eda14cbcSMatt Macy	AS_IF([test "x$enable_pyzfs" = xcheck -o "x$enable_pyzfs" = xyes], [
97eda14cbcSMatt Macy		ZFS_AC_PYTHON_MODULE([setuptools], [], [
98eda14cbcSMatt Macy			AS_IF([test "x$enable_pyzfs" = xyes], [
99eda14cbcSMatt Macy				AC_MSG_ERROR("Python $PYTHON_VERSION setuptools is not installed")
100eda14cbcSMatt Macy			], [test "x$enable_pyzfs" != xno], [
101eda14cbcSMatt Macy				enable_pyzfs=no
102eda14cbcSMatt Macy			])
103eda14cbcSMatt Macy		])
104eda14cbcSMatt Macy	])
105eda14cbcSMatt Macy
106eda14cbcSMatt Macy	dnl #
107eda14cbcSMatt Macy	dnl # Python "cffi" module is required to run pyzfs
108eda14cbcSMatt Macy	dnl #
109eda14cbcSMatt Macy	AS_IF([test "x$enable_pyzfs" = xcheck -o "x$enable_pyzfs" = xyes], [
110eda14cbcSMatt Macy		ZFS_AC_PYTHON_MODULE([cffi], [], [
111eda14cbcSMatt Macy			AS_IF([test "x$enable_pyzfs" = xyes], [
112eda14cbcSMatt Macy				AC_MSG_ERROR("Python $PYTHON_VERSION cffi is not installed")
113eda14cbcSMatt Macy			], [test "x$enable_pyzfs" != xno], [
114eda14cbcSMatt Macy				enable_pyzfs=no
115eda14cbcSMatt Macy			])
116eda14cbcSMatt Macy		])
117eda14cbcSMatt Macy	])
118eda14cbcSMatt Macy
119eda14cbcSMatt Macy	dnl #
120eda14cbcSMatt Macy	dnl # Set enable_pyzfs to 'yes' if every check passed
121eda14cbcSMatt Macy	dnl #
122eda14cbcSMatt Macy	AS_IF([test "x$enable_pyzfs" = xcheck], [enable_pyzfs=yes])
123eda14cbcSMatt Macy
124eda14cbcSMatt Macy	AM_CONDITIONAL([PYZFS_ENABLED], [test "x$enable_pyzfs" = xyes])
125eda14cbcSMatt Macy	AC_SUBST([PYZFS_ENABLED], [$enable_pyzfs])
126eda14cbcSMatt Macy	AC_SUBST(pythonsitedir, [$PYTHON_SITE_PKG])
127eda14cbcSMatt Macy
128eda14cbcSMatt Macy	AC_MSG_CHECKING([whether to enable pyzfs: ])
129eda14cbcSMatt Macy	AC_MSG_RESULT($enable_pyzfs)
130eda14cbcSMatt Macy])
131