Index: dist/src/Makefile.pre.in
===================================================================
RCS file: /cvsroot/python/python/dist/src/Makefile.pre.in,v
retrieving revision 1.148
diff -u -r1.148 Makefile.pre.in
--- dist/src/Makefile.pre.in	26 Sep 2004 17:26:55 -0000	1.148
+++ dist/src/Makefile.pre.in	13 Oct 2004 11:31:36 -0000
@@ -34,6 +34,8 @@
 AR=		@AR@
 RANLIB=		@RANLIB@
 
+CROSS_COMPILE=	@CROSS_COMPILE@
+
 # Shell used by make (some versions default to the login shell, which is bad)
 SHELL=		/bin/sh
 
@@ -56,7 +58,7 @@
 OPT=		@OPT@
 BASECFLAGS=	@BASECFLAGS@
 CFLAGS=		$(BASECFLAGS) $(OPT)
-CPPFLAGS=	-I. -I$(srcdir)/Include
+CPPFLAGS=	@CPPFLAGS@ -I. -I$(srcdir)/Include
 LDFLAGS=	@LDFLAGS@
 LDLAST=		@LDLAST@
 SGI_ABI=	@SGI_ABI@
@@ -161,7 +163,8 @@
 UNICODE_OBJS=   @UNICODE_OBJS@
 
 PYTHON=		python$(EXE)
-BUILDPYTHON=	python$(BUILDEXE)
+HOSTPYTHON=	python$(BUILDEXE)
+BUILDPYTHON=	@BUILDPYTHON@
 
 # === Definitions added by makesetup ===
 
@@ -187,7 +190,8 @@
 
 ##########################################################################
 # Parser
-PGEN=		Parser/pgen$(EXE)
+HOSTPGEN=	Parser/pgen$(EXE)
+BUILDPGEN=	@BUILDPGEN@
 
 POBJS=		\
 		Parser/acceler.o \
@@ -305,10 +309,10 @@
 # Rules
 
 # Default target
-all:		$(BUILDPYTHON) oldsharedmods sharedmods
+all:	crosscompile $(HOSTPYTHON) oldsharedmods sharedmods
 
 # Build the interpreter
-$(BUILDPYTHON):	Modules/$(MAINOBJ) $(LIBRARY) $(LDLIBRARY)
+$(HOSTPYTHON):	Modules/$(MAINOBJ) $(LIBRARY) $(LDLIBRARY)
 		$(LINKCC) $(LDFLAGS) $(LINKFORSHARED) -o $@ \
 			Modules/$(MAINOBJ) \
 			$(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST)
@@ -319,10 +323,12 @@
 
 # Build the shared modules
 sharedmods: $(BUILDPYTHON)
-	case $$MAKEFLAGS in \
-	*-s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py -q build;; \
-	*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py build;; \
-	esac
+	if test $(CROSS_COMPILE) != "yes"; then \
+	    case $$MAKEFLAGS in \
+	    *-s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py -q build;; \
+	    *) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py build;; \
+	    esac; \
+	fi
 
 # buildno should really depend on something like LIBRARY_SRC
 buildno: $(PARSER_OBJS) \
@@ -390,7 +396,7 @@
 $(DLLLIBRARY) libpython$(VERSION).dll.a: $(LIBRARY_OBJS)
 	if test -n "$(DLLLIBRARY)"; then \
 		$(LDSHARED) -Wl,--out-implib=$@ -o $(DLLLIBRARY) $^ \
-			$(LIBS) $(MODLIBS) $(SYSLIBS); \
+			$(LIBS) $(MODLIBS) $(SYSLIBS) $(SHLIBS); \
 	else true; \
 	fi
 
@@ -441,11 +447,11 @@
 	$(CXX) -c $(PY_CFLAGS) -o $@ $(srcdir)/Modules/ccpython.cc
 
 
