view patches/python-2.4.5-1.patch @ 6211:37158d8bead6

python-2.4, python-2.6 tools and cross build fixes.
author Jan Nieuwenhuizen <janneke@gnu.org>
date Tue, 28 Aug 2012 19:01:24 +0200
parents 40456bb74574
children
line wrap: on
line source

--- python-2.4.5/pyconfig.h.in.orig	2006-10-08 19:41:25.000000000 +0200
+++ python-2.4.5/pyconfig.h.in	2008-11-08 16:53:59.000000000 +0100
@@ -79,6 +79,9 @@
 /* Define to 1 if you have the <curses.h> header file. */
 #undef HAVE_CURSES_H
 
+/* Define to 1 if you have the `cwait' function. */
+#undef HAVE_CWAIT
+
 /* Define to 1 if you have the device macros. */
 #undef HAVE_DEVICE_MACROS
 
@@ -137,7 +140,7 @@
 /* Define to 1 if you have the `fstatvfs' function. */
 #undef HAVE_FSTATVFS
 
-/* Define if you have the 'fsync' function. */
+/* Define to 1 if you have the `fsync' function. */
 #undef HAVE_FSYNC
 
 /* Define to 1 if you have the `ftell64' function. */
@@ -326,6 +329,9 @@
 /* Define to 1 if you have the `pause' function. */
 #undef HAVE_PAUSE
 
+/* Define to 1 if you have the `pipe' function. */
+#undef HAVE_PIPE
+
 /* Define to 1 if you have the `plock' function. */
 #undef HAVE_PLOCK
 
@@ -335,6 +341,9 @@
 /* Define to 1 if you have the <poll.h> header file. */
 #undef HAVE_POLL_H
 
+/* Define to 1 if you have the `popen' function. */
+#undef HAVE_POPEN
+
 /* Define if your compiler supports function prototype */
 #undef HAVE_PROTOTYPES
 
@@ -440,6 +449,9 @@
 /* Define if you have the 'socketpair' function. */
 #undef HAVE_SOCKETPAIR
 
+/* Define to 1 if you have the `spawnv' function. */
+#undef HAVE_SPAWNV
+
 /* Define to 1 if you have the `statvfs' function. */
 #undef HAVE_STATVFS
 
@@ -499,6 +511,9 @@
 /* Define to 1 if you have the <sysexits.h> header file. */
 #undef HAVE_SYSEXITS_H
 
+/* Define to 1 if you have the `system' function. */
+#undef HAVE_SYSTEM
+
 /* Define to 1 if you have the <sys/audioio.h> header file. */
 #undef HAVE_SYS_AUDIOIO_H
 
--- python-2.4.5/Include/pyport.h.orig	2008-11-08 16:59:06.000000000 +0100
+++ python-2.4.5/Include/pyport.h	2008-11-08 16:59:59.000000000 +0100
@@ -482,31 +482,31 @@ the incompatibility will be fixed in Fre
   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(__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__)
+#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__)
+#			if defined(__CYGWIN__) || defined(__MINGW32__)
 #				define PyMODINIT_FUNC __declspec(dllexport) void
-#			else /* __CYGWIN__ */
+#			else /* __CYGWIN__ || __MINGW32__ */
 #				define PyMODINIT_FUNC void
-#			endif /* __CYGWIN__ */
+#			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__)
+#			if !defined(__CYGWIN__) && !defined(__MINGW32__)
 #				define PyAPI_FUNC(RTYPE) __declspec(dllimport) RTYPE
-#			endif /* !__CYGWIN__ */
+#			endif /* !__CYGWIN__ && ! __MINGW32__ */
 #			define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE
 			/* module init functions outside the core must be exported */
 #			if defined(__cplusplus)
