=== modified file 'Include/osdefs.h'
*** Include/osdefs.h
--- Include/osdefs.h
***************
*** 18,23 ****
--- 18,24 ----
  #define SEP '\\'
  #define ALTSEP '/'
  #define MAXPATHLEN 256
+ #define ROOTSEP ':'
  #endif
  #define DELIM ';'
  #endif
=== modified file 'Include/pyport.h'
*** Include/pyport.h
--- Include/pyport.h
***************
*** 478,508 ****
    BeOS and cygwin are the only other autoconf platform requiring special
    linkage handling and both of these use __declspec().
  */
! #if defined(__CYGWIN__) || defined(__BEOS__)
  #	define HAVE_DECLSPEC_DLL
  #endif
  
  /* only get special linkage if built as shared or platform is Cygwin */
! #if defined(Py_ENABLE_SHARED) || defined(__CYGWIN__)
  #	if defined(HAVE_DECLSPEC_DLL)
  #		ifdef Py_BUILD_CORE
  #			define PyAPI_FUNC(RTYPE) __declspec(dllexport) RTYPE
  #			define PyAPI_DATA(RTYPE) extern __declspec(dllexport) RTYPE
  			/* module init functions inside the core need no external linkage */
  			/* except for Cygwin to handle embedding (FIXME: BeOS too?) */
! #			if defined(__CYGWIN__)
  #				define PyMODINIT_FUNC __declspec(dllexport) void
! #			else /* __CYGWIN__ */
  #				define PyMODINIT_FUNC void
! #			endif /* __CYGWIN__ */
  #		else /* Py_BUILD_CORE */
  			/* Building an extension module, or an embedded situation */
  			/* public Python functions and data are imported */
  			/* Under Cygwin, auto-import functions to prevent compilation */
  			/* failures similar to http://python.org/doc/FAQ.html#3.24 */
! #			if !defined(__CYGWIN__)
  #				define PyAPI_FUNC(RTYPE) __declspec(dllimport) RTYPE
! #			endif /* !__CYGWIN__ */
  #			define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE
  			/* module init functions outside the core must be exported */
  #			if defined(__cplusplus)
--- 478,508 ----
    BeOS and cygwin are the only other autoconf platform requiring special
    linkage handling and both of these use __declspec().
  */
! #if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BEOS__)
  #	define HAVE_DECLSPEC_DLL
  #endif
  
  /* only get special linkage if built as shared or platform is Cygwin */
! #if defined(Py_ENABLE_SHARED) || defined(__CYGWIN__) || defined(__MINGW32__)
  #	if defined(HAVE_DECLSPEC_DLL)
  #		ifdef Py_BUILD_CORE
  #			define PyAPI_FUNC(RTYPE) __declspec(dllexport) RTYPE
  #			define PyAPI_DATA(RTYPE) extern __declspec(dllexport) RTYPE
  			/* module init functions inside the core need no external linkage */
  			/* except for Cygwin to handle embedding (FIXME: BeOS too?) */
! #			if defined(__CYGWIN__) || defined(__MINGW32__)
  #				define PyMODINIT_FUNC __declspec(dllexport) void
! #			else /* __CYGWIN__ || __MINGW32__ */
  #				define PyMODINIT_FUNC void
! #			endif /* __CYGWIN__ || __MINGW32__ */
  #		else /* Py_BUILD_CORE */
  			/* Building an extension module, or an embedded situation */
  			/* public Python functions and data are imported */
  			/* Under Cygwin, auto-import functions to prevent compilation */
  			/* failures similar to http://python.org/doc/FAQ.html#3.24 */
! #			if !defined(__CYGWIN__) && !defined(__MINGW32__)
  #				define PyAPI_FUNC(RTYPE) __declspec(dllimport) RTYPE
! #			endif /* !__CYGWIN__ && ! __MINGW32__ */
  #			define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE
  			/* module init functions outside the core must be exported */
  #			if defined(__cplusplus)
=== modified file 'Lib/distutils/command/build_ext.py'
*** Lib/distutils/command/build_ext.py
--- Lib/distutils/command/build_ext.py
***************
*** 666,672 ****
              # don't extend ext.libraries, it may be shared with other
              # extensions, it is a reference to the original list
              return ext.libraries + [pythonlib]