-$(GRAMMAR_H) $(GRAMMAR_C): $(PGEN) $(GRAMMAR_INPUT)
-		-$(PGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
+$(GRAMMAR_H) $(GRAMMAR_C): $(BUILDPGEN) $(GRAMMAR_INPUT)
+	-$(BUILDPGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
 
-$(PGEN):	$(PGENOBJS)
-		$(CC) $(OPT) $(LDFLAGS) $(PGENOBJS) $(LIBS) -o $(PGEN)
+$(HOSTPGEN):	$(PGENOBJS)
+	$(CC) $(OPT) $(LDFLAGS) $(PGENOBJS) $(LIBS) -o $(HOSTPGEN)
 
 Parser/grammar.o:	$(srcdir)/Parser/grammar.c \
 				$(srcdir)/Include/token.h \
@@ -458,14 +464,21 @@
 Python/compile.o Python/symtable.o: $(GRAMMAR_H)
 
 Python/getplatform.o: $(srcdir)/Python/getplatform.c
-		$(CC) -c $(PY_CFLAGS) -DPLATFORM='"$(MACHDEP)"' -o $@ $(srcdir)/Python/getplatform.c
+	$(CC) -c $(PY_CFLAGS) -DPLATFORM='"$(MACHDEP)"' -o $@ $(srcdir)/Python/getplatform.c
 
 Python/importdl.o: $(srcdir)/Python/importdl.c
-		$(CC) -c $(PY_CFLAGS) -I$(DLINCLDIR) -o $@ $(srcdir)/Python/importdl.c
+	$(CC) -c $(PY_CFLAGS) -I$(DLINCLDIR) -o $@ $(srcdir)/Python/importdl.c
 
 Objects/unicodectype.o:	$(srcdir)/Objects/unicodectype.c \
 				$(srcdir)/Objects/unicodetype_db.h
 
+#########################################################################
+# Rules for making python/pgen that will run on the build system
+# (only used for cross compiles)
+
+crosscompile buildpython/python$(BUILDEXE) buildpython/Parser/pgen$(BUILDEXE):
+	if test -d buildpython; then $(MAKE) -C buildpython; fi
+
 ############################################################################
 # Header files
 
@@ -615,7 +628,7 @@
 		else	true; \
 		fi; \
 	done
-	$(INSTALL_PROGRAM) $(BUILDPYTHON) $(DESTDIR)$(BINDIR)/python$(VERSION)$(EXE)
+	$(INSTALL_PROGRAM) $(HOSTPYTHON) $(DESTDIR)$(BINDIR)/python$(VERSION)$(EXE)
 	if test -f libpython$(VERSION)$(SO); then \
 		if test "$(SO)" = .dll; then \
 			$(INSTALL_SHARED) libpython$(VERSION)$(SO) $(DESTDIR)$(BINDIR); \
@@ -825,8 +838,9 @@
 # Install the dynamically loadable modules
 # This goes into $(exec_prefix)
 sharedinstall:
-	$(RUNSHARED) ./$(BUILDPYTHON) -E $(srcdir)/setup.py install \
-	   	--prefix=$(prefix) \
+	CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' CROSS_COMPILE='$(CROSS_COMPILE)' \
+		$(RUNSHARED) ./$(BUILDPYTHON) -E $(srcdir)/setup.py install \
+		--prefix=$(prefix) \
 		--install-scripts=$(BINDIR) \
 		--install-platlib=$(DESTSHARED) \
 		--root=/$(DESTDIR)
@@ -914,7 +928,7 @@
 config.status:	$(srcdir)/configure
 	$(SHELL) $(srcdir)/configure $(CONFIG_ARGS)
 
-.PRECIOUS: config.status $(BUILDPYTHON) Makefile Makefile.pre
+.PRECIOUS: config.status $(HOSTPYTHON) Makefile Makefile.pre
 
 # Some make's put the object file in the current directory
 .c.o:
@@ -954,11 +968,12 @@
 	find $(srcdir) -name '*.py[co]' -exec rm -f {} ';'
 
 clobber: clean
-	-rm -f $(BUILDPYTHON) $(PGEN) $(LIBRARY) $(LDLIBRARY) $(DLLLIBRARY) \
+	-rm -f $(HOSTPYTHON) $(HOSTPGEN) $(LIBRARY) $(LDLIBRARY) $(DLLLIBRARY) \
 		tags TAGS \
 		config.cache config.log pyconfig.h Modules/config.c
 	-rm -rf build platform
 	-rm -rf $(PYTHONFRAMEWORKDIR)
+	-rm -rf buildpython
 
 # Make things extra clean, before making a distribution:
 # remove all generated files, even Makefile[.pre]
Index: dist/src/README
===================================================================
RCS file: /cvsroot/python/python/dist/src/README,v
retrieving revision 1.183
diff -u -r1.183 README
--- dist/src/README	2 Sep 2004 16:37:51 -0000	1.183
+++ dist/src/README	13 Oct 2004 11:31:37 -0000
@@ -1101,6 +1101,40 @@
 do this.
 
 
+Cross Compiling
+---------------
+
+Python can be cross compiled by supplying different --host and --build
+parameters to configure.  (Python is compiled on the "build" system
+and executed on the "host" system, in case you forgot :).  Python is
+tricky to cross compile because it needs to execute parts of itself
+during construction.  To work around this, make's VPATH feature is
+used to compile a native python in the subdirectory "buildpython".
+When parts of python need to be executed during construction, the
+"buildpython" versions are used.
+
+A consequence of using the VPATH feature is that you may not do a
+cross compile build in the source directory.  In other words, do this:
+
+mkdir mydir
+cd mydir
+../Python/configure --host=powerpc-405-linux-gnu --build=i686-pc-linux-gnu
+make
+
+Cross compiling works well under linux, mileage may vary for other
+platforms.
+
+A few reminders on using configure to cross compile:
+- Cross compile tools must be in the PATH.
+- Cross compile tools must be prefixed with the host type
+(ie powerpc-405-linux-gnu-cc, powerpc-405-linux-gnu-ranlib, ...)
+- CC, CXX, AR, and RANLIB must be undefined when running configure and
+make.  Configure will detect them.
+
+If you need a cross compiler, check out Dan Kegel's crosstool:
+http://www.kegel.com/crosstool
+
+
 Miscellaneous issues
 ====================
 
Index: dist/src/configure
===================================================================
RCS file: /cvsroot/python/python/dist/src/configure,v
retrieving revision 1.458
--- dist/src/configure.in	18 Sep 2004 10:07:03 -0000	1.471
+++ dist/src/configure.in	13 Oct 2004 11:31:38 -0000
@@ -9,6 +9,12 @@
 AC_CONFIG_SRCDIR([Include/object.h])
 AC_CONFIG_HEADER(pyconfig.h)
 
+# find compiler while respecting --host setting
+AC_CANONICAL_HOST
+AC_CANONICAL_TARGET
+AC_CHECK_TOOLS(CC,gcc cc)
+AC_CHECK_TOOLS(CXX,g++ c++)
+
 dnl This is for stuff that absolutely must end up in pyconfig.h.
 dnl Please use pyport.h instead, if possible.
 AH_TOP([
@@ -104,28 +110,34 @@
 AC_MSG_CHECKING(MACHDEP)
 if test -z "$MACHDEP"
 then
+    if test "$cross_compiling" = "yes"
+    then
+        ac_sys_system="$host_os"
+        ac_sys_release=''
+    else
 	ac_sys_system=`uname -s`
-	if test "$ac_sys_system" = "AIX" -o "$ac_sys_system" = "Monterey64" \
-	-o "$ac_sys_system" = "UnixWare" -o "$ac_sys_system" = "OpenUNIX"; then
-		ac_sys_release=`uname -v`
-	else
-		ac_sys_release=`uname -r`
-	fi
-	ac_md_system=`echo $ac_sys_system |
-			   tr -d '[/ ]' | tr '[[A-Z]]' '[[a-z]]'`
-	ac_md_release=`echo $ac_sys_release |
-			   tr -d '[/ ]' | sed 's/^[[A-Z]]\.//' | sed 's/\..*//'`
-	MACHDEP="$ac_md_system$ac_md_release"
-
-	case $MACHDEP in
-	cygwin*) MACHDEP="cygwin";;
-	darwin*) MACHDEP="darwin";;
-	atheos*) MACHDEP="atheos";;
-        irix646) MACHDEP="irix6";;
-	'')	MACHDEP="unknown";;
-	esac
+        if test "$ac_sys_system" = "AIX" -o "$ac_sys_system" = "Monterey64" \
+           -o "$ac_sys_system" = "UnixWare" -o "$ac_sys_system" = "OpenUNIX"
+        then
+	    ac_sys_release=`uname -v`
+        else
+	    ac_sys_release=`uname -r`
+        fi
+    fi
+    ac_md_system=`echo $ac_sys_system tr -d '[/ ]' | tr '[[A-Z]]' '[[a-z]]'`
+    ac_md_release=`echo $ac_sys_release tr -d '[/ ]' | sed 's/^[[A-Z]]\.//' | sed 's/\..*//'`
+    MACHDEP="$ac_md_system$ac_md_release"
+
+    case $MACHDEP in
+    mingw32*) MACHDEP="win32";;
+    cygwin*) MACHDEP="cygwin";;
+    darwin*) MACHDEP="darwin";;
+    atheos*) MACHDEP="atheos";;
+    irix646) MACHDEP="irix6";;
+    '')	MACHDEP="unknown";;
+    esac
 fi
-	
+
 # Some systems cannot stand _XOPEN_SOURCE being defined at all; they
 # disable features if it is defined, without any means to access these
 # features as extensions. For these systems, we skip the definition of
@@ -389,8 +401,15 @@
     AC_MSG_RESULT(yes)
     BUILDEXEEXT=.exe
 else
-	AC_MSG_RESULT(no)
-	BUILDEXEEXT=$EXEEXT
+    AC_MSG_RESULT(no)
+    case "$build" in
+    *-*-mingw32*)
+        BUILDEXEEXT=".exe"
+        ;;
+    *)
+        BUILDEXEEXT="$EXEEXT"
+        ;;
+    esac
 fi
 rmdir CaseSensitiveTestDir
 
@@ -513,7 +532,8 @@
    ac_enable_profiling="yes",
    ac_enable_profiling="no",
    ac_enable_profiling="no")
