Commits

Mike Gilbert committed 9b716c4

Add patches from 2.6.8

Comments (0)

Files changed (20)

patches/01_all_static_library_location.patch

+Install libpythonX.Y.a in /usr/lib instead of /usr/lib/pythonX.Y/config.
+https://bugs.gentoo.org/show_bug.cgi?id=252372
+http://bugs.python.org/issue6103
+
+--- Makefile.pre.in
++++ Makefile.pre.in
+@@ -788,6 +788,19 @@
+ 		fi; \
+ 	else	true; \
+ 	fi
++	@if test -f $(LIBRARY) && test $(LIBRARY) != $(LDLIBRARY); then \
++		if test "$(PYTHONFRAMEWORKDIR)" = no-framework; then \
++			if test "$(SO)" = .dll; then \
++				$(INSTALL_DATA) $(LDLIBRARY) $(DESTDIR)$(LIBDIR); \
++			else \
++				$(INSTALL_DATA) $(LIBRARY) $(DESTDIR)$(LIBDIR); \
++				$(RANLIB) $(DESTDIR)$(LIBDIR)/$(LIBRARY); \
++			fi; \
++		else \
++			echo "Skipped install of $(LIBRARY) - use make frameworkinstall"; \
++		fi; \
++	else	true; \
++	fi
+ 
+ # Install the manual page
+ maninstall:
+@@ -946,18 +959,6 @@
+ 		else	true; \
+ 		fi; \
+ 	done
+-	@if test -d $(LIBRARY); then :; else \
+-		if test "$(PYTHONFRAMEWORKDIR)" = no-framework; then \
+-			if test "$(SO)" = .dll; then \
+-				$(INSTALL_DATA) $(LDLIBRARY) $(DESTDIR)$(LIBPL) ; \
+-			else \
+-				$(INSTALL_DATA) $(LIBRARY) $(DESTDIR)$(LIBPL)/$(LIBRARY) ; \
+-				$(RANLIB) $(DESTDIR)$(LIBPL)/$(LIBRARY) ; \
+-			fi; \
+-		else \
+-			echo Skip install of $(LIBRARY) - use make frameworkinstall; \
+-		fi; \
+-	fi
+ 	$(INSTALL_DATA) Modules/config.c $(DESTDIR)$(LIBPL)/config.c
+ 	$(INSTALL_DATA) Modules/python.o $(DESTDIR)$(LIBPL)/python.o
+ 	$(INSTALL_DATA) $(srcdir)/Modules/config.c.in $(DESTDIR)$(LIBPL)/config.c.in
+--- Misc/python-config.in
++++ Misc/python-config.in
+@@ -45,9 +45,4 @@
+ elif opt in ('--libs', '--ldflags'):
+     libs = getvar('LIBS').split() + getvar('SYSLIBS').split()
+     libs.append('-lpython'+pyver)
+-    # add the prefix/lib/pythonX.Y/config dir, but only if there is no
+-    # shared library in prefix/lib/.
+-    if opt == '--ldflags' and not getvar('Py_ENABLE_SHARED'):
+-        libs.insert(0, '-L' + getvar('LIBPL'))
+     print ' '.join(libs)
+-
+--- Modules/makesetup
++++ Modules/makesetup
+@@ -89,7 +89,7 @@
+ 	 then
+ 	 	ExtraLibDir=.
+ 	 else
+-	 	ExtraLibDir='$(LIBPL)'
++	 	ExtraLibDir='$(LIBDIR)'
+ 	 fi
+ 	 ExtraLibs="-L$ExtraLibDir -lpython\$(VERSION)";;
+ esac

patches/02_all_disable_modules_and_ssl.patch