!         elif sys.platform[:6] == "cygwin":
              template = "python%d.%d"
              pythonlib = (template %
                     (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
--- 666,672 ----
              # don't extend ext.libraries, it may be shared with other
              # extensions, it is a reference to the original list
              return ext.libraries + [pythonlib]
!         elif sys.platform[:6] == "cygwin" or sys.platform[:5] == "mingw":
              template = "python%d.%d"
              pythonlib = (template %
                     (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
=== modified file 'Makefile.pre.in'
*** Makefile.pre.in
--- Makefile.pre.in
***************
*** 18,23 ****
--- 18,25 ----
  #
  # See also the section "Build instructions" in the README file.
  
+ DELIM=@DELIM@
+ 
  # === Variables set by makesetup ===
  
  MODOBJS=        _MODOBJS_
=== modified file 'Modules/Setup.dist'
*** Modules/Setup.dist
--- Modules/Setup.dist
***************
*** 91,102 ****
  TESTPATH=
  
  # Path components for machine- or system-dependent modules and shared libraries
! MACHDEPPATH=:plat-$(MACHDEP)
  EXTRAMACHDEPPATH=
  
  # Path component for the Tkinter-related modules
  # The TKPATH variable is always enabled, to save you the effort.
! TKPATH=:lib-tk
  
  COREPYTHONPATH=$(DESTPATH)$(SITEPATH)$(TESTPATH)$(MACHDEPPATH)$(EXTRAMACHDEPPATH)$(TKPATH)
  PYTHONPATH=$(COREPYTHONPATH)
--- 91,102 ----
  TESTPATH=
  
  # Path components for machine- or system-dependent modules and shared libraries
! MACHDEPPATH=$(DELIM)plat-$(MACHDEP)
  EXTRAMACHDEPPATH=
  
  # Path component for the Tkinter-related modules
  # The TKPATH variable is always enabled, to save you the effort.
! TKPATH=$(DELIM)lib-tk
  
  COREPYTHONPATH=$(DESTPATH)$(SITEPATH)$(TESTPATH)$(MACHDEPPATH)$(EXTRAMACHDEPPATH)$(TKPATH)
  PYTHONPATH=$(COREPYTHONPATH)
***************
*** 109,115 ****
  # This only contains the minimal set of modules required to run the 
  # setup.py script in the root of the Python source tree.
  
! posix posixmodule.c		# posix (UNIX) system calls
  errno errnomodule.c		# posix (UNIX) errno values
  _sre _sre.c			# Fredrik Lundh's new regular expressions
  _codecs _codecsmodule.c		# access to the builtin codecs and codec registry
--- 109,115 ----
  # This only contains the minimal set of modules required to run the 
  # setup.py script in the root of the Python source tree.
  
! @POSIX@ posixmodule.c		# posix (UNIX) system calls
  errno errnomodule.c		# posix (UNIX) errno values
  _sre _sre.c			# Fredrik Lundh's new regular expressions
  _codecs _codecsmodule.c		# access to the builtin codecs and codec registry
=== modified file 'Modules/getpath.c'
*** Modules/getpath.c
--- Modules/getpath.c
***************
*** 120,125 ****
--- 120,133 ----
  #define LANDMARK "os.py"
  #endif
  
+ #ifndef __MINGW32__
+ #define IS_ABSOLUTE(x) (x[0] == SEP)
+ #else /* __MINGW32__ */
+ #define IS_ABSOLUTE(x) (x[0] == SEP || x[0] == ALTSEP\
+ 			|| (x[1] && x[1] == ROOTSEP\
+ 			    && x[2] && (x[2] == SEP || x[2] == ALTSEP)))
+ #endif /* __MINGW32__ */
+ 
  static char prefix[MAXPATHLEN+1];
  static char exec_prefix[MAXPATHLEN+1];
  static char progpath[MAXPATHLEN+1];
***************
*** 130,136 ****
  reduce(char *dir)
  {
      size_t i = strlen(dir);
!     while (i > 0 && dir[i] != SEP)
          --i;
      dir[i] = '\0';
  }
--- 138,149 ----
  reduce(char *dir)
  {
      size_t i = strlen(dir);
!     while (i > 0
! 	   && dir[i] != SEP
! #ifdef ALTSEP
! 	   && dir[i] != ALTSEP
! #endif /* ALTSEP */
! 	   )
          --i;
      dir[i] = '\0';
  }
***************
*** 203,213 ****
  joinpath(char *buffer, char *stuff)
  {
      size_t n, k;
!     if (stuff[0] == SEP)
          n = 0;
      else {
          n = strlen(buffer);
!         if (n > 0 && buffer[n-1] != SEP && n < MAXPATHLEN)
              buffer[n++] = SEP;
      }
      if (n > MAXPATHLEN)
--- 216,231 ----
  joinpath(char *buffer, char *stuff)
  {
      size_t n, k;
!     if (IS_ABSOLUTE(stuff))
          n = 0;
      else {
          n = strlen(buffer);
!         if (n > 0
! 	    && buffer[n-1] != SEP
! #ifdef ALTSEP
! 	    && buffer[n-1] != ALTSEP
! #endif /* ALTSEP */
! 	    && n < MAXPATHLEN)
              buffer[n++] = SEP;
      }
      if (n > MAXPATHLEN)
***************
*** 224,234 ****
  static void
  copy_absolute(char *path, char *p)
  {
!     if (p[0] == SEP)
          strcpy(path, p);
      else {
          getcwd(path, MAXPATHLEN);
!         if (p[0] == '.' && p[1] == SEP)
              p += 2;
          joinpath(path, p);
      }
--- 242,257 ----
  static void
  copy_absolute(char *path, char *p)
  {
!     if (IS_ABSOLUTE(p))
          strcpy(path, p);
      else {
          getcwd(path, MAXPATHLEN);
!         if (p[0] == '.'
! 	    && (p[1] == SEP
! #ifdef ALTSEP
! 		|| p[1] == ALTSEP
! #endif /* ALTSEP */
! 		))
              p += 2;
          joinpath(path, p);
      }
***************
*** 240,246 ****
  {
      char buffer[MAXPATHLEN + 1];
  
!     if (path[0] == SEP)
          return;
      copy_absolute(buffer, path);
      strcpy(path, buffer);
--- 263,269 ----
  {
      char buffer[MAXPATHLEN + 1];
  
!     if (IS_ABSOLUTE(path))
          return;
      copy_absolute(buffer, path);
      strcpy(path, buffer);
***************
*** 384,396 ****
      uint32_t nsexeclength = MAXPATHLEN;
  #endif
  
! 	/* If there is no slash in the argv0 path, then we have to
! 	 * assume python is on the user's $PATH, since there's no
! 	 * other way to find a directory to start the search from.  If
! 	 * $PATH isn't exported, you lose.
! 	 */
! 	if (strchr(prog, SEP))
! 		strncpy(progpath, prog, MAXPATHLEN);
  #ifdef __APPLE__
       /* On Mac OS X, if a script uses an interpreter of the form
        * "#!/opt/python2.3/bin/python", the kernel only passes "python"
--- 407,429 ----
      uint32_t nsexeclength = MAXPATHLEN;
  #endif
  
!     /* If PROG is an absolute name, then we're done.  If PROG is not
!      * an absolute name and contains SEP/ALTSEP, then it must be
!      * reachable from CWD.  Otherwise, python is on the user's $PATH,
!      * since there's no other way to find a directory to start the
!      * search from.  If $PATH isn't exported, you lose.
!      */
!     if (IS_ABSOLUTE(prog))
!     	strncpy(progpath, prog, MAXPATHLEN);
!     else if (strchr(prog, SEP)
! #ifdef ALTSEP
! 	     || strchr(prog, ALTSEP)
! #endif /* ALTSEP */
! 	     )
!       {
!     	getcwd(progpath, MAXPATHLEN);
! 	joinpath(progpath, prog);
!       }
  #ifdef __APPLE__
       /* On Mac OS X, if a script uses an interpreter of the form
        * "#!/opt/python2.3/bin/python", the kernel only passes "python"
***************
*** 406,411 ****
--- 439,447 ----
         ;
  #endif /* __APPLE__ */
  	else if (path) {
+ #ifdef __MINGW32__
+ 		char const *ext = strchr(prog, '.') ? "" : ".exe";
+ #endif
  		while (1) {
  			char *delim = strchr(path, DELIM);
  
***************
*** 420,428 ****
  				strncpy(progpath, path, MAXPATHLEN);
  
  			joinpath(progpath, prog);
  			if (isxfile(progpath))
  				break;
- 
  			if (!delim) {
  				progpath[0] = '\0';
  				break;
--- 456,466 ----
  				strncpy(progpath, path, MAXPATHLEN);
  
  			joinpath(progpath, prog);
+ #ifdef __MINGW32__
+ 			strcat(progpath, ext);
+ #endif
  			if (isxfile(progpath))
  				break;
  			if (!delim) {
  				progpath[0] = '\0';
  				break;
***************
*** 432,438 ****
  	}
  	else
  		progpath[0] = '\0';
! 	if (progpath[0] != SEP)
  		absolutize(progpath);
  	strncpy(argv0_path, progpath, MAXPATHLEN);
  	argv0_path[MAXPATHLEN] = '\0';
--- 470,476 ----
  	}
  	else
  		progpath[0] = '\0';
! 	if (!IS_ABSOLUTE(progpath))
  		absolutize(progpath);
  	strncpy(argv0_path, progpath, MAXPATHLEN);
  	argv0_path[MAXPATHLEN] = '\0';
***************
*** 478,484 ****
          while (linklen != -1) {
              /* It's not null terminated! */
              tmpbuffer[linklen] = '\0';
!             if (tmpbuffer[0] == SEP)
                  /* tmpbuffer should never be longer than MAXPATHLEN,
                     but extra check does not hurt */
                  strncpy(argv0_path, tmpbuffer, MAXPATHLEN);
--- 516,522 ----
          while (linklen != -1) {
              /* It's not null terminated! */
              tmpbuffer[linklen] = '\0';
!             if (IS_ABSOLUTE(tmpbuffer))
                  /* tmpbuffer should never be longer than MAXPATHLEN,
                     but extra check does not hurt */
                  strncpy(argv0_path, tmpbuffer, MAXPATHLEN);
***************
*** 545,551 ****
      while (1) {
          char *delim = strchr(defpath, DELIM);
  
!         if (defpath[0] != SEP)
              /* Paths are relative to prefix */
              bufsz += prefixsz;
  
--- 583,589 ----
      while (1) {
          char *delim = strchr(defpath, DELIM);
  
!         if (!IS_ABSOLUTE(defpath))
              /* Paths are relative to prefix */
              bufsz += prefixsz;
  
***************
*** 590,596 ****
          while (1) {
              char *delim = strchr(defpath, DELIM);
  
!             if (defpath[0] != SEP) {
                  strcat(buf, prefix);
                  strcat(buf, separator);
              }
--- 628,634 ----
          while (1) {
              char *delim = strchr(defpath, DELIM);
  
!             if (!IS_ABSOLUTE(defpath)) {
                  strcat(buf, prefix);
                  strcat(buf, separator);
              }
=== modified file 'Modules/posixmodule.c'
*** Modules/posixmodule.c
--- Modules/posixmodule.c
***************
*** 106,111 ****
--- 106,115 ----
  #define HAVE_FSYNC	1
  #define fsync _commit
  #else
+ #ifdef __MINGW32__             /* MINGW32 (cross-)compiler*/
+ #define HAVE_FSYNC	1
+ #define fsync _commit
+ #else
  #if defined(PYOS_OS2) && defined(PYCC_GCC) || defined(__VMS)
  /* Everything needed is defined in PC/os2emx/pyconfig.h or vms/pyconfig.h */
  #else			/* all other compilers */
***************
*** 131,142 ****
  #define HAVE_WAIT       1
  #define HAVE_TTYNAME	1
  #endif  /* PYOS_OS2 && PYCC_GCC && __VMS */
  #endif  /* _MSC_VER */
  #endif  /* __BORLANDC__ */
  #endif  /* ! __WATCOMC__ || __QNX__ */
  #endif /* ! __IBMC__ */
  
! #ifndef _MSC_VER
  
  #if defined(__sgi)&&_COMPILER_VERSION>=700
  /* declare ctermid_r if compiling with MIPSPro 7.x in ANSI C mode
--- 135,147 ----
  #define HAVE_WAIT       1
  #define HAVE_TTYNAME	1
  #endif  /* PYOS_OS2 && PYCC_GCC && __VMS */
+ #endif  /* __MINGW32__ */
  #endif  /* _MSC_VER */
  #endif  /* __BORLANDC__ */
  #endif  /* ! __WATCOMC__ || __QNX__ */
  #endif /* ! __IBMC__ */
  
! #if !defined(_MSC_VER) && !defined(__MINGW32__)
  
  #if defined(__sgi)&&_COMPILER_VERSION>=700
  /* declare ctermid_r if compiling with MIPSPro 7.x in ANSI C mode
***************
*** 182,188 ****
  #endif /* HAVE_LSTAT */
  #endif /* !HAVE_UNISTD_H */
  
! #endif /* !_MSC_VER */
  
  #ifdef HAVE_UTIME_H
  #include <utime.h>
--- 187,193 ----
  #endif /* HAVE_LSTAT */
  #endif /* !HAVE_UNISTD_H */
  
! #endif /* !_MSC_VER && !__MINGW32__ */
  
  #ifdef HAVE_UTIME_H
  #include <utime.h>
***************
*** 227,233 ****
  #endif
  #endif
  
! #ifdef _MSC_VER
  #include <direct.h>
  #include <io.h>
  #include <process.h>
--- 232,238 ----
  #endif
  #endif
  
! #if defined(_MSC_VER) || defined(__MINGW32__)
  #include <direct.h>
  #include <io.h>
  #include <process.h>
***************
*** 237,243 ****
  #include <shellapi.h>	/* for ShellExecute() */
  #define popen	_popen
  #define pclose	_pclose
! #endif /* _MSC_VER */
  
  #if defined(PYCC_VACPP) && defined(PYOS_OS2)
  #include <io.h>
--- 242,248 ----
  #include <shellapi.h>	/* for ShellExecute() */
  #define popen	_popen
  #define pclose	_pclose
! #endif /* _MSC_VER || __MINGW32__ */
  
  #if defined(PYCC_VACPP) && defined(PYOS_OS2)
  #include <io.h>
***************
*** 304,312 ****
  */
  #include <crt_externs.h>
  static char **environ;
! #elif !defined(_MSC_VER) && ( !defined(__WATCOMC__) || defined(__QNX__) )
  extern char **environ;
! #endif /* !_MSC_VER */
  
  static PyObject *
  convertenviron(void)
--- 309,317 ----
  */
  #include <crt_externs.h>
  static char **environ;
! #elif !defined(_MSC_VER) && !defined(__MINGW32__) && ( !defined(__WATCOMC__) || defined(__QNX__) )
  extern char **environ;
! #endif /* !_MSC_VER && ! __MINGW32__ */
  
  static PyObject *
  convertenviron(void)
***************
*** 1845,1851 ****
  	                      Py_FileSystemDefaultEncoding, &path, &mode))
  		return NULL;
  	Py_BEGIN_ALLOW_THREADS
! #if ( defined(__WATCOMC__) || defined(_MSC_VER) || defined(PYCC_VACPP) ) && !defined(__QNX__)
  	res = mkdir(path);
  #else
  	res = mkdir(path, mode);
--- 1850,1856 ----
  	                      Py_FileSystemDefaultEncoding, &path, &mode))
  		return NULL;
  	Py_BEGIN_ALLOW_THREADS
! #if ( defined(__WATCOMC__) || defined(_MSC_VER) || defined(__MINGW32__) || defined(PYCC_VACPP) ) && !defined(__QNX__)
  	res = mkdir(path);
  #else
  	res = mkdir(path, mode);
***************
*** 7285,7291 ****
  }
  #endif
  
! #ifdef MS_WINDOWS
  
  PyDoc_STRVAR(win32_urandom__doc__,
  "urandom(n) -> str\n\n\
--- 7290,7296 ----
  }
  #endif
  
! #if defined(MS_WINDOWS) && !defined(__MINGW32__)
  
  PyDoc_STRVAR(win32_urandom__doc__,
  "urandom(n) -> str\n\n\
***************
*** 7642,7648 ****
  #ifdef HAVE_GETLOADAVG
  	{"getloadavg",	posix_getloadavg, METH_NOARGS, posix_getloadavg__doc__},
  #endif
!  #ifdef MS_WINDOWS
   	{"urandom", win32_urandom, METH_VARARGS, win32_urandom__doc__},
   #endif
  	{NULL,		NULL}		 /* Sentinel */
--- 7647,7653 ----
  #ifdef HAVE_GETLOADAVG
  	{"getloadavg",	posix_getloadavg, METH_NOARGS, posix_getloadavg__doc__},
  #endif
!  #if defined(MS_WINDOWS) && !defined(__MINGW32__)
   	{"urandom", win32_urandom, METH_VARARGS, win32_urandom__doc__},
   #endif
  	{NULL,		NULL}		 /* Sentinel */
***************
*** 7921,7927 ****
  }
  
  
! #if (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__)) && !defined(__QNX__)
  #define INITFUNC initnt
  #define MODNAME "nt"
  
--- 7926,7932 ----
  }
  
  
! #if (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__) || defined(__MINGW32__)) && !defined(__QNX__)
  #define INITFUNC initnt
  #define MODNAME "nt"
  
=== modified file 'Modules/timemodule.c'
*** Modules/timemodule.c
--- Modules/timemodule.c
***************
*** 801,807 ****
--- 801,809 ----
  	   If Ctrl+C event delivered while not sleeping
  	   it will be ignored.
  	*/
+ #ifdef WITH_THREAD
  	main_thread = PyThread_get_thread_ident();
+ #endif
  	hInterruptEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
  	SetConsoleCtrlHandler( PyCtrlHandler, TRUE);
  #endif /* MS_WINDOWS */
***************
*** 899,905 ****
  		 */
  		ul_millis = (unsigned long)millisecs;
  		if (ul_millis == 0 ||
! 		    main_thread != PyThread_get_thread_ident())
  			Sleep(ul_millis);
  		else {
  			DWORD rc;
--- 901,910 ----
  		 */
  		ul_millis = (unsigned long)millisecs;
  		if (ul_millis == 0 ||
! #ifdef WITH_THREAD
! 		    main_thread != PyThread_get_thread_ident()
! #endif
! 		    )
  			Sleep(ul_millis);
  		else {
  			DWORD rc;
=== modified file 'Modules/xxsubtype.c'
*** Modules/xxsubtype.c
--- Modules/xxsubtype.c
***************
*** 1,6 ****
--- 1,10 ----
  #include "Python.h"
  #include "structmember.h"
  
+ #ifndef CLOCKS_PER_SEC
+ #include <bits/time.h>
+ #endif
+ 
  PyDoc_STRVAR(xxsubtype__doc__,
  "xxsubtype is an example module showing how to subtype builtin types from C.\n"
  "test_descr.py in the standard test suite requires it in order to complete.\n"
=== modified file 'Python/dynload_win.c'
*** Python/dynload_win.c
--- Python/dynload_win.c
***************
*** 23,28 ****
--- 23,31 ----
  /* Case insensitive string compare, to avoid any dependencies on particular
     C RTL implementations */
  
+ #ifdef __MINGW32__
+ #define strcasecmp py_strcasecmp
+ #endif
  static int strcasecmp (char *string1, char *string2)
  { 
  	int first, second;
=== modified file 'Python/frozenmain.c'
*** Python/frozenmain.c
--- Python/frozenmain.c
***************
*** 3,9 ****
  
  #include "Python.h"
  
! #ifdef MS_WINDOWS
  extern void PyWinFreeze_ExeInit(void);
  extern void PyWinFreeze_ExeTerm(void);
  extern int PyInitFrozenExtensions(void);
--- 3,9 ----
  
  #include "Python.h"
  
! #if defined(MS_WINDOWS) && !defined(__MINGW32__)
  extern void PyWinFreeze_ExeInit(void);
  extern void PyWinFreeze_ExeTerm(void);
  extern int PyInitFrozenExtensions(void);
***************
*** 32,43 ****
  		setbuf(stderr, (char *)NULL);
  	}
  
! #ifdef MS_WINDOWS
  	PyInitFrozenExtensions();
  #endif /* MS_WINDOWS */
  	Py_SetProgramName(argv[0]);
  	Py_Initialize();
! #ifdef MS_WINDOWS
  	PyWinFreeze_ExeInit();
  #endif
  
--- 32,43 ----
  		setbuf(stderr, (char *)NULL);
  	}
  
! #if defined(MS_WINDOWS) && !defined(__MINGW32__)
  	PyInitFrozenExtensions();
  #endif /* MS_WINDOWS */
  	Py_SetProgramName(argv[0]);
  	Py_Initialize();
! #if defined(MS_WINDOWS) && !defined(__MINGW32__)
  	PyWinFreeze_ExeInit();
  #endif
  
***************
*** 60,66 ****
  	if (inspect && isatty((int)fileno(stdin)))
  		sts = PyRun_AnyFile(stdin, "<stdin>") != 0;
  
! #ifdef MS_WINDOWS
  	PyWinFreeze_ExeTerm();
  #endif
  	Py_Finalize();
--- 60,66 ----
  	if (inspect && isatty((int)fileno(stdin)))
  		sts = PyRun_AnyFile(stdin, "<stdin>") != 0;
  
! #if defined(MS_WINDOWS) && !defined(__MINGW32__)
  	PyWinFreeze_ExeTerm();
  #endif
  	Py_Finalize();
=== modified file 'configure.in'
*** configure.in
--- configure.in
***************
*** 253,258 ****
--- 253,275 ----
  fi
  AC_MSG_RESULT($EXTRAPLATDIR)
  
+ AC_MSG_CHECKING(posix flavour)
+ if test -z "$POSIX"
+ then
+ 	case $ac_sys_system/$ac_sys_release in
+ 	mingw*)
+ 		DELIM=';'
+ 		POSIX=nt
+ 		;;
+ 	*)
+ 		DELIM=':'
+ 		POSIX=posix
+  		;;
+ 	esac
+  fi	
+ AC_SUBST(DELIM)
+ AC_MSG_RESULT($POSIX)
+ 
  # Record the configure-time value of MACOSX_DEPLOYMENT_TARGET,
  # it may influence the way we can build extensions, so distutils
  # needs to check it
***************
*** 573,578 ****
--- 590,599 ----
            LDLIBRARY='libpython$(VERSION).dll.a'
            DLLLIBRARY='libpython$(VERSION).dll'
            ;;
+     mingw*)
+           LDLIBRARY='libpython$(VERSION).dll.a'
+           DLLLIBRARY='libpython$(VERSION).dll'
+           ;;
      SunOS*)
  	  LDLIBRARY='libpython$(VERSION).so'
  	  BLDLIBRARY='-Wl,-R,$(LIBDIR) -L. -lpython$(VERSION)'
***************
*** 1298,1303 ****
--- 1319,1325 ----
  	case $ac_sys_system in
  	hp*|HP*)   SO=.sl;;
  	CYGWIN*)   SO=.dll;;
+ 	mingw*)    SO=.dll;;
  	*)	   SO=.so;;
  	esac
  else
***************
*** 1399,1404 ****
--- 1421,1428 ----
  	SCO_SV*) LDSHARED='$(CC) -Wl,-G,-Bexport';;
  	Monterey*) LDSHARED="cc -G -dy -Bdynamic -Bexport -L/usr/lib/ia64l64";;
  	CYGWIN*) LDSHARED="gcc -shared -Wl,--enable-auto-image-base";;
+ 	mingw*) LDSHARED='$(CC) -mdll'
+  		BLDSHARED='$(CC) -mdll libpython$(VERSION).dll';;
  	atheos*) LDSHARED="gcc -shared";;
  	*)	LDSHARED="ld";;
  	esac