- CC="$ac_save_cc"])
+ CC="$ac_save_cc"],
+ ac_enable_profiling="no")
 AC_MSG_RESULT($ac_enable_profiling)
 
 case "$ac_enable_profiling" in
@@ -578,6 +598,12 @@
 	  BLDLIBRARY='-L. -lpython$(VERSION)'
 	  RUNSHARED=DLL_PATH=`pwd`:${DLL_PATH:-/atheos/sys/libs:/atheos/autolnk/lib}
 	  ;;
+    mingw32*)
+	  AC_SUBST(PY_WIN32_DLL_VERSION)
+	  PY_WIN32_DLL_VERSION=`echo $VERSION | sed -e 's/\.//g'`
+	  LDLIBRARY='libpython$(VERSION).dll.a'
+	  DLLLIBRARY='python@PY_WIN32_DLL_VERSION@.dll'
+	  ;;
   esac
 else # shared is disabled
   case $ac_sys_system in
@@ -590,9 +616,9 @@
 
 AC_MSG_RESULT($LDLIBRARY)
 
-AC_PROG_RANLIB
-AC_SUBST(AR)
-AC_CHECK_PROGS(AR, ar aal, ar)
+# find tools while respecting --host setting
+AC_CHECK_TOOL(RANLIB,ranlib)
+AC_CHECK_TOOLS(AR,ar aal,ar)
 
 case $MACHDEP in
 bsdos*|hp*|HP*)
@@ -617,6 +643,7 @@
 
 # Check for --with-pydebug
 AC_MSG_CHECKING(for --with-pydebug)
+AC_SUBST(Py_DEBUG)
 AC_ARG_WITH(pydebug, 
             AC_HELP_STRING(--with-pydebug, build with Py_DEBUG defined),
 [
@@ -628,7 +655,8 @@
   Py_DEBUG='true'
 else AC_MSG_RESULT(no); Py_DEBUG='false'
 fi],
-[AC_MSG_RESULT(no)])
+[AC_MSG_RESULT(no)
+ Py_DEBUG='false'])
 
 # XXX Shouldn't the code above that fiddles with BASECFLAGS and OPT be
 # merged with this chunk of code?
@@ -695,9 +723,8 @@
     AC_MSG_CHECKING(whether $CC accepts -fno-strict-aliasing)
      ac_save_cc="$CC"
      CC="$CC -fno-strict-aliasing"
-     AC_TRY_RUN([int main() { return 0; }],
+     AC_TRY_COMPILE([], [],
      ac_cv_no_strict_aliasing_ok=yes,
-     ac_cv_no_strict_aliasing_ok=no,
      ac_cv_no_strict_aliasing_ok=no)
      CC="$ac_save_cc"
     AC_MSG_RESULT($ac_cv_no_strict_aliasing_ok)
@@ -746,9 +773,8 @@
 AC_CACHE_VAL(ac_cv_opt_olimit_ok,
 [ac_save_cc="$CC"
 CC="$CC -OPT:Olimit=0"
-AC_TRY_RUN([int main() { return 0; }],
+AC_TRY_COMPILE([], [],
   ac_cv_opt_olimit_ok=yes,
-  ac_cv_opt_olimit_ok=no,
   ac_cv_opt_olimit_ok=no)
 CC="$ac_save_cc"])
 AC_MSG_RESULT($ac_cv_opt_olimit_ok)
@@ -768,9 +794,8 @@
   AC_CACHE_VAL(ac_cv_olimit_ok,
   [ac_save_cc="$CC"
   CC="$CC -Olimit 1500"
-  AC_TRY_RUN([int main() { return 0; }],
+  AC_TRY_COMPILE([], [],
     ac_cv_olimit_ok=yes,
-    ac_cv_olimit_ok=no,
     ac_cv_olimit_ok=no)
   CC="$ac_save_cc"])
   AC_MSG_RESULT($ac_cv_olimit_ok)
@@ -905,6 +930,20 @@
 AC_MSG_RESULT($ac_cv_pthread)
 fi
 
+if test x"$ac_cv_pthread" = x"no" && test x"$ac_cv_pthread_is_default" = x"no"
+then
+	AC_MSG_CHECKING(for win32 threads)
+	AC_CACHE_VAL(ac_nt_thread,
+		[AC_TRY_LINK(
+			[
+#include <process.h>
+			],
+			[_beginthread(0, 0, 0);],
+			ac_nt_thread=yes,
+			ac_nt_thread=no)])
+	AC_MSG_RESULT($ac_nt_thread)
+fi
+
 # If we have set a CC compiler flag for thread support then
 # check if it works for CXX, too.
 ac_cv_cxx_thread=no
@@ -925,9 +964,12 @@
 then 
   CXX="$CXX -pthread"
   ac_cv_cxx_thread=yes
+elif test x"$ac_nt_thread" = x"yes"
+then
+  ac_cv_cxx_thread="none needed"
 fi
 
-if test $ac_cv_cxx_thread = yes
+if test x"$ac_cv_cxx_thread" = x"yes"
 then
   echo 'void foo();int main(){foo();}void foo(){}' > conftest.$ac_ext
   $CXX -c conftest.$ac_ext 2>&5
@@ -961,11 +1003,12 @@
 unistd.h utime.h \
 sys/audioio.h sys/bsdtty.h sys/file.h sys/lock.h sys/mkdev.h sys/modem.h \
 sys/param.h sys/poll.h sys/select.h sys/socket.h sys/time.h sys/times.h \
-sys/un.h sys/utsname.h sys/wait.h pty.h libutil.h \
-sys/resource.h netpacket/packet.h sysexits.h bluetooth.h \
+sys/un.h sys/utsname.h sys/wait.h sys/types.h pty.h libutil.h \
+sys/resource.h netpacket/packet.h sysexits.h winsock2.h bluetooth.h \
 bluetooth/bluetooth.h)
 AC_HEADER_DIRENT
 AC_HEADER_MAJOR
+AC_HEADER_TIME
 
 # On Solaris, term.h requires curses.h
 AC_CHECK_HEADER(term.h,,,[
@@ -1081,25 +1124,7 @@
 AC_CHECK_SIZEOF(uintptr_t, 4)
 fi
 
-# Hmph. AC_CHECK_SIZEOF() doesn't include <sys/types.h>.
-AC_MSG_CHECKING(size of off_t)
-AC_CACHE_VAL(ac_cv_sizeof_off_t,
-[AC_TRY_RUN([#include <stdio.h>
-#include <sys/types.h>
-main()
-{
-  FILE *f=fopen("conftestval", "w");
-  if (!f) exit(1);
-  fprintf(f, "%d\n", sizeof(off_t));
-  exit(0);
-}],
-ac_cv_sizeof_off_t=`cat conftestval`,
-ac_cv_sizeof_off_t=0,
-ac_cv_sizeof_off_t=4)
-])
-AC_MSG_RESULT($ac_cv_sizeof_off_t)
-AC_DEFINE_UNQUOTED(SIZEOF_OFF_T, $ac_cv_sizeof_off_t,
-[The number of bytes in an off_t.])
+AC_CHECK_SIZEOF(off_t, 4)
 
 AC_MSG_CHECKING(whether to enable large file support)
 if test "$have_long_long" = yes -a \
@@ -1115,25 +1140,19 @@
   AC_MSG_RESULT(no)
 fi
 
-# AC_CHECK_SIZEOF() doesn't include <time.h>.
-AC_MSG_CHECKING(size of time_t)
-AC_CACHE_VAL(ac_cv_sizeof_time_t,
-[AC_TRY_RUN([#include <stdio.h>
-#include <time.h>
-main()
-{
-  FILE *f=fopen("conftestval", "w");
-  if (!f) exit(1);
-  fprintf(f, "%d\n", sizeof(time_t));
-  exit(0);
-}],
-ac_cv_sizeof_time_t=`cat conftestval`,
-ac_cv_sizeof_time_t=0,
-ac_cv_sizeof_time_t=4)
-])
-AC_MSG_RESULT($ac_cv_sizeof_time_t)
-AC_DEFINE_UNQUOTED(SIZEOF_TIME_T, $ac_cv_sizeof_time_t, 
-[The number of bytes in a time_t.])
+AC_CHECK_SIZEOF(time_t, 4,
+		[$ac_includes_default
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+		])
 
 
 # if have pthread_t then define SIZEOF_PTHREAD_T
@@ -1257,6 +1276,7 @@
 	case $ac_sys_system in
 	hp*|HP*)   SO=.sl;;
 	CYGWIN*)   SO=.dll;;
+	mingw32*)  SO=.dll;;
 	*)	   SO=.so;;
 	esac
 else