+--- setup.py
++++ setup.py
+@@ -18,7 +18,18 @@
+ from distutils.spawn import find_executable
+ 
+ # This global variable is used to hold the list of modules to be disabled.
+-disabled_module_list = []
++pdm_env = "PYTHON_DISABLE_MODULES"
++if pdm_env in os.environ:
++    disabled_module_list = os.environ[pdm_env].split()
++else:
++    disabled_module_list = []
++
++pds_env = "PYTHON_DISABLE_SSL"
++if pds_env in os.environ:
++    disable_ssl = os.environ[pds_env]
++else:
++    disable_ssl = 0
++ 
+ 
+ def add_dir_to_list(dirlist, dir):
+     """Add the directory 'dir' to the list 'dirlist' (at the front) if
+@@ -355,6 +366,7 @@
+         return sys.platform
+ 
+     def detect_modules(self):
++        global disable_ssl
+         # Ensure that /usr/local is always used
+         add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
+         add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
+@@ -697,7 +709,7 @@
+         ssl_incs = find_file('openssl/ssl.h', inc_dirs,
+                              search_for_ssl_incs_in
+                              )
+-        if ssl_incs is not None:
++        if ssl_incs is not None and not disable_ssl:
+             krb5_h = find_file('krb5.h', inc_dirs,
+                                ['/usr/kerberos/include'])
+             if krb5_h:
+@@ -708,7 +720,8 @@
+                                      ] )
+ 
+         if (ssl_incs is not None and
+-            ssl_libs is not None):
++            ssl_libs is not None and
++            not disable_ssl):
+             exts.append( Extension('_ssl', ['_ssl.c'],
+                                    include_dirs = ssl_incs,
+                                    library_dirs = ssl_libs,
+@@ -742,6 +755,7 @@
+ 
+         if (ssl_incs is not None and
+             ssl_libs is not None and
++            not disable_ssl and
+             openssl_ver >= 0x00907000):
+             # The _hashlib module wraps optimized implementations
+             # of hash functions from the OpenSSL library.
+@@ -752,20 +766,22 @@
+             # these aren't strictly missing since they are unneeded.
+             #missing.extend(['_sha', '_md5'])
+         else:
+-            # The _sha module implements the SHA1 hash algorithm.
+-            exts.append( Extension('_sha', ['shamodule.c']) )
+-            # The _md5 module implements the RSA Data Security, Inc. MD5
+-            # Message-Digest Algorithm, described in RFC 1321.  The
+-            # necessary files md5.c and md5.h are included here.
+-            exts.append( Extension('_md5',
+-                            sources = ['md5module.c', 'md5.c'],
+-                            depends = ['md5.h']) )
+             missing.append('_hashlib')
+ 
+-        if (openssl_ver < 0x00908000):
+-            # OpenSSL doesn't do these until 0.9.8 so we'll bring our own hash
+-            exts.append( Extension('_sha256', ['sha256module.c']) )
+-            exts.append( Extension('_sha512', ['sha512module.c']) )
++        ### Build these unconditionally so emerge won't fail
++        ### when openssl is dropped/broken etc.
++        # The _sha module implements the SHA1 hash algorithm.
++        exts.append( Extension('_sha', ['shamodule.c']) )
++        # The _md5 module implements the RSA Data Security, Inc. MD5
++        # Message-Digest Algorithm, described in RFC 1321.  The
++        # necessary files md5.c and md5.h are included here.
++        exts.append( Extension('_md5',
++                        sources = ['md5module.c', 'md5.c'],
++                        depends = ['md5.h']) )
++
++        exts.append( Extension('_sha256', ['sha256module.c']) )
++        exts.append( Extension('_sha512', ['sha512module.c']) )
++        ###
+ 
+         # Modules that provide persistent dictionary-like semantics.  You will
+         # probably want to arrange for at least one of them to be available on

patches/03_all_add_portage_search_path.patch

+--- Lib/site.py
++++ Lib/site.py
+@@ -269,6 +269,7 @@
+                                         "python" + sys.version[:3],
+                                         "site-packages"))
+             sitedirs.append(os.path.join(prefix, "lib", "site-python"))
++            sitedirs.append(os.path.join(prefix, "lib", "portage", "pym"))
+         else:
+             sitedirs.append(prefix)
+             sitedirs.append(os.path.join(prefix, "lib", "site-packages"))

patches/04_all_libdir.patch

+--- Lib/distutils/command/install.py
++++ Lib/distutils/command/install.py
+@@ -41,8 +41,8 @@
+ 
+ INSTALL_SCHEMES = {
+     'unix_prefix': {
+-        'purelib': '$base/lib/python$py_version_short/site-packages',
+-        'platlib': '$platbase/lib/python$py_version_short/site-packages',
++        'purelib': '$base/@@GENTOO_LIBDIR@@/python$py_version_short/site-packages',
++        'platlib': '$platbase/@@GENTOO_LIBDIR@@/python$py_version_short/site-packages',
+         'headers': '$base/include/python$py_version_short/$dist_name',
+         'scripts': '$base/bin',
+         'data'   : '$base',
+--- Lib/distutils/sysconfig.py
++++ Lib/distutils/sysconfig.py
+@@ -120,7 +120,8 @@
+ 
+     if os.name == "posix":
+         libpython = os.path.join(prefix,
+-                                 "lib", "python" + get_python_version())
++                                "@@GENTOO_LIBDIR@@",
++                                "python" + get_python_version())
+         if standard_lib:
+             return libpython
+         else:
+--- Lib/site.py
++++ Lib/site.py
+@@ -265,11 +265,11 @@
+         if sys.platform in ('os2emx', 'riscos'):
+             sitedirs.append(os.path.join(prefix, "Lib", "site-packages"))
+         elif os.sep == '/':
+-            sitedirs.append(os.path.join(prefix, "lib",
++            sitedirs.append(os.path.join(prefix, "@@GENTOO_LIBDIR@@",
+                                         "python" + sys.version[:3],
+                                         "site-packages"))
+-            sitedirs.append(os.path.join(prefix, "lib", "site-python"))
+-            sitedirs.append(os.path.join(prefix, "lib", "portage", "pym"))
++            sitedirs.append(os.path.join(prefix, "@@GENTOO_LIBDIR@@", "site-python"))
++            sitedirs.append(os.path.join(prefix, "@@GENTOO_LIBDIR@@", "portage", "pym"))
+         else:
+             sitedirs.append(prefix)
+             sitedirs.append(os.path.join(prefix, "lib", "site-packages"))
+--- Makefile.pre.in
++++ Makefile.pre.in
+@@ -91,7 +91,7 @@
+ MANDIR=		@mandir@
+ INCLUDEDIR=	@includedir@
+ CONFINCLUDEDIR=	$(exec_prefix)/include
+-SCRIPTDIR=	$(prefix)/lib
++SCRIPTDIR=	$(prefix)/@@GENTOO_LIBDIR@@
+ 
+ # Detailed destination directories
+ BINLIBDEST=	$(LIBDIR)/python$(VERSION)
+--- Modules/getpath.c
++++ Modules/getpath.c
+@@ -129,7 +129,7 @@
+ static char exec_prefix[MAXPATHLEN+1];
+ static char progpath[MAXPATHLEN+1];
+ static char *module_search_path = NULL;
+-static char lib_python[] = "lib/python" VERSION;
++static char lib_python[] = "@@GENTOO_LIBDIR@@/python" VERSION;
+ 
+ static void
+ reduce(char *dir)
+@@ -524,7 +524,7 @@
+     }
+     else
+         strncpy(zip_path, PREFIX, MAXPATHLEN);
+-    joinpath(zip_path, "lib/python00.zip");
++    joinpath(zip_path, "@@GENTOO_LIBDIR@@/python00.zip");
+     bufsz = strlen(zip_path);   /* Replace "00" with version */
+     zip_path[bufsz - 6] = VERSION[0];
+     zip_path[bufsz - 5] = VERSION[2];
+@@ -534,7 +534,7 @@
+             fprintf(stderr,
+                 "Could not find platform dependent libraries <exec_prefix>\n");
+         strncpy(exec_prefix, EXEC_PREFIX, MAXPATHLEN);
+-        joinpath(exec_prefix, "lib/lib-dynload");
++        joinpath(exec_prefix, "@@GENTOO_LIBDIR@@/lib-dynload");
+     }
+     /* If we found EXEC_PREFIX do *not* reduce it!  (Yet.) */
+ 
+--- Modules/Setup.dist
++++ Modules/Setup.dist
+@@ -460,7 +460,7 @@
+ # Andrew Kuchling's zlib module.
+ # This require zlib 1.1.3 (or later).
+ # See http://www.gzip.org/zlib/
+-#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
++#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/@@GENTOO_LIBDIR@@ -lz
+ 
+ # Interface to the Expat XML parser
+ #
+--- setup.py
++++ setup.py
+@@ -420,8 +420,7 @@
+         # if a file is found in one of those directories, it can
+         # be assumed that no additional -I,-L directives are needed.
+         lib_dirs = self.compiler.library_dirs + [
+-            '/lib64', '/usr/lib64',
+-            '/lib', '/usr/lib',
++            '/@@GENTOO_LIBDIR@@', '/usr/@@GENTOO_LIBDIR@@',
+             ]
+         inc_dirs = self.compiler.include_dirs + ['/usr/include']
+         exts = []
+@@ -674,11 +673,11 @@
+             elif curses_library:
+                 readline_libs.append(curses_library)
+             elif self.compiler.find_library_file(lib_dirs +
+-                                               ['/usr/lib/termcap'],
++                                               ['/usr/@@GENTOO_LIBDIR@@/termcap'],
+                                                'termcap'):
+                 readline_libs.append('termcap')
+             exts.append( Extension('readline', ['readline.c'],
+-                                   library_dirs=['/usr/lib/termcap'],
++                                   library_dirs=['/usr/@@GENTOO_LIBDIR@@/termcap'],
+                                    extra_link_args=readline_extra_link_args,
+                                    libraries=readline_libs) )
+         else:

patches/05_all_verbose_building_of_extensions.patch

+--- Makefile.pre.in
++++ Makefile.pre.in
+@@ -395,7 +395,6 @@
+ # Build the shared modules
+ sharedmods: $(BUILDPYTHON)
+ 	@case $$MAKEFLAGS in \
+-	*s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' LDFLAGS='$(LDFLAGS)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py -q build;; \
+ 	*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' LDFLAGS='$(LDFLAGS)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py build;; \
+ 	esac
+ 

patches/06_all_dbm_automagic.patch

+--- setup.py
++++ setup.py
+@@ -1137,16 +1137,11 @@
+ 
+         # The standard Unix dbm module:
+         if platform not in ['cygwin']:
+-            if find_file("ndbm.h", inc_dirs, []) is not None:
+-                # Some systems have -lndbm, others don't
+-                if self.compiler.find_library_file(lib_dirs, 'ndbm'):
+-                    ndbm_libs = ['ndbm']
+-                else:
+-                    ndbm_libs = []
+-                exts.append( Extension('dbm', ['dbmmodule.c'],
+-                                       define_macros=[('HAVE_NDBM_H',None)],
+-                                       libraries = ndbm_libs ) )
+-            elif self.compiler.find_library_file(lib_dirs, 'gdbm'):
++            # To prevent automagic dependencies check for relevant modules in
++            # disabled_module_list.
++            if (self.compiler.find_library_file(lib_dirs, 'gdbm')
++                    and find_file("gdbm/ndbm.h", inc_dirs, []) is not None
++                    and 'gdbm' not in disabled_module_list):
+                 gdbm_libs = ['gdbm']
+                 if self.compiler.find_library_file(lib_dirs, 'gdbm_compat'):
+                     gdbm_libs.append('gdbm_compat')
+@@ -1162,7 +1157,7 @@
+                         libraries = gdbm_libs ) )
+                 else:
+                     missing.append('dbm')
+-            elif db_incs is not None:
++            elif db_incs is not None and 'bsddb' not in disabled_module_list:
+                 exts.append( Extension('dbm', ['dbmmodule.c'],
+                                        library_dirs=dblib_dir,
+                                        runtime_library_dirs=dblib_dir,
+@@ -1170,6 +1165,18 @@
+                                        define_macros=[('HAVE_BERKDB_H',None),
+                                                       ('DB_DBM_HSEARCH',None)],
+                                        libraries=dblibs))
++            # Check for ndbm.h here after checking berkdb because ndbm.h is
++            # only provided by db-1*
++            elif (find_file("ndbm.h", inc_dirs, []) is not None
++                     and 'bsddb' not in disabled_module_list):
++                # Some systems have -lndbm, others don't
++                if self.compiler.find_library_file(lib_dirs, 'ndbm'):
++                    ndbm_libs = ['ndbm']
++                else:
++                    ndbm_libs = []
++                exts.append( Extension('dbm', ['dbmmodule.c'],
++                                        define_macros=[('HAVE_NDBM_H',None)],
++                                        libraries = ndbm_libs ) )
+             else:
+                 missing.append('dbm')
+ 

patches/07_all_internal_expat.patch

+--- setup.py
++++ setup.py
+@@ -1326,18 +1326,15 @@
+         #
+         # More information on Expat can be found at www.libexpat.org.
+         #
+-        expatinc = os.path.join(os.getcwd(), srcdir, 'Modules', 'expat')
+-        define_macros = [
+-            ('HAVE_EXPAT_CONFIG_H', '1'),
+-        ]
++        # Use system expat
++        expatinc = '/usr/include'
++        define_macros = []
+ 
+         exts.append(Extension('pyexpat',
+                               define_macros = define_macros,
+                               include_dirs = [expatinc],
++                              libraries = ['expat'],
+                               sources = ['pyexpat.c',
+-                                         'expat/xmlparse.c',
+-                                         'expat/xmlrole.c',
+-                                         'expat/xmltok.c',
+                                          ],
+                               ))
+ 
+@@ -1349,6 +1346,7 @@
+             exts.append(Extension('_elementtree',
+                                   define_macros = define_macros,
+                                   include_dirs = [expatinc],
++                                  libraries = ['expat'],
+                                   sources = ['_elementtree.c'],
+                                   ))
+         else:

patches/08_all_non-zero_exit_status_on_failure.patch

+https://bugs.gentoo.org/show_bug.cgi?id=281968
+http://bugs.python.org/issue6731
+
+--- setup.py
++++ setup.py
+@@ -31,6 +31,8 @@
+     disable_ssl = 0
+  
+ 
++exit_status = 0
++
+ def add_dir_to_list(dirlist, dir):
+     """Add the directory 'dir' to the list 'dirlist' (at the front) if
+     1) 'dir' is not already in 'dirlist'
+@@ -279,6 +281,8 @@
+             print
+ 
+         if self.failed:
++            global exit_status
++            exit_status = 1
+             failed = self.failed[:]
+             print
+             print "Failed to build these modules:"
+@@ -2050,6 +2054,7 @@
+                      'Tools/scripts/2to3',
+                      'Lib/smtpd.py']
+         )
++    sys.exit(exit_status)
+ 
+ # --install-platlib
+ if __name__ == '__main__':

patches/09_all_use_external_libffi.patch

+http://bugs.python.org/issue6943
+http://hg.python.org/cpython/rev/f02881332342
+http://hg.python.org/cpython/rev/6d9be1a97c17
+
+--- configure.in
++++ configure.in
+@@ -2046,11 +2046,20 @@
+ ],
+ [AC_MSG_RESULT(no)])
+ 
++AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
++
+ # Check for use of the system libffi library
+ AC_MSG_CHECKING(for --with-system-ffi)
+ AC_ARG_WITH(system_ffi,
+             AC_HELP_STRING(--with-system-ffi, build _ctypes module using an installed ffi library))
+ 
++if test "$with_system_ffi" = "yes" && test -n "$PKG_CONFIG"; then
++    LIBFFI_INCLUDEDIR="`"$PKG_CONFIG" libffi --cflags-only-I 2>/dev/null | sed -e 's/^-I//;s/ *$//'`"
++else
++    LIBFFI_INCLUDEDIR=""
++fi
++AC_SUBST(LIBFFI_INCLUDEDIR)
++
+ AC_MSG_RESULT($with_system_ffi)
+ 
+ # Determine if signalmodule should be used.
+--- Makefile.pre.in
++++ Makefile.pre.in
+@@ -202,6 +202,8 @@
+ GRAMMAR_INPUT=	$(srcdir)/Grammar/Grammar
+ 
+ 
++LIBFFI_INCLUDEDIR=	@LIBFFI_INCLUDEDIR@
++
+ ##########################################################################
+ # Parser
+ PGEN=		Parser/pgen$(EXE)
+--- setup.py
++++ setup.py
+@@ -1929,7 +1929,9 @@
+             # in /usr/include/ffi
+             inc_dirs.append('/usr/include/ffi')
+ 
+-        ffi_inc = find_file('ffi.h', [], inc_dirs)
++        ffi_inc = [sysconfig.get_config_var("LIBFFI_INCLUDEDIR")]
++        if not ffi_inc:
++            ffi_inc = find_file('ffi.h', [], inc_dirs)
+         if ffi_inc is not None:
+             ffi_h = ffi_inc[0] + '/ffi.h'
+             fp = open(ffi_h)

