-# These are already checked: inttypes.h stdint.h stdlib.h string.h unistd.h.
-AC_CHECK_HEADERS([sys/types.h sys/stat.h fcntl.h termios.h sys/ioctl.h errno.h])
+# These are already checked: inttypes.h dlfcn.h memory.h stdint.h stdlib.h
+# string.h strings.h sys/types.h sys/stat.h unistd.h
+AC_CHECK_HEADERS([errno.h fcntl.h stddef.h sys/ioctl.h termios.h])
+
+case $target_os in
+*linux*)
+ # On Linux libudev is currently a hard requirement.
+ PKG_CHECK_MODULES([libudev], [libudev >= 0],
+ [CFLAGS="$CFLAGS $libudev_CFLAGS"; LIBS="$LIBS $libudev_LIBS"],
+ [AC_MSG_ERROR([libudev.h not found])])
+ ;;
+*darwin*)
+ LDFLAGS="$LDFLAGS -Wl,-framework -Wl,IOKit -Wl,-framework -Wl,CoreFoundation"
+ AC_CHECK_HEADER(IOKit/IOKitLib.h, [], [AC_MSG_ERROR([IOKit/IOKitLib.h not found])])
+ ;;
+esac