@@ -1357,6 +1377,7 @@
 	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";;
+	mingw32*) LDSHARED='$(CC) -mwindows -mconsole -shared -Wl,--enable-auto-image-base';;
 	atheos*) LDSHARED="gcc -shared";;
 	*)	LDSHARED="ld";;
 	esac
@@ -1478,8 +1499,8 @@
 AC_SUBST(SHLIBS)
 AC_MSG_CHECKING(SHLIBS)
 case "$ac_sys_system" in
-	*)
-		SHLIBS='$(LIBS)';;
+     mingw32*) SHLIBS='$(LIBS) -lwinmm';;
+     *) SHLIBS='$(LIBS)';;
 esac
 AC_MSG_RESULT($SHLIBS)
 
@@ -1631,6 +1652,13 @@
     AC_DEFINE(WITH_THREAD)
     posix_threads=yes
     THREADOBJ="Python/thread.o"
+elif test x"$ac_nt_thread" = x"yes"
+then
+    AC_DEFINE(WITH_THREAD)
+    AC_DEFINE(NT_THREADS, 1,
+	[Define to 1 if you want to use native win32 threads])
+    posix_threads=no
+    THREADOBJ="Python/thread.o"
 else
     if test ! -z "$with_threads" -a -d "$with_threads"
     then LDFLAGS="$LDFLAGS -L$with_threads"
