diff --git a/common/mlutils/unix_utils-c.c b/common/mlutils/unix_utils-c.c
index 1b5eb7957..6d8aa0b6c 100644
--- a/common/mlutils/unix_utils-c.c
+++ b/common/mlutils/unix_utils-c.c
@@ -55,6 +55,10 @@
 #include <windows.h>
 #endif
 
+#ifdef __APPLE__ && __MACH__
+#include <sys/mount.h>
+#endif
+
 #include <caml/alloc.h>
 #include <caml/fail.h>
 #include <caml/memory.h>
diff --git a/daemon/tsk.c b/daemon/tsk.c
index ad10d74fe..00a4b04b4 100644
--- a/daemon/tsk.c
+++ b/daemon/tsk.c
@@ -23,8 +23,8 @@
 #include <inttypes.h>
 #include <string.h>
 #include <unistd.h>
-#include <rpc/xdr.h>
 #include <rpc/types.h>
+#include <rpc/xdr.h>
 
 #include "guestfs_protocol.h"
 #include "daemon.h"
diff --git a/daemon/yara.c b/daemon/yara.c
index 0fd09815a..9e7bc9414 100644
--- a/daemon/yara.c
+++ b/daemon/yara.c
@@ -25,8 +25,8 @@
 #include <string.h>
 #include <unistd.h>
 #include <stdbool.h>
-#include <rpc/xdr.h>
 #include <rpc/types.h>
+#include <rpc/xdr.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 
diff --git a/lib/tsk.c b/lib/tsk.c
index 09e514bd2..cb1dc94ec 100644
--- a/lib/tsk.c
+++ b/lib/tsk.c
@@ -25,8 +25,8 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <string.h>
-#include <rpc/xdr.h>
 #include <rpc/types.h>
+#include <rpc/xdr.h>
 
 #include "guestfs.h"
 #include "guestfs_protocol.h"
diff --git a/lib/yara.c b/lib/yara.c
index edced3be8..27390d153 100644
--- a/lib/yara.c
+++ b/lib/yara.c
@@ -25,8 +25,8 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <string.h>
-#include <rpc/xdr.h>
 #include <rpc/types.h>
+#include <rpc/xdr.h>
 
 #include "guestfs.h"
 #include "guestfs_protocol.h"
diff --git a/m4/guestfs-libraries.m4 b/m4/guestfs-libraries.m4
index 17cf556d9..b78a5cefa 100644
--- a/m4/guestfs-libraries.m4
+++ b/m4/guestfs-libraries.m4
@@ -181,9 +181,14 @@ PKG_CHECK_MODULES([RPC], [libtirpc], [], [
     # If we don't have libtirpc, then we must have <rpc/xdr.h> and
     # some library to link to in libdir.
     RPC_CFLAGS=""
+    AC_CHECK_HEADER([rpc/types.h], [AC_DEFINE([HAVE_RPC_TYPES_H],
+        [], [no rpc/types.h])])
     AC_CHECK_HEADER([rpc/xdr.h],[],[
-        AC_MSG_ERROR([XDR header files are required])
-    ])
+        AC_MSG_ERROR([XDR header files are required])],
+[#ifdef HAVE_RPC_TYPES_H
+# include <rpc/types.h>
+#endif
+])
 
     old_LIBS="$LIBS"
     LIBS=""
