Porting fixes.

diff --git a/server/file.c b/server/file.c
index b4560a8..60b72a6 100644
--- a/server/file.c
+++ b/server/file.c
@@ -35,7 +35,9 @@
 #include <sys/types.h>
 #include <time.h>
 #include <unistd.h>
+#ifdef HAVE_UTIME_H
 #include <utime.h>
+#endif
 
 #include "winerror.h"
 #include "winbase.h"
diff --git a/server/named_pipe.c b/server/named_pipe.c
index f2323cc..32fae99 100644
--- a/server/named_pipe.c
+++ b/server/named_pipe.c
@@ -32,7 +32,9 @@
 #include <stdlib.h>
 #include <sys/time.h>
 #include <sys/types.h>
+#ifdef HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
+#endif
 #include <time.h>
 #include <unistd.h>
 
diff --git a/server/object.h b/server/object.h
index 7868e2f..234c972 100644
--- a/server/object.h
+++ b/server/object.h
@@ -21,7 +21,10 @@
 #ifndef __WINE_SERVER_OBJECT_H
 #define __WINE_SERVER_OBJECT_H
 
+#ifdef HAVE_SYS_POLL_H
 #include <sys/poll.h>
+#endif
+
 #include <sys/time.h>
 #include "wine/server_protocol.h"
 #include "list.h"
diff --git a/server/request.c b/server/request.c
index 15c4883..5411313 100644
--- a/server/request.c
+++ b/server/request.c
@@ -24,7 +24,9 @@
 #include <assert.h>
 #include <errno.h>
 #include <fcntl.h>
+#ifdef HAVE_PWD_H
 #include <pwd.h>
+#endif
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -39,8 +41,12 @@
 #ifdef HAVE_SYS_WAIT_H
 # include <sys/wait.h>
 #endif
+#ifdef HAVE_SYS_UIO_H
 #include <sys/uio.h>
+#endif
+#ifdef HAVE_SYS_UN_H
 #include <sys/un.h>
+#endif
 #include <unistd.h>
 
 #include "windef.h"
diff --git a/server/select.c b/server/select.c
index 2ea2354..324ec20 100644
--- a/server/select.c
+++ b/server/select.c
@@ -18,12 +18,16 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#include "config.h"
+
 #include <assert.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#ifdef HAVE_SYS_POLL_H
 #include <sys/poll.h>
+#endif
 #include <sys/time.h>
 #include <sys/types.h>
 #include <unistd.h>
diff --git a/server/serial.c b/server/serial.c
index 0e4d79f..998d9b6 100644
--- a/server/serial.c
+++ b/server/serial.c
@@ -32,9 +32,15 @@
 #include <sys/types.h>
 #include <time.h>
 #include <unistd.h>
+#ifdef HAVE_UTIME_H
 #include <utime.h>
+#endif
+#ifdef HAVE_TERMIOS_H
 #include <termios.h>
+#endif
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
 
 #include "winerror.h"
 #include "winbase.h"
diff --git a/server/smb.c b/server/smb.c
index ab00685..c3ab30b 100644
--- a/server/smb.c
+++ b/server/smb.c
@@ -33,9 +33,15 @@
 #include <sys/types.h>
 #include <time.h>
 #include <unistd.h>
+#ifdef HAVE_UTIME_H
 #include <utime.h>
+#endif
+#ifdef HAVE_TERMIOS_H
 #include <termios.h>
+#endif
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
 
 #include "winerror.h"
 #include "winbase.h"
diff --git a/server/sock.c b/server/sock.c
index d528ab5..3a4e514 100644
--- a/server/sock.c
+++ b/server/sock.c
@@ -37,7 +37,9 @@
 #ifdef HAVE_SYS_SOCKET_H
 # include <sys/socket.h>
 #endif
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
 #ifdef HAVE_SYS_FILIO_H
 # include <sys/filio.h>
 #endif
diff --git a/server/trace.c b/server/trace.c
index 1dd85f1..5069534 100644
--- a/server/trace.c
+++ b/server/trace.c
@@ -24,7 +24,11 @@
 #include <ctype.h>
 #include <stdio.h>
 #include <sys/types.h>
+
+#ifdef HAVE_SYS_UIO_H
 #include <sys/uio.h>
+#endif
+
 
 #include "windef.h"
 #include "winbase.h"