@@ -2041,6 +2069,7 @@
 	hp*|HP*) DYNLOADFILE="dynload_hpux.o";;
 	Darwin/*) DYNLOADFILE="dynload_next.o";;
 	atheos*) DYNLOADFILE="dynload_atheos.o";;
+	mingw32*) DYNLOADFILE="dynload_win.o";;
 	*)
 	# use dynload_shlib.c and dlopen() if we have it; otherwise stub
 	# out any dynamic loading
@@ -2062,13 +2091,21 @@
 
 AC_SUBST(MACHDEP_OBJS)
 AC_MSG_CHECKING(MACHDEP_OBJS)
+
+case "$ac_sys_system" in
+     mingw32*) extra_machdep_objs="PC/dl_nt.o PC/getpathp.o PC/import_nt.o"
+	       CPPFLAGS="-I\$(srcdir)/Python"
+	       POSIXMODULE_NAME=nt
+	       ;;
+esac
+
 if test -z "$MACHDEP_OBJS"
 then
 	MACHDEP_OBJS=$extra_machdep_objs
 else
 	MACHDEP_OBJS="$MACHDEP_OBJS $extra_machdep_objs"
 fi
-AC_MSG_RESULT(MACHDEP_OBJS)
+AC_MSG_RESULT($MACHDEP_OBJS)
 
 # checks for library functions
 AC_CHECK_FUNCS(alarm bind_textdomain_codeset chown clock confstr ctermid \
@@ -2391,7 +2428,6 @@
 AC_CHECK_FUNCS(getnameinfo)
 
 # checks for structures
-AC_HEADER_TIME
 AC_STRUCT_TM
 AC_STRUCT_TIMEZONE
 AC_CHECK_MEMBERS([struct stat.st_rdev])
@@ -2428,10 +2464,19 @@
 #		include <netdb.h>],
 	[struct addrinfo a],
 	ac_cv_struct_addrinfo=yes,
-	ac_cv_struct_addrinfo=no))
+	AC_TRY_COMPILE([
+#		ifdef HAVE_WINSOCK2_H
+#		include <ws2tcpip.h>
+#		else
+#		include <winsock.h>
+#		endif],
+	[struct addrinfo a],
+	ac_cv_struct_addrinfo=yes,
+	ac_cv_struct_addrinfo=no)
+))
 AC_MSG_RESULT($ac_cv_struct_addrinfo)
 if test $ac_cv_struct_addrinfo = yes; then
-	AC_DEFINE(HAVE_ADDRINFO, 1, [struct addrinfo (netdb.h)])
+	AC_DEFINE(HAVE_ADDRINFO, 1, [struct addrinfo])
 fi
 
 AC_MSG_CHECKING(for sockaddr_storage)
@@ -2441,7 +2486,14 @@
 #		include <sys/socket.h>],
 	[struct sockaddr_storage s],
 	ac_cv_struct_sockaddr_storage=yes,
-	ac_cv_struct_sockaddr_storage=no))
+	AC_TRY_COMPILE([#		ifdef HAVE_WINSOCK2_H
+#		include <winsock2.h>
+#		else
+#		include <winsock.h>
+#		endif],
+		[struct sockaddr_storage s],
+		[ac_cv_struct_sockaddr_storage=yes],
+		[ac_cv_struct_sockaddr_storage=no])))
 AC_MSG_RESULT($ac_cv_struct_sockaddr_storage)
 if test $ac_cv_struct_sockaddr_storage = yes; then
 	AC_DEFINE(HAVE_SOCKADDR_STORAGE, 1, [struct sockaddr_storage (sys/socket.h)])
@@ -2451,6 +2503,8 @@
 
 AC_C_CHAR_UNSIGNED
 AC_C_CONST
+# needed for expat when cross-compiling
+AC_C_BIGENDIAN
 
 works=no
 AC_MSG_CHECKING(for working volatile)
@@ -2838,14 +2892,24 @@
 fi
 
 # check for readline 4.0
-AC_CHECK_LIB(readline, rl_pre_input_hook,
-	AC_DEFINE(HAVE_RL_PRE_INPUT_HOOK, 1,
-        [Define if you have readline 4.0]), , -ltermcap)
+if test $have_readline = yes; then
+   AC_MSG_CHECKING(for rl_pre_input_hook in -lreadline)
+   AC_COMPILE_IFELSE([AC_LANG_SOURCE([[readline/readline.h]],
+		[[rl_pre_input_hook = 0]])],
+	[AC_DEFINE(HAVE_RL_PRE_INPUT_HOOK, 1, [Define if you have readline 4.0])]
+					   AC_MSG_RESULT(yes),
+	[AC_MSG_RESULT(no)])
+fi
 
 # check for readline 4.2
-AC_CHECK_LIB(readline, rl_completion_matches,
-	AC_DEFINE(HAVE_RL_COMPLETION_MATCHES, 1,
-        [Define if you have readline 4.2]), , -ltermcap)
+if test $have_readline = yes; then
+   AC_MSG_CHECKING(for rl_completion_matches in -lreadline)
+   AC_COMPILE_IFELSE([AC_LANG_SOURCE([[readline/readline.h]],
+		[[rl_completion_matches(0, 0)]])],
+	[AC_DEFINE(HAVE_RL_COMPLETION_MATCHES, 1, [Define if you have readline 4.2])]
+					       AC_MSG_RESULT(yes),
+	[AC_MSG_RESULT(no)])
+fi
 
 # also in readline 4.2
 AC_TRY_CPP([#include <readline/readline.h>],
@@ -3019,28 +3083,38 @@
   [Define if WINDOW in curses.h offers a field _flags.])
 fi
 
-AC_MSG_CHECKING(for /dev/ptmx)
+dnl Note for the "-e" file existance tests:
+dnl if building for another target host we cannot check the local
+dnl filesystem for /dev/* files. Just disable the feature in this case.
 
-if test -e /dev/ptmx
+if test x"$cross_compiling" = x"no"
 then
-  AC_MSG_RESULT(yes)
-  AC_DEFINE(HAVE_DEV_PTMX, 1,
-  [Define if we have /dev/ptmx.])
-else
-  AC_MSG_RESULT(no)
-fi
+  AC_MSG_CHECKING(for /dev/ptmx)
 
-AC_MSG_CHECKING(for /dev/ptc)
+  if test -e /dev/ptmx
+  then
+    AC_MSG_RESULT(yes)
+    AC_DEFINE(HAVE_DEV_PTMX, 1,
+    [Define if we have /dev/ptmx.])
+  else
+    AC_MSG_RESULT(no)
+  fi
 
-if test -e /dev/ptc
-then
-  AC_MSG_RESULT(yes)
-  AC_DEFINE(HAVE_DEV_PTC, 1,
-  [Define if we have /dev/ptc.])
+  AC_MSG_CHECKING(for /dev/ptc)
+
+  if test -e /dev/ptc
+  then
+    AC_MSG_RESULT(yes)
+    AC_DEFINE(HAVE_DEV_PTC, 1,
+    [Define if we have /dev/ptc.])
+  else
+    AC_MSG_RESULT(no)
+  fi
 else
-  AC_MSG_RESULT(no)
+  AC_MSG_WARN(Crosscompile:  you may loose PTY support on target.)
 fi
 
+
 AC_CHECK_TYPE(socklen_t,,
   AC_DEFINE(socklen_t,int,
             Define to `int' if <sys/socket.h> does not define.),[
@@ -3052,6 +3126,26 @@
 #endif
 ])
 
+AC_CACHE_CHECK([for function strcasecmp],
+	[py_cv_function_strcasecmp],
+	[AC_TRY_COMPILE([$ac_includes_default],
+		[strcasecmp(0, 0)],
+		[py_cv_function_strcasecmp=yes],
+		[py_cv_function_strcasecmp=no])])
+if test x"$py_cv_function_strcasecmp" = x"yes"; then
+   AC_DEFINE(HAVE_STRCASECMP, 1,
+	[Define to 1 if you have the 'srcasecmp' function.])
+fi
+
+# mingw32 doesn't have this macro
+AC_MSG_CHECKING(for REG_LEGAL_CHANGE_FILTER in windows.h)
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([[windows.h]],
+		[[int i = REG_LEGAL_CHANGE_FILTER]])],
+	[AC_DEFINE(HAVE_REG_LEGAL_CHANGE_FILTER, 1,
+		[Define to 1 if you have the 'REG_LEGAL_CHANGE_FILTER' macro.])
+	 AC_MSG_RESULT(yes)],
+	[AC_MSG_RESULT(no)])
+
 AC_SUBST(THREADHEADERS)
 
 for h in `(cd $srcdir;echo Python/thread_*.h)`
@@ -3060,7 +3154,7 @@
 done
 
 AC_SUBST(SRCDIRS)
-SRCDIRS="Parser Grammar Objects Python Modules Mac Mac/Python"
+SRCDIRS="Parser Grammar Objects Python Modules Mac Mac/Python PC"
 AC_MSG_CHECKING(for build directories)
 for dir in $SRCDIRS; do
     if test ! -d $dir; then
@@ -3069,17 +3163,47 @@
 done
 AC_MSG_RESULT(done)
 
+if test "$cross_compiling" = "yes"
+then
+    AC_MSG_NOTICE(cross compiling: configuring build python)
+    absconfigcommand=$(pwd)/$0
+    mkdir -p buildpython/Modules
+    cd buildpython
+    CC="" CXX="" AR="" RANLIB="" $absconfigcommand --prefix=$prefix
+    cd ..
+    BUILDPYTHON='buildpython/python$(BUILDEXE)'
+    BUILDPGEN='buildpython/Parser/pgen$(BUILDEXE)'
+    CROSS_COMPILE="yes"
+    case "$host" in
+    *-*-mingw32*)
+        AC_DEFINE_UNQUOTED(MS_WINDOWS,1, [Building for Windows NT])
+        POSIXMODULE_NAME="nt"
+        ;;
+    esac
+else
+    BUILDPYTHON='$(HOSTPYTHON)'
+    BUILDPGEN='$(HOSTPGEN)'
+    CROSS_COMPILE="no"
+fi
+AC_SUBST(BUILDPYTHON)
+AC_SUBST(BUILDPGEN)
+AC_SUBST(CROSS_COMPILE)
+if test -z "$POSIXMODULE_NAME"; then
+   POSIXMODULE_NAME="posix"
+fi
+AC_SUBST(POSIXMODULE_NAME)
+
 # generate output files
 AC_CONFIG_FILES(Makefile.pre Modules/Setup.config)
 AC_OUTPUT
 
-echo "creating Setup"
+echo "creating Modules/Setup"
 if test ! -f Modules/Setup
 then
 	cp $srcdir/Modules/Setup.dist Modules/Setup
 fi
 
-echo "creating Setup.local"
+echo "creating Modules/Setup.local"
 if test ! -f Modules/Setup.local
 then
 	echo "# Edit this file for local setup changes" >Modules/Setup.local
Index: dist/src/pyconfig.h.in
===================================================================
RCS file: /cvsroot/python/python/dist/src/pyconfig.h.in,v
retrieving revision 1.104
diff -u -r1.104 pyconfig.h.in
--- dist/src/pyconfig.h.in	18 Sep 2004 09:54:52 -0000	1.104
+++ dist/src/pyconfig.h.in	13 Oct 2004 11:31:38 -0000
@@ -28,7 +28,7 @@
    the case on Motorola V4 (R40V4.2) */
 #undef GETTIMEOFDAY_NO_TZ
 
