diff -x .svn -uNr R14B/erts/configure.in r14b0_mingw32p1/erts/configure.in
--- R14B/erts/configure.in	2011-06-25 11:28:11.904373330 +0300
+++ r14b0_mingw32p1/erts/configure.in	2011-06-25 11:28:44.153110619 +0300
@@ -403,7 +403,8 @@
 
 AC_MSG_CHECKING(for mixed cygwin and native VC++ environment)
 if test "X$host" = "Xwin32" -a "x$GCC" != x"yes"; then
-	if test -x /usr/bin/cygpath; then
+	CYGPATH=`which cygpath`
+	if test "$CYGPATH" != ""; then
 		CFLAGS="-O2"
 		MIXED_CYGWIN=yes
 		AC_MSG_RESULT([yes])
@@ -421,7 +422,25 @@
 
 AC_MSG_CHECKING(for mixed cygwin and native MinGW environment)
 if test "X$host" = "Xwin32" -a "x$GCC" = x"yes"; then
-	if test -x /usr/bin/cygpath; then
+	CYGPATH="`which cygpath`"
+	if test "$CYGPATH" != ""; then
+		CFLAGS="-O2"
+		MIXED_CYGWIN=yes
+		AC_MSG_RESULT([yes])
+		MIXED_CYGWIN_MINGW=yes
+	else
+		AC_MSG_RESULT([undeterminable])
+		AC_MSG_ERROR(Seems to be mixed windows but not with cygwin, cannot handle this!)
+	fi
+else
+	AC_MSG_RESULT([no])
+	MIXED_CYGWIN_MINGW=no
+fi
+
+AC_MSG_CHECKING(for mixed cygwin and msys MinGW environment)
+if test "`which mingwm10.dll`" != "" -a "X$host" = "Xwin32" -a "x$GCC" = x"yes"; then
+	CYGPATH="`which cygpath`"
+	if test "$CYGPATH" != ""; then
 		CFLAGS="-O2"
 		MIXED_CYGWIN=yes
 		AC_MSG_RESULT([yes])
@@ -3295,9 +3314,15 @@
 DED_LD_FLAG_RUNTIME_LIBRARY_PATH="-R"
 case $host_os in
 	win32)
-		DED_LD="ld.sh"
-		DED_LDFLAGS="-dll"
-		DED_LD_FLAG_RUNTIME_LIBRARY_PATH=
+		if test "X$MIXED_CYGWIN" = "Xyes" ; then
+			DED_LD="$CC"
+			DED_LDFLAGS="-shared"
+			DED_LD_FLAG_RUNTIME_LIBRARY_PATH=
+		else
+			DED_LD="ld.sh"
+			DED_LDFLAGS="-dll"
+			DED_LD_FLAG_RUNTIME_LIBRARY_PATH=
+		fi
 	;;
 	solaris2*|sysv4*)
 		DED_LDFLAGS="-G"
@@ -3588,6 +3613,9 @@
 			     test -f "$dir/lib/openssl.lib"; then
 				SSL_RUNTIME_LIBDIR="$rdir/lib"
 				SSL_LIBDIR="$dir/lib"
+			elif test -f "$dir/lib/libeay32.a" -o \
+				-f "$dir/lib/libssl32.a"; then
+				SSL_LIBDIR="$dir/lib"
 			else
 				is_real_ssl=no
 			fi
diff -x .svn -uNr R14B/erts/emulator/beam/global.h r14b0_mingw32p1/erts/emulator/beam/global.h
--- R14B/erts/emulator/beam/global.h	2011-06-25 11:28:11.214401514 +0300
+++ r14b0_mingw32p1/erts/emulator/beam/global.h	2011-06-25 11:28:43.573133900 +0300
@@ -1056,7 +1056,7 @@
 extern int erts_compat_rel;
 extern int erts_use_sender_punish;
 void erts_short_init(void);
-void erl_start(int, char**);
+void OTP_Export_Flags erl_start(int, char**);
 void erts_usage(void);
 Eterm erts_preloaded(Process* p);
 /* erl_md5.c */
diff -x .svn -uNr R14B/erts/emulator/drivers/win32/win_con.c r14b0_mingw32p1/erts/emulator/drivers/win32/win_con.c
--- R14B/erts/emulator/drivers/win32/win_con.c	2011-06-25 11:28:11.454392860 +0300
+++ r14b0_mingw32p1/erts/emulator/drivers/win32/win_con.c	2011-06-25 11:28:43.733126989 +0300
@@ -23,6 +23,7 @@
 #include <stdio.h>
 #include "sys.h"
 #include <windowsx.h>
+
 #include "resource.h"
 #include "erl_version.h"
 #include <commdlg.h>
@@ -1580,7 +1581,7 @@
 	    ++pClipMem;
         }
         GlobalUnlock(hClipMem);
-        write_inbuf(pMem, _tcsclen(pMem));
+        write_inbuf(pMem, _mbslen(pMem));
     }
     CloseClipboard();
 }
diff -x .svn -uNr R14B/erts/emulator/drivers/win32/win_efile.c r14b0_mingw32p1/erts/emulator/drivers/win32/win_efile.c
--- R14B/erts/emulator/drivers/win32/win_efile.c	2011-06-25 11:28:11.454392860 +0300
+++ r14b0_mingw32p1/erts/emulator/drivers/win32/win_efile.c	2011-06-25 11:28:43.733126989 +0300
@@ -21,6 +21,7 @@
  */
 
 #include <windows.h>
+#include <direct.h>
 #include "sys.h"
 #include <ctype.h>
 
@@ -184,7 +185,7 @@
     ov.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
     if (ov.hEvent == NULL)
 	return set_error(errInfo);
-    if (! write_file_gather(fd, iov, *size, NULL, &ov))
+    if (! WriteFileGather(fd, iov, *size, NULL, &ov))
 	return set_error(errInfo);
     if (WaitForSingleObject(ov.hEvent, INFINITE) != WAIT_OBJECT_0)
 	return set_error(errInfo);
diff -x .svn -uNr R14B/erts/emulator/drivers/win32/winsock_func.h r14b0_mingw32p1/erts/emulator/drivers/win32/winsock_func.h
--- R14B/erts/emulator/drivers/win32/winsock_func.h	2011-06-25 11:28:11.454392860 +0300
+++ r14b0_mingw32p1/erts/emulator/drivers/win32/winsock_func.h	2011-06-25 11:28:43.733126989 +0300
@@ -94,6 +94,8 @@
 		       int flags, const struct sockaddr FAR * to, int tolen);
   int (WSAAPI *recvfrom)(SOCKET s, char FAR * buf, int len, int flags,
 			 struct sockaddr FAR * from, int FAR * fromlen);
+  int (WSAAPI *select)(SOCKET s, fd_set *,fd_set *, fd_set *, 
+		       const struct timeval *);
 } WinSockFuncs;
 
 
diff -x .svn -uNr R14B/erts/emulator/Makefile.in r14b0_mingw32p1/erts/emulator/Makefile.in
--- R14B/erts/emulator/Makefile.in	2011-06-25 11:28:11.571054844 +0300
+++ r14b0_mingw32p1/erts/emulator/Makefile.in	2011-06-25 11:28:43.833122486 +0300
@@ -182,7 +182,7 @@
 else
 EMU_CC  = @EMU_CC@
 endif
-TYPE_FLAGS += -DSTATIC_ERLANG_DRIVER
+TYPE_FLAGS += -DSTATIC_ERLANG_DRIVER -DBUILDING_DLL
 else
 EMU_CC  = @EMU_CC@
 endif
@@ -202,6 +202,10 @@
 ifeq ($(TARGET),win32)
 LIB_PREFIX=
 LIB_SUFFIX=.lib
+ifeq ($(USING_MINGW), yes)
+LIB_PREFIX=lib
+LIB_SUFFIX=.a
+endif
 else
 LIB_PREFIX=lib
 LIB_SUFFIX=.a
@@ -232,17 +236,17 @@
 endif
 endif
 UNROLL_FLG = -funroll-loops
+ifeq ($(USING_MINGW), yes)
+RC=windres
+RES_EXT=@OBJEXT@
+MAKE_PRELOAD_EXTRA=-windres
+endif
 else
 ifeq ($(TARGET), win32)
 GEN_OPT_FLGS = $(OPT_LEVEL)
 UNROLL_FLG = 
 RC=rc.sh
-ifeq ($(USING_MINGW), yes)
-RES_EXT=@OBJEXT@
-MAKE_PRELOAD_EXTRA=-windres
-else
 RES_EXT=res
-endif
 else
 GEN_OPT_FLGS = 
 UNROLL_FLG = 
@@ -250,7 +254,6 @@
 endif
 endif
 
-
 ifdef PURIFY_CHILD_SETUP
 CS_PURIFY = $(PURIFY)
 CS_TYPE_FLAGS = $(TYPE_FLAGS)
@@ -262,6 +265,9 @@
 CS_CFLAGS_ = $(CS_TYPE_FLAGS) @DEFS@ $(WFLAGS) 
 ifeq ($(GCC),yes)
 CS_CFLAGS = $(subst -O2, $(GEN_OPT_FLGS) $(UNROLL_FLG), $(CS_CFLAGS_))
+ifeq ($(USING_MINGW),yes)
+LIBS    += -lws2_32 -lcomctl32
+endif
 else
 CS_CFLAGS = $(CS_CFLAGS_)
 endif
@@ -275,8 +281,13 @@
 LIBS += $(Z_LIB)
 else
 ifeq ($(TARGET),win32)
+ifeq ($(USING_MINGW),yes)
+LIBS += $(ERL_TOP)/erts/emulator/zlib/obj/$(TARGET)/$(TYPE)/libz.a
+DEPLIBS = $(ERL_TOP)/erts/emulator/zlib/obj/$(TARGET)/$(TYPE)/libz.a
+else
 LIBS    += -L$(ERL_TOP)/erts/emulator/zlib/obj/$(TARGET)/$(TYPE) -lz
 DEPLIBS = $(ERL_TOP)/erts/emulator/zlib/obj/$(TARGET)/$(TYPE)/z.lib
+endif
 else
 # Build on darwin fails if -lz is used
 LIBS += $(ERL_TOP)/erts/emulator/zlib/obj/$(TARGET)/$(TYPE)/libz.a
@@ -286,7 +297,11 @@
 endif
 
 ifeq ($(TARGET),win32)
+ifeq ($(USING_MINGW),yes)
+LIBS    += $(ERL_TOP)/erts/emulator/pcre/obj/$(TARGET)/$(TYPE)/$(LIB_PREFIX)epcre$(LIB_SUFFIX)
+else
 LIBS    += -L$(ERL_TOP)/erts/emulator/pcre/obj/$(TARGET)/$(TYPE) -lepcre