--- python-2.4.5/Include/osdefs.h.orig	2006-04-25 17:33:48.000000000 +0200
+++ python-2.4.5/Include/osdefs.h	2008-11-08 16:53:59.000000000 +0100
@@ -18,6 +18,7 @@ extern "C" {
 #define SEP '\\'
 #define ALTSEP '/'
 #define MAXPATHLEN 256
+#define ROOTSEP ':'
 #endif
 #define DELIM ';'
 #endif
--- python-2.4.5/Python/dynload_shlib.c.orig	2005-11-09 08:02:40.000000000 +0100
+++ python-2.4.5/Python/dynload_shlib.c	2008-11-08 16:53:59.000000000 +0100
@@ -32,7 +32,7 @@
 
 
 const struct filedescr _PyImport_DynLoadFiletab[] = {
-#ifdef __CYGWIN__
+#if defined(__CYGWIN__) || defined(__MINGW32__)
 	{".dll", "rb", C_EXTENSION},
 	{"module.dll", "rb", C_EXTENSION},
 #else
--- python-2.4.5/Python/frozenmain.c.orig	2002-06-30 17:26:10.000000000 +0200
+++ python-2.4.5/Python/frozenmain.c	2008-11-08 16:53:59.000000000 +0100
@@ -3,7 +3,7 @@
 
 #include "Python.h"
 
-#ifdef MS_WINDOWS
+#if defined (MS_WINDOWS) && ! defined (__MINGW32__)
 extern void PyWinFreeze_ExeInit(void);
 extern void PyWinFreeze_ExeTerm(void);
 extern int PyInitFrozenExtensions(void);
@@ -32,12 +32,12 @@ Py_FrozenMain(int argc, char **argv)
 		setbuf(stderr, (char *)NULL);
 	}
 
-#ifdef MS_WINDOWS
+#if defined (MS_WINDOWS) && ! defined (__MINGW32__)
 	PyInitFrozenExtensions();
 #endif /* MS_WINDOWS */
 	Py_SetProgramName(argv[0]);
 	Py_Initialize();
-#ifdef MS_WINDOWS
+#if defined (MS_WINDOWS) && ! defined (__MINGW32__)
 	PyWinFreeze_ExeInit();
 #endif
 
@@ -60,7 +60,7 @@ Py_FrozenMain(int argc, char **argv)
 	if (inspect && isatty((int)fileno(stdin)))
 		sts = PyRun_AnyFile(stdin, "<stdin>") != 0;
 
-#ifdef MS_WINDOWS
+#if defined (MS_WINDOWS) && ! defined (__MINGW32__)
 	PyWinFreeze_ExeTerm();
 #endif
 	Py_Finalize();
--- python-2.4.5/Python/dynload_win.c.orig	2004-07-02 10:53:57.000000000 +0200
+++ python-2.4.5/Python/dynload_win.c	2008-11-08 16:53:59.000000000 +0100
@@ -23,6 +23,9 @@ const struct filedescr _PyImport_DynLoad
 /* 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;
--- python-2.4.5/configure.in.orig	2006-10-17 18:03:36.000000000 +0200
+++ python-2.4.5/configure.in	2008-11-08 16:59:59.000000000 +0100
@@ -9,6 +9,11 @@ AC_INIT(python, PYTHON_VERSION, http://w
 AC_CONFIG_SRCDIR([Include/object.h])
 AC_CONFIG_HEADER(pyconfig.h)
 
+# find compiler while respecting --host setting
+AC_CANONICAL_HOST()
+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([
@@ -159,9 +164,15 @@ AC_SUBST(FRAMEWORKUNIXTOOLSPREFIX)
 # Set name for machine-dependent library files
 AC_SUBST(MACHDEP)
 AC_MSG_CHECKING(MACHDEP)
-if test -z "$MACHDEP"
-then
+if test -z "$MACHDEP"; then
+    if test "$cross_compiling" = "no"; then
 	ac_sys_system=`uname -s`
+    else
+	m=`$CC -dumpmachine`
+ 	changequote(<<, >>)#dnl
+	ac_sys_system=`expr "$m" : "[^-]*-\([^-]*\)"`
+ 	changequote([, ])#dnl
+    fi
 	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`
@@ -311,6 +322,23 @@ then
 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
@@ -466,9 +494,11 @@ if test -d casesensitivetestdir
 then
     AC_MSG_RESULT(yes)
     BUILDEXEEXT=.exe
+    case_sensitive=no
 else
-	AC_MSG_RESULT(no)
-	BUILDEXEEXT=$EXEEXT
+    AC_MSG_RESULT(no)
+    BUILDEXEEXT=$EXEEXT
+    case_sensitive=yes
 fi
 rmdir CaseSensitiveTestDir
 
@@ -631,6 +661,10 @@ if test $enable_shared = "yes"; then
           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)'
@@ -675,9 +709,9 @@ fi
 
 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*)
@@ -1362,6 +1396,7 @@ then
 	case $ac_sys_system in
 	hp*|HP*)   SO=.sl;;
 	CYGWIN*)   SO=.dll;;
+	mingw*)    SO=.dll;;
 	*)	   SO=.so;;
 	esac
 else
@@ -1484,6 +1519,9 @@ then
 	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 -L. -lpython$(VERSION) -lwsock32 -luuid -loleaut32 -lole32 '
+		LIBC='-lwsock32 -luuid -loleaut32 -lole32';;
 	atheos*) LDSHARED="gcc -shared";;
 	*)	LDSHARED="ld";;
 	esac
@@ -1574,6 +1611,11 @@ then
 		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)
@@ -2167,6 +2209,7 @@ then
 	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
@@ -2387,6 +2430,8 @@ AC_CHECK_FUNCS(gettimeofday, 
   )
 )
 
+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)
@@ -3203,25 +3248,33 @@ then
 fi
 
 AC_MSG_CHECKING(for /dev/ptmx)
-
-if test -r /dev/ptmx
+if test -z "$ac_cv_have_dev_ptmx"
 then
-  AC_MSG_RESULT(yes)
-  AC_DEFINE(HAVE_DEV_PTMX, 1,
-  [Define if we have /dev/ptmx.])
-else
-  AC_MSG_RESULT(no)
+    ac_cv_have_dev_ptmx=no
+    if test "$cross_compiling" = "no" -a -r /dev/ptmx
+    then
+        ac_cv_have_dev_ptmx=yes
+    fi
+fi
+AC_MSG_RESULT($ac_cv_have_dev_ptmx)
+if test "$ac_cv_have_dev_ptmx" = "yes"
+then
+    AC_DEFINE([HAVE_DEV_PTMX], 1, [Define if we have /dev/ptmx.])
 fi
 
 AC_MSG_CHECKING(for /dev/ptc)
-
-if test -r /dev/ptc
+if test -z "$ac_cv_have_dev_ptc"
 then
-  AC_MSG_RESULT(yes)
-  AC_DEFINE(HAVE_DEV_PTC, 1,
-  [Define if we have /dev/ptc.])
-else
-  AC_MSG_RESULT(no)
+    ac_cv_have_dev_ptc=no
+    if test "$cross_compiling" = "no" -a -r /dev/ptc
+    then
+        ac_cv_have_dev_ptc=yes
+    fi
+fi
+AC_MSG_RESULT($ac_cv_have_dev_ptc)
+if test "$ac_cv_have_dev_ptc" = "yes"
+then
+    AC_DEFINE([HAVE_DEV_PTC], 1, [Define if we have /dev/ptc.])
 fi
 
 AC_CHECK_TYPE(socklen_t,,
@@ -3252,6 +3305,67 @@ for dir in $SRCDIRS; do
 done
 AC_MSG_RESULT(done)
 
+# Cross compiling
+AC_SUBST(cross_compiling)
+
+if test "$cross_compiling" = "yes"; then
+    AC_MSG_CHECKING(cc for build)
+    ## /usr/bin/cc still uses wrong assembler
+    ## CC_FOR_BUILD="${CC_FOR_BUILD-/usr/bin/cc}"
+    CC_FOR_BUILD="${CC_FOR_BUILD-PATH=/usr/bin:$PATH cc}"
+else
+    CC_FOR_BUILD="${CC_FOR_BUILD-$CC}"
+fi   
+     
+if test "$cross_compiling" = "yes"; then
+   AC_MSG_RESULT($CC_FOR_BUILD)
+fi
+
+AC_ARG_VAR(CC_FOR_BUILD,[build system C compiler (default: cc)])
+	
+if test "$cross_compiling" = "yes"; then
+    AC_MSG_CHECKING(python for build)
+    PYTHON_FOR_BUILD="${PYTHON_FOR_BUILD-python}"
+else
+    PYTHON_FOR_BUILD='./$(BUILDPYTHON)'
+fi   
+
+if test "$cross_compiling" = "yes"; then
+    AC_MSG_RESULT($PYTHON_FOR_BUILD)
+fi
+AC_ARG_VAR(PYTHON_FOR_BUILD,[build system python (default: python)])
+AC_SUBST(PYTHON_FOR_BUILD)
+  			
+if test "$cross_compiling" = "yes"; then
+    CFLAGS_FOR_BUILD=${CFLAGS_FOR_BUILD-}
+    changequote(<<, >>)#dnl
+    python_include=`$PYTHON_FOR_BUILD -c 'import sys; sys.stdout.write ("%s/include/python%s" % (sys.prefix, sys.version[:3]))'`
+    changequote([, ])#dnl
+    CPPFLAGS_FOR_BUILD=${CPPFLAGS_FOR_BUILD-"-I$python_include"}
+    CROSS_COMMENT=#
+    if test "$case_sensitive" = "yes"
+    then
+        EXEEXT_FOR_BUILD=
+    else
+        EXEEXT_FOR_BUILD=.exe
+    fi
+    LDFLAGS_FOR_BUILD=${LDFLAGS_FOR_BUILD-}
+    LIBS_FOR_BUILD=${LIBS_FOR_BUILD-}
+    O_FOR_BUILD=x
+    RUNSHARED="CROSS_TARGET=$ac_sys_system SRCDIR=$srcdir SO=${SO}"
+else
+    CROSS_COMMENT=
+    EXEEXT_FOR_BUILD=$BUILDEXEEXT
+    O_FOR_BUILD=o
+fi
+AC_SUBST(CFLAGS_FOR_BUILD)
+AC_SUBST(CPPFLAGS_FOR_BUILD)
+AC_SUBST(CROSS_COMMENT)
+AC_SUBST(EXEEXT_FOR_BUILD)
+AC_SUBST(LDFLAGS_FOR_BUILD)
+AC_SUBST(LIBS_FOR_BUILD)
+AC_SUBST(O_FOR_BUILD)
+
 # generate output files
 AC_CONFIG_FILES(Makefile.pre Modules/Setup.config)
 AC_OUTPUT
@@ -3259,7 +3373,7 @@ AC_OUTPUT
 echo "creating Setup"
 if test ! -f Modules/Setup
 then
-	cp $srcdir/Modules/Setup.dist Modules/Setup
+	sed -e "s/@POSIX@/$POSIX/" $srcdir/Modules/Setup.dist > Modules/Setup
 fi
 
 echo "creating Setup.local"
--- python-2.4.5/README.orig	2008-11-08 16:59:06.000000000 +0100
+++ python-2.4.5/README	2008-11-08 16:59:59.000000000 +0100
@@ -1148,6 +1148,37 @@ release-build performance).  The Unix, W
 do this.
 
 
+Cross Compiling
+---------------
+
+Python can be cross compiled by supplying different --build and --host
+parameters to configure.  Python is compiled on the "build" system and
+executed on the "host" system.  Cross compiling python requires a
+native Python on the build host, and a natively compiled tool `Pgen'.
+
+Before cross compiling, Python must first be compiled and installed on
+the build host.  The configure script will use `cc' and `python', or
+environment variables CC_FOR_BUILD or PYTHON_FOR_BUILD, eg:
+
+   CC_FOR_BUILD=gcc-3.3 \
+   PYTHON_FOR_BUILD=python2.4 \
+   .../configure --build=i686-linux --host=i586-mingw32
+
+Cross compiling has been tested under linux, mileage may vary for
+other platforms.
+
+A few reminders on using configure to cross compile:
+- Cross compile tools must be in PATH,
+- Cross compile tools must be prefixed with the host type
+  (ie i586-mingw32-gcc, i586-mingw32-ranlib, ...),
+- CC, CXX, AR, and RANLIB must be undefined when running configure,
+  they will be auto-detected.
+
+If you need a cross compiler, Debian ships several several (eg: avr,
+m68hc1x, mingw32), while dpkg-cross easily creates others.  Otherwise,
+check out Dan Kegel's crosstool: http://www.kegel.com/crosstool .
+
+
 Miscellaneous issues
 ====================
 
--- python-2.4.5/Lib/distutils/command/build_ext.py.orig	2004-11-10 23:23:15.000000000 +0100
+++ python-2.4.5/Lib/distutils/command/build_ext.py	2008-11-08 16:53:59.000000000 +0100
@@ -612,6 +612,8 @@ class build_ext (Command):
             ext_path[len(ext_path) - 1] = ext_path[len(ext_path) - 1][:8]
         # extensions in debug_mode are named 'module_d.pyd' under windows
         so_ext = get_config_var('SO')
+        if os.environ.get('CROSS_COMPILING') == 'yes':
+            so_ext = os.environ.get('SO')
         if os.name == 'nt' and self.debug:
             return apply(os.path.join, ext_path) + '_d' + so_ext
         return apply(os.path.join, ext_path) + so_ext
@@ -664,7 +666,7 @@ class build_ext (Command):
             # 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":
+        elif sys.platform[:6] == "cygwin" or sys.platform[:5] == "mingw":
             template = "python%d.%d"
             pythonlib = (template %
                    (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
--- python-2.4.5/Modules/posixmodule.c.orig	2008-11-08 16:59:06.000000000 +0100
+++ python-2.4.5/Modules/posixmodule.c	2008-11-08 16:59:59.000000000 +0100
@@ -118,6 +118,11 @@ corresponding Unix manual entries for mo
 #define HAVE_FSYNC	1
 #define fsync _commit
 #else
+#ifdef __MINGW32__             /* MINGW32 (cross-)compiler*/
+#define HAVE_FSYNC	1
+#define HAVE_PIPE	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 */
@@ -143,12 +147,13 @@ corresponding Unix manual entries for mo
 #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__ */
 
-#ifndef _MSC_VER
+#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
@@ -194,7 +199,7 @@ extern int lstat(const char *, struct st
 #endif /* HAVE_LSTAT */
 #endif /* !HAVE_UNISTD_H */
 
-#endif /* !_MSC_VER */
+#endif /* !_MSC_VER && !__MINGW32__ */
 
 #ifdef HAVE_UTIME_H
 #include <utime.h>
@@ -239,7 +244,7 @@ extern int lstat(const char *, struct st
 #endif
 #endif
 
-#ifdef _MSC_VER
+#if defined(_MSC_VER) || defined(__MINGW32__)
 #include <direct.h>
 #include <io.h>
 #include <process.h>
@@ -249,7 +254,7 @@ extern int lstat(const char *, struct st
 #include <shellapi.h>	/* for ShellExecute() */
 #define popen	_popen
 #define pclose	_pclose
-#endif /* _MSC_VER */
+#endif /* _MSC_VER || __MINGW32__ */
 
 #if defined(PYCC_VACPP) && defined(PYOS_OS2)
 #include <io.h>
@@ -320,9 +325,9 @@ extern int lstat(const char *, struct st
 */
 #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 */
+#endif /* !_MSC_VER && ! __MINGW32__ */
 
 static PyObject *
 convertenviron(void)
@@ -1824,7 +1829,7 @@ posix_mkdir(PyObject *self, PyObject *ar
 	                      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);
@@ -7301,7 +7306,7 @@ posix_getloadavg(PyObject *self, PyObjec
 }
 #endif
 
-#ifdef MS_WINDOWS
+#if defined(MS_WINDOWS) && !defined(__MINGW32__)
 
 PyDoc_STRVAR(win32_urandom__doc__,
 "urandom(n) -> str\n\n\
@@ -7658,7 +7663,7 @@ static PyMethodDef posix_methods[] = {
 #ifdef HAVE_GETLOADAVG
 	{"getloadavg",	posix_getloadavg, METH_NOARGS, posix_getloadavg__doc__},
 #endif
- #ifdef MS_WINDOWS
+ #if defined(MS_WINDOWS) && !defined(__MINGW32__)
  	{"urandom", win32_urandom, METH_VARARGS, win32_urandom__doc__},
  #endif
 	{NULL,		NULL}		 /* Sentinel */
@@ -7931,7 +7936,7 @@ all_ins(PyObject *d)
 }
 
 
-#if (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__)) && !defined(__QNX__)
+#if (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__) || defined (__MINGW32__)) && !defined(__QNX__)
 #define INITFUNC initnt
 #define MODNAME "nt"
 
--- python-2.4.5/Modules/timemodule.c.orig	2008-11-08 16:59:06.000000000 +0100
+++ python-2.4.5/Modules/timemodule.c	2008-11-08 16:59:59.000000000 +0100
@@ -816,7 +816,9 @@ inittime(void)
 	   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 */
@@ -917,8 +919,11 @@ floatsleep(double secs)
 		 * by Guido, only the main thread can be interrupted.
 		 */
 		ul_millis = (unsigned long)millisecs;
-		if (ul_millis == 0 ||
-		    main_thread != PyThread_get_thread_ident())
+		if (ul_millis == 0
+#ifdef WITH_THREAD
+		    || main_thread != PyThread_get_thread_ident()
+#endif
+		    )
 			Sleep(ul_millis);
 		else {
 			DWORD rc;
--- python-2.4.5/Modules/getpath.c.orig	2008-11-08 16:59:06.000000000 +0100
+++ python-2.4.5/Modules/getpath.c	2008-11-08 16:59:59.000000000 +0100
@@ -120,6 +120,14 @@
 #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,7 +138,12 @@ static void
 reduce(char *dir)
 {
     size_t i = strlen(dir);
-    while (i > 0 && dir[i] != SEP)
+    while (i > 0
+	   && dir[i] != SEP
+#ifdef ALTSEP
+	   && dir[i] != ALTSEP
+#endif /* ALTSEP */
+	   )
         --i;
     dir[i] = '\0';
 }
@@ -203,11 +216,16 @@ static void
 joinpath(char *buffer, char *stuff)
 {
     size_t n, k;
-    if (stuff[0] == SEP)
+    if (IS_ABSOLUTE(stuff))
         n = 0;
     else {
         n = strlen(buffer);
-        if (n > 0 && buffer[n-1] != SEP && n < MAXPATHLEN)
+        if (n > 0
+	    && buffer[n-1] != SEP
+#ifdef ALTSEP
+	    && buffer[n-1] != ALTSEP
+#endif /* ALTSEP */
+	    && n < MAXPATHLEN)
             buffer[n++] = SEP;
     }
     if (n > MAXPATHLEN)
@@ -224,11 +242,16 @@ joinpath(char *buffer, char *stuff)
 static void
 copy_absolute(char *path, char *p)
 {
-    if (p[0] == SEP)
+    if (IS_ABSOLUTE(p))
         strcpy(path, p);
     else {
         getcwd(path, MAXPATHLEN);
-        if (p[0] == '.' && p[1] == SEP)
+        if (p[0] == '.'
+	    && (p[1] == SEP
+#ifdef ALTSEP
+		|| p[1] == ALTSEP
+#endif /* ALTSEP */
+		))
             p += 2;
         joinpath(path, p);
     }
@@ -240,7 +263,7 @@ absolutize(char *path)
 {
     char buffer[MAXPATHLEN + 1];
 
-    if (path[0] == SEP)
+    if (IS_ABSOLUTE(path))
         return;
     copy_absolute(buffer, path);
     strcpy(path, buffer);
@@ -388,13 +411,23 @@ calculate_path(void)
 #endif
 #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);
+    /* 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"
@@ -410,6 +443,9 @@ calculate_path(void)
        ;
 #endif /* __APPLE__ */
 	else if (path) {
+#ifdef __MINGW32__
+		char const *ext = strchr(prog, '.') ? "" : ".exe";
+#endif
 		while (1) {
 			char *delim = strchr(path, DELIM);
 
@@ -424,9 +460,11 @@ calculate_path(void)
 				strncpy(progpath, path, MAXPATHLEN);
 
 			joinpath(progpath, prog);
+#ifdef __MINGW32__
+			strcat(progpath, ext);
+#endif
 			if (isxfile(progpath))
 				break;
-
 			if (!delim) {
 				progpath[0] = '\0';
 				break;
@@ -436,7 +474,7 @@ calculate_path(void)
 	}
 	else
 		progpath[0] = '\0';
-	if (progpath[0] != SEP)
+	if (!IS_ABSOLUTE(progpath))
 		absolutize(progpath);
 	strncpy(argv0_path, progpath, MAXPATHLEN);
 	argv0_path[MAXPATHLEN] = '\0';
@@ -482,7 +520,7 @@ calculate_path(void)
         while (linklen != -1) {
             /* It's not null terminated! */
             tmpbuffer[linklen] = '\0';
-            if (tmpbuffer[0] == SEP)
+            if (IS_ABSOLUTE(tmpbuffer))
                 /* tmpbuffer should never be longer than MAXPATHLEN,
                    but extra check does not hurt */
                 strncpy(argv0_path, tmpbuffer, MAXPATHLEN);
@@ -549,7 +587,7 @@ calculate_path(void)
     while (1) {
         char *delim = strchr(defpath, DELIM);
 
-        if (defpath[0] != SEP)
+        if (!IS_ABSOLUTE(defpath))
             /* Paths are relative to prefix */
             bufsz += prefixsz;
 
@@ -594,7 +632,7 @@ calculate_path(void)
         while (1) {
             char *delim = strchr(defpath, DELIM);
 
-            if (defpath[0] != SEP) {
+            if (!IS_ABSOLUTE(defpath)) {
                 strcat(buf, prefix);
                 strcat(buf, separator);
             }
--- python-2.4.5/Modules/xxsubtype.c.orig	2002-08-14 03:45:37.000000000 +0200
+++ python-2.4.5/Modules/xxsubtype.c	2008-11-08 16:53:59.000000000 +0100
@@ -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"
--- python-2.4.5/Modules/Setup.dist.orig	2008-11-08 16:59:06.000000000 +0100
+++ python-2.4.5/Modules/Setup.dist	2008-11-08 16:59:59.000000000 +0100
@@ -91,12 +91,12 @@ SITEPATH=
 TESTPATH=
 
 # Path components for machine- or system-dependent modules and shared libraries
-MACHDEPPATH=:plat-$(MACHDEP)
+MACHDEPPATH=$(DELIM)plat-$(MACHDEP)
 EXTRAMACHDEPPATH=
 
 # Path component for the Tkinter-related modules
 # The TKPATH variable is always enabled, to save you the effort.
-TKPATH=:lib-tk
+TKPATH=$(DELIM)lib-tk
 
 COREPYTHONPATH=$(DESTPATH)$(SITEPATH)$(TESTPATH)$(MACHDEPPATH)$(EXTRAMACHDEPPATH)$(TKPATH)
 PYTHONPATH=$(COREPYTHONPATH)
@@ -109,7 +109,7 @@ PYTHONPATH=$(COREPYTHONPATH)
 # 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
 pwd pwdmodule.c			# this is needed to find out the user's home dir
 				# if $HOME is not set
--- python-2.4.5/setup.py.orig	2008-11-08 16:59:06.000000000 +0100
+++ python-2.4.5/setup.py	2008-11-08 16:59:59.000000000 +0100
@@ -103,6 +103,8 @@ class PyBuildExt(build_ext):
         # Fix up the autodetected modules, prefixing all the source files
         # with Modules/ and adding Python's include directory to the path.
         (srcdir,) = sysconfig.get_config_vars('srcdir')
+        if os.environ.get('CROSS_COMPILING') == 'yes':
+            srcdir = os.environ.get('SRCDIR')
         if not srcdir:
             # Maybe running on Windows but not using CYGWIN?
             raise ValueError("No source directory; cannot proceed.")
@@ -199,6 +201,10 @@ class PyBuildExt(build_ext):
             self.announce('WARNING: skipping import check for Cygwin-based "%s"'
                 % ext.name)
             return
+        if os.environ.get('CROSS_COMPILING') == '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)))
@@ -232,11 +238,14 @@ class PyBuildExt(build_ext):
                           level=3)
 
     def get_platform(self):
-        # Get value of sys.platform
-        for platform in ['cygwin', 'beos', 'darwin', 'atheos', 'osf1']:
-            if sys.platform.startswith(platform):
+        # Get value of target's sys.platform
+        p = sys.platform
+        if os.environ.get('CROSS_COMPILING') == 'yes':
+            p = os.environ.get('CROSS_TARGET')
+        for platform in ['cygwin', 'mingw', 'beos', 'darwin', 'atheos', 'osf1']:
+            if p.startswith(platform):
                 return platform
-        return sys.platform
+        return p
 
     def detect_modules(self):
         # Ensure that /usr/local is always used
@@ -327,6 +327,8 @@ class PyBuildExt(build_ext):
         math_libs = ['m']
         if platform in ['darwin', 'beos', 'mac']:
             math_libs = []
+        if platform in ['mingw']:
+            math_libs += ['wsock32']
 
         # XXX Omitted modules: gl, pure, dl, SGI-specific modules
 
@@ -1141,6 +1150,8 @@ class PyBuildInstallLib(install_lib):
     # mode 755. All installed directories will get mode 755.
 
     so_ext = sysconfig.get_config_var("SO")
+    if os.environ.get('CROSS_COMPILING') == 'yes':
+        so_ext = os.environ.get('SO')
 
     def install(self):
         outfiles = install_lib.install(self)
--- python-2.4.5/Makefile.pre.in.orig	2006-10-08 19:41:25.000000000 +0200
+++ python-2.4.5/Makefile.pre.in	2008-11-08 16:59:59.000000000 +0100
@@ -18,6 +18,8 @@
 #
 # See also the section "Build instructions" in the README file.
 
+DELIM=@DELIM@
+
 # === Variables set by makesetup ===
 
 MODOBJS=        _MODOBJS_
@@ -67,6 +69,16 @@ CFLAGSFORSHARED=@CFLAGSFORSHARED@
 # C flags used for building the interpreter object files
 PY_CFLAGS=	$(CFLAGS) $(CPPFLAGS) $(CFLAGSFORSHARED) -DPy_BUILD_CORE
 
+# For cross compile: build compiler options
+CC_FOR_BUILD=	@CC_FOR_BUILD@
+CROSS_COMPILING=	@cross_compiling@
+EXEEXT_FOR_BUILD=	@EXEEXT_FOR_BUILD@
+O_FOR_BUILD=	@O_FOR_BUILD@
+
+CFLAGS_FOR_BUILD=	@CFLAGS_FOR_BUILD@
+CPPFLAGS_FOR_BUILD=	@CPPFLAGS_FOR_BUILD@ -I$(srcdir)/Include
+LDFLAGS_FOR_BUILD=	@LDFLAGS_FOR_BUILD@
+LIBS_FOR_BUILD=	@LIBS_FOR_BUILD@
 
 # Machine-dependent subdirectories
 MACHDEP=	@MACHDEP@
@@ -165,7 +177,8 @@ MACHDEP_OBJS=	@MACHDEP_OBJS@
 UNICODE_OBJS=   @UNICODE_OBJS@
 
 PYTHON=		python$(EXE)
-BUILDPYTHON=	python$(BUILDEXE)
+BUILDPYTHON=	python$(EXE)
+PYTHON_FOR_BUILD=	@PYTHON_FOR_BUILD@
 
 # === Definitions added by makesetup ===
 
@@ -191,7 +204,7 @@ GRAMMAR_INPUT=	$(srcdir)/Grammar/Grammar
 
 ##########################################################################
 # Parser
-PGEN=		Parser/pgen$(EXE)
+PGEN_FOR_BUILD=	Parser/pgen$(EXEEXT_FOR_BUILD)
 
 POBJS=		\
 		Parser/acceler.o \
@@ -208,14 +221,27 @@ POBJS=		\
 
 PARSER_OBJS=	$(POBJS) Parser/myreadline.o Parser/tokenizer.o
 
-PGOBJS=		\
-		Objects/obmalloc.o \
-		Python/mysnprintf.o \
-		Parser/tokenizer_pgen.o \
-		Parser/printgrammar.o \
-		Parser/pgenmain.o
+POBJS_FOR_BUILD=		\
+		Parser/acceler.$(O_FOR_BUILD) \
+		Parser/grammar1.$(O_FOR_BUILD) \
+		Parser/listnode.$(O_FOR_BUILD) \
+		Parser/node.$(O_FOR_BUILD) \
+		Parser/parser.$(O_FOR_BUILD) \
+		Parser/parsetok.$(O_FOR_BUILD) \
+		Parser/bitset.$(O_FOR_BUILD) \
+		Parser/metagrammar.$(O_FOR_BUILD) \
+		Parser/firstsets.$(O_FOR_BUILD) \
+		Parser/grammar.$(O_FOR_BUILD) \
+		Parser/pgen.$(O_FOR_BUILD)
+
+PGOBJS_FOR_BUILD=		\
+		Objects/obmalloc.$(O_FOR_BUILD) \
+		Python/mysnprintf.$(O_FOR_BUILD) \
+		Parser/tokenizer_pgen.$(O_FOR_BUILD) \
+		Parser/printgrammar.$(O_FOR_BUILD) \
+		Parser/pgenmain.$(O_FOR_BUILD)
 
-PGENOBJS=	$(PGENMAIN) $(POBJS) $(PGOBJS)
+PGENOBJS=	$(POBJS_FOR_BUILD) $(PGOBJS_FOR_BUILD)
 
 
 ##########################################################################
@@ -317,15 +343,15 @@ $(BUILDPYTHON):	Modules/$(MAINOBJ) $(LIB
 			Modules/$(MAINOBJ) \
 			$(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST)
 
-platform: $(BUILDPYTHON)
-	$(RUNSHARED) ./$(BUILDPYTHON) -E -c 'import sys ; from distutils.util import get_platform ; print get_platform()+"-"+sys.version[0:3]' >platform
+platform: @CROSS_COMMENT@ $(BUILDPYTHON)
+	$(RUNSHARED) $(PYTHON_FOR_BUILD) -E -c 'import sys ; from distutils.util import get_platform ; print get_platform()+"-"+sys.version[0:3]' >platform
 
 
 # Build the shared modules
-sharedmods: $(BUILDPYTHON)
+sharedmods: @CROSS_COMMENT@ $(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;; \
+	*-s*) $(RUNSHARED) CC='$(CC)' CROSS_COMPILING='$(CROSS_COMPILING)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' $(PYTHON_FOR_BUILD) -E $(srcdir)/setup.py -q build;; \
+	*) $(RUNSHARED) CC='$(CC)' CROSS_COMPILING='$(CROSS_COMPILING)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' $(PYTHON_FOR_BUILD) -E $(srcdir)/setup.py build;; \
 	esac
 
 # buildno should really depend on something like LIBRARY_SRC
@@ -454,11 +480,11 @@ Modules/ccpython.o: $(srcdir)/Modules/cc
 	$(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): $(PGEN_FOR_BUILD) $(GRAMMAR_INPUT)
+		-$(PGEN_FOR_BUILD) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
 
-$(PGEN):	$(PGENOBJS)
-		$(CC) $(OPT) $(LDFLAGS) $(PGENOBJS) $(LIBS) -o $(PGEN)
+$(PGEN_FOR_BUILD):	$(PGENOBJS)
+		$(CC_FOR_BUILD) $(OPT) $(LDFLAGS_FOR_BUILD) $(PGENOBJS) $(LIBS_FOR_BUILD) -o $(PGEN_FOR_BUILD)
 
 Parser/grammar.o:	$(srcdir)/Parser/grammar.c \
 				$(srcdir)/Include/token.h \
@@ -480,6 +506,13 @@ Objects/unicodectype.o:	$(srcdir)/Object
 				$(srcdir)/Objects/unicodetype_db.h
 
 ############################################################################
+# Cross compile rules
+
+.SUFFIXES: .x
+.c.x:
+	$(CC_FOR_BUILD) -c $(CPPFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) -o $@ $<
+				
+############################################################################
 # Header files
 
 PYTHON_HEADERS= \
@@ -548,7 +581,7 @@ $(LIBRARY_OBJS) $(MODOBJS) Modules/$(MAI
 
 TESTOPTS=	-l $(EXTRATESTOPTS)
 TESTPROG=	$(srcdir)/Lib/test/regrtest.py
-TESTPYTHON=	$(RUNSHARED) ./$(BUILDPYTHON) -E -tt
+TESTPYTHON=	$(RUNSHARED) $(PYTHON_FOR_BUILD) -E -tt
 test:		all platform
 		-find $(srcdir)/Lib -name '*.py[co]' -print | xargs rm -f
 		-$(TESTPYTHON) $(TESTPROG) $(TESTOPTS)
@@ -602,7 +602,7 @@ testuniversal:	all platform
 		-find $(srcdir)/Lib -name '*.py[co]' -print | xargs rm -f
 		-$(TESTPYTHON) $(TESTPROG) $(TESTOPTS) -uall
 		$(TESTPYTHON) $(TESTPROG) $(TESTOPTS) -uall
-		$(RUNSHARED) /usr/libexec/oah/translate ./$(BUILDPYTHON) -E -tt $(TESTPROG) $(TESTOPTS) -uall
+		$(RUNSHARED) /usr/libexec/oah/translate $(PYTHON_FOR_BUILD) -E -tt $(TESTPROG) $(TESTOPTS) -uall
 
 
 # Like testall, but with a single pass only
@@ -630,7 +663,7 @@ bininstall:	altbininstall
 
 # Install the interpreter with $(VERSION) affixed
 # This goes into $(exec_prefix)
-altbininstall:	$(BUILDPYTHON)
+altbininstall: @CROSS_COMMENT@ $(BUILDPYTHON)
 	@if test "$(PYTHONFRAMEWORKDIR)" != no-framework; then \
 		if test ! -f $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Versions/Current/Resources/Info.plist; then \
 			echo 'Framework build: use "make frameworkinstall" in stead of "make install"'; \
@@ -693,7 +726,7 @@ LIBSUBDIRS=	lib-old lib-tk site-packages
 		logging bsddb bsddb/test csv idlelib idlelib/Icons \
 		distutils distutils/command distutils/tests $(XMLLIBSUBDIRS) \
 		curses $(MACHDEPS)
-libinstall:	$(BUILDPYTHON) $(srcdir)/Lib/$(PLATDIR)
+libinstall: $(srcdir)/Lib/$(PLATDIR) @CROSS_COMMENT@ $(BUILDPYTHON)
 	@for i in $(SCRIPTDIR) $(LIBDEST); \
 	do \
 		if test ! -d $(DESTDIR)$$i; then \
@@ -749,19 +782,19 @@ libinstall:	$(BUILDPYTHON) $(srcdir)/Lib
 	done
 	$(INSTALL_DATA) $(srcdir)/LICENSE $(DESTDIR)$(LIBDEST)/LICENSE.txt
 	PYTHONPATH=$(DESTDIR)$(LIBDEST)  $(RUNSHARED) \
-		./$(BUILDPYTHON) -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py \
+		$(PYTHON_FOR_BUILD) -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py \
 		-d $(LIBDEST) -f \
 		-x 'badsyntax|site-packages' $(DESTDIR)$(LIBDEST)
 	PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
-		./$(BUILDPYTHON) -Wi -tt -O $(DESTDIR)$(LIBDEST)/compileall.py \
+		$(PYTHON_FOR_BUILD) -Wi -tt -O $(DESTDIR)$(LIBDEST)/compileall.py \
 		-d $(LIBDEST) -f \
 		-x 'badsyntax|site-packages' $(DESTDIR)$(LIBDEST)
 	-PYTHONPATH=$(DESTDIR)$(LIBDEST)  $(RUNSHARED) \
-		./$(BUILDPYTHON) -Wi -t $(DESTDIR)$(LIBDEST)/compileall.py \
+		$(PYTHON_FOR_BUILD) -Wi -t $(DESTDIR)$(LIBDEST)/compileall.py \
 		-d $(LIBDEST)/site-packages -f \
 		-x badsyntax $(DESTDIR)$(LIBDEST)/site-packages
 	-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
-		./$(BUILDPYTHON) -Wi -t -O $(DESTDIR)$(LIBDEST)/compileall.py \
+		$(PYTHON_FOR_BUILD) -Wi -t -O $(DESTDIR)$(LIBDEST)/compileall.py \
 		-d $(LIBDEST)/site-packages -f \
 		-x badsyntax $(DESTDIR)$(LIBDEST)/site-packages
 
@@ -769,9 +802,10 @@ libinstall:	$(BUILDPYTHON) $(srcdir)/Lib
 $(srcdir)/Lib/$(PLATDIR):
 	mkdir $(srcdir)/Lib/$(PLATDIR)
 	cp $(srcdir)/Lib/plat-generic/regen $(srcdir)/Lib/$(PLATDIR)/regen
-	export PATH; PATH="`pwd`:$$PATH"; \
-	export PYTHONPATH; PYTHONPATH="`pwd`/Lib"; \
-	export DYLD_FRAMEWORK_PATH; DYLD_FRAMEWORK_PATH="`pwd`"; \
+@CROSS_COMMENT@	export PATH; PATH="`pwd`:$$PATH"; \
+@CROSS_COMMENT@	export LD_LIBRARY_PATH; LD_LIBRARY_PATH="`pwd`:$$LD_LIBRARY_PATH"; \
+@CROSS_COMMENT@	export PYTHONPATH; PYTHONPATH="`pwd`/Lib"; \
+@CROSS_COMMENT@	export DYLD_FRAMEWORK_PATH; DYLD_FRAMEWORK_PATH="`pwd`"; \
 	export EXE; EXE="$(BUILDEXE)"; \
 	cd $(srcdir)/Lib/$(PLATDIR); ./regen
 
@@ -856,8 +889,9 @@ libainstall:	all
 # 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_COMPILING='$(CROSS_COMPILING)' \
+		$(RUNSHARED) $(PYTHON_FOR_BUILD) -E $(srcdir)/setup.py install \
+		--prefix=$(prefix) \
 		--install-scripts=$(BINDIR) \
 		--install-platlib=$(DESTSHARED) \
 		--root=/$(DESTDIR)
@@ -906,11 +940,11 @@ frameworkinstallstructure:	$(LDLIBRARY)
 frameworkinstallmaclib:
 	ln -sf ../../../Python $(DESTDIR)$(prefix)/lib/python$(VERSION)/config/libpython$(VERSION).a
 	cd Mac/OSX && $(MAKE) installmacsubtree \
-		$(RUNSHARED) DESTDIR=$(DESTDIR)
+		$(RUNSHARED) PYTHON_FOR_BUILD=$(PYTHON_FOR_BUILD) DESTDIR=$(DESTDIR)
 
 # This installs the IDE, the Launcher and other apps into /Applications
 frameworkinstallapps:
-	cd Mac/OSX && $(MAKE) installapps DESTDIR=$(DESTDIR)
+	cd Mac/OSX && $(MAKE) installapps DESTDIR=$(DESTDIR) PYTHON_FOR_BUILD=$(PYTHON_FOR_BUILD)
 
 # This install the unix python and pythonw tools in /usr/local/bin
 frameworkinstallunixtools:
@@ -922,12 +956,12 @@ frameworkaltinstallunixtools:
 # This installs the Demos and Tools into the applications directory.
 # It is not part of a normal frameworkinstall
 frameworkinstallextras:
-	cd Mac/OSX && $(MAKE) installextras DESTDIR=$(DESTDIR)
+	cd Mac/OSX && $(MAKE) installextras DESTDIR=$(DESTDIR) PYTHON_FOR_BUILD=$(PYTHON_FOR_BUILD)
 
 # This installs a few of the useful scripts in Tools/scripts
 scriptsinstall:
 	SRCDIR=$(srcdir) $(RUNSHARED) \
-	./$(BUILDPYTHON) $(srcdir)/Tools/scripts/setup.py install \
+	./$(PYTHON_FOR_BUILD) $(srcdir)/Tools/scripts/setup.py install \
 	--prefix=$(prefix) \
 	--install-scripts=$(BINDIR) \
 	--root=/$(DESTDIR)
@@ -981,11 +1015,12 @@ clean:
 	find $(srcdir) -name '*.py[co]' -exec rm -f {} ';'
 
 clobber: clean
-	-rm -f $(BUILDPYTHON) $(PGEN) $(LIBRARY) $(LDLIBRARY) $(DLLLIBRARY) \
+	-rm -f $(BUILDPYTHON) $(PGEN_FOR_BUILD) $(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]