-/* struct addrinfo (netdb.h) */
+/* struct addrinfo */
 #undef HAVE_ADDRINFO
 
 /* Define to 1 if you have the `alarm' function. */
@@ -365,6 +365,9 @@
 /* Define to 1 if you have the `realpath' function. */
 #undef HAVE_REALPATH
 
+/* Define to 1 if you have the 'REG_LEGAL_CHANGE_FILTER' macro. */
+#undef HAVE_REG_LEGAL_CHANGE_FILTER
+
 /* Define if you have readline 2.1 */
 #undef HAVE_RL_CALLBACK
 
@@ -456,6 +459,9 @@
 /* Define to 1 if you have the <stdlib.h> header file. */
 #undef HAVE_STDLIB_H
 
+/* Define to 1 if you have the 'srcasecmp' function. */
+#undef HAVE_STRCASECMP
+
 /* Define to 1 if you have the `strdup' function. */
 #undef HAVE_STRDUP
 
@@ -573,9 +579,6 @@
 /* Define to 1 if you have the <termios.h> header file. */
 #undef HAVE_TERMIOS_H
 
-/* Define to 1 if you have the <term.h> header file. */
-#undef HAVE_TERM_H
-
 /* Define to 1 if you have the <thread.h> header file. */
 #undef HAVE_THREAD_H
 
@@ -640,6 +643,9 @@
 /* Define to 1 if you have the `wcscoll' function. */
 #undef HAVE_WCSCOLL
 
+/* Define to 1 if you have the <winsock2.h> header file. */
+#undef HAVE_WINSOCK2_H
+
 /* Define if tzset() actually switches the local timezone in a meaningful way.
    */
 #undef HAVE_WORKING_TZSET
@@ -661,9 +667,15 @@
    <sysmacros.h>. */
 #undef MAJOR_IN_SYSMACROS
 
+/* Building for Windows NT */
+#undef MS_WINDOWS
+
 /* Define if mvwdelch in curses.h is an expression. */
 #undef MVWDELCH_IS_EXPRESSION
 
+/* Define to 1 if you want to use native win32 threads */
+#undef NT_THREADS
+
 /* Define to the address where bug reports for this package should be sent. */
 #undef PACKAGE_BUGREPORT
 
@@ -724,7 +736,7 @@
 /* The size of a `long long', as computed by sizeof. */
 #undef SIZEOF_LONG_LONG
 
-/* The number of bytes in an off_t. */
+/* The size of a `off_t', as computed by sizeof. */
 #undef SIZEOF_OFF_T
 
 /* The number of bytes in a pthread_t. */
@@ -733,7 +745,7 @@
 /* The size of a `short', as computed by sizeof. */
 #undef SIZEOF_SHORT
 
-/* The number of bytes in a time_t. */
+/* The size of a `time_t', as computed by sizeof. */
 #undef SIZEOF_TIME_T
 
 /* The size of a `uintptr_t', as computed by sizeof. */
Index: dist/src/setup.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/setup.py,v
retrieving revision 1.202
diff -u -r1.202 setup.py
--- dist/src/setup.py	28 Sep 2004 03:49:52 -0000	1.202
+++ dist/src/setup.py	13 Oct 2004 11:31:38 -0000
@@ -201,6 +201,10 @@
             self.announce('WARNING: skipping import check for Cygwin-based "%s"'
                 % ext.name)
             return
+        if os.environ.get('CROSS_COMPILE') == 'yes':    
+            self.announce('WARNING: skipping import check for cross compiled "%s"'
+                % ext.name)
+            return
         ext_filename = os.path.join(
             self.build_lib,
             self.get_ext_filename(self.get_ext_fullname(ext.name)))
Index: dist/src/Include/pyport.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Include/pyport.h,v
retrieving revision 2.70
diff -u -r2.70 pyport.h
--- dist/src/Include/pyport.h	23 Sep 2004 19:11:21 -0000	2.70
+++ dist/src/Include/pyport.h	13 Oct 2004 11:31:39 -0000
@@ -65,6 +65,11 @@
  * without loss of information.  Similarly for intptr_t, wrt a signed
  * integral type.
  */
+
+#ifdef HAVE_INTTYPES_H       /* needed for uintptr_t (at least by mingw32) */
+#include <inttypes.h>
+#endif  /* HAVE_INTTYPES_H */
+
 #ifdef HAVE_UINTPTR_T
 typedef uintptr_t	Py_uintptr_t;
 typedef intptr_t	Py_intptr_t;
@@ -399,6 +404,42 @@
 #endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) */
 
 
+#if defined(__MINGW32__)
+#define MS_WIN32 1
+#define MS_WINDOWS 1
+#ifndef PYTHONPATH
+#	define PYTHONPATH ".\\DLLs;.\\lib;.\\lib\\plat-win;.\\lib\\lib-tk"
+#endif
+
+#include <basetsd.h>
+
+#if defined(Py_ENABLE_SHARED)
+#define MS_COREDLL 1
+#else  /* Py_ENABLE_SHARED */
+#define MS_NO_COREDLL 1
+#endif  /* Py_ENABLE_SHARED */
+
+#define HAVE_LARGEFILE_SUPPORT 1
+
+#if Py_UNICODE_SIZE == 2
+#define Py_WIN_WIDE_FILENAMES
+#endif
+
+#define SIZEOF_HKEY 4		/* XXX is mingw 64bit capable? */
+#define HAVE_TZNAME 1		/* no tests in configure.in */
+
+/* XXX ugly but hard to do in configure.in */
+#define HAVE_GETPEERNAME 1
+#if defined(HAVE_WINSOCK2_H)
+# define HAVE_GETADDRINFO 1
+# define HAVE_GETNAMEINFO 1
+# define ENABLE_IPV6 1
+#endif  /* HAVE_WINSOCK2_H */
+
+
+#endif  /* __MINGW32__ */
+
+
 /* These are pulled from various places. It isn't obvious on what platforms
    they are necessary, nor what the exact prototype should look like (which
    is likely to vary between platforms!) If you find you need one of these
@@ -478,7 +519,7 @@
   BeOS and cygwin are the only other autoconf platform requiring special
   linkage handling and both of these use __declspec().
 */
-#if defined(__CYGWIN__) || defined(__BEOS__)
+#if defined(__CYGWIN__) || defined(__BEOS__) || defined(__MINGW32__)
 #	define HAVE_DECLSPEC_DLL
 #endif
 
@@ -500,7 +541,7 @@
 			/* 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__)
+#			if !defined(__CYGWIN__) && !defined(__MINGW32__)
 #				define PyAPI_FUNC(RTYPE) __declspec(dllimport) RTYPE
 #			endif /* !__CYGWIN__ */
 #			define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE
Index: dist/src/Modules/Setup.config.in
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/Setup.config.in,v
retrieving revision 1.12
diff -u -r1.12 Setup.config.in
--- dist/src/Modules/Setup.config.in	12 Dec 2002 17:37:50 -0000	1.12
+++ dist/src/Modules/Setup.config.in	13 Oct 2004 11:31:39 -0000
@@ -11,3 +11,7 @@
 
 # The rest of the modules previously listed in this file are built
 # by the setup.py script in Python 2.1 and later.