+endif
 else
 LIBS    += $(ERL_TOP)/erts/emulator/pcre/obj/$(TARGET)/$(TYPE)/$(LIB_PREFIX)epcre$(LIB_SUFFIX)
 endif
@@ -908,9 +923,17 @@
 
 ifeq ($(TARGET), win32)
 # Only the basic erlang to begin with eh?
+ifeq ($(USING_MINGW), yes)
+$(BINDIR)/$(EMULATOR_EXECUTABLE): $(INIT_OBJS) $(OBJS) $(DEPLIBS)
+	$(PURIFY) $(LD) -mwindows -shared -Xlinker --out-implib \
+	-Xlinker $(BINDIR)/erl_dll.a -o $(BINDIR)/$(EMULATOR_EXECUTABLE) \
+	sys/$(ERLANG_OSTYPE)/erl.def \
+	$(LDFLAGS) $(DEXPORT) $(INIT_OBJS) $(OBJS) $(LIBS)
+else
 $(BINDIR)/$(EMULATOR_EXECUTABLE): $(INIT_OBJS) $(OBJS) $(DEPLIBS)
 	$(PURIFY) $(LD) -dll -def:sys/$(ERLANG_OSTYPE)/erl.def -implib:$(BINDIR)/erl_dll.lib -o $(BINDIR)/$(EMULATOR_EXECUTABLE) \
 	$(LDFLAGS) $(DEXPORT) $(INIT_OBJS) $(OBJS) $(LIBS)
+endif
 else
 
 
@@ -945,8 +968,12 @@
 SED_REPL_CHK_IO=s|$$(OBJDIR)/erl_check_io.o|$$(OBJDIR)/erl_check_io.kp.o $$(OBJDIR)/erl_check_io.nkp.o|g
 
 ifeq ($(TARGET),win32)
+ifeq ($(USING_MINGW), yes)
+SED_PREFIX=
+else
 #SED_PREFIX=$(SED_REPL_WIN_DRIVE);
 SED_PREFIX=
+endif
 else
 SED_PREFIX=
 endif
diff -x .svn -uNr R14B/erts/emulator/pcre/Makefile.in r14b0_mingw32p1/erts/emulator/pcre/Makefile.in
--- R14B/erts/emulator/pcre/Makefile.in	2011-06-25 11:28:11.434392197 +0300
+++ r14b0_mingw32p1/erts/emulator/pcre/Makefile.in	2011-06-25 11:28:43.713127303 +0300
@@ -13,6 +13,8 @@
 
 # %ExternalCopyright%
 
+USING_MINGW=@MIXED_CYGWIN_MINGW@
+
 ARFLAGS = rc
 
 O = \
@@ -75,7 +77,11 @@
 include $(ERL_TOP)/make/$(TARGET)/otp.mk
 
 ifeq ($(TARGET), win32)
+ifeq ($(USING_MINGW), yes)
+LIBRARY=$(OBJDIR)/libepcre.a
+else
 LIBRARY=$(OBJDIR)/epcre.lib
+endif
 else
 LIBRARY=$(OBJDIR)/libepcre.a
 endif
@@ -99,8 +105,14 @@
 #### end OTP targets
 
 ifeq ($(TARGET), win32)
+ifeq ($(USING_MINGW), yes)
+$(LIBRARY): $(OBJS)
+	$(AR) crv $@ $(OBJS)
+	$(RANLIB) $@
+else
 $(LIBRARY): $(OBJS)
 	$(AR) -out:$@ $(OBJS)
+endif
 else
 $(LIBRARY): $(OBJS)
 	$(AR) $(ARFLAGS) $@ $(OBJS)
diff -x .svn -uNr R14B/erts/emulator/sys/win32/dosmap.c r14b0_mingw32p1/erts/emulator/sys/win32/dosmap.c
--- R14B/erts/emulator/sys/win32/dosmap.c	2011-06-25 11:28:11.524388094 +0300
+++ r14b0_mingw32p1/erts/emulator/sys/win32/dosmap.c	2011-06-25 11:28:43.803124179 +0300
@@ -24,7 +24,7 @@
 
 /* Only use for win32 if linking to MSVCR??.DLL and not if statically linking
    to LIBCMT.LIB */
-#if defined(WIN32) && defined(_MT) && defined(_DLL)
+#if defined(WIN32)
 
 #include <errno.h>
 #include <winerror.h>
diff -x .svn -uNr R14B/erts/emulator/sys/win32/erl_win_sys.h r14b0_mingw32p1/erts/emulator/sys/win32/erl_win_sys.h
--- R14B/erts/emulator/sys/win32/erl_win_sys.h	2011-06-25 11:28:11.524388094 +0300
+++ r14b0_mingw32p1/erts/emulator/sys/win32/erl_win_sys.h	2011-06-25 11:28:43.803124179 +0300
@@ -107,6 +107,13 @@
 #define HAVE_ERTS_CHECK_IO_DEBUG
 int erts_check_io_debug(void);
 
+#ifdef BUILDING_DLL
+# define OTP_Export_Flags  __declspec(dllexport)
+#else
+# define OTP_Export_Flags  __declspec(dllimport)
+#endif
+
+
 /*
  * For erl_time_sup
  */
diff -x .svn -uNr R14B/erts/emulator/sys/win32/sys.c r14b0_mingw32p1/erts/emulator/sys/win32/sys.c
--- R14B/erts/emulator/sys/win32/sys.c	2011-06-25 11:28:11.524388094 +0300
+++ r14b0_mingw32p1/erts/emulator/sys/win32/sys.c	2011-06-25 11:28:43.803124179 +0300
@@ -31,8 +31,7 @@
 #include "global.h"
 #include "erl_threads.h"
 #include "../../drivers/win32/win_con.h"
-
-
+#include "../common/erl_check_io.h"
 
 void erts_sys_init_float(void);
 
@@ -57,7 +56,9 @@
 #define __argv e_argv
 #endif
 
-static void init_console();
+struct async_io;
+
+static void init_console(void);
 static int get_and_remove_option(int* argc, char** argv, const char* option);
 static char *get_and_remove_option2(int *argc, char **argv, 
 				    const char *option);
@@ -150,7 +151,7 @@
 
 HMODULE beam_module = NULL;
 
-void erl_sys_init();
+void erl_sys_init(void);
 
 void erl_sys_args(int* argc, char** argv);
 
@@ -253,7 +254,7 @@
 }
 
 static void
-init_console()
+init_console(void)
 {
     char* mode = erts_read_env("ERL_CONSOLE_MODE");
 
@@ -273,7 +274,7 @@
     erts_free_read_env(mode);
 }
 
-int sys_max_files() 
+int sys_max_files(void)
 {
     return max_files;
 }
@@ -289,10 +290,10 @@
  */
 
 static int