patches/10_all_sys.platform_linux2.patch

+http://bugs.python.org/issue12326
+http://hg.python.org/cpython/rev/c816479f6aaf
+
+--- configure.in
++++ configure.in
+@@ -260,6 +260,7 @@
+ 	MACHDEP="$ac_md_system$ac_md_release"
+ 
+ 	case $MACHDEP in
++	linux*) MACHDEP="linux2";;
+ 	cygwin*) MACHDEP="cygwin";;
+ 	darwin*) MACHDEP="darwin";;
+ 	atheos*) MACHDEP="atheos";;

patches/11_all_regenerate_platform-specific_modules.patch

+http://bugs.python.org/issue12619
+
+--- Lib/plat-aix4/regen
++++ Lib/plat-aix4/regen
+@@ -5,4 +5,4 @@
+         exit 1;;
+ esac
+ set -v
+-h2py.py -i '(u_long)' /usr/include/netinet/in.h
++python$EXE ../../Tools/scripts/h2py.py -i '(u_long)' /usr/include/netinet/in.h
+--- Lib/plat-linux2/regen
++++ Lib/plat-linux2/regen
+@@ -5,4 +5,4 @@
+ 	exit 1;;
+ esac
+ set -v
+-h2py -i '(u_long)' /usr/include/sys/types.h /usr/include/netinet/in.h /usr/include/dlfcn.h
++python$EXE ../../Tools/scripts/h2py.py -i '(u_long)' /usr/include/sys/types.h /usr/include/netinet/in.h /usr/include/dlfcn.h /usr/include/linux/cdrom.h
+--- Lib/plat-sunos5/regen
++++ Lib/plat-sunos5/regen
+@@ -5,5 +5,4 @@
+ 	exit 1;;
+ esac
+ set -v
+-h2py -i '(u_long)' /usr/include/sys/types.h /usr/include/netinet/in.h /usr/include/sys/stropts.h /usr/include/dlfcn.h
+-
++python$EXE ../../Tools/scripts/h2py.py -i '(u_long)' /usr/include/sys/types.h /usr/include/netinet/in.h /usr/include/sys/stropts.h /usr/include/dlfcn.h
+--- Lib/plat-unixware7/regen
++++ Lib/plat-unixware7/regen
+@@ -5,5 +5,5 @@
+ 	exit 1;;
+ esac
+ set -v
+-h2py -i '(u_long)' /usr/include/netinet/in.h
+-h2py /usr/include/sys/stropts.h
++python$EXE ../../Tools/scripts/h2py.py -i '(u_long)' /usr/include/netinet/in.h
++python$EXE ../../Tools/scripts/h2py.py /usr/include/sys/stropts.h
+--- Makefile.pre.in
++++ Makefile.pre.in
+@@ -355,7 +355,7 @@
+ 
+ # Default target
+ all:		build_all
+-build_all:	$(BUILDPYTHON) oldsharedmods sharedmods
++build_all:	$(BUILDPYTHON) oldsharedmods sharedmods platformspecificmods
+ 
+ # Compile a binary with gcc profile guided optimization.
+ profile-opt:
+@@ -400,6 +400,26 @@
+ 	*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' LDFLAGS='$(LDFLAGS)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py build;; \
+ 	esac
+ 
++# Build the platform-specific modules
++platformspecificmods: $(BUILDPYTHON) sharedmods
++	@PLATDIR=$(PLATDIR); \
++	if test ! -f $(srcdir)/Lib/$(PLATDIR)/regen; then \
++		$(INSTALL) -d $(srcdir)/Lib/$(PLATDIR); \
++		if test -f $(srcdir)/Lib/$${PLATDIR%?}/regen; then \
++			cp $(srcdir)/Lib/$${PLATDIR%?}/regen $(srcdir)/Lib/$(PLATDIR)/regen; \
++		else \
++			cp $(srcdir)/Lib/plat-generic/regen $(srcdir)/Lib/$(PLATDIR)/regen; \
++		fi \
++	fi
++	@EXE="$(BUILDEXE)"; export EXE; \
++	PATH="`pwd`:$$PATH"; export PATH; \
++	PYTHONPATH="`pwd`/Lib"; export PYTHONPATH; \
++	cd $(srcdir)/Lib/$(PLATDIR); \
++	$(RUNSHARED) ./regen || exit 1; \
++	for module in *.py; do \
++		$(RUNSHARED) $(BUILDPYTHON) -c "import py_compile; py_compile.compile('$$module', cfile='/dev/null', doraise=True)" || exit 1; \
++	done
++
+ # Build static library
+ # avoid long command lines, same as LIBRARY_OBJS
+ $(LIBRARY): $(LIBRARY_OBJS)
+@@ -845,7 +865,7 @@
+ 		multiprocessing multiprocessing/dummy \
+ 		lib-old \
+ 		curses pydoc_data $(MACHDEPS)
+-libinstall:	build_all $(srcdir)/Lib/$(PLATDIR)
++libinstall:	build_all
+ 	@for i in $(SCRIPTDIR) $(LIBDEST); \
+ 	do \
+ 		if test ! -d $(DESTDIR)$$i; then \
+@@ -920,16 +940,6 @@
+ 	-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
+ 		./$(BUILDPYTHON) -Wi -t -c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()"
+ 
+-# Create the PLATDIR source directory, if one wasn't distributed..
+-$(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`"; \
+-	export EXE; EXE="$(BUILDEXE)"; \
+-	cd $(srcdir)/Lib/$(PLATDIR); $(RUNSHARED) ./regen
+-
+ # Install the include files
+ INCLDIRSTOMAKE=$(INCLUDEDIR) $(CONFINCLUDEDIR) $(INCLUDEPY) $(CONFINCLUDEPY)
+ inclinstall:
+@@ -1212,7 +1222,7 @@
+ Python/thread.o: @THREADHEADERS@
+ 
+ # Declare targets that aren't real files
+-.PHONY: all build_all sharedmods oldsharedmods test quicktest memtest
++.PHONY: all build_all sharedmods oldsharedmods platformspecificmods test quicktest memtest
+ .PHONY: install altinstall oldsharedinstall bininstall altbininstall
+ .PHONY: maninstall libinstall inclinstall libainstall sharedinstall
+ .PHONY: frameworkinstall frameworkinstallframework frameworkinstallstructure

patches/21_all_distutils_c++.patch

+http://bugs.python.org/issue1222585
+
+--- configure.in
++++ configure.in
+@@ -1723,6 +1723,7 @@
+ # Set info about shared libraries.
+ AC_SUBST(SO)
+ AC_SUBST(LDSHARED)
++AC_SUBST(LDCXXSHARED)
+ AC_SUBST(BLDSHARED)
+ AC_SUBST(CCSHARED)
+ AC_SUBST(LINKFORSHARED)
+@@ -1775,36 +1776,47 @@
+ 	IRIX/5*) LDSHARED="ld -shared";;
+ 	IRIX*/6*) LDSHARED="ld ${SGI_ABI} -shared -all";;
+ 	SunOS/5*) 
+-		if test "$GCC" = "yes"
+-		then LDSHARED='$(CC) -shared'
+-		else LDSHARED='$(CC) -G';
++		if test "$GCC" = "yes" ; then
++			LDSHARED='$(CC) -shared'
++			LDCXXSHARED='$(CXX) -shared'
++		else
++			LDSHARED='$(CC) -G'
++			LDCXXSHARED='$(CXX) -G'
+ 		fi ;;
+ 	hp*|HP*)
+-		if test "$GCC" = "yes"
+-		then LDSHARED='$(CC) -shared'
+-		else LDSHARED='ld -b';
++		if test "$GCC" = "yes" ; then
++			LDSHARED='$(CC) -shared'
++			LDCXXSHARED='$(CXX) -shared'
++		else
++			LDSHARED='ld -b'
+ 		fi ;;
+ 	OSF*) LDSHARED="ld -shared -expect_unresolved \"*\"";;
+ 	Darwin/1.3*)
+ 		LDSHARED='$(CC) $(LDFLAGS) -bundle'
++		LDCXXSHARED='$(CXX) $(LDFLAGS) -bundle'
+ 		if test "$enable_framework" ; then
+ 			# Link against the framework. All externals should be defined.
+ 			BLDSHARED="$LDSHARED "'$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)'
+ 			LDSHARED="$LDSHARED "'$(PYTHONFRAMEWORKPREFIX)/$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)'
++			LDCXXSHARED="$LDCXXSHARED "'$(PYTHONFRAMEWORKPREFIX)/$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)'
+ 		else
+ 			# No framework. Ignore undefined symbols, assuming they come from Python
+ 			LDSHARED="$LDSHARED -undefined suppress"
++			LDCXXSHARED="$LDCXXSHARED -undefined suppress"
+ 		fi ;;
+ 	Darwin/1.4*|Darwin/5.*|Darwin/6.*)
+ 		LDSHARED='$(CC) $(LDFLAGS) -bundle'
++		LDCXXSHARED='$(CXX) $(LDFLAGS) -bundle'
+ 		if test "$enable_framework" ; then
+ 			# Link against the framework. All externals should be defined.
+ 			BLDSHARED="$LDSHARED "'$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)'
+ 			LDSHARED="$LDSHARED "'$(PYTHONFRAMEWORKPREFIX)/$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)'
++			LDCXXSHARED="$LDCXXSHARED "'$(PYTHONFRAMEWORKPREFIX)/$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)'
+ 		else
+ 			# No framework, use the Python app as bundle-loader
+ 			BLDSHARED="$LDSHARED "'-bundle_loader $(BUILDPYTHON)'
+ 			LDSHARED="$LDSHARED "'-bundle_loader $(BINDIR)/python$(VERSION)$(EXE)'
++			LDCXXSHARED="$LDCXXSHARED "'-bundle_loader $(BINDIR)/python$(VERSION)$(EXE)'
+ 		fi ;;
+ 	Darwin/*)
+ 		# Use -undefined dynamic_lookup whenever possible (10.3 and later).
+@@ -1816,26 +1828,35 @@
+ 				LDFLAGS="${UNIVERSAL_ARCH_FLAGS} -isysroot ${UNIVERSALSDK} ${LDFLAGS}"
+ 			fi
+ 			LDSHARED='$(CC) $(LDFLAGS) -bundle -undefined dynamic_lookup'
++			LDCXXSHARED='$(CXX) $(LDFLAGS) -bundle -undefined dynamic_lookup'
+ 			BLDSHARED="$LDSHARED"
+ 		else
+ 			LDSHARED='$(CC) $(LDFLAGS) -bundle'
++			LDCXXSHARED='$(CXX) $(LDFLAGS) -bundle'
+ 			if test "$enable_framework" ; then
+ 				# Link against the framework. All externals should be defined.
+ 				BLDSHARED="$LDSHARED "'$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)'
+ 				LDSHARED="$LDSHARED "'$(PYTHONFRAMEWORKPREFIX)/$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)'
++				LDCXXSHARED="$LDCXXSHARED "'$(PYTHONFRAMEWORKPREFIX)/$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)'
+ 			else
+ 				# No framework, use the Python app as bundle-loader
+ 				BLDSHARED="$LDSHARED "'-bundle_loader $(BUILDPYTHON)'
+ 				LDSHARED="$LDSHARED "'-bundle_loader $(BINDIR)/python$(VERSION)$(EXE)'
++				LDCXXSHARED="$LDCXXSHARED "'-bundle_loader $(BINDIR)/python$(VERSION)$(EXE)'
+ 			fi
+ 		fi
+ 		;;
+-	Linux*|GNU*|QNX*) LDSHARED='$(CC) -shared';;
+-	BSD/OS*/4*) LDSHARED="gcc -shared";;
++	Linux*|GNU*|QNX*)
++		LDSHARED='$(CC) -shared'
++		LDCXXSHARED='$(CXX) -shared';;
++	BSD/OS*/4*)
++		LDSHARED="gcc -shared"
++		LDCXXSHARED="g++ -shared";;
+ 	FreeBSD*)
+ 		if [[ "`$CC -dM -E - </dev/null | grep __ELF__`" != "" ]]
+ 		then
+ 			LDSHARED='$(CC) -shared ${LDFLAGS}'
++			LDCXXSHARED='$(CXX) -shared ${LDFLAGS}'
+ 		else
+ 			LDSHARED="ld -Bshareable ${LDFLAGS}"
+ 		fi;;
+@@ -1843,6 +1864,7 @@
+ 		if [[ "`$CC -dM -E - </dev/null | grep __ELF__`" != "" ]]
+ 		then
+ 				LDSHARED='$(CC) -shared $(CCSHARED) ${LDFLAGS}'
++				LDCXXSHARED='$(CXX) -shared $(CCSHARED) ${LDFLAGS}'
+ 		else
+ 				case `uname -r` in
+ 				[[01]].* | 2.[[0-7]] | 2.[[0-7]].*)
+@@ -1850,23 +1872,36 @@
+ 				   ;;
+ 				*)
+ 				   LDSHARED='$(CC) -shared $(CCSHARED) ${LDFLAGS}'
++				   LDCXXSHARED='$(CXX) -shared $(CCSHARED) ${LDFLAGS}'
+ 				   ;;
+ 				esac
+ 		fi;;
+-	NetBSD*|DragonFly*) LDSHARED="cc -shared ${LDFLAGS}";;
++	NetBSD*|DragonFly*)
++		LDSHARED="cc -shared ${LDFLAGS}"
++		LDCXXSHARED="c++ -shared ${LDFLAGS}";;
+ 	OpenUNIX*|UnixWare*)
+-		if test "$GCC" = "yes"
+-		then LDSHARED='$(CC) -shared'
+-		else LDSHARED='$(CC) -G'
++		if test "$GCC" = "yes" ; then
++			LDSHARED='$(CC) -shared'
++			LDCXXSHARED='$(CXX) -shared'
++		else
++			LDSHARED='$(CC) -G'
++			LDCXXSHARED='$(CXX) -G'
+ 		fi;;
+-	SCO_SV*) LDSHARED='$(CC) -Wl,-G,-Bexport';;
++	SCO_SV*)
++		LDSHARED='$(CC) -Wl,-G,-Bexport'
++		LDCXXSHARED='$(CXX) -Wl,-G,-Bexport';;
+ 	Monterey*) LDSHARED="cc -G -dy -Bdynamic -Bexport -L/usr/lib/ia64l64";;
+-	CYGWIN*) LDSHARED="gcc -shared -Wl,--enable-auto-image-base";;
+-	atheos*) LDSHARED="gcc -shared";;
++	CYGWIN*)
++		LDSHARED="gcc -shared -Wl,--enable-auto-image-base"
++		LDCXXSHARED="g++ -shared -Wl,--enable-auto-image-base";;
++	atheos*)
++		LDSHARED="gcc -shared"
++		LDCXXSHARED="g++ -shared";;
+ 	*)	LDSHARED="ld";;
+ 	esac
+ fi
+ AC_MSG_RESULT($LDSHARED)
++LDCXXSHARED=${LDCXXSHARED-$LDSHARED}
+ BLDSHARED=${BLDSHARED-$LDSHARED}
+ # CCSHARED are the C *flags* used to create objects to go into a shared
+ # library (module) -- this is only needed for a few systems
+--- Lib/distutils/cygwinccompiler.py
++++ Lib/distutils/cygwinccompiler.py
+@@ -132,9 +132,13 @@
+         self.set_executables(compiler='gcc -mcygwin -O -Wall',
+                              compiler_so='gcc -mcygwin -mdll -O -Wall',
+                              compiler_cxx='g++ -mcygwin -O -Wall',
++                             compiler_so_cxx='g++ -mcygwin -mdll -O -Wall',
+                              linker_exe='gcc -mcygwin',
+                              linker_so=('%s -mcygwin %s' %
+-                                        (self.linker_dll, shared_option)))
++                                        (self.linker_dll, shared_option)),
++                             linker_exe_cxx='g++ -mcygwin',
++                             linker_so_cxx=('%s -mcygwin %s' %
++                                            (self.linker_dll, shared_option)))
+ 
+         # cygwin and mingw32 need different sets of libraries
+         if self.gcc_version == "2.91.57":
+@@ -160,8 +164,12 @@
+                 raise CompileError, msg
+         else: # for other files use the C-compiler
+             try:
+-                self.spawn(self.compiler_so + cc_args + [src, '-o', obj] +
+-                           extra_postargs)
++                if self.detect_language(src) == 'c++':
++                    self.spawn(self.compiler_so_cxx + cc_args + [src, '-o', obj] +
++                               extra_postargs)
++                else:
++                    self.spawn(self.compiler_so + cc_args + [src, '-o', obj] +
++                               extra_postargs)
+             except DistutilsExecError, msg:
+                 raise CompileError, msg
+ 
+@@ -322,10 +330,15 @@
+         self.set_executables(compiler='gcc -mno-cygwin -O -Wall',
+                              compiler_so='gcc -mno-cygwin -mdll -O -Wall',
+                              compiler_cxx='g++ -mno-cygwin -O -Wall',
++                             compiler_so_cxx='g++ -mno-cygwin -mdll -O -Wall',
+                              linker_exe='gcc -mno-cygwin',
+                              linker_so='%s -mno-cygwin %s %s'
+                                         % (self.linker_dll, shared_option,
+-                                           entry_point))
++                                           entry_point),
++                             linker_exe_cxx='g++ -mno-cygwin',
++                             linker_so_cxx='%s -mno-cygwin %s %s'
++                                            % (self.linker_dll, shared_option,
++                                               entry_point))
+         # Maybe we should also append -mthreads, but then the finished
+         # dlls need another dll (mingwm10.dll see Mingw32 docs)
+         # (-mthreads: Support thread-safe exception handling on `Mingw32')
+--- Lib/distutils/emxccompiler.py
++++ Lib/distutils/emxccompiler.py
+@@ -65,8 +65,12 @@
+         # XXX optimization, warnings etc. should be customizable.
+         self.set_executables(compiler='gcc -Zomf -Zmt -O3 -fomit-frame-pointer -mprobe -Wall',
+                              compiler_so='gcc -Zomf -Zmt -O3 -fomit-frame-pointer -mprobe -Wall',
++                             compiler_cxx='g++ -Zomf -Zmt -O3 -fomit-frame-pointer -mprobe -Wall',
++                             compiler_so_cxx='g++ -Zomf -Zmt -O3 -fomit-frame-pointer -mprobe -Wall',
+                              linker_exe='gcc -Zomf -Zmt -Zcrtdll',
+-                             linker_so='gcc -Zomf -Zmt -Zcrtdll -Zdll')
++                             linker_so='gcc -Zomf -Zmt -Zcrtdll -Zdll',
++                             linker_exe_cxx='g++ -Zomf -Zmt -Zcrtdll',
++                             linker_so_cxx='g++ -Zomf -Zmt -Zcrtdll -Zdll')
+ 
+         # want the gcc library statically linked (so that we don't have
+         # to distribute a version dependent on the compiler we have)
+@@ -83,8 +87,12 @@
+                 raise CompileError, msg
+         else: # for other files use the C-compiler
+             try:
+-                self.spawn(self.compiler_so + cc_args + [src, '-o', obj] +
+-                           extra_postargs)
++                if self.detect_language(src) == 'c++':
++                    self.spawn(self.compiler_so_cxx + cc_args + [src, '-o', obj] +
++                               extra_postargs)
++                else:
++                    self.spawn(self.compiler_so + cc_args + [src, '-o', obj] +
++                               extra_postargs)
+             except DistutilsExecError, msg:
+                 raise CompileError, msg
+ 
+--- Lib/distutils/sysconfig.py
++++ Lib/distutils/sysconfig.py
+@@ -167,9 +167,12 @@
+     varies across Unices and is stored in Python's Makefile.
+     """
+     if compiler.compiler_type == "unix":
+-        (cc, cxx, opt, cflags, ccshared, ldshared, so_ext) = \
+-            get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS',
+-                            'CCSHARED', 'LDSHARED', 'SO')
++        (cc, cxx, ccshared, ldshared, ldcxxshared, so_ext) = \
++            get_config_vars('CC', 'CXX', 'CCSHARED', 'LDSHARED',
++                            'LDCXXSHARED', 'SO')
++
++        cflags = ''
++        cxxflags = ''
+ 
+         if 'CC' in os.environ:
+             cc = os.environ['CC']
+@@ -177,28 +180,40 @@
+             cxx = os.environ['CXX']
+         if 'LDSHARED' in os.environ:
+             ldshared = os.environ['LDSHARED']
++        if 'LDCXXSHARED' in os.environ:
++            ldcxxshared = os.environ['LDCXXSHARED']
+         if 'CPP' in os.environ:
+             cpp = os.environ['CPP']
+         else:
+             cpp = cc + " -E"           # not always
+         if 'LDFLAGS' in os.environ:
+             ldshared = ldshared + ' ' + os.environ['LDFLAGS']
++            ldcxxshared = ldcxxshared + ' ' + os.environ['LDFLAGS']
+         if 'CFLAGS' in os.environ:
+-            cflags = opt + ' ' + os.environ['CFLAGS']
++            cflags = os.environ['CFLAGS']
+             ldshared = ldshared + ' ' + os.environ['CFLAGS']
++        if 'CXXFLAGS' in os.environ:
++            cxxflags = os.environ['CXXFLAGS']
++            ldcxxshared = ldcxxshared + ' ' + os.environ['CXXFLAGS']
+         if 'CPPFLAGS' in os.environ:
+             cpp = cpp + ' ' + os.environ['CPPFLAGS']
+             cflags = cflags + ' ' + os.environ['CPPFLAGS']
++            cxxflags = cxxflags + ' ' + os.environ['CPPFLAGS']
+             ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
++            ldcxxshared = ldcxxshared + ' ' + os.environ['CPPFLAGS']
+ 
+         cc_cmd = cc + ' ' + cflags
++        cxx_cmd = cxx + ' ' + cxxflags
+         compiler.set_executables(
+             preprocessor=cpp,
+             compiler=cc_cmd,
+             compiler_so=cc_cmd + ' ' + ccshared,
+-            compiler_cxx=cxx,
++            compiler_cxx=cxx_cmd,
++            compiler_so_cxx=cxx_cmd + ' ' + ccshared,
+             linker_so=ldshared,
+-            linker_exe=cc)
++            linker_exe=cc,
++            linker_so_cxx=ldcxxshared,
++            linker_exe_cxx=cxx)
+ 
+         compiler.shared_lib_extension = so_ext
+ 
+@@ -546,7 +561,7 @@
+                 for key in ('LDFLAGS', 'BASECFLAGS', 'LDSHARED',
+                         # a number of derived variables. These need to be
+                         # patched up as well.
+-                        'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
++                        'CFLAGS', 'CXXFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
+                     flags = _config_vars[key]
+                     flags = re.sub('-arch\s+\w+\s', ' ', flags)
+                     flags = re.sub('-isysroot [^ \t]*', ' ', flags)
+@@ -565,7 +580,7 @@
+                     for key in ('LDFLAGS', 'BASECFLAGS', 'LDSHARED',
+                         # a number of derived variables. These need to be
+                         # patched up as well.
+-                        'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
++                        'CFLAGS', 'CXXFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
+ 
+                         flags = _config_vars[key]
+                         flags = re.sub('-arch\s+\w+\s', ' ', flags)
+@@ -589,7 +604,7 @@
+                         for key in ('LDFLAGS', 'BASECFLAGS', 'LDSHARED',
+                              # a number of derived variables. These need to be
+                              # patched up as well.
+-                            'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
++                            'CFLAGS', 'CXXFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
+ 
+                             flags = _config_vars[key]
+                             flags = re.sub('-isysroot\s+\S+(\s|$)', ' ', flags)
+--- Lib/distutils/unixccompiler.py
++++ Lib/distutils/unixccompiler.py
+@@ -114,14 +114,17 @@
+     # are pretty generic; they will probably have to be set by an outsider
+     # (eg. using information discovered by the sysconfig about building
+     # Python extensions).
+-    executables = {'preprocessor' : None,
+-                   'compiler'     : ["cc"],
+-                   'compiler_so'  : ["cc"],
+-                   'compiler_cxx' : ["cc"],
+-                   'linker_so'    : ["cc", "-shared"],
+-                   'linker_exe'   : ["cc"],
+-                   'archiver'     : ["ar", "-cr"],
+-                   'ranlib'       : None,
++    executables = {'preprocessor'    : None,
++                   'compiler'        : ["cc"],
++                   'compiler_so'     : ["cc"],
++                   'compiler_cxx'    : ["c++"],
++                   'compiler_so_cxx' : ["c++"],
++                   'linker_so'       : ["cc", "-shared"],
++                   'linker_exe'      : ["cc"],
++                   'linker_so_cxx'   : ["c++", "-shared"],
++                   'linker_exe_cxx'  : ["c++"],
++                   'archiver'        : ["ar", "-cr"],
++                   'ranlib'          : None,
+                   }
+ 
+     if sys.platform[:6] == "darwin":
+@@ -171,11 +174,18 @@
+ 
+     def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
+         compiler_so = self.compiler_so
++        compiler_so_cxx = self.compiler_so_cxx
+         if sys.platform == 'darwin':
+             compiler_so = _darwin_compiler_fixup(compiler_so, cc_args + extra_postargs)
++            compiler_so_cxx = _darwin_compiler_fixup(compiler_so_cxx, cc_args +
++                                                     extra_postargs)
+         try:
+-            self.spawn(compiler_so + cc_args + [src, '-o', obj] +
+-                       extra_postargs)
++            if self.detect_language(src) == 'c++':
++                self.spawn(compiler_so_cxx + cc_args + [src, '-o', obj] +
++                           extra_postargs)
++            else:
++                self.spawn(compiler_so + cc_args + [src, '-o', obj] +
++                           extra_postargs)
+         except DistutilsExecError, msg:
+             raise CompileError, msg
+ 
+@@ -232,23 +242,16 @@
+                 ld_args.extend(extra_postargs)
+             self.mkpath(os.path.dirname(output_filename))
+             try:
+-                if target_desc == CCompiler.EXECUTABLE:
+-                    linker = self.linker_exe[:]
++                if target_lang == "c++":
++                    if target_desc == CCompiler.EXECUTABLE:
++                        linker = self.linker_exe_cxx[:]
++                    else:
++                        linker = self.linker_so_cxx[:]
+                 else:
+-                    linker = self.linker_so[:]
+-                if target_lang == "c++" and self.compiler_cxx:
+-                    # skip over environment variable settings if /usr/bin/env
+-                    # is used to set up the linker's environment.
+-                    # This is needed on OSX. Note: this assumes that the
+-                    # normal and C++ compiler have the same environment
+-                    # settings.
+-                    i = 0
+-                    if os.path.basename(linker[0]) == "env":
+-                        i = 1
+-                        while '=' in linker[i]:
+-                            i = i + 1
+-
+-                    linker[i] = self.compiler_cxx[i]
++                    if target_desc == CCompiler.EXECUTABLE:
++                        linker = self.linker_exe[:]
++                    else:
++                        linker = self.linker_so[:]
+ 
+                 if sys.platform == 'darwin':
+                     linker = _darwin_compiler_fixup(linker, ld_args)
+--- Makefile.pre.in
++++ Makefile.pre.in
+@@ -104,6 +104,7 @@
+ SO=		@SO@
+ LDSHARED=	@LDSHARED@
+ BLDSHARED=	@BLDSHARED@
++LDCXXSHARED=	@LDCXXSHARED@
+ DESTSHARED=	$(BINLIBDEST)/lib-dynload
+ 
+ # Executable suffix (.exe on Windows and Mac OS X)
+@@ -397,7 +398,7 @@
+ # Build the shared modules
+ sharedmods: $(BUILDPYTHON)
+ 	@case $$MAKEFLAGS in \
+-	*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' LDFLAGS='$(LDFLAGS)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py build;; \
++	*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' LDFLAGS='$(LDFLAGS)' CFLAGS='$(CFLAGS)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py build;; \
+ 	esac
+ 
+ # Build the platform-specific modules

patches/22_all_turkish_locale.patch

+https://bugs.gentoo.org/show_bug.cgi?id=250075
+http://bugs.python.org/issue1813
+
+--- Lib/decimal.py
++++ Lib/decimal.py
+@@ -153,6 +153,13 @@
+ ROUND_HALF_DOWN = 'ROUND_HALF_DOWN'
+ ROUND_05UP = 'ROUND_05UP'
+ 
++import string
++
++def ascii_upper(s):
++    trans_table = string.maketrans(string.ascii_lowercase, string.ascii_uppercase)
++    return s.translate(trans_table)
++
++
+ # Errors
+ 
+ class DecimalException(ArithmeticError):
+@@ -3645,7 +3652,7 @@
+                                     if name.startswith('_round_')]
+ for name in rounding_functions:
+     # name is like _round_half_even, goes to the global ROUND_HALF_EVEN value.
+-    globalname = name[1:].upper()
++    globalname = ascii_upper(name[1:])
+     val = globals()[globalname]
+     Decimal._pick_rounding_function[val] = name
+ 
+--- Lib/email/__init__.py
++++ Lib/email/__init__.py
+@@ -109,15 +109,19 @@
+     'Text',
+     ]
+ 
++import string
++lower_map = string.maketrans(string.ascii_uppercase, string.ascii_lowercase)
++
++
+ for _name in _LOWERNAMES:
+-    importer = LazyImporter(_name.lower())
++    importer = LazyImporter(_name.translate(lower_map))
+     sys.modules['email.' + _name] = importer
+     setattr(sys.modules['email'], _name, importer)
+ 
+ 
+ import email.mime
+ for _name in _MIMENAMES:
+-    importer = LazyImporter('mime.' + _name.lower())
++    importer = LazyImporter('mime.' + _name.translate(lower_map))
+     sys.modules['email.MIME' + _name] = importer
+     setattr(sys.modules['email'], 'MIME' + _name, importer)
+     setattr(sys.modules['email.mime'], _name, importer)
+--- Lib/locale.py
++++ Lib/locale.py
+@@ -313,6 +313,14 @@
+ # overridden below)
+ _setlocale = setlocale
+ 
++# Avoid relying on the locale-dependent .lower() method
++# (see bug #1813).
++_ascii_lower_map = ''.join(
++    chr(x + 32 if x >= ord('A') and x <= ord('Z') else x)
++    for x in range(256)
++)
++
++
+ def normalize(localename):
+ 
+     """ Returns a normalized locale code for the given locale
+@@ -330,7 +338,7 @@
+ 
+     """
+     # Normalize the locale name and extract the encoding
+-    fullname = localename.lower()
++    fullname = localename.encode('ascii').translate(_ascii_lower_map)
+     if ':' in fullname:
+         # ':' is sometimes used as encoding delimiter.
+         fullname = fullname.replace(':', '.')
+--- Lib/test/test_codecs.py
++++ Lib/test/test_codecs.py
+@@ -1,5 +1,6 @@
+ from test import test_support
+ import unittest
++import locale
+ import codecs
+ import sys, StringIO, _testcapi
+ 
+@@ -1133,6 +1134,16 @@
+         self.assertRaises(LookupError, codecs.lookup, "__spam__")
+         self.assertRaises(LookupError, codecs.lookup, " ")
+ 
++    def test_lookup_with_locale(self):
++        # Bug #1813: when normalizing codec name, lowercasing must be locale
++        # agnostic, otherwise the looked up codec name might end up wrong.
++        try:
++            locale.setlocale(locale.LC_CTYPE, 'tr')
++        except locale.Error:
++            # SKIPped test
++            return
++        codecs.lookup('ISO8859_1')
++
+     def test_getencoder(self):
+         self.assertRaises(TypeError, codecs.getencoder)
+         self.assertRaises(LookupError, codecs.getencoder, "__spam__")
+--- Python/codecs.c
++++ Python/codecs.c
+@@ -45,6 +45,12 @@
+     return -1;
+ }
+ 
++/* isupper() forced into the ASCII locale */
++#define ascii_isupper(x) (((x) >= 0x41) && ((x) <= 0x5A))
++/* tolower() forced into the ASCII locale */
++#define ascii_tolower(x) (ascii_isupper(x) ? ((x) + 0x20) : (x))
++
++
+ /* Convert a string to a normalized Python string: all characters are
+    converted to lower case, spaces are replaced with underscores. */
+ 
+@@ -70,7 +76,7 @@
+         if (ch == ' ')
+             ch = '-';
+         else
+-            ch = tolower(Py_CHARMASK(ch));
++            ch = ascii_tolower(Py_CHARMASK(ch));
+         p[i] = ch;
+     }
+     return v;

patches/23_all_arm_OABI.patch

+https://bugs.gentoo.org/show_bug.cgi?id=266703
+http://bugs.python.org/issue1762561
+
+--- Objects/floatobject.c
++++ Objects/floatobject.c
+@@ -1691,9 +1691,18 @@
+ /* this is for the benefit of the pack/unpack routines below */
+ 
+ typedef enum {
+-    unknown_format, ieee_big_endian_format, ieee_little_endian_format
++    unknown_format,
++    ieee_big_endian_format,
++    ieee_little_endian_format,
++    ieee_arm_mixed_endian_format
+ } float_format_type;
+ 
++/* byte order of a C double for each of the recognised IEEE formats */
++
++static const unsigned char BIG_ENDIAN_BYTEORDER[8] = {7,6,5,4,3,2,1,0};
++static const unsigned char LITTLE_ENDIAN_BYTEORDER[8] = {0,1,2,3,4,5,6,7};
++static const unsigned char ARM_MIXED_ENDIAN_BYTEORDER[8] = {4,5,6,7,0,1,2,3};
++
+ static float_format_type double_format, float_format;
+ static float_format_type detected_double_format, detected_float_format;
+ 
+@@ -1730,6 +1739,8 @@
+         return PyString_FromString("IEEE, little-endian");
+     case ieee_big_endian_format:
+         return PyString_FromString("IEEE, big-endian");
++    case ieee_arm_mixed_endian_format:
++        return PyString_FromString("IEEE, ARM mixed-endian");
+     default:
+         Py_FatalError("insane float_format or double_format");
+         return NULL;
+@@ -1743,8 +1754,9 @@
+ "used in Python's test suite.\n"
+ "\n"
+ "typestr must be 'double' or 'float'.  This function returns whichever of\n"
+-"'unknown', 'IEEE, big-endian' or 'IEEE, little-endian' best describes the\n"
+-"format of floating point numbers used by the C type named by typestr.");
++"'unknown', 'IEEE, big-endian', 'IEEE, little-endian' or\n"
++"'IEEE, ARM mixed-endian' best describes the format of floating-point\n"
++"numbers used by the C type named by typestr.");
+ 
+ static PyObject *
+ float_setformat(PyTypeObject *v, PyObject* args)
+@@ -1782,11 +1794,15 @@
+     else if (strcmp(format, "IEEE, big-endian") == 0) {
+         f = ieee_big_endian_format;
+     }
++    else if (strcmp(format, "IEEE, ARM mixed-endian") == 0 &&
++             p == &double_format) {
++        f = ieee_arm_mixed_endian_format;
++    }
+     else {
+         PyErr_SetString(PyExc_ValueError,
+                         "__setformat__() argument 2 must be "
+-                        "'unknown', 'IEEE, little-endian' or "
+-                        "'IEEE, big-endian'");
++                        "'unknown', 'IEEE, little-endian', "
++                        "'IEEE, big-endian' or 'IEEE, ARM mixed-endian'");
+         return NULL;
+ 
+     }
+@@ -1809,8 +1825,10 @@
+ "used in Python's test suite.\n"
+ "\n"
+ "typestr must be 'double' or 'float'.  fmt must be one of 'unknown',\n"
+-"'IEEE, big-endian' or 'IEEE, little-endian', and in addition can only be\n"
+-"one of the latter two if it appears to match the underlying C reality.\n"
++"'IEEE, big-endian', 'IEEE, little-endian' or 'IEEE, ARM mixed-endian'\n"
++"and in addition can only be one of the last three if it appears to\n"
++"match the underlying C reality.  Note that the ARM mixed-endian\n"
++"format can only be set for the 'double' type, not for 'float'.\n"
+ "\n"
+ "Overrides the automatic determination of C-level floating point type.\n"
+ "This affects how floats are converted to and from binary strings.");
+@@ -2005,7 +2023,11 @@
+        Note that if we're on some whacked-out platform which uses
+        IEEE formats but isn't strictly little-endian or big-
+        endian, we will fall back to the portable shifts & masks
+-       method. */
++       method.
++
++       Addendum: We also attempt to detect the mixed-endian IEEE format
++       used by the ARM old ABI (OABI) and also used by the FPA
++       floating-point unit on some older ARM processors. */
+ 
+ #if SIZEOF_DOUBLE == 8
+     {
+@@ -2014,6 +2036,8 @@
+             detected_double_format = ieee_big_endian_format;
+         else if (memcmp(&x, "\x05\x04\x03\x02\x01\xff\x3f\x43", 8) == 0)
+             detected_double_format = ieee_little_endian_format;
++        else if (memcmp(&x, "\x01\xff\x3f\x43\x05\x04\x03\x02", 8) == 0)
++            detected_double_format = ieee_arm_mixed_endian_format;
+         else
+             detected_double_format = unknown_format;
+     }
+@@ -2353,17 +2377,31 @@
+     }
+     else {
+         const char *s = (char*)&x;
+-        int i, incr = 1;
++        int i;
++        const unsigned char *byteorder;
+ 
+-        if ((double_format == ieee_little_endian_format && !le)
+-            || (double_format == ieee_big_endian_format && le)) {
+-            p += 7;
+-            incr = -1;
++        switch (double_format) {
++        case ieee_little_endian_format:
++            byteorder = LITTLE_ENDIAN_BYTEORDER;
++            break;
++        case ieee_big_endian_format:
++            byteorder = BIG_ENDIAN_BYTEORDER;
++            break;
++        case ieee_arm_mixed_endian_format:
++            byteorder = ARM_MIXED_ENDIAN_BYTEORDER;
++            break;
++        default:
++            Py_FatalError("insane float_format or double_format");
++            return -1;
+         }
+ 
+-        for (i = 0; i < 8; i++) {
+-            *p = *s++;
+-            p += incr;
++        if (le) {
++            for (i = 0; i < 8; i++)
++                p[byteorder[i]] = *s++;
++        }
++        else {
++            for (i = 0; i < 8; i++)
++                p[7-byteorder[i]] = *s++;
+         }
+         return 0;
+     }
+@@ -2522,22 +2560,33 @@
+     }
+     else {
+         double x;
++        char *s = (char*)&x;
++        const unsigned char *byteorder;
++        int i;
++
++        switch (double_format) {
++        case ieee_little_endian_format:
++            byteorder = LITTLE_ENDIAN_BYTEORDER;
++            break;
++        case ieee_big_endian_format:
++            byteorder = BIG_ENDIAN_BYTEORDER;
++            break;
++        case ieee_arm_mixed_endian_format:
++            byteorder = ARM_MIXED_ENDIAN_BYTEORDER;
++            break;
++        default:
++            Py_FatalError("insane float_format or double_format");
++            return -1.0;
++        }
+ 
+-        if ((double_format == ieee_little_endian_format && !le)
+-            || (double_format == ieee_big_endian_format && le)) {
+-            char buf[8];
+-            char *d = &buf[7];
+-            int i;
+-
+-            for (i = 0; i < 8; i++) {
+-                *d-- = *p++;
+-            }
+-            memcpy(&x, buf, 8);
++        if (le) {
++            for (i=0; i<8; i++)
++                *s++ = p[byteorder[i]];
+         }
+         else {
+-            memcpy(&x, p, 8);
++            for (i=0; i<8; i++)
++                *s++ = p[7-byteorder[i]];
+         }
+-
+         return x;
+     }
+ }

patches/24_all_ctypes_mmap_wx.patch

+https://bugs.gentoo.org/show_bug.cgi?id=329499
+http://bugs.python.org/issue5504
+http://hg.python.org/cpython/rev/e13ea83e2edb
+
+--- Modules/_ctypes/callbacks.c
++++ Modules/_ctypes/callbacks.c
+@@ -21,8 +21,8 @@
+     Py_XDECREF(self->converters);
+     Py_XDECREF(self->callable);
+     Py_XDECREF(self->restype);
+-    if (self->pcl)
+-        FreeClosure(self->pcl);
++    if (self->pcl_write)
++        ffi_closure_free(self->pcl_write);
+     PyObject_GC_Del(self);
+ }
+ 
+@@ -373,7 +373,8 @@
+         return NULL;
+     }
+ 
+-    p->pcl = NULL;
++    p->pcl_exec = NULL;
++    p->pcl_write = NULL;
+     memset(&p->cif, 0, sizeof(p->cif));
+     p->converters = NULL;
+     p->callable = NULL;
+@@ -403,8 +404,9 @@
+ 
+     assert(CThunk_CheckExact(p));
+ 
+-    p->pcl = MallocClosure();
+-    if (p->pcl == NULL) {
++    p->pcl_write = ffi_closure_alloc(sizeof(ffi_closure),
++                                     &p->pcl_exec);
++    if (p->pcl_write == NULL) {
+         PyErr_NoMemory();
+         goto error;
+     }
+@@ -449,7 +451,9 @@
+                      "ffi_prep_cif failed with %d", result);
+         goto error;
+     }
+-    result = ffi_prep_closure(p->pcl, &p->cif, closure_fcn, p);
++    result = ffi_prep_closure_loc(p->pcl_write, &p->cif, closure_fcn,
++                                  p,
++                                  p->pcl_exec);
+     if (result != FFI_OK) {
+         PyErr_Format(PyExc_RuntimeError,
+                      "ffi_prep_closure failed with %d", result);
+--- Modules/_ctypes/_ctypes.c
++++ Modules/_ctypes/_ctypes.c
+@@ -3443,7 +3443,7 @@
+     self->callable = callable;
+ 
+     self->thunk = thunk;
+-    *(void **)self->b_ptr = (void *)thunk->pcl;
++    *(void **)self->b_ptr = (void *)thunk->pcl_exec;
+ 
+     Py_INCREF((PyObject *)thunk); /* for KeepRef */
+     if (-1 == KeepRef((CDataObject *)self, 0, (PyObject *)thunk)) {
+--- Modules/_ctypes/ctypes.h
++++ Modules/_ctypes/ctypes.h
+@@ -95,7 +95,8 @@
+ 
+ typedef struct {
+     PyObject_VAR_HEAD
+-    ffi_closure *pcl; /* the C callable */
++    ffi_closure *pcl_write; /* the C callable, writeable */
++    void *pcl_exec;         /* the C callable, executable */
+     ffi_cif cif;
+     int flags;
+     PyObject *converters;
+@@ -427,9 +428,6 @@
+ 
+ #endif
+ 
+-extern void FreeClosure(void *);
+-extern void *MallocClosure(void);
+-
+ extern void _AddTraceback(char *, char *, int);
+ 
+ extern PyObject *CData_FromBaseObj(PyObject *type, PyObject *base, Py_ssize_t index, char *adr);
+--- Modules/_ctypes/malloc_closure.c
++++ Modules/_ctypes/malloc_closure.c
+@@ -93,7 +93,7 @@
+ /******************************************************************/
+ 
+ /* put the item back into the free list */
+-void FreeClosure(void *p)
++void ffi_closure_free(void *p)
+ {
+     ITEM *item = (ITEM *)p;
+     item->next = free_list;
+@@ -101,7 +101,7 @@
+ }
+ 
+ /* return one item from the free list, allocating more if needed */
+-void *MallocClosure(void)
++void *ffi_closure_alloc(size_t ignored, void** codeloc)
+ {
+     ITEM *item;
+     if (!free_list)
+@@ -110,5 +110,7 @@
+         return NULL;
+     item = free_list;
+     free_list = item->next;
+-    return item;
++	*codeloc = (void *)item;
++    return (void *)item;
+ }
++
+--- setup.py
++++ setup.py
+@@ -1885,8 +1885,7 @@
+                    '_ctypes/callbacks.c',
+                    '_ctypes/callproc.c',
+                    '_ctypes/stgdict.c',
+-                   '_ctypes/cfield.c',
+-                   '_ctypes/malloc_closure.c']
++                   '_ctypes/cfield.c']
+         depends = ['_ctypes/ctypes.h']
+ 
+         if sys.platform == 'darwin':

patches/25_all_gdbm-1.9.patch

+http://bugs.python.org/issue13007
+http://hg.python.org/cpython/rev/14cafb8d1480
+
+--- Lib/whichdb.py
++++ Lib/whichdb.py
+@@ -91,7 +91,7 @@
+         return ""
+ 
+     # Check for GNU dbm
+-    if magic == 0x13579ace:
++    if magic in (0x13579ace, 0x13579acd, 0x13579acf):
+         return "gdbm"
+ 
+     # Check for old Berkeley db hash file format v2

patches/26_all_expat-2.1.patch

+http://bugs.python.org/issue9054
+http://hg.python.org/cpython/rev/5b536c90ca36
+
+--- Modules/pyexpat.c
++++ Modules/pyexpat.c
+@@ -456,6 +456,9 @@
+     PyObject *args;
+     PyObject *temp;
+ 
++    if (!have_handler(self, CharacterData))
++        return -1;
++
+     args = PyTuple_New(1);
+     if (args == NULL)
+         return -1;

patches/41_all_crosscompile.patch

+--- configure.in
++++ configure.in
+@@ -3905,7 +3905,7 @@
+   AC_MSG_RESULT(no)
+ fi
+ 
+-AC_MSG_CHECKING(for %zd printf() format support)
++AC_CACHE_CHECK([for %zd printf() format support], [py_cv_has_zd_printf], [dnl
+ AC_TRY_RUN([#include <stdio.h>
+ #include <stddef.h>
+ #include <string.h>
+@@ -3939,10 +3939,13 @@
+ 	return 1;
+ 
+     return 0;
+-}],
+-[AC_MSG_RESULT(yes)
+- AC_DEFINE(PY_FORMAT_SIZE_T, "z", [Define to printf format modifier for Py_ssize_t])],
+- AC_MSG_RESULT(no))
++}], [py_cv_has_zd_printf="yes"],
++    [py_cv_has_zd_printf="no"],
++    [py_cv_has_zd_printf="cross -- assuming yes"]
++)])
++if test "$py_cv_has_zd_printf" != "no" ; then
++  AC_DEFINE(PY_FORMAT_SIZE_T, "z", [Define to printf format modifier for Py_ssize_t])
++fi
+ 
+ AC_CHECK_TYPE(socklen_t,,
+   AC_DEFINE(socklen_t,int,
+--- Makefile.pre.in
++++ Makefile.pre.in
+@@ -176,6 +176,7 @@
+ 
+ PYTHON=		python$(EXE)
+ BUILDPYTHON=	python$(BUILDEXE)
++HOSTPYTHON=    $(BUILDPYTHON)
+ 
+ # The task to run while instrument when building the profile-opt target
+ PROFILE_TASK=	$(srcdir)/Tools/pybench/pybench.py -n 2 --with-gc --with-syscheck
+@@ -209,6 +210,7 @@
+ # Parser
+ PGEN=		Parser/pgen$(EXE)
+ 
++HOSTPGEN=      $(PGEN)$(EXE)
+ POBJS=		\
+ 		Parser/acceler.o \
+ 		Parser/grammar1.o \
+@@ -398,7 +400,7 @@
+ # Build the shared modules
+ sharedmods: $(BUILDPYTHON)
+ 	@case $$MAKEFLAGS in \
+-	*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' LDFLAGS='$(LDFLAGS)' CFLAGS='$(CFLAGS)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py build;; \
++	*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' LDFLAGS='$(LDFLAGS)' CFLAGS='$(CFLAGS)' ./$(HOSTPYTHON) -E $(srcdir)/setup.py build;; \
+ 	esac
+ 
+ # Build the platform-specific modules
+@@ -540,7 +542,7 @@
+ 
+ $(GRAMMAR_H) $(GRAMMAR_C): $(PGEN) $(GRAMMAR_INPUT)
+ 		-@$(INSTALL) -d Include
+-		-$(PGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
++		-$(HOSTPGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
+ 
+ $(PGEN):	$(PGENOBJS)
+ 		$(CC) $(OPT) $(LDFLAGS) $(PGENOBJS) $(LIBS) -o $(PGEN)
+@@ -923,23 +925,23 @@
+ 	done
+ 	$(INSTALL_DATA) $(srcdir)/LICENSE $(DESTDIR)$(LIBDEST)/LICENSE.txt
+ 	PYTHONPATH=$(DESTDIR)$(LIBDEST)  $(RUNSHARED) \
+-		./$(BUILDPYTHON) -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py \
++		./$(HOSTPYTHON) -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py \
+ 		-d $(LIBDEST) -f \
+ 		-x 'bad_coding|badsyntax|site-packages' $(DESTDIR)$(LIBDEST)
+ 	PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
+-		./$(BUILDPYTHON) -Wi -tt -O $(DESTDIR)$(LIBDEST)/compileall.py \
++		./$(HOSTPYTHON) -Wi -tt -O $(DESTDIR)$(LIBDEST)/compileall.py \
+ 		-d $(LIBDEST) -f \
+ 		-x 'bad_coding|badsyntax|site-packages' $(DESTDIR)$(LIBDEST)
+ 	-PYTHONPATH=$(DESTDIR)$(LIBDEST)  $(RUNSHARED) \
+-		./$(BUILDPYTHON) -Wi -t $(DESTDIR)$(LIBDEST)/compileall.py \
++		./$(HOSTPYTHON) -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 \
++		./$(HOSTPYTHON) -Wi -t -O $(DESTDIR)$(LIBDEST)/compileall.py \
+ 		-d $(LIBDEST)/site-packages -f \
+ 		-x badsyntax $(DESTDIR)$(LIBDEST)/site-packages
+ 	-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
+-		./$(BUILDPYTHON) -Wi -t -c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()"
++		./$(HOSTPYTHON) -Wi -t -c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()"
+ 
+ # Install the include files
+ INCLDIRSTOMAKE=$(INCLUDEDIR) $(CONFINCLUDEDIR) $(INCLUDEPY) $(CONFINCLUDEPY)
+@@ -1015,7 +1017,7 @@
+ # Install the dynamically loadable modules
+ # This goes into $(exec_prefix)
+ sharedinstall:
+-	$(RUNSHARED) ./$(BUILDPYTHON) -E $(srcdir)/setup.py install \
++	$(RUNSHARED) ./$(HOSTPYTHON) -E $(srcdir)/setup.py install \
+ 	   	--prefix=$(prefix) \
+ 		--install-scripts=$(BINDIR) \
+ 		--install-platlib=$(DESTSHARED) \
+--- setup.py
++++ setup.py
+@@ -334,6 +334,7 @@
+         try:
+             imp.load_dynamic(ext.name, ext_filename)
+         except ImportError, why:
++            return
+             self.failed.append(ext.name)
+             self.announce('*** WARNING: renaming "%s" since importing it'
+                           ' failed: %s' % (ext.name, why), level=3)

patches/61_all_process_data.patch

+GENTOO_PYTHON_PROCESS_NAME environmental variable is set by python-wrapper and wrapper scripts generated by
+python_generate_wrapper_scripts() and specifies process name.
+GENTOO_PYTHON_WRAPPER_SCRIPT_PATH environmental variable is set by wrapper scripts generated by
+python_generate_wrapper_scripts() and specifies sys.argv[0] in target executables.
+GENTOO_PYTHON_TARGET_SCRIPT_PATH environmental variable is set by wrapper scripts generated by
+python_generate_wrapper_scripts() and specifies paths to actually executed scripts.
+GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION environmental variable is used by wrapper scripts generated by
+python_generate_wrapper_scripts() to check if Python supports GENTOO_PYTHON_TARGET_SCRIPT_PATH environmental variable.
+
+--- Modules/main.c
++++ Modules/main.c
+@@ -251,6 +251,7 @@
+     int version = 0;
+     int saw_unbuffered_flag = 0;
+     PyCompilerFlags cf;
++    char *target_script_name = getenv("GENTOO_PYTHON_TARGET_SCRIPT_PATH");
+ 
+     cf.cf_flags = 0;
+ 
+@@ -465,7 +466,10 @@
+             filename = argv[_PyOS_optind];
+ 
+ #else
+-        filename = argv[_PyOS_optind];
++        if (target_script_name != NULL && *target_script_name != '\0')
++            filename = target_script_name;
++        else
++            filename = argv[_PyOS_optind];
+ #endif
+     }
+ 
+--- Modules/posixmodule.c
++++ Modules/posixmodule.c
+@@ -396,6 +396,10 @@
+         char *p = strchr(*e, '=');
+         if (p == NULL)
+             continue;
++        if ((strlen("GENTOO_PYTHON_PROCESS_NAME") == (int)(p-*e) && strncmp("GENTOO_PYTHON_PROCESS_NAME", *e, (int)(p-*e)) == 0) ||
++            (strlen("GENTOO_PYTHON_TARGET_SCRIPT_PATH") == (int)(p-*e) && strncmp("GENTOO_PYTHON_TARGET_SCRIPT_PATH", *e, (int)(p-*e)) == 0) ||
++            (strlen("GENTOO_PYTHON_WRAPPER_SCRIPT_PATH") == (int)(p-*e) && strncmp("GENTOO_PYTHON_WRAPPER_SCRIPT_PATH", *e, (int)(p-*e)) == 0))
++            continue;
+         k = PyString_FromStringAndSize(*e, (int)(p-*e));
+         if (k == NULL) {
+             PyErr_Clear();
+--- Modules/python.c
++++ Modules/python.c
+@@ -6,9 +6,22 @@
+ #include <floatingpoint.h>
+ #endif
+ 
++#ifdef __linux__
++#include <linux/prctl.h>
++#include <sys/prctl.h>
++#ifndef PR_SET_NAME
++#define PR_SET_NAME 15
++#endif
++#endif
++
+ int
+ main(int argc, char **argv)
+ {
++	if (getenv("GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION")) {
++		printf("GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n");
++		return 0;
++	}
++
+ 	/* 754 requires that FP exceptions run in "no stop" mode by default,
+ 	 * and until C vendors implement C99's ways to control FP exceptions,
+ 	 * Python requires non-stop mode.  Alas, some platforms enable FP
+@@ -20,5 +33,15 @@
+ 	m = fpgetmask();
+ 	fpsetmask(m & ~FP_X_OFL);
+ #endif
++
++#ifdef __linux__
++	char *process_name = getenv("GENTOO_PYTHON_PROCESS_NAME");
++#ifdef HAVE_UNSETENV
++	unsetenv("GENTOO_PYTHON_PROCESS_NAME");
++#endif
++	if (process_name != NULL && *process_name != '\0')
++		prctl(PR_SET_NAME, process_name);
++#endif
++
+ 	return Py_Main(argc, argv);
+ }
+--- Python/sysmodule.c
++++ Python/sysmodule.c
+@@ -1492,6 +1492,10 @@
+ makeargvobject(int argc, char **argv)
+ {
+     PyObject *av;
++    char *wrapper_script_name = getenv("GENTOO_PYTHON_WRAPPER_SCRIPT_PATH");
++#ifdef HAVE_UNSETENV
++    unsetenv("GENTOO_PYTHON_WRAPPER_SCRIPT_PATH");
++#endif
+     if (argc <= 0 || argv == NULL) {
+         /* Ensure at least one (empty) argument is seen */
+         static char *empty_argv[1] = {""};
+@@ -1516,7 +1520,11 @@
+             } else
+                 v = PyString_FromString(argv[i]);
+ #else
+-            PyObject *v = PyString_FromString(argv[i]);
++            PyObject *v;
++            if (i == 0 && wrapper_script_name != NULL && *wrapper_script_name != '\0')
++                v = PyString_FromString(wrapper_script_name);
++            else
++                v = PyString_FromString(argv[i]);
+ #endif
+             if (v == NULL) {
+                 Py_DECREF(av);
+@@ -1544,7 +1552,15 @@
+     if (PySys_SetObject("argv", av) != 0)
+         Py_FatalError("can't assign sys.argv");
+     if (updatepath && path != NULL) {
+-        char *argv0 = argv[0];
++        char *target_script_name = getenv("GENTOO_PYTHON_TARGET_SCRIPT_PATH");
++#ifdef HAVE_UNSETENV
++        unsetenv("GENTOO_PYTHON_TARGET_SCRIPT_PATH");
++#endif
++        char *argv0;
++        if (target_script_name != NULL && *target_script_name != '\0')
++            argv0 = target_script_name;
++        else
++            argv0 = argv[0];
+         char *p = NULL;
+         Py_ssize_t n = 0;
+         PyObject *a;

patches/62_all_xml.use_pyxml.patch

+--- Lib/xml/__init__.py
++++ Lib/xml/__init__.py
+@@ -28,20 +28,23 @@
+ _MINIMUM_XMLPLUS_VERSION = (0, 8, 4)
+ 
+ 
+-try:
++def use_pyxml():
+     import _xmlplus
+-except ImportError:
+-    pass
+-else:
+-    try:
+-        v = _xmlplus.version_info
+-    except AttributeError:
+-        # _xmlplus is too old; ignore it
+-        pass
++    v = _xmlplus.version_info
++    if v >= _MINIMUM_XMLPLUS_VERSION:
++        import sys
++        _xmlplus.__path__.extend(__path__)
++        sys.modules[__name__] = _xmlplus
++        cleared_modules = []
++        redefined_modules = []
++        for module in sys.modules:
++            if module.startswith("xml.") and not module.startswith(("xml.marshal", "xml.schema", "xml.utils", "xml.xpath", "xml.xslt")):
++                cleared_modules.append(module)
++            if module.startswith(("xml.__init__", "xml.dom", "xml.parsers", "xml.sax")) and sys.modules[module] is not None:
++                redefined_modules.append(module)
++        for module in cleared_modules:
++            del sys.modules[module]
++        for module in sorted(redefined_modules):
++            __import__(module)
+     else:
+-        if v >= _MINIMUM_XMLPLUS_VERSION:
+-            import sys
+-            _xmlplus.__path__.extend(__path__)
+-            sys.modules[__name__] = _xmlplus
+-        else:
+-            del v
++        raise ImportError("PyXML too old: %s" % ".".join(str(x) for x in v))