xref: /freebsd/sys/contrib/openzfs/config/always-pyzfs.m4 (revision dae1713419a669d4f6c7acddf81a21297c809741)
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], [
9*dae17134SMartin 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 #
21eda14cbcSMatt Macydnl # Determines if pyzfs can be built, requires Python 2.7 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 #
65eda14cbcSMatt Macy	dnl # Require python-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],
69eda14cbcSMatt Macy			[3.*], [PYTHON_REQUIRED_VERSION=">= '3.4.0'"],
70eda14cbcSMatt Macy			[2.*], [PYTHON_REQUIRED_VERSION=">= '2.7.0'"],
71eda14cbcSMatt Macy			[AC_MSG_ERROR("Python $PYTHON_VERSION unknown")]
72eda14cbcSMatt Macy		)
73eda14cbcSMatt Macy
74eda14cbcSMatt Macy		AX_PYTHON_DEVEL([$PYTHON_REQUIRED_VERSION], [
75eda14cbcSMatt Macy			AS_IF([test "x$enable_pyzfs" = xyes], [
76eda14cbcSMatt Macy				AC_MSG_ERROR("Python $PYTHON_REQUIRED_VERSION development library is not installed")
77eda14cbcSMatt Macy			], [test "x$enable_pyzfs" != xno], [
78eda14cbcSMatt Macy				enable_pyzfs=no
79eda14cbcSMatt Macy			])
80eda14cbcSMatt Macy		])
81eda14cbcSMatt Macy	])
82eda14cbcSMatt Macy
83eda14cbcSMatt Macy	dnl #
84eda14cbcSMatt Macy	dnl # Python "setuptools" module is required to build and install pyzfs
85eda14cbcSMatt Macy	dnl #
86eda14cbcSMatt Macy	AS_IF([test "x$enable_pyzfs" = xcheck -o "x$enable_pyzfs" = xyes], [
87eda14cbcSMatt Macy		ZFS_AC_PYTHON_MODULE([setuptools], [], [
88eda14cbcSMatt Macy			AS_IF([test "x$enable_pyzfs" = xyes], [
89eda14cbcSMatt Macy				AC_MSG_ERROR("Python $PYTHON_VERSION setuptools is not installed")
90eda14cbcSMatt Macy			], [test "x$enable_pyzfs" != xno], [
91eda14cbcSMatt Macy				enable_pyzfs=no
92eda14cbcSMatt Macy			])
93eda14cbcSMatt Macy		])
94eda14cbcSMatt Macy	])
95eda14cbcSMatt Macy
96eda14cbcSMatt Macy	dnl #
97eda14cbcSMatt Macy	dnl # Python "cffi" module is required to run pyzfs
98eda14cbcSMatt Macy	dnl #
99eda14cbcSMatt Macy	AS_IF([test "x$enable_pyzfs" = xcheck -o "x$enable_pyzfs" = xyes], [
100eda14cbcSMatt Macy		ZFS_AC_PYTHON_MODULE([cffi], [], [
101eda14cbcSMatt Macy			AS_IF([test "x$enable_pyzfs" = xyes], [
102eda14cbcSMatt Macy				AC_MSG_ERROR("Python $PYTHON_VERSION cffi is not installed")
103eda14cbcSMatt Macy			], [test "x$enable_pyzfs" != xno], [
104eda14cbcSMatt Macy				enable_pyzfs=no
105eda14cbcSMatt Macy			])
106eda14cbcSMatt Macy		])
107eda14cbcSMatt Macy	])
108eda14cbcSMatt Macy
109eda14cbcSMatt Macy	dnl #
110eda14cbcSMatt Macy	dnl # Set enable_pyzfs to 'yes' if every check passed
111eda14cbcSMatt Macy	dnl #
112eda14cbcSMatt Macy	AS_IF([test "x$enable_pyzfs" = xcheck], [enable_pyzfs=yes])
113eda14cbcSMatt Macy
114eda14cbcSMatt Macy	AM_CONDITIONAL([PYZFS_ENABLED], [test "x$enable_pyzfs" = xyes])
115eda14cbcSMatt Macy	AC_SUBST([PYZFS_ENABLED], [$enable_pyzfs])
116eda14cbcSMatt Macy	AC_SUBST(pythonsitedir, [$PYTHON_SITE_PKG])
117eda14cbcSMatt Macy
118eda14cbcSMatt Macy	AC_MSG_CHECKING([whether to enable pyzfs: ])
119eda14cbcSMatt Macy	AC_MSG_RESULT($enable_pyzfs)
120eda14cbcSMatt Macy])
121