-get_and_remove_option(argc, argv, option)
-    int* argc;			/* Number of arguments. */
-    char* argv[];		/* The argument vector. */
-    const char* option;		/* Option to search for and remove. */
+get_and_remove_option(
+    int * argc,			/* Number of arguments. */
+    char * argv[],		/* The argument vector. */
+    const char * option)	/* Option to search for and remove. */
 {
     int i;
 
@@ -342,9 +343,9 @@
 char os_type[] = "win32";
 
 void
-os_flavor(namebuf, size)
-char* namebuf;			/* Where to return the name. */
-unsigned size;			/* Size of name buffer. */
+os_flavor(
+    char * namebuf,		/* Where to return the name. */
+    unsigned size)		/* Size of name buffer. */
 {
     switch (int_os_version.dwPlatformId) {
     case VER_PLATFORM_WIN32_WINDOWS:
@@ -360,10 +361,10 @@
 }
 
 void
-os_version(pMajor, pMinor, pBuild)
-int* pMajor;			/* Pointer to major version. */
-int* pMinor;			/* Pointer to minor version. */
-int* pBuild;			/* Pointer to build number. */
+os_version(
+    int * pMajor,			/* Pointer to major version. */
+    int * pMinor,			/* Pointer to minor version. */
+    int * pBuild)			/* Pointer to build number. */
 {
   *pMajor = int_os_version.dwMajorVersion;
   *pMinor = int_os_version.dwMinorVersion;
@@ -617,12 +618,12 @@
  */
 
 static DriverData*
-new_driver_data(port_num, packet_bytes, wait_objs_required, use_threads)
-    int port_num;		/* The port number. */
-    int packet_bytes;		/* Number of bytes in header. */
-    int wait_objs_required;	/* The number objects this port is going
-				/* wait for (typically 1 or 2). */
-    int use_threads;		/* TRUE if threads are intended to be used. */
+new_driver_data(
+    int port_num,		/* The port number. */
+    int packet_bytes,		/* Number of bytes in header. */
+    int wait_objs_required,	/* The number objects this port is going
+				   wait for (typically 1 or 2). */
+    int use_threads)		/* TRUE if threads are intended to be used. */
 {
     DriverData* dp;
     
@@ -820,12 +821,12 @@
  */
 
 static ErlDrvData
-set_driver_data(dp, ifd, ofd, read_write, report_exit)
-    DriverData* dp;
-    HANDLE ifd;
-    HANDLE ofd;
-    int read_write;
-    int report_exit;
+set_driver_data(
+    DriverData * dp,
+    HANDLE ifd,
+    HANDLE ofd,
+    int read_write,
+    int report_exit)
 {
     int index = dp - driver_data;
     int result;
@@ -922,10 +923,10 @@
  */
 
 static void
-async_read_file(aio, buf, numToRead)
-    AsyncIo* aio;		/* Pointer to driver data. */
-    LPVOID buf;			/* Pointer to buffer to receive data. */
-    DWORD numToRead;		/* Number of bytes to read. */
+async_read_file(
+    AsyncIo * aio,		/* Pointer to driver data. */
+    LPVOID buf, 		/* Pointer to buffer to receive data. */
+    DWORD numToRead)		/* Number of bytes to read. */
 {
     aio->pendingError = NO_ERROR;
 #ifdef HARD_POLL_DEBUG
@@ -934,8 +935,8 @@
     if (aio->thread != (HANDLE) -1) {
 	DEBUGF(("async_read_file: signaling thread 0x%x, event 0x%x\n",
 		aio->thread, aio->ioAllowed));
-	OV_BUFFER_PTR(aio) = buf;
-	OV_NUM_TO_READ(aio) = numToRead;
+	aio->ov.Internal = (ULONG_PTR)buf;
+	aio->ov.InternalHigh = (ULONG_PTR)numToRead;
 	ResetEvent(aio->ov.hEvent);
 	SetEvent(aio->ioAllowed);
     } else {
@@ -976,17 +977,17 @@
  * ----------------------------------------------------------------------
  */
 static int
-async_write_file(aio, buf, numToWrite)
-    AsyncIo* aio;		/* Pointer to async control block. */
-    LPVOID buf;			/* Pointer to buffer with data to write. */
-    DWORD numToWrite;		/* Number of bytes to write. */
+async_write_file(
+    AsyncIo * aio,		/* Pointer to async control block. */
+    LPVOID buf,			/* Pointer to buffer with data to write. */
+    DWORD numToWrite)		/* Number of bytes to write. */
 {
     aio->pendingError = NO_ERROR;
     if (aio->thread != (HANDLE) -1) {
 	DEBUGF(("async_write_file: signaling thread 0x%x, event 0x%x\n",
 		aio->thread, aio->ioAllowed));
-	OV_BUFFER_PTR(aio) = buf;
-	OV_NUM_TO_READ(aio) = numToWrite;
+	aio->ov.Internal = (ULONG_PTR)buf;
+	aio->ov.InternalHigh = (ULONG_PTR)numToWrite;
 	ResetEvent(aio->ov.hEvent);
 	SetEvent(aio->ioAllowed);
     } else {
@@ -1023,12 +1024,12 @@
  * ----------------------------------------------------------------------
  */
 static int
-get_overlapped_result(aio, pBytesRead, wait)
-    AsyncIo* aio;		/* Pointer to async control block. */
-    LPDWORD pBytesRead;		/* Where to place the number of bytes
+get_overlapped_result(
+    AsyncIo * aio,		/* Pointer to async control block. */
+    LPDWORD pBytesRead,		/* Where to place the number of bytes
 				 * transferred.
 				 */
-    BOOL wait;			/* If true, wait until result is ready. */
+    BOOL wait)			/* If true, wait until result is ready. */
 {
     DWORD error = NO_ERROR;	/* Error status from last function. */
 
@@ -1098,7 +1099,7 @@
     return 0;
 }
 static int
-spawn_init()
+spawn_init(void)
 {
     int i;
 #ifdef ERTS_SMP
@@ -1280,11 +1281,12 @@
  *  The length returned is equivalent with length(argv[0]) if the
  *  comman line should have been prepared by _setargv for the main function
 */
-int parse_command(char* cmd){
+int parse_command(char * cmd)
+{
 #define NORMAL 2
 #define STRING 1
 #define STOP 0
-    int i =0;
+    int i = 0;
     int state = NORMAL;
     while (cmd[i]) {
 	switch (cmd[i]) {
@@ -1659,7 +1661,7 @@
      */
 
     calls = (Uint) erts_smp_atomic_inctest(&pipe_creation_counter);
-    sprintf(pipe_name, "\\\\.\\pipe\\erlang44_%d_%d",
+    sprintf(pipe_name, "\\\\.\\pipe\\erlang44_%d_%lu",
 	    getpid(), calls);
 
     DEBUGF(("Creating pipe %s\n", pipe_name));
@@ -2244,13 +2246,13 @@
  */
 
 static void
-output(ErlDrvData drv_data, char* buf, int len)
-/*     long drv_data;		/* The slot to use in the driver data table.
+output(
+       ErlDrvData drv_data, 	/* The slot to use in the driver data table.
 				 * For Windows NT, this is *NOT* a file handle.
 				 * The handle is found in the driver data.
 				 */
-/*     char *buf;			/* Pointer to data to write to the port program. */
-/*     int len;			/* Number of bytes to write. */
+       char* buf, 	    	/* Pointer to data to write to the port program. */
+       int len)			/* Number of bytes to write. */
 {
     DriverData* dp;
     int pb;			/* The header size for this port. */
@@ -2344,9 +2346,9 @@
  */
 
 static void
-ready_input(ErlDrvData drv_data, ErlDrvEvent ready_event)
-/*     long drv_data;		/* Driver data. */
-/*     HANDLE ready_event;	/* The handle for the ready event. */
+ready_input(
+    ErlDrvData drv_data,	/* Driver data. */
+    ErlDrvEvent ready_event)	/* The handle for the ready event. */
 {
     int error = 0;		/* The error code (assume initially no errors). */
     DWORD bytesRead;		/* Number of bytes read. */
@@ -2644,8 +2646,8 @@
     free(p);
 }
 
-static Preload* preloaded = NULL;
-static unsigned* res_name = NULL;
+static Preload * preloaded = NULL;
+static unsigned * res_name = NULL;
 static int num_preloaded = 0;
 
 /* Return a pointer to a vector of names of preloaded modules */
diff -x .svn -uNr R14B/erts/emulator/zlib/Makefile.in r14b0_mingw32p1/erts/emulator/zlib/Makefile.in
--- R14B/erts/emulator/zlib/Makefile.in	2011-06-25 11:28:10.774417711 +0300
+++ r14b0_mingw32p1/erts/emulator/zlib/Makefile.in	2011-06-25 11:28:43.349807086 +0300
@@ -13,6 +13,8 @@
 # To install in $HOME instead of /usr/local, use:
 #    make install prefix=$HOME
 
+USING_MINGW=@MIXED_CYGWIN_MINGW@
+
 ARFLAGS = rc
 CFLAGS = $(subst -O2, -O3, @CFLAGS@ @DEFS@ @EMU_THR_DEFS@)
 #CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7
@@ -45,7 +47,11 @@
 include $(ERL_TOP)/make/$(TARGET)/otp.mk
 
 ifeq ($(TARGET), win32)
+ifeq ($(USING_MINGW), yes)
+LIBRARY=$(OBJDIR)/libz.a
+else
 LIBRARY=$(OBJDIR)/z.lib
+endif
 else
 LIBRARY=$(OBJDIR)/libz.a
 endif
@@ -69,8 +75,14 @@
 #### end OTP targets
 
 ifeq ($(TARGET), win32)
+ifeq ($(USING_MINGW), yes)
+$(LIBRARY): $(OBJS)
+	$(AR) crv $@ $(OBJS)
+	$(RANLIB) $@
+else
 $(LIBRARY): $(OBJS)
 	$(AR) -out:$@ $(OBJS)
+endif
 else
 $(LIBRARY): $(OBJS)
 	$(AR) $(ARFLAGS) $@ $(OBJS)
diff -x .svn -uNr R14B/erts/epmd/src/Makefile.in r14b0_mingw32p1/erts/epmd/src/Makefile.in
--- R14B/erts/epmd/src/Makefile.in	2011-06-25 11:28:10.427765937 +0300
+++ r14b0_mingw32p1/erts/epmd/src/Makefile.in	2011-06-25 11:28:42.989821537 +0300
@@ -81,6 +81,7 @@
 # The targets
 ifeq ($(findstring win32,$(TARGET)),win32)
 EPMD = epmd.exe
+LIBS += -lws2_32
 else
 EPMD = epmd
 endif
diff -x .svn -uNr R14B/erts/etc/common/Makefile.in r14b0_mingw32p1/erts/etc/common/Makefile.in
--- R14B/erts/etc/common/Makefile.in	2011-06-25 11:28:11.861043203 +0300
+++ r14b0_mingw32p1/erts/etc/common/Makefile.in	2011-06-25 11:28:44.113111737 +0300
@@ -176,6 +176,8 @@
 MC_OUTPUTS= \
 	$(OBJDIR)/erlsrv_logmess.h $(OBJDIR)/erlsrv_logmess.res
 	MT_FLAG="-MD"
+RC=windres
+MC=mc.sh
 endif
 INET_GETHOST = $(BINDIR)/inet_gethost.exe
 INSTALL_EMBEDDED_PROGS += $(BINDIR)/typer.exe $(BINDIR)/dialyzer.exe $(BINDIR)/erlc.exe $(BINDIR)/start_erl.exe $(BINDIR)/escript.exe $(BINDIR)/run_test.exe
@@ -202,8 +204,11 @@
 WINDSOCK = -lws2_32
 endif
 PORT_ENTRY_POINT=erl_port_entry
+ifeq ($(USING_MINGW), yes)
+ENTRY_LDFLAGS=--thumb-entry=$(PORT_ENTRY_POINT)
+else
 ENTRY_LDFLAGS=-entry:$(PORT_ENTRY_POINT)
-
+endif
 else
 ENTRY_LDFLAGS=
 ENTRY_OBJ=
@@ -296,7 +301,7 @@
 	$(CC) $(CFLAGS) -o $@ -c inet_gethost.c
 
 $(BINDIR)/inet_gethost@EXEEXT@: $(OBJDIR)/inet_gethost.o $(ENTRY_OBJ)
-	$(PURIFY) $(LD) $(LDFLAGS) $(ENTRY_LDFLAGS) -o $@ $(OBJDIR)/inet_gethost.o $(ENTRY_OBJ) $(LIBS) $(ERTS_INTERNAL_LIBS)
+	$(PURIFY) $(LD) $(LDFLAGS) $(ENTRY_LDFLAGS) -o $@ $(OBJDIR)/inet_gethost.o $(ENTRY_OBJ) $(LIBS) $(ERTS_INTERNAL_LIBS) $(WINDSOCK)
 
 $(BINDIR)/run_erl: $(OBJDIR)/safe_string.o $(OBJDIR)/run_erl.o
 	$(LD) $(LDFLAGS) -o $@ $(OBJDIR)/safe_string.o $(OBJDIR)/run_erl.o $(LIBS)
@@ -367,8 +372,12 @@
 
 ifeq ($(TARGET),win32)
 
+ifeq ($(USING_MINGW), yes)
 $(BINDIR)/$(ERLEXEC): $(OBJDIR)/erlexec.o $(OBJDIR)/win_erlexec.o $(OBJDIR)/init_file.o  $(OBJDIR)/$(ERLRES_OBJ)
+	$(LD) -shared $(LDFLAGS) -o $@ $(OBJDIR)/erlexec.o $(OBJDIR)/win_erlexec.o $(OBJDIR)/init_file.o $(OBJDIR)/$(ERLRES_OBJ) $(ERTS_INTERNAL_LIBS)
+else
 	$(LD) -dll $(LDFLAGS) -o $@ $(OBJDIR)/erlexec.o $(OBJDIR)/win_erlexec.o $(OBJDIR)/init_file.o $(OBJDIR)/$(ERLRES_OBJ) $(ERTS_INTERNAL_LIBS)
+endif
 
 $(BINDIR)/erl@EXEEXT@: $(OBJDIR)/erl.o $(OBJDIR)/init_file.o $(OBJDIR)/$(ERLRES_OBJ)
 	$(LD) $(LDFLAGS) -o $@ $(OBJDIR)/erl.o $(OBJDIR)/init_file.o $(OBJDIR)/$(ERLRES_OBJ) 
diff -x .svn -uNr R14B/erts/etc/win32/msys_tools/erlc r14b0_mingw32p1/erts/etc/win32/msys_tools/erlc
--- R14B/erts/etc/win32/msys_tools/erlc	1970-01-01 02:00:00.000000000 +0200
+++ r14b0_mingw32p1/erts/etc/win32/msys_tools/erlc	2011-06-25 11:28:44.036448148 +0300
@@ -0,0 +1,51 @@
+#! /bin/sh
+# Note! This shellscript expects to be run in a cygwin environment,
+# it converts erlc command lines to native windows erlc commands, which
+# basically means running the command cygpath on whatever is a path...
+
+CMD=""
+ECHO_ONLY=false
+for x in "$@"; do 
+    case "$x" in
+	--echo_only)
+	    ECHO_ONLY=true;;
+	-I/*|-o/*)
+	    y=`echo $x | sed 's,^-[Io]\(/.*\),\1,g'`;
+	    z=`echo $x | sed 's,^-\([Io]\)\(/.*\),\1,g'`;
+	    MPATH=`cygpath -m $y`;
+	    CMD="$CMD -$z$MPATH";; 
+	/*)
+	    MPATH=`cygpath -m $x`;
+	    CMD="$CMD \"$MPATH\"";;
+# Needed for  +'{preproc_flags,whatever}'
+	+{preproc_flags,*})
+	     y=`echo $x | sed 's,^+{preproc_flags\,"\(.*\)"},\1,g'`;
+	     FLAGS=""
+	     for xx in "$y"; do
+	         case "$xx" in
+		    -I/*|-o/*)
+	    	        yy=`echo $xx | sed 's,^-[Io]\(/.*\),\1,g'`;
+	                zz=`echo $xx | sed 's,^-\([Io]\)\(/.*\),\1,g'`;
+	    	        MPATH2=`cygpath -m $yy|sed 's,/,\\\\\\\\\\\\\\\\,g'`;
+		        FLAGS="$FLAGS -$zz$MPATH2"
+	     	 esac
+	     done
+	     y=$FLAGS
+	     z=`eval $0 --echo_only $y`;
+	     case "$z" in # Dont "doubledoublequote"
+		 \"*\") 
+		 CMD="$CMD +'{preproc_flags,$z}'";;
+		 *)
+		 CMD="$CMD +'{preproc_flags,\"$z\"}'";;
+	     esac;;
+	*)
+	    y=`echo $x | sed 's,",\\\",g'`;
+	    CMD="$CMD \"$y\"";;
+    esac
+done
+if [ $ECHO_ONLY = true ]; then
+    echo $CMD
+else
+    #echo "Executing: erlc.exe $CMD"
+    eval erlc.exe $CMD
+fi
diff -x .svn -uNr R14B/erts/etc/win32/msys_tools/make_bootstrap_ini.sh r14b0_mingw32p1/erts/etc/win32/msys_tools/make_bootstrap_ini.sh
--- R14B/erts/etc/win32/msys_tools/make_bootstrap_ini.sh	1970-01-01 02:00:00.000000000 +0200
+++ r14b0_mingw32p1/erts/etc/win32/msys_tools/make_bootstrap_ini.sh	2011-06-25 11:28:44.036448148 +0300
@@ -0,0 +1,27 @@
+#! /bin/sh
+# Create a local init-file for erlang in the build environment.
+if [ -z "$1" ]; then
+	echo "error: $0: No rootdir given"
+ 	exit 1
+else
+    RDIR=$1
+fi
+if [ -z "$2" ]; then
+	echo "error: $0: No bindir given"
+ 	exit 1
+else
+    BDIR=$2
+fi
+
+# /d/ -> d:/
+# / -> \\
+DRDIR=`echo "$RDIR" | sed -e 's,^/\([a-zA-Z]\)/,\1:/,' -e 's,/,\\\\\\\\,g'`
+DBDIR=`echo "$BDIR" | sed -e 's,^/\([a-zA-Z]\)/,\1:/,' -e 's,/,\\\\\\\\,g'`
+
+cat > $RDIR/bin/erl.ini <<EOF
+[erlang]
+Bindir=$DBDIR
+Progname=erl
+Rootdir=$DRDIR
+EOF
+
diff -x .svn -uNr R14B/erts/etc/win32/msys_tools/make_local_ini.sh r14b0_mingw32p1/erts/etc/win32/msys_tools/make_local_ini.sh
--- R14B/erts/etc/win32/msys_tools/make_local_ini.sh	1970-01-01 02:00:00.000000000 +0200
+++ r14b0_mingw32p1/erts/etc/win32/msys_tools/make_local_ini.sh	2011-06-25 11:28:44.033114948 +0300
@@ -0,0 +1,23 @@
+#! /bin/sh
+# Create a local init-file for erlang in the build environment.
+if [ -z "$1" ]; then
+    if [ -z $ERL_TOP ]; then
+	echo "error: $0: No rootdir available"
+ 	exit 1
+    else
+	RDIR=$ERL_TOP
+    fi
+else
+    RDIR=$1
+fi
+
+# /d/ -> d:/
+# / -> \\
+DDIR=`echo "$RDIR" | sed -e 's,^/\([a-zA-Z]\)/,\1:/,' -e 's,/,\\\\\\\\,g'`
+
+cat > $RDIR/bin/erl.ini <<EOF
+[erlang]
+Bindir=$DDIR\\\\bin\\\\win32
+Progname=erl
+Rootdir=$DDIR
+EOF
diff -x .svn -uNr R14B/erts/etc/win32/msys_tools/mc.sh r14b0_mingw32p1/erts/etc/win32/msys_tools/mc.sh
--- R14B/erts/etc/win32/msys_tools/mc.sh	1970-01-01 02:00:00.000000000 +0200
+++ r14b0_mingw32p1/erts/etc/win32/msys_tools/mc.sh	2011-06-25 11:28:44.036448148 +0300
@@ -0,0 +1,64 @@
+#! /bin/sh
+# set -x
+# Save the command line for debug outputs
+SAVE="$@"
+CMD=""
+OUTPUT_DIRNAME=""
+
+MCC="wmc.exe -i"
+RCC="wrc.exe -i"
+
+while test -n "$1" ; do
+    x="$1"
+    case "$x" in
+	-o)
+	    shift
+	    OUTPUT_DIRNAME="$1";;
+	-o/*)
+	    y=`echo $x | sed 's,^-[Io]\(/.*\),\1,g'`;
+	    OUTPUT_DIRNAME="$y";;
+	-I)
+	    shift
+	    MPATH=`cygpath -m $1`;
+	    CMD="$CMD -I\"$MPATH\"";;
+	-I/*)
+	    y=`echo $x | sed 's,^-[Io]\(/.*\),\1,g'`;
+	    MPATH=`cygpath -m $y`;
+	    CMD="$CMD -I\"$MPATH\"";;
+	*)
+	    MPATH=`cygpath -m -a $x`;
+	    INFILE=$MPATH;;
+	    #CMD="$CMD \"$MPATH\"";; 
+    esac
+    shift
+done
+p=$$
+if [ "X$MC_SH_DEBUG_LOG" != "X" ]; then
+    echo mc.sh "$SAVE" >>$MC_SH_DEBUG_LOG
+    echo $MCC $INFILE $CMD >>$MC_SH_DEBUG_LOG
+fi
+if [ -n "$OUTPUT_DIRNAME" ]; then
+    cd $OUTPUT_DIRNAME
+    RES=$?
+    if [ "$RES" != "0" ]; then
+	echo "mc.sh: Error: could not cd to $OUTPUT_DIRNAME">&2
+	exit $RES
+    fi
+fi
+eval $MCC "$INFILE" "$CMD"  >/tmp/mc.exe.${p}.1 2>/tmp/mc.exe.${p}.2
+RES=$?
+cat /tmp/mc.exe.${p}.2 >&2
+cat /tmp/mc.exe.${p}.1
+rm -f /tmp/mc.exe.${p}.2 /tmp/mc.exe.${p}.1
+if [ $RES -eq 0 ]; then
+    XINFILE=`echo $INFILE | sed 's,.*/\([^/]*\),\1,' | sed 's,.mc$,.rc,'`
+    if [ "X$MC_SH_DEBUG_LOG" != "X" ]; then
+	echo $RCC $XINFILE $CMD >>$MC_SH_DEBUG_LOG
+    fi
+    eval $RCC $XINFILE "$CMD"  >/tmp/rc.exe.${p}.1 2>/tmp/rc.exe.${p}.2
+    RES=$?
+    cat /tmp/rc.exe.${p}.2 >&2
+    cat /tmp/rc.exe.${p}.1
+    rm -f /tmp/rc.exe.${p}.2 /tmp/rc.exe.${p}.1
+fi
+exit $RES
diff -x .svn -uNr R14B/erts/etc/win32/nsis/erlang20.nsi r14b0_mingw32p1/erts/etc/win32/nsis/erlang20.nsi
--- R14B/erts/etc/win32/nsis/erlang20.nsi	2011-06-25 11:28:11.804378322 +0300
+++ r14b0_mingw32p1/erts/etc/win32/nsis/erlang20.nsi	2011-06-25 11:28:44.046447746 +0300
@@ -19,7 +19,7 @@
 ;--------------------------------
 ;Configuration
 
-	SetCompressor bzip2
+	SetCompressor lzma
 
 Var MYTEMP
 ;Var MUI_TEMP
diff -x .svn -uNr R14B/erts/etc/win32/nsis/Makefile r14b0_mingw32p1/erts/etc/win32/nsis/Makefile
--- R14B/erts/etc/win32/nsis/Makefile	2011-06-25 11:28:11.804378322 +0300
+++ r14b0_mingw32p1/erts/etc/win32/nsis/Makefile	2011-06-25 11:28:44.046447746 +0300
@@ -23,7 +23,7 @@
 
 VERSION_HEADER = erlang.nsh
 MAKENSIS = makensis
-MAKENSISFLAGS = /V2
+MAKENSISFLAGS = 
 CUSTOM_MODERN=custom_modern.exe
 
 # This is not the way we usually do in our makefiles, 
diff -x .svn -uNr R14B/erts/etc/win32/win_erlexec.c r14b0_mingw32p1/erts/etc/win32/win_erlexec.c
--- R14B/erts/etc/win32/win_erlexec.c	2011-06-25 11:28:11.821044808 +0300
+++ r14b0_mingw32p1/erts/etc/win32/win_erlexec.c	2011-06-25 11:28:44.066446943 +0300
@@ -43,9 +43,7 @@
 #define  LOAD_BEAM_DYNAMICALLY 1
 static int start(char* emu, char** argv);
 static void start_winsock(void);
-static char* last_error(void);
 static char* last_wsa_error(void);
-static char* win32_errorstr(int error);
 static int has_console(void);
 static char** fnuttify_argv(char **argv);
 static void free_fnuttified(char **v);
@@ -297,7 +295,7 @@
     exit(1);
 }
 
-static char*
+char*
 last_error(void)
 {
     return win32_errorstr(GetLastError());
@@ -309,7 +307,7 @@
  * isn't called again.
  */
 
-static char*
+char*
 win32_errorstr(int error)
 {
     static LPTSTR lpBufPtr = NULL;
diff -x .svn -uNr R14B/erts/lib_src/common/erl_misc_utils.c r14b0_mingw32p1/erts/lib_src/common/erl_misc_utils.c
--- R14B/erts/lib_src/common/erl_misc_utils.c	2011-06-25 11:28:11.881042889 +0300
+++ r14b0_mingw32p1/erts/lib_src/common/erl_misc_utils.c	2011-06-25 11:28:44.133111424 +0300
@@ -23,6 +23,118 @@
 
 #if defined(__WIN32__)
 #  include <windows.h>
+#if defined(__MINGW32__)
+#  include <ddk/ntddk.h>
+#  include <ddk/winddk.h>
+/* ------------------ begin logical processor information ------------------- */
+typedef enum _LOGICAL_PROCESSOR_RELATIONSHIP
+{
+   RelationProcessorCore    = 0,
+   RelationNumaNode         = 1,
+   RelationCache            = 2,
+   RelationProcessorPackage = 3,
+   RelationGroup            = 4,
+   RelationAll              = 0xffff
+} LOGICAL_PROCESSOR_RELATIONSHIP;
+
+typedef enum _PROCESSOR_CACHE_TYPE
+{
+   CacheUnified,
+   CacheInstruction,
+   CacheData,
+   CacheTrace
+} PROCESSOR_CACHE_TYPE;
+
+typedef struct _PROCESSOR_GROUP_INFO
+{
+   BYTE MaximumProcessorCount;
+   BYTE ActiveProcessorCount;
+   BYTE Reserved[38];
+   KAFFINITY ActiveProcessorMask;
+} PROCESSOR_GROUP_INFO, *PPROCESSOR_GROUP_INFO;
+
+typedef struct _CACHE_DESCRIPTOR
+{   
+   BYTE Level;
+   BYTE Associativity;
+   WORD LineSize;
+   DWORD Size;
+   PROCESSOR_CACHE_TYPE Type;
+} CACHE_DESCRIPTOR, *PCACHE_DESCRIPTOR;
+
+typedef struct _GROUP_AFFINITY
+{
+   KAFFINITY Mask;
+   WORD Group;
+   WORD Reserved[3];
+} GROUP_AFFINITY, *PGROUP_AFFINITY;
+
+typedef struct _PROCESSOR_RELATIONSHIP
+{
+   BYTE Flags;
+   BYTE Reserved[21];
+   WORD GroupCount;
+   GROUP_AFFINITY GroupMask[ANYSIZE_ARRAY];
+} PROCESSOR_RELATIONSHIP, *PPROCESSOR_RELATIONSHIP;
+
+typedef struct _NUMA_NODE_RELATIONSHIP
+{
+   DWORD NodeNumber;
+   BYTE Reserved[20];
+   GROUP_AFFINITY GroupMask;
+} NUMA_NODE_RELATIONSHIP, *PNUMA_NODE_RELATIONSHIP;
+
+typedef struct _CACHE_RELATIONSHIP
+{
+   BYTE Level;
+   BYTE Associativity;
+   WORD LineSize;
+   PROCESSOR_CACHE_TYPE Type;
+   BYTE Reserved[20];
+   GROUP_AFFINITY GroupMask;
+} CACHE_RELATIONSHIP, *PCACHE_RELATIONSHIP;
+
+typedef struct _GROUP_RELATIONSHIP
+{
+   WORD MaximumGroupCount;
+   WORD ActiveGroupCount;
+   BYTE Reserved[20];
+   PROCESSOR_GROUP_INFO GroupInfo[ANYSIZE_ARRAY];
+} GROUP_RELATIONSHIP, *PGROUP_RELATIONSHIP;
+
+typedef struct _SYSTEM_LOGICAL_PROCESSOR_INFORMATION
+{
+   ULONG_PTR ProcessorMask;
+   LOGICAL_PROCESSOR_RELATIONSHIP Relationship;
+   union {
+      struct {
+	 BYTE Flags;
+      }
+      ProcessorCore;
+      struct {
+	 DWORD NodeNumber;
+      } NumaNode;
+      CACHE_DESCRIPTOR Cache;
+      ULONGLONG Reserved[2];
+   };
+} SYSTEM_LOGICAL_PROCESSOR_INFORMATION, *PSYSTEM_LOGICAL_PROCESSOR_INFORMATION;
+
+typedef struct _SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
+{
+   LOGICAL_PROCESSOR_RELATIONSHIP Relationship;
+   DWORD Size;
+   union {
+      PROCESSOR_RELATIONSHIP Processor;
+      NUMA_NODE_RELATIONSHIP NumaNode;
+      CACHE_RELATIONSHIP Cache;
+      GROUP_RELATIONSHIP Group;
+   };
+} SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX, *PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX;
+
+/* ------------------- end logical processor information -------------------- */
+WINBASEAPI BOOL WINAPI GetLogicalProcessorInformation(PSYSTEM_LOGICAL_PROCESSOR_INFORMATION,PDWORD);
+WINBASEAPI BOOL WINAPI GetLogicalProcessorInformationEx(LOGICAL_PROCESSOR_RELATIONSHIP,PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX,PDWORD);
+#endif
 #endif
 
 #include "erl_misc_utils.h"
@@ -159,7 +271,11 @@
 
 #if defined(__WIN32__)
 
+#if defined(__GNUC__)
+static inline int  __attribute__((always_inline))
+#else
 static __forceinline int
+#endif
 get_proc_affinity(erts_cpu_info_t *cpuinfo, cpu_set_t *cpuset)
 {
     DWORD pamask, samask;
@@ -173,7 +289,11 @@
     }
 }
 
+#if defined(__GNUC__)
+static inline int __attribute__((always_inline))
+#else
 static __forceinline int
+#endif
 set_thr_affinity(cpu_set_t *set)
 {
     if (*set == (cpu_set_t) 0)
@@ -1118,7 +1238,11 @@
 #define ERTS_MU_RELATION_CACHE                2 /* RelationCache */
 #define ERTS_MU_RELATION_PROCESSOR_PACKAGE    3 /* RelationProcessorPackage */
 
+#if defined(__GNUC__)
+static inline int  __attribute__((always_inline))
+#else
 static __forceinline int
+#endif
 rel_cmp_val(int r)
 {
     switch (r) {
diff -x .svn -uNr R14B/erts/lib_src/Makefile.in r14b0_mingw32p1/erts/lib_src/Makefile.in
--- R14B/erts/lib_src/Makefile.in	2011-06-25 11:28:11.887708799 +0300
+++ r14b0_mingw32p1/erts/lib_src/Makefile.in	2011-06-25 11:28:44.136444623 +0300
@@ -530,8 +530,12 @@
 SED_REPL_TARGET=s|$(TARGET)/|$$(TARGET)/|g
 
 ifeq ($(TARGET),win32)
+ifeq ($(USING_MINGW), yes)
+SED_PREFIX=
+else
 #SED_PREFIX=$(SED_REPL_WIN_DRIVE);
 SED_PREFIX=
+endif
 DEP_FLAGS=$(subst -O3,,$(subst -O2,,$(CFLAGS))) $(INCLUDES)
 else
 SED_PREFIX=
diff -x .svn -uNr R14B/erts/lib_src/win/ethr_event.c r14b0_mingw32p1/erts/lib_src/win/ethr_event.c
--- R14B/erts/lib_src/win/ethr_event.c	2011-06-25 11:28:11.887708799 +0300
+++ r14b0_mingw32p1/erts/lib_src/win/ethr_event.c	2011-06-25 11:28:44.136444623 +0300
@@ -92,9 +92,15 @@
 	}
 
 	if (state != ETHR_EVENT_OFF_WAITER__) {
+#if defined(__MINGW32__)
+	    state = InterlockedCompareExchange(&e->state,
+					       ETHR_EVENT_OFF_WAITER__,
+					       ETHR_EVENT_OFF__);
+#else	   
 	    state = _InterlockedCompareExchange(&e->state,
 						ETHR_EVENT_OFF_WAITER__,
 						ETHR_EVENT_OFF__);
+#endif
 	    if (state == ETHR_EVENT_ON__)
 		return 0;
 	    ETHR_ASSERT(state == ETHR_EVENT_OFF__);
diff -x .svn -uNr R14B/erts/Makefile.in r14b0_mingw32p1/erts/Makefile.in
--- R14B/erts/Makefile.in	2011-06-25 11:28:11.904373330 +0300
+++ r14b0_mingw32p1/erts/Makefile.in	2011-06-25 11:28:44.153110619 +0300
@@ -85,6 +85,7 @@
 
 # The copying of beam.dll should be removed when the beam dll need no longer be
 # in the same directory...
+
 local_setup:
 	@cd start_scripts && $(MAKE)
 	@rm -f $(ERL_TOP)/bin/erl $(ERL_TOP)/bin/erlc $(ERL_TOP)/bin/cerl \
@@ -104,8 +105,7 @@
 		cp $(ERL_TOP)/bin/$(TARGET)/escript.exe $(ERL_TOP)/bin/escript.exe; \
 	 	chmod 755 $(ERL_TOP)/bin/erl.exe $(ERL_TOP)/bin/erlc.exe \
 			 $(ERL_TOP)/bin/werl.exe; \
-		$(ERL_TOP)/erts/etc/win32/cygwin_tools/make_local_ini.sh \
-			$(ERL_TOP); \
+		make_local_ini.sh $(ERL_TOP); \
 	else \
 	sed	-e "s;%FINAL_ROOTDIR%;$(ERL_TOP);"   \
 		-e "s;erts-.*/bin;bin/$(TARGET);"    \
diff -x .svn -uNr R14B/lib/crypto/c_src/Makefile.in r14b0_mingw32p1/lib/crypto/c_src/Makefile.in
--- R14B/lib/crypto/c_src/Makefile.in	2011-06-25 11:28:03.498037264 +0300
+++ r14b0_mingw32p1/lib/crypto/c_src/Makefile.in	2011-06-25 11:28:37.623365391 +0300
@@ -26,6 +26,8 @@
 include ../vsn.mk
 VSN=$(CRYPTO_VSN)
 
+USING_MINGW=@MIXED_CYGWIN_MINGW@
+
 # ----------------------------------------------------
 # The following variables differ between systems.
 # Set by configure.
@@ -112,7 +114,11 @@
 
 $(LIBDIR)/crypto$(TYPEMARKER).dll: $(OBJS)
 	$(INSTALL_DIR) $(LIBDIR)
-	$(LD) $(LDFLAGS) -o $@  $(SSL_DED_LD_RUNTIME_LIBRARY_PATH) -L$(SSL_LIBDIR) $(OBJS) -llibeay32
+ifeq ($(USING_MINGW), yes)	
+	$(LD) $(LDFLAGS) -o $@  $(SSL_DED_LD_RUNTIME_LIBRARY_PATH) -L$(SSL_LIBDIR) $(OBJS) -leay32
+else	
+	$(LD) $(LDFLAGS) -o $@  $(SSL_DED_LD_RUNTIME_LIBRARY_PATH) -L$(SSL_LIBDIR) $(OBJS) -llibeay32	
+endif
 
 clean:
 ifeq ($(findstring win32,$(TARGET)), win32)
diff -x .svn -uNr R14B/lib/erl_interface/configure.in r14b0_mingw32p1/lib/erl_interface/configure.in
--- R14B/lib/erl_interface/configure.in	2011-06-25 11:28:06.584582964 +0300
+++ r14b0_mingw32p1/lib/erl_interface/configure.in	2011-06-25 11:28:40.363258833 +0300
@@ -228,7 +228,8 @@
 
 AC_MSG_CHECKING(for mixed cygwin and native VC++ environment)
 if test "X$CC" = "Xcc.sh" -a "X$host" = "Xwin32" -a "x$GCC" != x"yes"; then
-	if test -x /usr/bin/cygpath; then
+	CYGPATH="`which cygpath`"
+ 	if test "$CYGPATH" != ""; then
 		CFLAGS="-O2"
 		MIXED_CYGWIN=yes
 		AC_MSG_RESULT([yes])
@@ -245,7 +246,8 @@
 
 AC_MSG_CHECKING(for mixed cygwin and native MinGW environment)
 if test "X$CC" = "Xcc.sh" -a "X$host" = "Xwin32" -a "x$GCC" = x"yes"; then
-	if test -x /usr/bin/cygpath; then
+	CYGPATH="`which cygpath`"
+	if test "$CYGPATH" != ""; then
 		CFLAGS="-O2"
 		MIXED_CYGWIN=yes
 		AC_MSG_RESULT([yes])
@@ -258,6 +260,24 @@
 	AC_MSG_RESULT([no])
 	MIXED_CYGWIN_MINGW=no
 fi
+
+AC_MSG_CHECKING(for mixed cygwin and msys MinGW environment)
+if test "`which mingwm10.dll`" != "" -a "X$host" = "Xwin32" -a "x$GCC" = x"yes"; then
+	CYGPATH="`which cygpath`"
+	if test "$CYGPATH" != ""; then
+		CFLAGS="-O2"
+		MIXED_CYGWIN=yes
+		AC_MSG_RESULT([yes])
+		MIXED_CYGWIN_MINGW=yes
+	else
+		AC_MSG_RESULT([undeterminable])
+		AC_MSG_ERROR(Seems to be mixed windows but not with cygwin, cannot handle this!)
+	fi
+else
+	AC_MSG_RESULT([no])
+	MIXED_CYGWIN_MINGW=no
+fi
+
 AC_SUBST(MIXED_CYGWIN_MINGW)
 
 AC_MSG_CHECKING(if we mix cygwin with any native compiler)
diff -x .svn -uNr R14B/lib/erl_interface/src/Makefile.in r14b0_mingw32p1/lib/erl_interface/src/Makefile.in
--- R14B/lib/erl_interface/src/Makefile.in	2011-06-25 11:28:06.537918171 +0300
+++ r14b0_mingw32p1/lib/erl_interface/src/Makefile.in	2011-06-25 11:28:40.313261330 +0300
@@ -234,7 +234,7 @@
 
 else
 
-ifeq ($USING_MINGW,yes)
+ifeq ($(USING_MINGW), yes)
 TARGETS = \
 	$(BINDIR) \
 	$(OBJDIR) \
@@ -626,7 +626,15 @@
 ifeq ($(TARGET),win32)
 
 # Windows archive creation
+ifeq ($(USING_MINGW), yes)
+$(MD_EILIB) : $(MD_EIOBJECTS)
+	$(AR) crv $@ $(MD_EIOBJECTS)
+	$(RANLIB) $@
 
+$(MD_ERLLIB) : $(MD_ERLOBJECTS)
+	$(AR) crv $@ $(MD_ERLOBJECTS)
+	$(RANLIB) $@
+else
 $(ST_EILIB) : $(ST_EIOBJECTS)
 	$(AR) -out:$@ $(ST_EIOBJECTS)
 	$(RANLIB) $@
@@ -658,7 +666,7 @@
 $(MDD_ERLLIB) : $(MDD_ERLOBJECTS)
 	$(AR) -out:$@ $(MDD_ERLOBJECTS)
 	$(RANLIB) $@
-
+endif
 else
 
 # Unix archive creation
@@ -698,9 +706,15 @@
 ###########################################################################
 
 ifeq ($(TARGET),win32)
+ifeq ($(USING_MINGW), yes)
+$(ERL_CALL): $(ERLCALL) ../include/ei.h $(MD_EILIB)
+	$(PURIFY) $(CC) -lmsvcrt $(PROG_CFLAGS) $(THR_DEFS) -o $@ $(ERLCALL) \
+		-L$(OBJDIR) -lei_md $(THR_LIBS) $(LIBS) -lws2_32
+else
 $(ERL_CALL): $(ERLCALL) ../include/ei.h $(MD_EILIB)
 	$(PURIFY) $(CC) -MD $(PROG_CFLAGS) $(THR_DEFS) -o $@ $(ERLCALL) \
 		-L$(OBJDIR) -lei_md $(THR_LIBS) $(LIBS) -lsocket
+endif		
 else
 ifeq ($(findstring vxworks,$(TARGET)),vxworks)
 $(ERL_CALL): $(ST_OBJDIR)/erl_call.o $(ST_OBJDIR)/erl_start.o ../include/ei.h $(ST_EILIB)
diff -x .svn -uNr R14B/lib/gs/tcl/Makefile.in r14b0_mingw32p1/lib/gs/tcl/Makefile.in
--- R14B/lib/gs/tcl/Makefile.in	2011-06-25 11:28:07.367885833 +0300
+++ r14b0_mingw32p1/lib/gs/tcl/Makefile.in	2011-06-25 11:28:40.939903820 +0300
@@ -33,11 +33,7 @@
 # be set for that system only.
 # ----------------------------------------------------
 
-ifeq ($(TARGET),win32)
-TCL_TAR = binaries/win32.tar.gz
-else
 TCL_TAR = @TCL_TAR@
-endif
 
 CONFIGURE_FILES = ../configure ../configure.in
 
diff -x .svn -uNr R14B/lib/ic/java_src/com/ericsson/otp/ic/Makefile r14b0_mingw32p1/lib/ic/java_src/com/ericsson/otp/ic/Makefile
--- R14B/lib/ic/java_src/com/ericsson/otp/ic/Makefile	2011-06-25 11:28:05.767948100 +0300
+++ r14b0_mingw32p1/lib/ic/java_src/com/ericsson/otp/ic/Makefile	2011-06-25 11:28:39.573290543 +0300
@@ -96,7 +96,7 @@
 debug opt: $(JAVA_DEST_ROOT)$(JARFILE)
 
 $(JAVA_DEST_ROOT)$(JARFILE): $(TARGET_FILES)
-	@(cd $(JAVA_DEST_ROOT) ; $(JAR) $(JARFLAGS) $(JARFILE) $(JAVA_CLASS_SUBDIR))
+	@(cd $(JAVA_DEST_ROOT) ; $(JAR) $(JARFLAGS) $(JARFILE) $(JAVA_CLASS_SUBDIR)/*.class)
 
 clean:
 	rm -f $(TARGET_FILES) *~
diff -x .svn -uNr R14B/lib/jinterface/java_src/com/ericsson/otp/erlang/Makefile.otp r14b0_mingw32p1/lib/jinterface/java_src/com/ericsson/otp/erlang/Makefile.otp
--- R14B/lib/jinterface/java_src/com/ericsson/otp/erlang/Makefile.otp	2011-06-25 11:28:02.964723383 +0300
+++ r14b0_mingw32p1/lib/jinterface/java_src/com/ericsson/otp/erlang/Makefile.otp	2011-06-25 11:28:37.230047847 +0300
@@ -82,7 +82,7 @@
 	if [ ! -d "$(JAVA_DEST_ROOT)" ];then mkdir "$(JAVA_DEST_ROOT)"; fi
 
 $(JAVA_DEST_ROOT)$(JARFILE): $(TARGET_FILES)
-	@(cd $(JAVA_DEST_ROOT) ; $(JAR) $(JARFLAGS) $(JARFILE) $(JAVA_CLASS_SUBDIR))
+	@(cd $(JAVA_DEST_ROOT) ; $(JAR) $(JARFLAGS) $(JARFILE) $(JAVA_CLASS_SUBDIR)/*.class)
 
 clean:
 	rm -f $(TARGET_FILES) *~
diff -x .svn -uNr R14B/lib/odbc/configure.in r14b0_mingw32p1/lib/odbc/configure.in
--- R14B/lib/odbc/configure.in	2011-06-25 11:28:07.281222645 +0300
+++ r14b0_mingw32p1/lib/odbc/configure.in	2011-06-25 11:28:40.853240143 +0300
@@ -77,7 +77,26 @@
 	AC_MSG_RESULT([no])
 	MIXED_CYGWIN_VC=no
 fi
+
+AC_MSG_CHECKING(for mixed cygwin and msys MinGW environment)
+if test "`which mingwm10.dll`" != "" -a "X$host" = "Xwin32" -a "x$GCC" = x"yes"; then
+	CYGPATH="`which cygpath`"
+	if test "$CYGPATH" != ""; then
+		CFLAGS="-O2"
+		MIXED_CYGWIN=yes
+		AC_MSG_RESULT([yes])
+		MIXED_CYGWIN_MINGW=yes
+	else
+		AC_MSG_RESULT([undeterminable])
+		AC_MSG_ERROR(Seems to be mixed windows but not with cygwin, cannot handle this!)
+	fi
+else
+	AC_MSG_RESULT([no])
+	MIXED_CYGWIN_MINGW=no
+fi
+
 AC_SUBST(MIXED_CYGWIN_VC)
+AC_SUBST(MIXED_CYGWIN_MINGW)
 
 AC_PROG_MAKE_SET
 
diff -x .svn -uNr R14B/lib/odbc/c_src/Makefile.in r14b0_mingw32p1/lib/odbc/c_src/Makefile.in
--- R14B/lib/odbc/c_src/Makefile.in	2011-06-25 11:28:07.277888467 +0300
+++ r14b0_mingw32p1/lib/odbc/c_src/Makefile.in	2011-06-25 11:28:40.846573745 +0300
@@ -21,6 +21,8 @@
 include $(ERL_TOP)/make/target.mk
 include $(ERL_TOP)/make/$(TARGET)/otp.mk
 
+USING_MINGW=@MIXED_CYGWIN_MINGW@
+
 ifeq ($(TYPE),debug)
 TYPEMARKER = .debug
 TYPEFLAGS = -g
@@ -56,7 +58,11 @@
 EI_LIB = -lerl_interface_md -lei_md 
 ENTRY_OBJ=$(ERL_TOP)/erts/obj/$(TARGET)/port_entry.o
 PORT_ENTRY_POINT=erl_port_entry
+ifeq ($(USING_MINGW), yes)
+ENTRY_LDFLAGS=--thumb-entry=$(PORT_ENTRY_POINT)
+else
 ENTRY_LDFLAGS=-entry:$(PORT_ENTRY_POINT)
+endif
 WIN32_TARGET = $(WIN_BIN_DIR)/odbcserver.exe
 EXE_TARGET = $(WIN32_TARGET)
 else
@@ -81,8 +87,8 @@
 CFLAGS = $(TYPEFLAGS) @CFLAGS@ @THR_DEFS@ @DEFS@
 EI_LDFLAGS = -L$(EI_ROOT)/obj$(TYPEMARKER)/$(TARGET)
 LD = @LD@
-LDFLAGS =  $(ODBC_LIB) $(EI_LDFLAGS)
-LIBS = @LIBS@ @THR_LIBS@ $(EI_LIB)
+LDFLAGS = $(EI_LDFLAGS)
+LIBS = @LIBS@ @THR_LIBS@ $(EI_LIB) $(ODBC_LIB)
 INCLUDES = -I. $(ODBC_INCLUDE) $(EI_INCLUDE)
 TARGET_FLAGS =  @TARGET_FLAGS@
 
@@ -111,10 +117,16 @@
 endif
 
 ifdef WIN32_TARGET
+ifeq ($(USING_MINGW), yes)
+$(WIN32_TARGET): $(OBJ_DIR)/odbcserver.o
+	$(CC) $(LDFLAGS) -o $@ $(OBJ_DIR)/odbcserver.o $(ENTRY_OBJ) \
+		$(LIBS) $(ENTRY_LDFLAGS)
+else
 $(WIN32_TARGET): $(OBJ_DIR)/odbcserver.o
 	$(LD) $(LDFLAGS) -o $@ $(OBJ_DIR)/odbcserver.o $(ENTRY_OBJ) \
 		$(LIBS) $(ENTRY_LDFLAGS)
 endif
+endif
 
 $(OBJ_DIR)/odbcserver.o: odbcserver.c
 	$(CC) $(CFLAGS) $(INCLUDES) $(TARGET_FLAGS) -o $@ -c odbcserver.c
diff -x .svn -uNr R14B/lib/os_mon/c_src/Makefile.in r14b0_mingw32p1/lib/os_mon/c_src/Makefile.in
--- R14B/lib/os_mon/c_src/Makefile.in	2011-06-25 11:28:05.471293341 +0300
+++ r14b0_mingw32p1/lib/os_mon/c_src/Makefile.in	2011-06-25 11:28:39.266635697 +0300
@@ -19,6 +19,8 @@
 include $(ERL_TOP)/make/target.mk
 include $(ERL_TOP)/make/$(TARGET)/otp.mk
 
+USING_MINGW=@MIXED_CYGWIN_MINGW@
+
 CC = @CC@
 LD = @LD@
 LIBS = @LIBS@
@@ -61,7 +63,11 @@
 
 ENTRY_OBJ=$(ERL_TOP)/erts/obj/$(TARGET)/port_entry.o
 PORT_ENTRY_POINT=erl_port_entry
+ifeq ($(USING_MINGW), yes)
+ENTRY_LDFLAGS=--thumb-entry=$(PORT_ENTRY_POINT)
+else
 ENTRY_LDFLAGS=-entry:$(PORT_ENTRY_POINT)
+endif
 else
 ifeq ($(findstring vxworks_simso,$(TARGET)),vxworks_simso)
 PROGRAMS =
diff -x .svn -uNr R14B/lib/public_key/src/Makefile r14b0_mingw32p1/lib/public_key/src/Makefile
--- R14B/lib/public_key/src/Makefile	2011-06-25 11:27:55.481677234 +0300
+++ r14b0_mingw32p1/lib/public_key/src/Makefile	2011-06-25 11:28:33.226871779 +0300
@@ -69,7 +69,7 @@
 # ----------------------------------------------------
 # FLAGS
 # ----------------------------------------------------
-PUB_KEY_ERL_FLAGS += -I $(INCLUDE) -I ../asn1/
+PUB_KEY_ERL_FLAGS += -pa $(ERL_TOP)/lib/public_key/ebin -I ../asn1/
 
 ERL_COMPILE_FLAGS += $(PUB_KEY_ERL_FLAGS) \
 		     $(PUB_KEY_FLAGS) \
diff -x .svn -uNr R14B/lib/public_key/src/pubkey_cert.erl r14b0_mingw32p1/lib/public_key/src/pubkey_cert.erl
--- R14B/lib/public_key/src/pubkey_cert.erl	2011-06-25 11:27:55.481677234 +0300
+++ r14b0_mingw32p1/lib/public_key/src/pubkey_cert.erl	2011-06-25 11:28:33.226871779 +0300
@@ -21,7 +21,7 @@
 
 -module(pubkey_cert).
 
--include("public_key.hrl").
+-include_lib("public_key/include/public_key.hrl").
 
 -export([init_validation_state/3, prepare_for_next_cert/2,
  	 validate_time/3, validate_signature/6,
diff -x .svn -uNr R14B/lib/public_key/src/pubkey_cert_records.erl r14b0_mingw32p1/lib/public_key/src/pubkey_cert_records.erl
--- R14B/lib/public_key/src/pubkey_cert_records.erl	2011-06-25 11:27:55.481677234 +0300
+++ r14b0_mingw32p1/lib/public_key/src/pubkey_cert_records.erl	2011-06-25 11:28:33.226871779 +0300
@@ -21,7 +21,7 @@
 
 -module(pubkey_cert_records).
 
--include("public_key.hrl").
+-include_lib("public_key/include/public_key.hrl").
 
 -export([decode_cert/1, transform/2]).
 
diff -x .svn -uNr R14B/lib/public_key/src/pubkey_pem.erl r14b0_mingw32p1/lib/public_key/src/pubkey_pem.erl
--- R14B/lib/public_key/src/pubkey_pem.erl	2011-06-25 11:27:55.478343545 +0300
+++ r14b0_mingw32p1/lib/public_key/src/pubkey_pem.erl	2011-06-25 11:28:33.226871779 +0300
@@ -40,7 +40,7 @@
 
 -module(pubkey_pem).
 
--include("public_key.hrl").
+-include_lib("public_key/include/public_key.hrl").
 
 -export([encode/1, decode/1, decipher/2, cipher/3]).
 %% Backwards compatibility
diff -x .svn -uNr R14B/lib/public_key/src/public_key.erl r14b0_mingw32p1/lib/public_key/src/public_key.erl
--- R14B/lib/public_key/src/public_key.erl	2011-06-25 11:27:55.478343545 +0300
+++ r14b0_mingw32p1/lib/public_key/src/public_key.erl	2011-06-25 11:28:33.226871779 +0300
@@ -21,7 +21,7 @@
 
 -module(public_key).
 
--include("public_key.hrl").
+-include_lib("public_key/include/public_key.hrl").
 
 -export([pem_decode/1, pem_encode/1, 
 	 der_decode/2, der_encode/2,
diff -x .svn -uNr R14B/lib/runtime_tools/c_src/Makefile.in r14b0_mingw32p1/lib/runtime_tools/c_src/Makefile.in
--- R14B/lib/runtime_tools/c_src/Makefile.in	2011-06-25 11:28:02.041426135 +0300
+++ r14b0_mingw32p1/lib/runtime_tools/c_src/Makefile.in	2011-06-25 11:28:36.530074964 +0300
@@ -38,6 +38,10 @@
 LIBS = $(DED_LIBS)
 LDFLAGS += $(DED_LDFLAGS)
 
+ifeq ($(TARGET),win32)
+LIBS += -lws2_32
+endif
+
 SYSINCLUDE = $(DED_SYS_INCLUDE)
 ifeq ($(findstring vxworks,$(TARGET)),vxworks)
 	SYSINCLUDE += -I$(ERL_TOP)/erts/etc/vxworks
diff -x .svn -uNr R14B/lib/ssl/c_src/debuglog.c r14b0_mingw32p1/lib/ssl/c_src/debuglog.c
--- R14B/lib/ssl/c_src/debuglog.c	2011-06-25 11:28:06.207931416 +0300
+++ r14b0_mingw32p1/lib/ssl/c_src/debuglog.c	2011-06-25 11:28:39.963275379 +0300
@@ -33,9 +33,10 @@
 #ifndef __WIN32__
 static char tr_format_buf[256];
 static char *tr_format(const char *format);
-static int vfprintclistf(FILE *fp, const char *format, va_list args);
 #endif
 
+static int vfprintclistf(FILE *fp, const char *format, va_list args);
+
 int debug = 0;
 int debugmsg = 0;
 FILE *ssllogfp = NULL;
@@ -178,8 +179,7 @@
  *  
  */
 
-static int vfprintclistf(FILE *fp, const char *format, va_list args)
-{
+static int vfprintclistf(FILE *fp, const char *format, va_list args) {
 
     int i, len, width, prec, written = 0;
     char *s, *prevs, *fstart;
diff -x .svn -uNr R14B/lib/ssl/c_src/Makefile.in r14b0_mingw32p1/lib/ssl/c_src/Makefile.in
--- R14B/lib/ssl/c_src/Makefile.in	2011-06-25 11:28:06.204598217 +0300
+++ r14b0_mingw32p1/lib/ssl/c_src/Makefile.in	2011-06-25 11:28:39.959941691 +0300
@@ -63,6 +63,8 @@
 BINDIR = $(PRIVDIR)/bin/$(TARGET)
 OBJDIR = $(PRIVDIR)/obj/$(TARGET)
 
+USING_MINGW=@MIXED_CYGWIN_MINGW@
+
 # ----------------------------------------------------
 # File suffixes
 # ----------------------------------------------------
@@ -175,7 +177,11 @@
 
 # Win32/Cygwin
 $(BINDIR)/ssl_esock.exe: $(OBJS)
-	$(LD) $(SSL_CC_RUNTIME_LIBRARY_PATH) -L$(SSL_LIBDIR) -o $@ $^ -lwsock32 -llibeay32 -lssleay32
+ifeq ($(USING_MINGW), yes)
+	$(LD) $(SSL_CC_RUNTIME_LIBRARY_PATH) -L$(SSL_LIBDIR) -o $@ $^ -lws2_32 -leay32 -lssl32
+else
+	$(LD) $(SSL_CC_RUNTIME_LIBRARY_PATH) -L$(SSL_LIBDIR) -o $@ $^ -lwsock32 -llibeay32 -lssleay32	
+endif
 
 # Unix only, and only when linking statically
 $(SSL_MAKEFILE):
diff -x .svn -uNr R14B/lib/tools/c_src/Makefile.in r14b0_mingw32p1/lib/tools/c_src/Makefile.in
--- R14B/lib/tools/c_src/Makefile.in	2011-06-25 11:28:01.268122865 +0300
+++ r14b0_mingw32p1/lib/tools/c_src/Makefile.in	2011-06-25 11:28:35.706774191 +0300
@@ -130,6 +130,10 @@
 
 EMEM_ETHR_LIBS=$(subst -l$(ETHR_LIB_NAME),-l$(ETHR_LIB_NAME)$(TYPEMARKER),$(subst -lerts_internal_r,-lerts_internal_r$(TYPEMARKER),$(ETHR_LIBS)))
 
+ifeq ($(TARGET),win32)
+LIBS += -lws2_32
+endif
+
 EMEM_LIBS =	$(LIBS) \
 		-L$(ERL_TOP)/erts/lib/$(TARGET) \
 		-L$(ERL_TOP)/erts/lib/internal/$(TARGET) \
diff -x .svn -uNr R14B/lib/wx/configure.in r14b0_mingw32p1/lib/wx/configure.in
--- R14B/lib/wx/configure.in	2011-06-25 11:28:00.968134908 +0300
+++ r14b0_mingw32p1/lib/wx/configure.in	2011-06-25 11:28:35.480115645 +0300
@@ -72,7 +72,8 @@
 
 AC_MSG_CHECKING(for mixed cygwin and native VC++ environment)
 if test "X$CC" = "Xcc.sh" -a "X$host" = "Xwin32" -a "x$GCC" != x"yes"; then
-	if test -x /usr/bin/cygpath; then
+	CYGPATH=`which cygpath`
+	if test "$CYGPATH" != ""; then
 		CFLAGS="-Owx"		
 		MIXED_CYGWIN=yes
 		AC_MSG_RESULT([yes])
@@ -90,7 +91,27 @@
 
 AC_MSG_CHECKING(for mixed cygwin and native MinGW environment)
 if test "X$CC" = "Xcc.sh" -a "X$host" = "Xwin32" -a "x$GCC" = x"yes"; then
-	if test -x /usr/bin/cygpath; then
+	CYGPATH=`which cygpath`
+	if test "$CYGPATH" != ""; then
+		CFLAGS="-O2"
+		MIXED_CYGWIN=yes
+		AC_MSG_RESULT([yes])
+		MIXED_CYGWIN_MINGW=yes
+		CPPFLAGS="$CPPFLAGS -DERTS_MIXED_CYGWIN_MINGW"
+	else
+		AC_MSG_RESULT([undeterminable])
+		AC_MSG_ERROR(Seems to be mixed windows but not with cygwin, cannot handle this!)
+	fi
+else
+	AC_MSG_RESULT([no])
+	MIXED_CYGWIN_MINGW=no
+fi
+AC_SUBST(MIXED_CYGWIN_MINGW)
+
+AC_MSG_CHECKING(for mixed cygwin and msys MinGW environment)
+if test "`which mingwm10.dll`" != "" -a "X$host" = "Xwin32" -a "x$GCC" = x"yes"; then
+	CYGPATH="`which cygpath`"
+	if test "$CYGPATH" != ""; then
 		CFLAGS="-O2"
 		MIXED_CYGWIN=yes
 		AC_MSG_RESULT([yes])
@@ -165,7 +186,12 @@
 	LDFLAGS="-bundle -flat_namespace -undefined warning -fPIC -framework OpenGL $LDFLAGS"
 	;;
     win32)
-        LDFLAGS="-dll $LDFLAGS"
+    	if test "X$MIXED_CYGWIN" = "Xyes" ; then
+	    DED_LD="$CC"
+	    LDFLAGS="-shared -fPIC"
+	else
+            LDFLAGS="-dll $LDFLAGS"
+	fi
 	;;
     mingw32)
 	LDFLAGS="-shared -fPIC $LDFLAGS"
@@ -247,7 +273,7 @@
 if test "$cross_compiling" = "yes"; then
     echo "Cross compilation of the wx driver is not supported yet, wx will NOT be usable" > ./CONF_INFO
     WXERL_CAN_BUILD_DRIVER=false
-elif test X"$MIXED_CYGWIN_VC" != X"yes" ; then
+elif test X"$MIXED_CYGWIN_VC" != X"yes" || test X"$MIXED_CYGWIN_MINGW" != X"yes" ; then
     m4_include(wxwin.m4)
 
     AM_OPTIONS_WXCONFIG
@@ -502,6 +528,8 @@
 
 if test X"$WX_HAVE_STATIC_LIBS" = X"true" ; then
    LIBS=$WX_LIBS_STATIC   
+else
+   LIBS=$WX_LIBS
 fi
 
 AC_LINK_IFELSE([
diff -x .svn -uNr R14B/lib/wx/c_src/Makefile.in r14b0_mingw32p1/lib/wx/c_src/Makefile.in
--- R14B/lib/wx/c_src/Makefile.in	2011-06-25 11:28:00.668144994 +0300
+++ r14b0_mingw32p1/lib/wx/c_src/Makefile.in	2011-06-25 11:28:35.316789845 +0300
@@ -109,6 +109,10 @@
 CC_O		= $(CC) -c $(CFLAGS) $(COMMON_CFLAGS)
 CPP_O		= $(CPP) -c $(CPP_FLAGS) $(COMMON_CFLAGS) 
 
+ifeq ($(SYS_TYPE),win32)
+LIBS += -lopengl32 -lglu32
+endif
+
 # Targets
 
 opt:     $(TARGET_DIR)/$(TARGET_API)$(SO_EXT) 
diff -x .svn -uNr R14B/Makefile.in r14b0_mingw32p1/Makefile.in
--- R14B/Makefile.in	2011-06-25 11:28:11.917706129 +0300
+++ r14b0_mingw32p1/Makefile.in	2011-06-25 11:28:44.166443907 +0300
@@ -215,8 +215,13 @@
 # depending on which system is preferred.)
 LOCAL_PATH     = $(ERL_TOP)/erts/bin/$(TARGET):$(ERL_TOP)/erts/bin
 ifeq ($(TARGET),win32)
+ifeq ($(BUILD_ENVIRONMENT), msys)
+WIN32_WRAPPER_PATH=$(ERL_TOP)/erts/etc/win32/msys_tools
+BOOT_PREFIX=$(WIN32_WRAPPER_PATH):$(BOOTSTRAP_ROOT)/bootstrap/bin:
+else
 WIN32_WRAPPER_PATH=$(ERL_TOP)/erts/etc/win32/cygwin_tools
 BOOT_PREFIX=$(WIN32_WRAPPER_PATH):$(BOOTSTRAP_ROOT)/bootstrap/bin:
+endif
 else
 BOOT_PREFIX=$(BOOTSTRAP_ROOT)/bootstrap/bin:
 endif
diff -x .svn -uNr R14B/otp_build r14b0_mingw32p1/otp_build
--- R14B/otp_build	2011-06-25 11:28:11.917706129 +0300
+++ r14b0_mingw32p1/otp_build	2011-06-25 11:28:44.163109730 +0300
@@ -67,6 +67,7 @@
     echo "Before trying to build on windows, consider the following option"
     echo "    env_win32 - echo environment settings for win32 with visual C++, use with eval"
     echo "    env_mingw32 - echo environment settings for win32 with MinGW, use with eval"
+    echo "env_msys - echo environment settings for MinGW with msys, use with eval"
     echo ""
     echo "Before trying to build for vxworks, consider the following option"
     echo "    env_vxworks <cpu>  - echo environment settings for vxworks, use with eval"
@@ -187,7 +188,7 @@
 		CONFIG_FLAGS="$CONFIG_FLAGS --host=$TARGET"
 	fi
 	if target_contains win32; then
-		CONFIG_FLAGS="--build=$BUILDSYS build_alias=win32 --host=win32 --target=win32 $CONFIG_FLAGS" 
+		CONFIG_FLAGS="--build=$BUILDSYS build_alias=win32 --host=win32 --target=win32 $CONFIG_FLAGS --without-termcap"
 	else
 	        # Link SSL static for all binary distributions if not overridden
 	        XX=`echo $* | grep -v dynamic-ssl-lib`
@@ -815,7 +816,6 @@
 	return
     fi
 
-
     echo_setenv OVERRIDE_TARGET win32 ';'
     echo_setenv MINGW_EXE_PATH $found ';'
     echo_setenv WINE_EXE_PATH $found2 ';'
@@ -827,6 +827,31 @@
     echo_envinfo
 }
 
+echo_env_msys ()
+{
+    #echo_envinfo
+    if [ X"$SHELL" = X"" ]; then
+	echo "You need to export the shell variable first," \
+		"for bourne-like shells, type:" >&2
+	echo 'export SHELL' >&2
+	echo "and for csh-like shells, type:" >&2
+	echo 'setenv SHELL $SHELL' >&2
+	echo " - then try again." >&2
+	exit 1
+    fi
+    echo_env_erltop
+
+    P1=$ERL_TOP/erts/etc/win32/msys_tools
+    P2=`echo $P1:$PATH | \
+        sed 's,",,g;s,:\.:,:,g;s,:\([a-zA-Z]\):/,:/\1/,g;'`
+
+    echo_setenv OVERRIDE_TARGET win32 ';'
+    echo_setenv BUILD_ENVIRONMENT msys ';'
+    echo_setenv RANLIB ranlib ';'
+    echo_setenv PATH "$P2"
+    echo_envinfo
+}
+
 lookup_prog_in_path ()
 {
     PROG=$1
@@ -1214,6 +1239,8 @@
 		echo_env_win32;;
 	env_mingw32)
 		echo_env_mingw32;;
+	env_msys)
+		echo_env_msys;;
 	env_vxworks)
 		echo_env_vxworks "$2";;
 	env_cross)
