diff --git a/configure b/configure
index da1da01c4601a93ac0b6750a7414bdfb83717302..45fb1751849b1cbd9be92c5841763acd66555ce3 100755
--- a/configure
+++ b/configure
@@ -3235,7 +3235,7 @@ else
 fi
 done
 
-for ac_hdr in wctype.h sys/syscall.h syscall.h sys/param.h sys/vfs.h sys/mount.h sys/statfs.h float.h linux/cdrom.h linux/ucdrom.h sys/cdio.h sys/filio.h sys/modem.h strings.h sys/strtio.h dlfcn.h unistd.h sys/sockio.h net/if.h netinet/in.h sys/file.h
+for ac_hdr in wctype.h sys/syscall.h syscall.h sys/param.h sys/vfs.h sys/mount.h sys/statfs.h float.h linux/cdrom.h linux/ucdrom.h sys/cdio.h sys/filio.h sys/modem.h strings.h sys/strtio.h dlfcn.h unistd.h sys/sockio.h net/if.h netinet/in.h sys/file.h libio.h curses.h ncurses.h elf.h
 do
 ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
diff --git a/configure.in b/configure.in
index 65c19c17ab984401868fac594d34f8d2f0dd0fdb..165d284edc0984fe83f7ebb5384724a222181976 100644
--- a/configure.in
+++ b/configure.in
@@ -344,7 +344,7 @@ fi
 dnl **** Check for functions and header files ****
 
 AC_CHECK_FUNCS(clone getpagesize memmove sendmsg sigaltstack strerror stricmp tcgetattr timegm usleep wait4 waitpid vfscanf)
-AC_CHECK_HEADERS(wctype.h sys/syscall.h syscall.h sys/param.h sys/vfs.h sys/mount.h sys/statfs.h float.h linux/cdrom.h linux/ucdrom.h sys/cdio.h sys/filio.h sys/modem.h strings.h sys/strtio.h dlfcn.h unistd.h sys/sockio.h net/if.h netinet/in.h sys/file.h)
+AC_CHECK_HEADERS(wctype.h sys/syscall.h syscall.h sys/param.h sys/vfs.h sys/mount.h sys/statfs.h float.h linux/cdrom.h linux/ucdrom.h sys/cdio.h sys/filio.h sys/modem.h strings.h sys/strtio.h dlfcn.h unistd.h sys/sockio.h net/if.h netinet/in.h sys/file.h libio.h curses.h ncurses.h elf.h)
 AC_HEADER_STAT()
 AC_C_CONST()
 AC_TYPE_SIZE_T()
diff --git a/console/ncurses.c b/console/ncurses.c
index b5b5fc63abe04262da165cc5d32f98f14756fe52..ce0245559f643bb90349767cce885236ef0848a2 100644
--- a/console/ncurses.c
+++ b/console/ncurses.c
@@ -21,7 +21,13 @@
 
 #include "debug.h"
 #undef ERR /* Use ncurses's err() */
-#include <curses.h>
+#ifdef HAVE_CURSES_H
+# include <curses.h>
+#else
+# ifdef HAVE_NCURSES_H
+#  include <ncurses.h>
+# endif
+#endif
 
 SCREEN *ncurses_screen;
 
diff --git a/debugger/stabs.c b/debugger/stabs.c
index 61581ad896689fa3969027fa0c4962d473077c85..67565ca2a261303a58aee0b76eeeded97ac26060 100644
--- a/debugger/stabs.c
+++ b/debugger/stabs.c
@@ -4,6 +4,8 @@
  * Copyright (C) 1996, Eric Youngdale.
  */
 
+#include "config.h"
+
 #include <sys/types.h>
 #include <fcntl.h>
 #include <sys/stat.h>
@@ -26,7 +28,9 @@
 #endif
 
 #ifdef __ELF__
-#include <elf.h>
+#ifdef HAVE_ELF_H
+# include <elf.h>
+#endif
 #include <link.h>
 #include <sys/mman.h>
 #elif defined(__EMX__)
diff --git a/include/config.h.in b/include/config.h.in
index 9f1223440a89429f5fa51394702622cf0abe0abd..fc41763af7b548b45b9a1cce9b20c80a43549275 100644
--- a/include/config.h.in
+++ b/include/config.h.in
@@ -126,12 +126,21 @@
 /* Define if you have the waitpid function.  */
 #undef HAVE_WAITPID
 
+/* Define if you have the <curses.h> header file.  */
+#undef HAVE_CURSES_H
+
 /* Define if you have the <dlfcn.h> header file.  */
 #undef HAVE_DLFCN_H
 
+/* Define if you have the <elf.h> header file.  */
+#undef HAVE_ELF_H
+
 /* Define if you have the <float.h> header file.  */
 #undef HAVE_FLOAT_H
 
+/* Define if you have the <libio.h> header file.  */
+#undef HAVE_LIBIO_H
+
 /* Define if you have the <linux/cdrom.h> header file.  */
 #undef HAVE_LINUX_CDROM_H
 
@@ -141,6 +150,9 @@
 /* Define if you have the <machine/soundcard.h> header file.  */
 #undef HAVE_MACHINE_SOUNDCARD_H
 
+/* Define if you have the <ncurses.h> header file.  */
+#undef HAVE_NCURSES_H
+
 /* Define if you have the <net/if.h> header file.  */
 #undef HAVE_NET_IF_H
 
diff --git a/include/console.h b/include/console.h
index 75587a449fed1feca7150c87ccd066601163d8fe..949fe65c364fdab105e664a75400e090123cdc6e 100644
--- a/include/console.h
+++ b/include/console.h
@@ -12,18 +12,18 @@
 
 #include "config.h"
 
-/* Which libs can be used for wine's curses implementation... */
-#ifdef HAVE_LIBNCURSES 
-#define WINE_NCURSES
+/* Can we compile with curses/ncurses? */
+#if (	(defined(HAVE_LIBNCURSES) || defined(HAVE_LIBCURSES)) &&	\
+	(defined(HAVE_CURSES_H) || defined(HAVE_NCURSES_H))		\
+)
+# define WINE_NCURSES
 #else
-   #ifdef HAVE_LIBCURSES
-   #define WINE_NCURSES
-   #endif   
+# undef WINE_NCURSES
 #endif
 
 #define CONSOLE_DEFAULT_DRIVER "tty"
 /* If you have problems, try setting the next line to xterm */
-#define CONSOLE_XTERM_PROG "nxterm" /* We should check for this first... */
+#define CONSOLE_XTERM_PROG "xterm" /* We should check for this first... */
 
 typedef struct CONSOLE_DRIVER
 {
diff --git a/misc/port.c b/misc/port.c
index aba2d0a1c3d4af436150703e6c6642ea9b14d9b9..5e03c6e0adee70f77fb51deb693a67bb99637633 100644
--- a/misc/port.c
+++ b/misc/port.c
@@ -12,7 +12,9 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <termios.h>
-#include <libio.h>
+#ifdef HAVE_LIBIO_H
+# include <libio.h>
+#endif
 
 #ifndef HAVE_USLEEP
 #ifdef __EMX__