--- ncurses/tinfo/access.c~0	2010-01-23 19:57:43.000000000 +0200
+++ ncurses/tinfo/access.c	2012-02-23 11:58:23.767249400 +0200
@@ -72,9 +72,9 @@ _nc_rootname(char *path)
 NCURSES_EXPORT(bool)
 _nc_is_abs_path(const char *path)
 {
-#if defined(__EMX__) || defined(__DJGPP__)
-#define is_pathname(s) ((((s) != 0) && ((s)[0] == '/')) \
-		  || (((s)[0] != 0) && ((s)[1] == ':')))
+#if defined(__EMX__) || defined(__DJGPP__) || defined(__MINGW32__)
+#define is_pathname(s) ((((s)[0] == '/') || ((s)[0] == '\\'))	\
+			|| (((s)[0] != 0) && ((s)[1] == ':')))
 #else
 #define is_pathname(s) ((s) != 0 && (s)[0] == '/')
 #endif
@@ -88,9 +88,13 @@ NCURSES_EXPORT(unsigned)
 _nc_pathlast(const char *path)
 {
     const char *test = strrchr(path, '/');
-#ifdef __EMX__
+#if defined(__EMX__) || defined(__MINGW32__) || defined(__DJGPP__)
     if (test == 0)
 	test = strrchr(path, '\\');
+    else if (strrchr(test, '\\') != 0)
+	test = strrchr(test, '\\');
+    if (test == 0 && path[0] && path[1] == ':')
+	test = path + 1;
 #endif
     if (test == 0)
 	test = path;
--- ncurses/tinfo/home_terminfo.c~0	2010-12-26 01:43:58.000000000 +0200
+++ ncurses/tinfo/home_terminfo.c	2012-02-23 12:21:51.298499400 +0200
@@ -52,7 +52,12 @@ _nc_home_terminfo(void)
 
     if (use_terminfo_vars()) {
 	if (MyBuffer == 0) {
-	    if ((home = getenv("HOME")) != 0) {
+	    home = getenv("HOME");
+#ifdef __MINGW32__
+	    if (home == 0)
+		home = getenv("USERPROFILE");
+#endif
+	    if (home != 0) {
 		size_t want = (strlen(home) + sizeof(PRIVATE_INFO));
 		MyBuffer = typeMalloc(char, want);
 		if (MyBuffer == 0)
--- ncurses/tinfo/write_entry.c~0	2010-12-26 01:23:08.000000000 +0200
+++ ncurses/tinfo/write_entry.c	2012-02-23 12:58:47.721434400 +0200
@@ -401,7 +401,11 @@ _nc_write_entry(TERMTYPE *const tp)
 	    _nc_warning("terminal alias %s too long.", ptr);
 	    continue;
 	}
-	if (strchr(ptr, '/') != 0) {
+	if (strchr(ptr, '/') != 0
+#ifdef __MINGW32__
+	    || strchr(ptr, '\\') != 0
+#endif
+	    				) {
 	    _nc_warning("cannot link alias %s.", ptr);
 	    continue;
 	}
@@ -411,6 +415,10 @@ _nc_write_entry(TERMTYPE *const tp)
 
 	if (strcmp(filename, linkname) == 0) {
 	    _nc_warning("self-synonym ignored");
+#ifdef __MINGW32__
+	} else if (stricmp(filename, linkname) == 0) {
+	    _nc_warning("self-synonym ignored");
+#endif
 	} else if (stat(linkname, &statbuf) >= 0 &&
 		   statbuf.st_mtime < start_time) {
 	    _nc_warning("alias %s multiply defined.", ptr);
--- include/nc_mingw.h~0	2010-09-26 01:16:12.000000000 +0300
+++ include/nc_mingw.h	2012-02-23 12:13:22.454749400 +0200
@@ -66,4 +66,10 @@
 #define wcwidth(ucs) _nc_wcwidth(ucs)
 extern int _nc_wcwidth(wchar_t);
 
+/* Newer versions of MSVCRT barf with invalid parameter error when
+   passed X_OK of 1, the value defined on MinGW headers.  So we
+   disable it here.  */
+#undef X_OK
+#define X_OK 0
+
 #endif /* NC_MINGW_H */
--- README.MinGW~0	2011-02-26 18:57:17.000000000 +0200
+++ README.MinGW	2012-02-23 14:15:04.626559400 +0200
@@ -132,6 +132,10 @@
 
    make dlls
 
+(If you don't have lib.exe from the Microsoft tool-chain, "make dlls"
+will complain that it cannot invoke that command; ignore these
+complaints.)
+
 A lot is still TODO, e.g.:
 
   - Wide Character support
--- ncurses/base/lib_initscr.c~0	2009-02-14 22:55:49.000000000 +0200
+++ ncurses/base/lib_initscr.c	2012-02-23 14:12:25.939059400 +0200
@@ -51,6 +51,7 @@ NCURSES_EXPORT(WINDOW *)
 initscr(void)
 {
     WINDOW *result;
+    SCREEN *st;
 
     NCURSES_CONST char *name;
 
@@ -84,7 +85,16 @@ initscr(void)
 	    }
 	}
 #endif
-	if (newterm(name, stdout, stdin) == 0) {
+	st = newterm(name, stdout, stdin);
+#if defined(__MINGW32__) && defined(USE_TERM_DRIVER)
+	/* Don't fail too soon if someone defines $TERM to a bogus
+	   value, since usually this variable is a no-op on Windows.  */
+	if (st == 0) {
+	    name = "unknown";
+	    st = newterm(name, stdout, stdin);
+	}
+#endif
+	if (st == 0) {
 	    fprintf(stderr, "Error opening terminal: %s.\n", name);
 	    exit(EXIT_FAILURE);
 	}
--- progs/infocmp.c~0	2010-05-02 01:04:08.000000000 +0300
+++ progs/infocmp.c	2012-02-26 08:46:27.518763800 +0200
@@ -1239,10 +1239,14 @@ terminal_env(void)
     char *terminal;
 
     if ((terminal = getenv("TERM")) == 0) {
+#if defined(__MINGW32__) && defined(USE_TERM_DRIVER)
+	terminal = "unknown";
+#else
 	(void) fprintf(stderr,
 		       "%s: environment variable TERM not set\n",
 		       _nc_progname);
 	exit(EXIT_FAILURE);
+#endif
     }
     return terminal;
 }
--- progs/tput.c~0	2010-01-09 18:53:24.000000000 +0200
+++ progs/tput.c	2012-02-26 08:54:09.361044000 +0200
@@ -406,6 +406,11 @@ main(int argc, char **argv)
 	argv += optind;
     }
 
+#if defined(__MINGW32__) && defined(USE_TERM_DRIVER)
+    if (term == 0)
+	term = "unknown";
+#endif
+
     if (term == 0 || *term == '\0')
 	quit(2, "No value for $TERM and no -T specified");
 
--- misc/Makefile~	2012-02-26 11:56:57.408914000 +0200
+++ misc/Makefile	2012-02-26 12:04:14.612039000 +0200
@@ -59,7 +59,7 @@
 datadir		= ${prefix}/share
 
 tabsetdir	= $(datadir)/tabset
-ticdir		= d:/usr/share/terminfo
+ticdir		= $(datadir)/terminfo
 ticfile		= $(ticdir).db
 source		= ${top_srcdir}/misc/terminfo.src
 
@@ -68,7 +68,7 @@
 INSTALL_SCRIPT	= ${INSTALL}
 INSTALL_DATA	= ${INSTALL} -m 644
 
-PKG_CONFIG_LIBDIR = /d/usr/lib/pkgconfig
+PKG_CONFIG_LIBDIR = ${libdir}/pkgconfig
 
 ################################################################################
 all :	terminfo.tmp
--- mk-dlls.sh~0	2012-02-23 13:15:51.674559400 +0200
+++ mk-dlls.sh	2012-02-26 13:58:15.188990800 +0200
@@ -32,7 +32,9 @@
 #
 # Build DLLs on MinGW
 #
-LC_ALL=C gcc -v 2>&1 | grep Target | grep mingw
+ABI_VERSION="`egrep '^NCURSES_MAJOR[ 	]*=' ./dist.mk | sed -e 's/^[^0-9]*//'`"
+
+LC_ALL=C gcc -v 2>&1 | grep -i target | grep mingw
 if [ $? -eq 1 ]; then
   echo "$0 requires a mingw environment" >&2
 else
@@ -52,7 +54,7 @@
     rm -rf tmp-dll
   popd
   echo $ARCH > mingw_arch
-  echo Building DLLs and Import Libraries for Win${ARCH}
+  echo Building DLLs and Import Libraries for Win${ARCH} and ABI=${ABI_VERSION}
 
   if [ -d lib ]; then
     cf="-shared"
@@ -64,19 +66,21 @@
         do
           if [ -f libncurses${t}${m}.a ]; then
             f=libncurses${t}${m}.a
-            g=ncurses${t}${m}
-            gi=libw${g}.dll.a
-            td=$TEMP/tmp-${g}
+            g=libncurses${t}
+            gi=${g}${m}.dll.a
+            td=$TEMP/tmp-${g}${m}
             bd=`pwd`
             rm -rf "${td}"
             mkdir "${td}"
             pushd "${td}"
               ar x "${bd}/${f}" `ar t "${bd}/${f}"`
-              gcc $cf -o w${g}.dll -Wl,--out-implib,${gi} -Wl,--output-def,w${g}.def -Wl,$lf `ar t "${bd}/$f"` -lregex.dll 
-              lib //NOLOGO /MACHINE:i386 /DEF:w${g}.def
+              gcc $cf -o ${g}${ABI_VERSION}${m}.dll -Wl,--out-implib,${gi} -Wl,--output-def,${g}${m}.def -Wl,$lf `ar t "${bd}/$f"` -lregex.dll
+              lib //NOLOGO /MACHINE:i386 /DEF:${g}${m}.def
               rm -f `ar t "${bd}/$f"`
-              mv w${g}.dll "${bd}"
-              mv w${g}.lib "${bd}"
+              mv ${g}${ABI_VERSION}${m}.dll "${bd}"
+              if [ -f ${g}${m}.lib ]; then
+		  mv ${g}${m}.lib "${bd}"
+	      fi
               mv ${gi} "${bd}"
             popd
             rm -rf "${td}"
@@ -85,20 +89,22 @@
             do
               for f in lib${l}${t}${m}.a
               do
-                g=${l}${t}${m}
-                td=$TEMP/tmp-${g}
-                gi2=libw${g}.dll.a
+                g=lib${l}${t}
+                td=$TEMP/tmp-${g}${m}
+                gi2=${g}${m}.dll.a
                 bd=`pwd`
                 rm -rf "${td}"
                 mkdir "${td}"
                 echo $g
                 pushd "${td}"
                   ar x "${bd}/$f" `ar t "${bd}/$f"`
-                  gcc $cf -o w${g}.dll -Wl,--out-implib,${gi2} -Wl,--output-def,w${g}.def -Wl,$lf `ar t "${bd}/$f"` "${bd}/${gi}" -lregex.dll 
-                  lib //NOLOGO /MACHINE:i386 /DEF:w${g}.def
+                  gcc $cf -o ${g}${ABI_VERSION}${m}.dll -Wl,--out-implib,${gi2} -Wl,--output-def,${g}${m}.def -Wl,$lf `ar t "${bd}/$f"` "${bd}/${gi}" -lregex.dll 
+                  lib //NOLOGO /MACHINE:i386 /DEF:${g}${m}.def
                   rm -f `ar t "${bd}/$f"`
-                  mv w${g}.dll "${bd}"
-                  mv w${g}.lib "${bd}"
+                  mv ${g}${ABI_VERSION}${m}.dll "${bd}"
+                  if [ -f ${g}${m}.lib ]; then
+		      mv ${g}${m}.lib "${bd}"
+		  fi
                   mv ${gi2} "${bd}"
                 popd
                 rm -rf "${td}"
