From cc420402bf14cbb0b3495339910b840561bbc769 Mon Sep 17 00:00:00 2001
From: Brian Behlendorf <behlendorf1@llnl.gov>
Date: Mon, 15 Dec 2008 16:46:34 -0800
Subject: [PATCH] Moving addition configure checks to m4 macros

---
 config/kernel-bio-args.m4 | 24 ++++++++++++++++++++++++
 config/kernel.m4          |  2 ++
 config/user-ioctl.m4      | 35 +++++++++++++++++++++++++++++++++++
 config/user-libdiskmgt.m4 |  8 ++++++++
 config/user-libefi.m4     |  8 ++++++++
 config/user-libshare.m4   |  8 ++++++++
 config/user.m4            |  2 ++
 7 files changed, 87 insertions(+)
 create mode 100644 config/kernel-bio-args.m4
 create mode 100644 config/user-ioctl.m4
 create mode 100644 config/user-libdiskmgt.m4
 create mode 100644 config/user-libefi.m4
 create mode 100644 config/user-libshare.m4

diff --git a/config/kernel-bio-args.m4 b/config/kernel-bio-args.m4
new file mode 100644
index 0000000000..0e652dbc40
--- /dev/null
+++ b/config/kernel-bio-args.m4
@@ -0,0 +1,24 @@
+dnl #
+dnl # 2.6.x API change
+dnl # bio_end_io_t uses 2 args (size was dropped from prototype)
+dnl #
+AC_DEFUN([ZFS_AC_CONFIG_KERNEL_BIO_ARGS],
+	[AC_MSG_CHECKING([whether bio_end_io_t wants 2 args])
+	tmp_flags="$EXTRA_KCFLAGS"
+	EXTRA_KCFLAGS="-Werror"
+	ZFS_LINUX_TRY_COMPILE([
+		#include <linux/bio.h>
+	],[
+		void (*wanted_end_io)(struct bio *, int) = NULL;
+		bio_end_io_t *local_end_io;
+
+		local_end_io = wanted_end_io;
+	],[
+		AC_MSG_RESULT(yes)
+		AC_DEFINE(HAVE_2ARGS_BIO_END_IO_T, 1,
+		          [bio_end_io_t wants 2 args])
+	],[
+		AC_MSG_RESULT(no)
+	])
+	EXTRA_KCFLAGS="$tmp_flags"
+])
diff --git a/config/kernel.m4 b/config/kernel.m4
index 8563c9ae58..df62b2f258 100644
--- a/config/kernel.m4
+++ b/config/kernel.m4
@@ -37,4 +37,6 @@ AC_DEFUN([ZFS_AC_CONFIG_KERNEL], [
         AC_SUBST(KERNELMAKE_PARAMS)
         AC_SUBST(KERNELCPPFLAGS)
         AC_SUBST(HOSTCFLAGS)
+
+	ZFS_AC_CONFIG_KERNEL_BIO_ARGS
 ])
diff --git a/config/user-ioctl.m4 b/config/user-ioctl.m4
new file mode 100644
index 0000000000..453e0f1f60
--- /dev/null
+++ b/config/user-ioctl.m4
@@ -0,0 +1,35 @@
+dnl #
+dnl # Check for ioctl()
+dnl #
+AC_DEFUN([ZFS_AC_CONFIG_USER_IOCTL], [
+	AC_MSG_CHECKING(checking for ioctl())
+	AC_EGREP_HEADER(ioctl, unistd.h, is_unistd=yes, is_unistd=no)
+	AC_EGREP_HEADER(ioctl, sys/ioctl.h, is_sys_ioctl=yes, is_sys_ioctl=no)
+	AC_EGREP_HEADER(ioctl, stropts.h, is_stropts=yes, is_stropts=no)
+
+	if test $is_unistd = yes; then
+		result=unistd.h
+		AC_DEFINE([HAVE_IOCTL_IN_UNISTD_H], 1,
+		[Define to 1 if ioctl() defined in <unistd.h>])
+	else
+
+		if test $is_sys_ioctl = yes; then
+			result=sys/ioctl.h
+			AC_DEFINE([HAVE_IOCTL_IN_SYS_IOCTL_H], 1,
+			[Define to 1 if ioctl() defined in <sys/ioctl.h>])
+		elif test $is_stropts = yes; then
+			AC_DEFINE([HAVE_IOCTL_IN_STROPTS_H], 1,
+			result=stropts.h
+			[Define to 1 if ioctl() defined in <stropts.h>])
+		else
+			result=no
+		fi
+	fi
+
+	if test $result = no; then
+                AC_MSG_RESULT([no])
+                AC_MSG_ERROR([*** Cannot locate ioctl() definition])
+	else
+		AC_MSG_RESULT(yes)
+	fi
+])
diff --git a/config/user-libdiskmgt.m4 b/config/user-libdiskmgt.m4
new file mode 100644
index 0000000000..53e043bda4
--- /dev/null
+++ b/config/user-libdiskmgt.m4
@@ -0,0 +1,8 @@
+dnl #
+dnl # Check for libdiskmgt
+dnl #
+AC_DEFUN([ZFS_AC_CONFIG_USER_LIBDISKMGT], [
+	AC_CHECK_LIB([diskmgt], [libdiskmgt_error],
+		[AC_DEFINE([HAVE_LIBDISKMGT], 1,
+		[Define to 1 if 'libdiskmgt' library available])])
+])
diff --git a/config/user-libefi.m4 b/config/user-libefi.m4
new file mode 100644
index 0000000000..aebc1d5412
--- /dev/null
+++ b/config/user-libefi.m4
@@ -0,0 +1,8 @@
+dnl #
+dnl # Check for libefi
+dnl #
+AC_DEFUN([ZFS_AC_CONFIG_USER_LIBEFI], [
+	AC_CHECK_LIB([efi], [efi_alloc_and_init],
+		[AC_DEFINE([HAVE_LIBEFI], 1,
+		[Define to 1 if 'libefi' library available])])
+])
diff --git a/config/user-libshare.m4 b/config/user-libshare.m4
new file mode 100644
index 0000000000..3b92bbaa5e
--- /dev/null
+++ b/config/user-libshare.m4
@@ -0,0 +1,8 @@
+dnl #
+dnl # Check for libshare
+dnl #
+AC_DEFUN([ZFS_AC_CONFIG_USER_LIBSHARE], [
+	AC_CHECK_LIB([share], [sa_init],
+		[AC_DEFINE([HAVE_LIBSHARE], 1,
+		[Define to 1 if 'libshare' library available])])
+])
diff --git a/config/user.m4 b/config/user.m4
index 719fd6a503..d9f9d621fe 100644
--- a/config/user.m4
+++ b/config/user.m4
@@ -3,5 +3,7 @@ dnl # Default ZFS user configuration
 dnl #
 AC_DEFUN([ZFS_AC_CONFIG_USER], [
 	ZFS_AC_CONFIG_USER_LIBEFI
+	ZFS_AC_CONFIG_USER_LIBDISKMGT
+	ZFS_AC_CONFIG_USER_LIBSHARE
 	ZFS_AC_CONFIG_USER_IOCTL
 ])