***************
*** 1488,1493 ****
--- 1512,1522 ----
  		then
  			LINKFORSHARED='-Wl,--out-implib=$(LDLIBRARY)'
  		fi;;
+ 	mingw*)
+ 		if test $enable_shared = "no"
+ 		then
+ 			LINKFORSHARED='-Wl,--out-implib=$(LDLIBRARY)'
+ 		fi;;
  	esac
  fi
  AC_MSG_RESULT($LINKFORSHARED)
***************
*** 2081,2086 ****
--- 2110,2116 ----
  	hp*|HP*) DYNLOADFILE="dynload_hpux.o";;
  	Darwin/*) DYNLOADFILE="dynload_next.o";;
  	atheos*) DYNLOADFILE="dynload_atheos.o";;
+ 	mingw*) DYNLOADFILE="dynload_win.o";;
  	*)
  	# use dynload_shlib.c and dlopen() if we have it; otherwise stub
  	# out any dynamic loading
***************
*** 2290,2295 ****
--- 2320,2327 ----
    )
  )
  
+ AC_CHECK_FUNCS(cwait fsync pipe popen spawnv system)
+ 
  AC_MSG_CHECKING(for major, minor, and makedev)
  AC_TRY_LINK([
  #if defined(MAJOR_IN_MKDEV)
***************
*** 3234,3240 ****
  echo "creating Setup"
  if test ! -f Modules/Setup
  then
! 	cp $srcdir/Modules/Setup.dist Modules/Setup
  fi
  
  echo "creating Setup.local"
--- 3266,3272 ----
  echo "creating Setup"
  if test ! -f Modules/Setup
  then
! 	sed -e "s/@POSIX@/$POSIX/" $srcdir/Modules/Setup.dist > Modules/Setup
  fi
  
  echo "creating Setup.local"

