xref: /freebsd/sys/contrib/openzfs/config/always-pyzfs.m4 (revision e92ffd9b626833ebdbf2742c8ffddc6cd94b963e)
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 #
21*e92ffd9bSMartin 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 #
503ff01b23SMartin Matuska	dnl # Python "packaging" (or, failing that, "distlib") module is required to build and install pyzfs
513ff01b23SMartin Matuska	dnl #
523ff01b23SMartin Matuska	AS_IF([test "x$enable_pyzfs" = xcheck -o "x$enable_pyzfs" = xyes], [
533ff01b23SMartin Matuska		ZFS_AC_PYTHON_MODULE([packaging], [], [
543ff01b23SMartin Matuska			ZFS_AC_PYTHON_MODULE([distlib], [], [
553ff01b23SMartin Matuska				AS_IF([test "x$enable_pyzfs" = xyes], [
563ff01b23SMartin Matuska					AC_MSG_ERROR("Python $PYTHON_VERSION packaging and distlib modules are not installed")
573ff01b23SMartin Matuska				], [test "x$enable_pyzfs" != xno], [
583ff01b23SMartin Matuska					enable_pyzfs=no
593ff01b23SMartin Matuska				])
603ff01b23SMartin Matuska			])
613ff01b23SMartin Matuska		])
623ff01b23SMartin Matuska	])
633ff01b23SMartin Matuska
643ff01b23SMartin Matuska	dnl #
65*e92ffd9bSMartin Matuska	dnl # Require python3-devel libraries
66eda14cbcSMatt Macy	dnl #
67eda14cbcSMatt Macy	AS_IF([test "x$enable_pyzfs" = xcheck  -o "x$enable_pyzfs" = xyes], [
68eda14cbcSMatt Macy		AS_CASE([$PYTHON_VERSION],
69*e92ffd9bSMartin Matuska			[3.*], [PYTHON_REQUIRED_VERSION=">= '3.6.0'"],
70eda14cbcSMatt Macy			[AC_MSG_ERROR("Python $PYTHON_VERSION unknown")]
71eda14cbcSMatt Macy		)
72eda14cbcSMatt Macy
73eda14cbcSMatt Macy		AX_PYTHON_DEVEL([$PYTHON_REQUIRED_VERSION], [
74eda14cbcSMatt Macy			AS_IF([test "x$enable_pyzfs" = xyes], [
75eda14cbcSMatt Macy				AC_MSG_ERROR("Python $PYTHON_REQUIRED_VERSION development library is not installed")
76eda14cbcSMatt Macy			], [test "x$enable_pyzfs" != xno], [
77eda14cbcSMatt Macy				enable_pyzfs=no
78eda14cbcSMatt Macy			])
79eda14cbcSMatt Macy		])
80eda14cbcSMatt Macy	])
81eda14cbcSMatt Macy
82eda14cbcSMatt Macy	dnl #
83eda14cbcSMatt Macy	dnl # Python "setuptools" module is required to build and install pyzfs
84eda14cbcSMatt Macy	dnl #
85eda14cbcSMatt Macy	AS_IF([test "x$enable_pyzfs" = xcheck -o "x$enable_pyzfs" = xyes], [
86eda14cbcSMatt Macy		ZFS_AC_PYTHON_MODULE([setuptools], [], [
87eda14cbcSMatt Macy			AS_IF([test "x$enable_pyzfs" = xyes], [
88eda14cbcSMatt Macy				AC_MSG_ERROR("Python $PYTHON_VERSION setuptools is not installed")
89eda14cbcSMatt Macy			], [test "x$enable_pyzfs" != xno], [
90eda14cbcSMatt Macy				enable_pyzfs=no
91eda14cbcSMatt Macy			])
92eda14cbcSMatt Macy		])
93eda14cbcSMatt Macy	])
94eda14cbcSMatt Macy
95eda14cbcSMatt Macy	dnl #
96eda14cbcSMatt Macy	dnl # Python "cffi" module is required to run pyzfs
97eda14cbcSMatt Macy	dnl #
98eda14cbcSMatt Macy	AS_IF([test "x$enable_pyzfs" = xcheck -o "x$enable_pyzfs" = xyes], [
99eda14cbcSMatt Macy		ZFS_AC_PYTHON_MODULE([cffi], [], [
100eda14cbcSMatt Macy			AS_IF([test "x$enable_pyzfs" = xyes], [
101eda14cbcSMatt Macy				AC_MSG_ERROR("Python $PYTHON_VERSION cffi is not installed")
102eda14cbcSMatt Macy			], [test "x$enable_pyzfs" != xno], [
103eda14cbcSMatt Macy				enable_pyzfs=no
104eda14cbcSMatt Macy			])
105eda14cbcSMatt Macy		])
106eda14cbcSMatt Macy	])
107eda14cbcSMatt Macy
108eda14cbcSMatt Macy	dnl #
109eda14cbcSMatt Macy	dnl # Set enable_pyzfs to 'yes' if every check passed
110eda14cbcSMatt Macy	dnl #
111eda14cbcSMatt Macy	AS_IF([test "x$enable_pyzfs" = xcheck], [enable_pyzfs=yes])
112eda14cbcSMatt Macy
113eda14cbcSMatt Macy	AM_CONDITIONAL([PYZFS_ENABLED], [test "x$enable_pyzfs" = xyes])
114eda14cbcSMatt Macy	AC_SUBST([PYZFS_ENABLED], [$enable_pyzfs])
115eda14cbcSMatt Macy	AC_SUBST(pythonsitedir, [$PYTHON_SITE_PKG])
116eda14cbcSMatt Macy
117eda14cbcSMatt Macy	AC_MSG_CHECKING([whether to enable pyzfs: ])
118eda14cbcSMatt Macy	AC_MSG_RESULT($enable_pyzfs)
119eda14cbcSMatt Macy])
120