+
+# The posix module
+@POSIXMODULE_NAME@ posixmodule.c
+
Index: dist/src/Modules/Setup.dist
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/Setup.dist,v
retrieving revision 1.48
diff -u -r1.48 Setup.dist
--- dist/src/Modules/Setup.dist	31 Aug 2004 13:50:12 -0000	1.48
+++ dist/src/Modules/Setup.dist	13 Oct 2004 11:31:39 -0000
@@ -109,7 +109,7 @@
 # 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
+# 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
Index: dist/src/Modules/_hotshot.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_hotshot.c,v
retrieving revision 1.37
diff -u -r1.37 _hotshot.c
--- dist/src/Modules/_hotshot.c	3 Aug 2004 08:33:55 -0000	1.37
+++ dist/src/Modules/_hotshot.c	13 Oct 2004 11:31:40 -0000
@@ -911,7 +911,7 @@
 /* A couple of useful helper functions. */
 
 #ifdef MS_WINDOWS
-static LARGE_INTEGER frequency = {0, 0};
+static LARGE_INTEGER frequency = {{0, 0}};
 #endif
 
 static unsigned long timeofday_diff = 0;
Index: dist/src/Modules/fpectlmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/fpectlmodule.c,v
retrieving revision 2.19
diff -u -r2.19 fpectlmodule.c
--- dist/src/Modules/fpectlmodule.c	3 May 2003 09:14:53 -0000	2.19
+++ dist/src/Modules/fpectlmodule.c	13 Oct 2004 11:31:40 -0000
@@ -224,7 +224,7 @@
     PyOS_setsig(SIGFPE, handler);
 
 /*-- Microsoft Windows, NT ------------------------------------------------*/
-#elif defined(_MSC_VER)
+#elif defined(_MSC_VER) || defined(__MINGW32__)
     /* Reference: Visual C++ Books Online 4.2,
        Run-Time Library Reference, _control87, _controlfp */
 #include <float.h>
Index: dist/src/Modules/mathmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/mathmodule.c,v
retrieving revision 2.74
diff -u -r2.74 mathmodule.c
--- dist/src/Modules/mathmodule.c	22 Mar 2004 08:43:55 -0000	2.74
+++ dist/src/Modules/mathmodule.c	13 Oct 2004 11:31:40 -0000
@@ -3,14 +3,14 @@
 #include "Python.h"
 #include "longintrepr.h"
 
-#ifndef _MSC_VER
+#if !defined(_MSC_VER) && !defined(__MINGW32__)
 #ifndef __STDC__
 extern double fmod (double, double);
 extern double frexp (double, int *);
 extern double ldexp (double, int);
 extern double modf (double, double *);
 #endif /* __STDC__ */
-#endif /* _MSC_VER */
+#endif /* _MSC_VER/__MINGW32__ */
 
 /* Call is_error when errno != 0, and where x is the result libm
  * returned.  is_error will usually set up an exception and return
Index: dist/src/Modules/posixmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/posixmodule.c,v
retrieving revision 2.327
diff -u -r2.327 posixmodule.c
--- dist/src/Modules/posixmodule.c	27 Sep 2004 19:54:33 -0000	2.327
+++ dist/src/Modules/posixmodule.c	13 Oct 2004 11:31:41 -0000
@@ -102,6 +102,16 @@
 #define HAVE_FSYNC	1
 #define fsync _commit
 #else
+#ifdef __MINGW32__		/* Mingw compiler */
+#define HAVE_GETCWD     1
+#define HAVE_OPENDIR    1
+#define HAVE_SPAWNV	1
+#define HAVE_EXECV      1
+#define HAVE_PIPE       1
+#define HAVE_POPEN      1
+#define HAVE_SYSTEM	1
+#define HAVE_CWAIT	1
+#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 */
@@ -127,6 +137,7 @@
 #define HAVE_WAIT       1
 #define HAVE_TTYNAME	1
 #endif  /* PYOS_OS2 && PYCC_GCC && __VMS */
+#endif  /* __MINGW32__ */
 #endif  /* _MSC_VER */
 #endif  /* __BORLANDC__ */
 #endif  /* ! __WATCOMC__ || __QNX__ */
@@ -144,7 +155,7 @@
 #if defined(PYCC_VACPP)
 extern int mkdir(char *);
 #else
-#if ( defined(__WATCOMC__) || defined(_MSC_VER) ) && !defined(__QNX__)
+#if ( defined(__WATCOMC__) || defined(_MSC_VER) || defined(__MINGW32__) ) && !defined(__QNX__)
 extern int mkdir(const char *);
 #else
 extern int mkdir(const char *, mode_t);
@@ -223,7 +234,7 @@
 #endif
 #endif
 
-#ifdef _MSC_VER
+#if defined(_MSC_VER) || defined(__MINGW32__)
 #include <direct.h>
 #include <io.h>
 #include <process.h>
@@ -300,7 +311,7 @@
 */
 #include <crt_externs.h>
 static char **environ;
-#elif !defined(_MSC_VER) && ( !defined(__WATCOMC__) || defined(__QNX__) )
+#elif !defined(_MSC_VER) && !defined(__MINGW32__) && ( !defined(__WATCOMC__) || defined(__QNX__) )
 extern char **environ;
 #endif /* !_MSC_VER */
 
@@ -1779,7 +1790,7 @@
 	                      Py_FileSystemDefaultEncoding, &path, &mode))
 		return NULL;
 	Py_BEGIN_ALLOW_THREADS
-#if ( defined(__WATCOMC__) || defined(_MSC_VER) || defined(PYCC_VACPP) ) && !defined(__QNX__)
+#if ( defined(__WATCOMC__) || defined(_MSC_VER) || defined(__MINGW32__) || defined(PYCC_VACPP) ) && !defined(__QNX__)
 	res = mkdir(path);
 #else
 	res = mkdir(path, mode);
@@ -4121,7 +4132,7 @@
 	int i;
 	int x;
 
