diff --git a/configure b/configure
index 1cb0e59da578034e37ea15386b2f21860f4af6b0..ffb1825fe64c421f06c14dfce239e874041e18ea 100755
--- a/configure
+++ b/configure
@@ -6836,6 +6836,56 @@ fi
 
 done
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether sys/types.h defines makedev" >&5
+$as_echo_n "checking whether sys/types.h defines makedev... " >&6; }
+if ${ac_cv_header_sys_types_h_makedev+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <sys/types.h>
+int
+main ()
+{
+return makedev(0, 0);
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_header_sys_types_h_makedev=yes
+else
+  ac_cv_header_sys_types_h_makedev=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_sys_types_h_makedev" >&5
+$as_echo "$ac_cv_header_sys_types_h_makedev" >&6; }
+
+if test $ac_cv_header_sys_types_h_makedev = no; then
+ac_fn_c_check_header_mongrel "$LINENO" "sys/mkdev.h" "ac_cv_header_sys_mkdev_h" "$ac_includes_default"
+if test "x$ac_cv_header_sys_mkdev_h" = xyes; then :
+
+$as_echo "#define MAJOR_IN_MKDEV 1" >>confdefs.h
+
+fi
+
+
+
+  if test $ac_cv_header_sys_mkdev_h = no; then
+    ac_fn_c_check_header_mongrel "$LINENO" "sys/sysmacros.h" "ac_cv_header_sys_sysmacros_h" "$ac_includes_default"
+if test "x$ac_cv_header_sys_sysmacros_h" = xyes; then :
+
+$as_echo "#define MAJOR_IN_SYSMACROS 1" >>confdefs.h
+
+fi
+
+
+  fi
+fi
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether stat file-mode macros are broken" >&5
 $as_echo_n "checking whether stat file-mode macros are broken... " >&6; }
 if ${ac_cv_header_stat_broken+:} false; then :
diff --git a/configure.ac b/configure.ac
index 6189aa99c73bc34d83988f39bf6b9e3fa56d9c9e..201bc779b65e8d7f6c89701d84537c33bcd81126 100644
--- a/configure.ac
+++ b/configure.ac
@@ -512,6 +512,7 @@ AC_CHECK_HEADERS(\
 	valgrind/valgrind.h \
 	zlib.h
 )
+AC_HEADER_MAJOR()
 AC_HEADER_STAT()
 
 dnl **** Checks for headers that depend on other ones ****
diff --git a/dlls/ntdll/cdrom.c b/dlls/ntdll/cdrom.c
index ee360459230baaf2705400a04882984573293808..2c64106072d747528fedd1bb88b0d34f1c949bf3 100644
--- a/dlls/ntdll/cdrom.c
+++ b/dlls/ntdll/cdrom.c
@@ -38,6 +38,11 @@
 #ifdef HAVE_SYS_STAT_H
 # include <sys/stat.h>
 #endif
+#ifdef MAJOR_IN_MKDEV
+# include <sys/mkdev.h>
+#elif defined(MAJOR_IN_SYSMACROS)
+# include <sys/sysmacros.h>
+#endif
 #include <sys/types.h>
 
 #ifdef HAVE_SYS_IOCTL_H
diff --git a/dlls/ntdll/directory.c b/dlls/ntdll/directory.c
index 93fe594e972498568df876166080c8362cee540e..4d431c08d30b259fe71c122bac1d1b8ef52c33a1 100644
--- a/dlls/ntdll/directory.c
+++ b/dlls/ntdll/directory.c
@@ -47,6 +47,11 @@
 #ifdef HAVE_SYS_ATTR_H
 #include <sys/attr.h>
 #endif
+#ifdef MAJOR_IN_MKDEV
+# include <sys/mkdev.h>
+#elif defined(MAJOR_IN_SYSMACROS)
+# include <sys/sysmacros.h>
+#endif
 #ifdef HAVE_SYS_VNODE_H
 /* Work around a conflict with Solaris' system list defined in sys/list.h. */
 #define list SYSLIST
diff --git a/dlls/ntdll/file.c b/dlls/ntdll/file.c
index 7e5da599c3187f986362622ec0b64665f45eff1c..b3bd9d68c97b2db1f1810c34f73311e984eaef2f 100644
--- a/dlls/ntdll/file.c
+++ b/dlls/ntdll/file.c
@@ -57,6 +57,11 @@
 #ifdef HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
 #endif
+#ifdef MAJOR_IN_MKDEV
+# include <sys/mkdev.h>
+#elif defined(MAJOR_IN_SYSMACROS)
+# include <sys/sysmacros.h>
+#endif
 #ifdef HAVE_UTIME_H
 # include <utime.h>
 #endif
diff --git a/include/config.h.in b/include/config.h.in
index 0650f31b4fbb3a07da2c72476eab6828b9f6712f..06b192f91beb41a2a6ff16ea9e3e637d1a3da498 100644
--- a/include/config.h.in
+++ b/include/config.h.in
@@ -1335,6 +1335,14 @@
 /* Define to 1 if you have the `__res_get_state' function. */
 #undef HAVE___RES_GET_STATE
 
+/* Define to 1 if `major', `minor', and `makedev' are declared in <mkdev.h>.
+   */
+#undef MAJOR_IN_MKDEV
+
+/* Define to 1 if `major', `minor', and `makedev' are declared in
+   <sysmacros.h>. */
+#undef MAJOR_IN_SYSMACROS
+
 /* Define to the address where bug reports for this package should be sent. */
 #undef PACKAGE_BUGREPORT
 
diff --git a/server/fd.c b/server/fd.c
index 1fd1ce70b7f2a0db866bbc1ade175d26ade222d4..17b1b66a367dec777930410a64540060a320cb60 100644
--- a/server/fd.c
+++ b/server/fd.c
@@ -83,6 +83,11 @@
 #endif
 #include <sys/stat.h>
 #include <sys/time.h>
+#ifdef MAJOR_IN_MKDEV
+#include <sys/mkdev.h>
+#elif defined(MAJOR_IN_SYSMACROS)
+#include <sys/sysmacros.h>
+#endif
 #include <sys/types.h>
 #include <unistd.h>
 #ifdef HAVE_SYS_SYSCALL_H