-	if (i = GetEnvironmentVariable("COMSPEC",NULL,0)) {
+	if ((i = GetEnvironmentVariable("COMSPEC",NULL,0))) {
 		char *comshell;
 
 		s1 = (char *)alloca(i);
@@ -5190,7 +5201,7 @@
 	int mode = 0777;
 	int fd;
 
-#ifdef MS_WINDOWS
+#ifdef Py_WIN_WIDE_FILENAMES
 	if (unicode_file_names()) {
 		PyUnicodeObject *po;
 		if (PyArg_ParseTuple(args, "Ui|i:mkdir", &po, &flag, &mode)) {
@@ -7211,6 +7222,7 @@
 
 #ifdef MS_WINDOWS
 
+#include <wincrypt.h>
 PyDoc_STRVAR(win32_urandom__doc__,
 "urandom(n) -> str\n\n\
 Return a string of n random bytes suitable for cryptographic use.");
@@ -7839,7 +7851,7 @@
 }
 
 
-#if (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__)) && !defined(__QNX__)
+#if (defined(_MSC_VER) || defined(__MINGW32__) || defined(__WATCOMC__) || defined(__BORLANDC__)) && !defined(__QNX__)
 #define INITFUNC initnt
 #define MODNAME "nt"
 
Index: dist/src/Modules/selectmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/selectmodule.c,v
retrieving revision 2.77
diff -u -r2.77 selectmodule.c
--- dist/src/Modules/selectmodule.c	7 Aug 2004 17:21:27 -0000	2.77
+++ dist/src/Modules/selectmodule.c	13 Oct 2004 11:31:41 -0000
@@ -104,7 +104,7 @@
 		v = PyObject_AsFileDescriptor( o );
 		if (v == -1) goto finally;
 
-#if defined(_MSC_VER)
+#if defined(_MSC_VER) || defined(__MINGW32__)
 		max = 0;		     /* not used for Win32 */
 #else  /* !_MSC_VER */
 		if (v < 0 || v >= FD_SETSIZE) {
@@ -157,7 +157,7 @@
 	for (j = 0; fd2obj[j].sentinel >= 0; j++) {
 		fd = fd2obj[j].fd;
 		if (FD_ISSET(fd, set)) {
-#ifndef _MSC_VER
+#if !defined(_MSC_VER) && !defined(__MINGW32__)
 			if (fd > FD_SETSIZE) {
 				PyErr_SetString(PyExc_SystemError,
 			   "filedescriptor out of range returned in select()");
Index: dist/src/Modules/socketmodule.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/socketmodule.h,v
retrieving revision 1.12
diff -u -r1.12 socketmodule.h
--- dist/src/Modules/socketmodule.h	23 Mar 2004 23:16:54 -0000	1.12
+++ dist/src/Modules/socketmodule.h	13 Oct 2004 11:31:41 -0000
@@ -22,7 +22,12 @@
 # define HAVE_GETNAMEINFO
 # define ENABLE_IPV6
 #else
+#if defined(HAVE_WINSOCK2_H)
+# include <winsock2.h>
+# include <ws2tcpip.h>
+#else
 # include <winsock.h>
+#endif  /* HAVE_WINSOCK2_H */
 #endif
 #endif
 
Index: dist/src/Objects/fileobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/fileobject.c,v
retrieving revision 2.192
diff -u -r2.192 fileobject.c
--- dist/src/Objects/fileobject.c	11 Jun 2004 04:49:03 -0000	2.192
+++ dist/src/Objects/fileobject.c	13 Oct 2004 11:31:41 -0000
@@ -15,7 +15,7 @@
 #include <windows.h>
 #endif
 
-#ifdef _MSC_VER
+#if defined(_MSC_VER) || defined(__MINGW32__)
 /* Need GetVersion to see if on NT so safe to use _wfopen */
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
@@ -176,7 +176,7 @@
 	}
 
 	if (f->f_fp == NULL) {
-#ifdef _MSC_VER
+#if defined(_MSC_VER) || defined(__MINGW32__)
 		/* MSVC 6 (Microsoft) leaves errno at 0 for bad mode strings,
 		 * across all Windows flavors.  When it sets EINVAL varies
 		 * across Windows flavors, the exact conditions aren't
Index: dist/src/PC/_winreg.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/PC/_winreg.c,v
retrieving revision 1.15
diff -u -r1.15 _winreg.c
--- dist/src/PC/_winreg.c	30 Nov 2003 22:01:43 -0000	1.15
+++ dist/src/PC/_winreg.c	13 Oct 2004 11:31:42 -0000
@@ -1455,6 +1455,14 @@
 
 #define ADD_KEY(val) inskey(d, #val, val)
 
+#if !defined(HAVE_REG_LEGAL_CHANGE_FILTER)
+/* this is not in the mingw headers; definition taken from VC6's winnt.h */
+#define REG_LEGAL_CHANGE_FILTER  (REG_NOTIFY_CHANGE_NAME                \
+                                  | REG_NOTIFY_CHANGE_ATTRIBUTES        \
+                                  | REG_NOTIFY_CHANGE_LAST_SET          \
+                                  | REG_NOTIFY_CHANGE_SECURITY)
+#endif  /* HAVE_REG_LEGAL_CHANGE_FILTER */
+
 PyMODINIT_FUNC init_winreg(void)
 {
 	PyObject *m, *d;
Index: dist/src/PC/dl_nt.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/PC/dl_nt.c,v
retrieving revision 1.4
diff -u -r1.4 dl_nt.c
--- dist/src/PC/dl_nt.c	26 Jul 2001 13:41:05 -0000	1.4
+++ dist/src/PC/dl_nt.c	13 Oct 2004 11:31:42 -0000
@@ -10,7 +10,7 @@
 #include "windows.h"
 
 /* NT and Python share these */
-#include "pyconfig.h"
+/* #include "pyconfig.h"		/\* XXX Python.h already incudes this *\/ */
 #include "Python.h"
 
 char dllVersionBuffer[16] = ""; // a private buffer
Index: dist/src/Python/dynload_win.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/dynload_win.c,v
retrieving revision 2.13
diff -u -r2.13 dynload_win.c
--- dist/src/Python/dynload_win.c	2 Jul 2004 08:53:57 -0000	2.13
+++ dist/src/Python/dynload_win.c	13 Oct 2004 11:31:42 -0000
@@ -20,6 +20,8 @@
 };
 
 
+#ifndef HAVE_STRCASECMP
+
 /* Case insensitive string compare, to avoid any dependencies on particular
    C RTL implementations */
 
@@ -37,6 +39,7 @@
 	return (first - second);
 } 
 
+#endif  /* HAVE_STRCASECMP */
 
 /* Function to return the name of the "python" DLL that the supplied module
    directly imports.  Looks through the list of imported modules and
@@ -248,7 +251,7 @@
 				return NULL;
 			}
 		}
-		p = GetProcAddress(hDLL, funcname);
+		p = GetProcAddress(hDLL, (LPCSTR) funcname);
 	}
 
 	return p;
Index: dist/src/Python/thread_nt.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/thread_nt.h,v
retrieving revision 2.23
diff -u -r2.23 thread_nt.h
--- dist/src/Python/thread_nt.h	4 Jul 2003 04:40:45 -0000	2.23
+++ dist/src/Python/thread_nt.h	13 Oct 2004 11:31:42 -0000
@@ -153,7 +153,7 @@
 	HANDLE done;
 } callobj;
 
-static int
+static void
 bootstrap(void *call)
 {
 	callobj *obj = (callobj*)call;
@@ -164,7 +164,7 @@
 	obj->id = PyThread_get_thread_ident();
 	ReleaseSemaphore(obj->done, 1, NULL);
 	func(arg);
-	return 0;
+/*	return 0; */
 }
 
 long
@@ -220,12 +220,14 @@
 static void do_PyThread_exit_thread(int no_cleanup)
 {
 	dprintf(("%ld: PyThread_exit_thread called\n", PyThread_get_thread_ident()));
-	if (!initialized)
+        if (!initialized)
+        {
 		if (no_cleanup)
 			_exit(0);
 		else
 			exit(0);
-	_endthread();
+        }
+        _endthread();
 }
 
 void PyThread_exit_thread(void)
