about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/interpreters/python/cpython/2.7
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/development/interpreters/python/cpython/2.7')
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.5.2-ctypes-util-find_library.patch34
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.5.2-tkinter-x11.patch27
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.6.2-ssl-threads.patch13
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.6.5-FD_SETSIZE.patch41
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.6.5-export-PySignal_SetWakeupFd.patch11
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.6.5-ncurses-abi6.patch16
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.7.3-dbm.patch27
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.7.3-dylib.patch10
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.7.3-getpath-exe-extension.patch31
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.7.3-no-libm.patch11
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/cpython/2.7/atomic_pyc.patch116
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/cpython/2.7/cross-compile.patch32
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/cpython/2.7/default.nix284
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/cpython/2.7/deterministic-build.patch36
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/cpython/2.7/nix-store-mtime.patch12
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/cpython/2.7/no-ldconfig.patch117
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/cpython/2.7/python-2.7-distutils-C++.patch259
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/cpython/2.7/search-path.patch27
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/cpython/2.7/use-correct-tcl-tk-on-darwin.patch48
19 files changed, 1152 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.5.2-ctypes-util-find_library.patch b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.5.2-ctypes-util-find_library.patch
new file mode 100644
index 000000000000..22bc0f7ced0a
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.5.2-ctypes-util-find_library.patch
@@ -0,0 +1,34 @@
+--- origsrc/Lib/ctypes/util.py	2007-09-14 15:05:26.000000000 -0500
++++ src/Lib/ctypes/util.py	2008-11-25 17:54:47.319296200 -0600
+@@ -41,6 +41,20 @@
+                 continue
+         return None
+ 
++elif sys.platform == "cygwin":
++    def find_library(name):
++        for libdir in ['/usr/lib', '/usr/local/lib']:
++            for libext in ['lib%s.dll.a' % name, 'lib%s.a' % name]:
++                implib = os.path.join(libdir, libext)
++                if not os.path.exists(implib):
++                    continue
++                cmd = "dlltool -I " + implib + " 2>/dev/null"
++                res = os.popen(cmd).read().replace("\n","")
++                if not res:
++                    continue
++                return res
++        return None
++
+ elif os.name == "posix":
+     # Andreas Degert's find functions, using gcc, /sbin/ldconfig, objdump
+     import re, tempfile, errno
+@@ -157,6 +173,10 @@
+             print cdll.LoadLibrary("libcrypto.dylib")
+             print cdll.LoadLibrary("libSystem.dylib")
+             print cdll.LoadLibrary("System.framework/System")
++        elif sys.platform == "cygwin":
++            print cdll.LoadLibrary("cygbz2-1.dll") 
++            print find_library("crypt")
++            print cdll.LoadLibrary("cygcrypt-0.dll") 
+         else:
+             print cdll.LoadLibrary("libm.so")
+             print cdll.LoadLibrary("libcrypt.so")
diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.5.2-tkinter-x11.patch b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.5.2-tkinter-x11.patch
new file mode 100644
index 000000000000..28b6dafc3f15
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.5.2-tkinter-x11.patch
@@ -0,0 +1,27 @@
+--- origsrc/setup.py	2008-02-04 17:41:02.000000000 -0600
++++ src/setup.py	2008-07-02 02:11:28.671875000 -0500
+@@ -1277,12 +1279,6 @@
+             include_dirs.append('/usr/X11/include')
+             added_lib_dirs.append('/usr/X11/lib')
+ 
+-        # If Cygwin, then verify that X is installed before proceeding
+-        if host_platform == 'cygwin':
+-            x11_inc = find_file('X11/Xlib.h', [], include_dirs)
+-            if x11_inc is None:
+-                return
+-
+         # Check for BLT extension
+         if self.compiler.find_library_file(lib_dirs + added_lib_dirs,
+                                            'BLT8.0'):
+@@ -1300,9 +1296,8 @@
+         if host_platform in ['aix3', 'aix4']:
+             libs.append('ld')
+ 
+-        # Finally, link with the X11 libraries (not appropriate on cygwin)
+-        if host_platform != "cygwin":
+-            libs.append('X11')
++        # Finally, link with the X11 libraries
++        libs.append('X11')
+ 
+         ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
+                         define_macros=[('WITH_APPINIT', 1)] + defs,
diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.6.2-ssl-threads.patch b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.6.2-ssl-threads.patch
new file mode 100644
index 000000000000..bef137efda7b
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.6.2-ssl-threads.patch
@@ -0,0 +1,13 @@
+--- origsrc/Modules/_ssl.c	2009-01-26 10:55:41.000000000 -0600
++++ src/Modules/_ssl.c	2009-08-20 00:04:59.346816700 -0500
+@@ -15,6 +15,10 @@
+ 
+ #include "Python.h"
+ 
++#ifdef __CYGWIN__
++#undef WITH_THREAD
++#endif
++
+ #ifdef WITH_THREAD
+ #include "pythread.h"
+ #define PySSL_BEGIN_ALLOW_THREADS { \
diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.6.5-FD_SETSIZE.patch b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.6.5-FD_SETSIZE.patch
new file mode 100644
index 000000000000..d1dae8c47dc1
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.6.5-FD_SETSIZE.patch
@@ -0,0 +1,41 @@
+--- Python-2.6.5.orig/Modules/selectmodule.c	2012-02-02 22:35:21.835125000 -0500
++++ Python-2.6.5/Modules/selectmodule.c	2012-02-02 22:41:41.210125000 -0500
+@@ -6,6 +6,21 @@
+    >= 0.
+ */
+ 
++/* Windows #defines FD_SETSIZE to 64 if FD_SETSIZE isn't already defined.
++   64 is too small (too many people have bumped into that limit).
++   Here we boost it.
++
++   Cygwin also defines FD_SETSIZE to 64, so also increase the limit on
++   Cygwin.  We must do this before sys/types.h is included, which otherwise
++   sets FD_SETSIZE to the default.
++
++   Users who want even more than the boosted limit should #define
++   FD_SETSIZE higher before this; e.g., via compiler /D switch.
++*/
++#if (defined(MS_WINDOWS) || defined(__CYGWIN__)) && !defined(FD_SETSIZE)
++#define FD_SETSIZE 512
++#endif
++
+ #include "Python.h"
+ #include <structmember.h>
+ 
+@@ -16,16 +31,6 @@
+ #undef HAVE_BROKEN_POLL
+ #endif
+ 
+-/* Windows #defines FD_SETSIZE to 64 if FD_SETSIZE isn't already defined.
+-   64 is too small (too many people have bumped into that limit).
+-   Here we boost it.
+-   Users who want even more than the boosted limit should #define
+-   FD_SETSIZE higher before this; e.g., via compiler /D switch.
+-*/
+-#if defined(MS_WINDOWS) && !defined(FD_SETSIZE)
+-#define FD_SETSIZE 512
+-#endif
+-
+ #if defined(HAVE_POLL_H)
+ #include <poll.h>
+ #elif defined(HAVE_SYS_POLL_H)
diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.6.5-export-PySignal_SetWakeupFd.patch b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.6.5-export-PySignal_SetWakeupFd.patch
new file mode 100644
index 000000000000..ea696978236a
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.6.5-export-PySignal_SetWakeupFd.patch
@@ -0,0 +1,11 @@
+--- origsrc/Include/pyerrors.h	2008-06-08 23:58:54.000000000 -0500
++++ src/Include/pyerrors.h	2010-05-12 04:19:31.535297200 -0500
+@@ -232,7 +232,7 @@ PyAPI_FUNC(int) PyErr_CheckSignals(void)
+ PyAPI_FUNC(void) PyErr_SetInterrupt(void);
+ 
+ /* In signalmodule.c */
+-int PySignal_SetWakeupFd(int fd);
++PyAPI_FUNC(int) PySignal_SetWakeupFd(int fd);
+ 
+ /* Support for adding program text to SyntaxErrors */
+ PyAPI_FUNC(void) PyErr_SyntaxLocation(const char *, int);
diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.6.5-ncurses-abi6.patch b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.6.5-ncurses-abi6.patch
new file mode 100644
index 000000000000..e1cf5ad4bbf9
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.6.5-ncurses-abi6.patch
@@ -0,0 +1,16 @@
+--- origsrc/Include/py_curses.h	2009-09-06 16:23:05.000000000 -0500
++++ src/Include/py_curses.h	2010-04-14 15:21:23.008971400 -0500
+@@ -17,6 +17,13 @@
+ #define NCURSES_OPAQUE 0
+ #endif /* __APPLE__ */
+ 
++#ifdef __CYGWIN__
++/* the following define is necessary for Cygwin; without it, the
++   Cygwin-supplied ncurses.h sets NCURSES_OPAQUE to 1, and then Python
++   can't get at the WINDOW flags field. */
++#define NCURSES_INTERNALS
++#endif /* __CYGWIN__ */
++
+ #ifdef __FreeBSD__
+ /*
+ ** On FreeBSD, [n]curses.h and stdlib.h/wchar.h use different guards
diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.7.3-dbm.patch b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.7.3-dbm.patch
new file mode 100644
index 000000000000..bfaeb37c287d
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.7.3-dbm.patch
@@ -0,0 +1,27 @@
+--- origsrc/setup.py.orig	2012-11-27 10:20:47.442395900 -0500
++++ src/setup.py	2012-11-27 10:53:15.583020900 -0500
+@@ -1141,7 +1141,7 @@
+ 
+         dbm_order = ['gdbm']
+         # The standard Unix dbm module:
+-        if host_platform not in ['cygwin']:
++        if host_platform not in ['win32']:
+             config_args = [arg.strip("'")
+                            for arg in sysconfig.get_config_var("CONFIG_ARGS").split()]
+             dbm_args = [arg for arg in config_args
+@@ -1192,6 +1192,15 @@
+                                     ],
+                                 libraries = gdbm_libs)
+                             break
++                        if find_file("ndbm.h", inc_dirs, []) is not None:
++                            print("building dbm using gdbm")
++                            dbmext = Extension(
++                                'dbm', ['dbmmodule.c'],
++                                define_macros=[
++                                    ('HAVE_NDBM_H', None),
++                                    ],
++                                libraries = gdbm_libs)
++                            break
+                 elif cand == "bdb":
+                     if db_incs is not None:
+                         print "building dbm using bdb"
diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.7.3-dylib.patch b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.7.3-dylib.patch
new file mode 100644
index 000000000000..6e1fc8b53e83
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.7.3-dylib.patch
@@ -0,0 +1,10 @@
+--- origsrc/Lib/distutils/unixccompiler.py.orig	2012-11-27 07:44:15.409993500 -0500
++++ src/Lib/distutils/unixccompiler.py	2012-11-27 08:09:57.801770900 -0500
+@@ -141,6 +141,7 @@
+     static_lib_format = shared_lib_format = dylib_lib_format = "lib%s%s"
+     if sys.platform == "cygwin":
+         exe_extension = ".exe"
++        dylib_lib_extension = ".dll.a"
+ 
+     def preprocess(self, source,
+                    output_file=None, macros=None, include_dirs=None,
diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.7.3-getpath-exe-extension.patch b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.7.3-getpath-exe-extension.patch
new file mode 100644
index 000000000000..68f6921ba6aa
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.7.3-getpath-exe-extension.patch
@@ -0,0 +1,31 @@
+--- origsrc/Modules/getpath.c.orig	2012-11-27 12:07:56.098645900 -0500
++++ src/Modules/getpath.c	2012-11-27 12:10:11.254895900 -0500
+@@ -436,6 +436,28 @@
+                         if (isxfile(progpath))
+                                 break;
+ 
++#ifdef __CYGWIN__
++                        /*
++                         * Cygwin automatically removes the ".exe" extension from argv[0]
++                         * to make programs feel like they are in a more Unix-like
++                         * environment.  Unfortunately, this can make it problemmatic for
++                         * Cygwin to distinguish between a directory and an executable with
++                         * the same name excluding the ".exe" extension.  For example, the
++                         * Cygwin Python build directory has a "Python" directory and a
++                         * "python.exe" executable.  This causes isxfile() to erroneously
++                         * return false.  If isdir() returns true and there is enough space
++                         * to append the ".exe" extension, then we try again with the
++                         * extension appended.
++                         */
++#define EXE ".exe"
++                        if (isdir(progpath) && strlen(progpath) + strlen(EXE) <= MAXPATHLEN)
++                        {
++                            strcat(progpath, EXE);
++                            if (isxfile(progpath))
++                                break;
++                        }
++#endif /* __CYGWIN__ */
++
+                         if (!delim) {
+                                 progpath[0] = '\0';
+                                 break;
diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.7.3-no-libm.patch b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.7.3-no-libm.patch
new file mode 100644
index 000000000000..55281db6768f
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/2.7.3-no-libm.patch
@@ -0,0 +1,11 @@
+--- origsrc/setup.py.orig	2012-11-27 09:28:34.051770900 -0500
++++ src/setup.py	2012-11-27 09:28:47.239270900 -0500
+@@ -470,7 +470,7 @@
+ 
+         # Check for MacOS X, which doesn't need libm.a at all
+         math_libs = ['m']
+-        if host_platform in ['darwin', 'beos']:
++        if host_platform in ['darwin', 'beos', 'cygwin']:
+             math_libs = []
+ 
+         # XXX Omitted modules: gl, pure, dl, SGI-specific modules
diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/atomic_pyc.patch b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/atomic_pyc.patch
new file mode 100644
index 000000000000..06d3718d4993
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/atomic_pyc.patch
@@ -0,0 +1,116 @@
+diff --git a/Lib/py_compile.py b/Lib/py_compile.py
+index 978da73d74..3559eb95ca 100644
+--- a/Lib/py_compile.py
++++ b/Lib/py_compile.py
+@@ -120,16 +120,27 @@ def compile(file, cfile=None, dfile=None, doraise=False):
+             return
+     if cfile is None:
+         cfile = file + (__debug__ and 'c' or 'o')
+-    with open(cfile, 'wb') as fc:
+-        fc.write('\0\0\0\0')
+-        if "DETERMINISTIC_BUILD" in os.environ:
++    # Atomically write the pyc/pyo file.  Issue #13146.
++    # id() is used to generate a pseudo-random filename.
++    path_tmp = '{}.{}'.format(cfile, id(cfile))
++    try:
++        with open(path_tmp, 'wb') as fc:
+             fc.write('\0\0\0\0')
+-        else:
+-            wr_long(fc, timestamp)
+-        marshal.dump(codeobject, fc)
+-        fc.flush()
+-        fc.seek(0, 0)
+-        fc.write(MAGIC)
++            if "DETERMINISTIC_BUILD" in os.environ:
++                fc.write('\0\0\0\0')
++            else:
++                wr_long(fc, timestamp)
++            marshal.dump(codeobject, fc)
++            fc.flush()
++            fc.seek(0, 0)
++            fc.write(MAGIC)
++        os.rename(path_tmp, cfile)
++    except OSError:
++        try:
++            os.unlink(path_tmp)
++        except OSError:
++            pass
++        raise
+ 
+ def main(args=None):
+     """Compile several source files.
+diff --git a/Python/import.c b/Python/import.c
+index 1e31d79279..f78a1efcf0 100644
+--- a/Python/import.c
++++ b/Python/import.c
+@@ -951,6 +951,8 @@ static void
+ write_compiled_module(PyCodeObject *co, char *cpathname, struct stat *srcstat, time_t mtime)
+ {
+     FILE *fp;
++    size_t cpathname_len;
++    char *cpathname_tmp;
+ #ifdef MS_WINDOWS   /* since Windows uses different permissions  */
+     mode_t mode = srcstat->st_mode & ~S_IEXEC;
+     /* Issue #6074: We ensure user write access, so we can delete it later
+@@ -963,11 +965,28 @@ write_compiled_module(PyCodeObject *co, char *cpathname, struct stat *srcstat, t
+     mode_t mode = srcstat->st_mode & ~S_IXUSR & ~S_IXGRP & ~S_IXOTH;
+ #endif
+ 
++#ifdef MS_WINDOWS
+     fp = open_exclusive(cpathname, mode);
++#else
++    /* Under POSIX, we first write to a tmp file and then take advantage
++       of atomic renaming. */
++    cpathname_len = strlen(cpathname);
++    cpathname_tmp = PyMem_MALLOC(cpathname_len + 5);
++    if (cpathname_tmp == NULL) {
++        PyErr_Clear();
++        return;
++    }
++    memcpy(cpathname_tmp, cpathname, cpathname_len);
++    memcpy(cpathname_tmp + cpathname_len, ".tmp", 5);
++    fp = open_exclusive(cpathname_tmp, mode);
++#endif
+     if (fp == NULL) {
+         if (Py_VerboseFlag)
+             PySys_WriteStderr(
+                 "# can't create %s\n", cpathname);
++#ifndef MS_WINDOWS
++        PyMem_FREE(cpathname_tmp);
++#endif
+         return;
+     }
+     PyMarshal_WriteLongToFile(pyc_magic, fp, Py_MARSHAL_VERSION);
+@@ -979,7 +998,12 @@ write_compiled_module(PyCodeObject *co, char *cpathname, struct stat *srcstat, t
+             PySys_WriteStderr("# can't write %s\n", cpathname);
+         /* Don't keep partial file */
+         fclose(fp);
++#ifdef MS_WINDOWS
+         (void) unlink(cpathname);
++#else
++        (void) unlink(cpathname_tmp);
++        PyMem_FREE(cpathname_tmp);
++#endif
+         return;
+     }
+     /* Now write the true mtime (as a 32-bit field) */
+@@ -989,6 +1013,19 @@ write_compiled_module(PyCodeObject *co, char *cpathname, struct stat *srcstat, t
+         PyMarshal_WriteLongToFile((long)mtime, fp, Py_MARSHAL_VERSION);
+         fflush(fp);
+     }
++    /* Under POSIX, do an atomic rename */
++#ifndef MS_WINDOWS
++    if (rename(cpathname_tmp, cpathname)) {
++        if (Py_VerboseFlag)
++            PySys_WriteStderr("# can't write %s\n", cpathname);
++        /* Don't keep tmp file */
++        fclose(fp);
++        (void) unlink(cpathname_tmp);
++        PyMem_FREE(cpathname_tmp);
++        return;
++    }
++    PyMem_FREE(cpathname_tmp);
++#endif
+     fclose(fp);
+     if (Py_VerboseFlag)
+         PySys_WriteStderr("# wrote %s\n", cpathname);
diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/cross-compile.patch b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/cross-compile.patch
new file mode 100644
index 000000000000..c83b56437a49
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/cross-compile.patch
@@ -0,0 +1,32 @@
+--- ./setup.py.orig	2018-04-29 15:47:33.000000000 -0700
++++ ./setup.py	2018-11-11 09:41:58.097682221 -0800
+@@ -458,8 +458,6 @@
+         if not cross_compiling:
+             add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
+             add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
+-        if cross_compiling:
+-            self.add_gcc_paths()
+         self.add_multiarch_paths()
+ 
+         # Add paths specified in the environment variables LDFLAGS and
+@@ -517,7 +515,10 @@
+         # be assumed that no additional -I,-L directives are needed.
+         inc_dirs = self.compiler.include_dirs[:]
+         lib_dirs = self.compiler.library_dirs[:]
+-        if not cross_compiling:
++        if cross_compiling:
++            inc_dirs = []
++            lib_dirs = []
++        else:
+             for d in (
+                 '/usr/include',
+                 ):
+@@ -582,6 +584,8 @@ class PyBuildExt(build_ext):
+         # Some modules that are normally always on:
+         #exts.append( Extension('_weakref', ['_weakref.c']) )
+ 
++        self.compiler.library_dirs = lib_dirs + [ '.' ]
++
+         # array objects
+         exts.append( Extension('array', ['arraymodule.c']) )
+ 
diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/default.nix b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/default.nix
new file mode 100644
index 000000000000..696be2136ecc
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/default.nix
@@ -0,0 +1,284 @@
+{ stdenv, fetchurl, fetchpatch
+, bzip2
+, expat
+, libffi
+, gdbm
+, db
+, ncurses
+, openssl
+, readline
+, sqlite
+, tcl ? null, tk ? null, tix ? null, xlibsWrapper ? null, libX11 ? null, x11Support ? false
+, zlib
+, self
+, configd, coreutils
+, python-setup-hook
+# Some proprietary libs assume UCS2 unicode, especially on darwin :(
+, ucsEncoding ? 4
+# For the Python package set
+, packageOverrides ? (self: super: {})
+, buildPackages
+, sourceVersion
+, sha256
+, passthruFun
+, static ? false
+}:
+
+assert x11Support -> tcl != null
+                  && tk != null
+                  && xlibsWrapper != null
+                  && libX11 != null;
+
+with stdenv.lib;
+
+let
+
+  pythonForBuild = buildPackages.${"python${sourceVersion.major}${sourceVersion.minor}"};
+
+  passthru = passthruFun rec {
+    inherit self sourceVersion packageOverrides;
+    implementation = "cpython";
+    libPrefix = "python${pythonVersion}";
+    executable = libPrefix;
+    pythonVersion = with sourceVersion; "${major}.${minor}";
+    sitePackages = "lib/${libPrefix}/site-packages";
+    inherit hasDistutilsCxxPatch pythonForBuild;
+  } // {
+    inherit ucsEncoding;
+  };
+
+  version = with sourceVersion; "${major}.${minor}.${patch}${suffix}";
+
+  src = fetchurl {
+    url = with sourceVersion; "https://www.python.org/ftp/python/${major}.${minor}.${patch}/Python-${version}.tar.xz";
+    inherit sha256;
+  };
+
+  hasDistutilsCxxPatch = !(stdenv.cc.isGNU or false);
+  patches =
+    [ # Look in C_INCLUDE_PATH and LIBRARY_PATH for stuff.
+      ./search-path.patch
+
+      # Python recompiles a Python if the mtime stored *in* the
+      # pyc/pyo file differs from the mtime of the source file.  This
+      # doesn't work in Nix because Nix changes the mtime of files in
+      # the Nix store to 1.  So treat that as a special case.
+      ./nix-store-mtime.patch
+
+      # patch python to put zero timestamp into pyc
+      # if DETERMINISTIC_BUILD env var is set
+      ./deterministic-build.patch
+
+      # Fix python bug #27177 (https://bugs.python.org/issue27177)
+      # The issue is that `match.group` only recognizes python integers
+      # instead of everything that has `__index__`.
+      # This bug was fixed upstream, but not backported to 2.7
+      (fetchpatch {
+        name = "re_match_index.patch";
+        url = "https://bugs.python.org/file43084/re_match_index.patch";
+        sha256 = "0l9rw6r5r90iybdkp3hhl2pf0h0s1izc68h5d3ywrm92pq32wz57";
+      })
+
+      # Fix race-condition during pyc creation. Has a slight backwards
+      # incompatible effect: pyc symlinks will now be overridden
+      # (https://bugs.python.org/issue17222). Included in python >= 3.4,
+      # backported in debian since 2013.
+      # https://bugs.python.org/issue13146
+      ./atomic_pyc.patch
+    ] ++ optionals (x11Support && stdenv.isDarwin) [
+      ./use-correct-tcl-tk-on-darwin.patch
+    ] ++ optionals stdenv.isLinux [
+
+      # Disable the use of ldconfig in ctypes.util.find_library (since
+      # ldconfig doesn't work on NixOS), and don't use
+      # ctypes.util.find_library during the loading of the uuid module
+      # (since it will do a futile invocation of gcc (!) to find
+      # libuuid, slowing down program startup a lot).
+      ./no-ldconfig.patch
+
+    ] ++ optionals stdenv.hostPlatform.isCygwin [
+      ./2.5.2-ctypes-util-find_library.patch
+      ./2.5.2-tkinter-x11.patch
+      ./2.6.2-ssl-threads.patch
+      ./2.6.5-export-PySignal_SetWakeupFd.patch
+      ./2.6.5-FD_SETSIZE.patch
+      ./2.6.5-ncurses-abi6.patch
+      ./2.7.3-dbm.patch
+      ./2.7.3-dylib.patch
+      ./2.7.3-getpath-exe-extension.patch
+      ./2.7.3-no-libm.patch
+    ] ++ optionals hasDistutilsCxxPatch [
+
+      # Patch from http://bugs.python.org/issue1222585 adapted to work with
+      # `patch -p1' and with a last hunk removed
+      # Upstream distutils is calling C compiler to compile C++ code, which
+      # only works for GCC and Apple Clang. This makes distutils to call C++
+      # compiler when needed.
+      ./python-2.7-distutils-C++.patch
+    ] ++ optional (stdenv.hostPlatform != stdenv.buildPlatform) [
+      ./cross-compile.patch
+    ];
+
+  preConfigure = ''
+      # Purity.
+      for i in /usr /sw /opt /pkg; do
+        substituteInPlace ./setup.py --replace $i /no-such-path
+      done
+    '' + optionalString (stdenv ? cc && stdenv.cc.libc != null) ''
+      for i in Lib/plat-*/regen; do
+        substituteInPlace $i --replace /usr/include/ ${stdenv.cc.libc}/include/
+      done
+    '' + optionalString stdenv.isDarwin ''
+      substituteInPlace configure --replace '`/usr/bin/arch`' '"i386"'
+      substituteInPlace Lib/multiprocessing/__init__.py \
+        --replace 'os.popen(comm)' 'os.popen("${coreutils}/bin/nproc")'
+    '';
+
+  configureFlags = [
+    "--enable-shared"
+    "--with-threads"
+    "--enable-unicode=ucs${toString ucsEncoding}"
+  ] ++ optionals (stdenv.hostPlatform.isCygwin || stdenv.hostPlatform.isAarch64) [
+    "--with-system-ffi"
+  ] ++ optionals stdenv.hostPlatform.isCygwin [
+    "--with-system-expat"
+    "ac_cv_func_bind_textdomain_codeset=yes"
+  ] ++ optionals stdenv.isDarwin [
+    "--disable-toolbox-glue"
+  ] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
+    "PYTHON_FOR_BUILD=${getBin buildPackages.python}/bin/python"
+    "ac_cv_buggy_getaddrinfo=no"
+    # Assume little-endian IEEE 754 floating point when cross compiling
+    "ac_cv_little_endian_double=yes"
+    "ac_cv_big_endian_double=no"
+    "ac_cv_mixed_endian_double=no"
+    "ac_cv_x87_double_rounding=yes"
+    "ac_cv_tanh_preserves_zero_sign=yes"
+    # Generally assume that things are present and work
+    "ac_cv_posix_semaphores_enabled=yes"
+    "ac_cv_broken_sem_getvalue=no"
+    "ac_cv_wchar_t_signed=yes"
+    "ac_cv_rshift_extends_sign=yes"
+    "ac_cv_broken_nice=no"
+    "ac_cv_broken_poll=no"
+    "ac_cv_working_tzset=yes"
+    "ac_cv_have_long_long_format=yes"
+    "ac_cv_have_size_t_format=yes"
+    "ac_cv_computed_gotos=yes"
+    "ac_cv_file__dev_ptmx=yes"
+    "ac_cv_file__dev_ptc=yes"
+  ]
+    # Never even try to use lchmod on linux,
+    # don't rely on detecting glibc-isms.
+  ++ optional stdenv.hostPlatform.isLinux "ac_cv_func_lchmod=no"
+  ++ optional static "LDFLAGS=-static";
+
+  buildInputs =
+    optional (stdenv ? cc && stdenv.cc.libc != null) stdenv.cc.libc ++
+    [ bzip2 openssl zlib ]
+    ++ optional (stdenv.hostPlatform.isCygwin || stdenv.hostPlatform.isAarch64) libffi
+    ++ optional stdenv.hostPlatform.isCygwin expat
+    ++ [ db gdbm ncurses sqlite readline ]
+    ++ optionals x11Support [ tcl tk xlibsWrapper libX11 ]
+    ++ optional (stdenv.isDarwin && configd != null) configd;
+  nativeBuildInputs =
+    optionals (stdenv.hostPlatform != stdenv.buildPlatform)
+    [ buildPackages.stdenv.cc buildPackages.python ];
+
+  mkPaths = paths: {
+    C_INCLUDE_PATH = makeSearchPathOutput "dev" "include" paths;
+    LIBRARY_PATH = makeLibraryPath paths;
+  };
+
+  # Python 2.7 needs this
+  crossCompileEnv = stdenv.lib.optionalAttrs (stdenv.hostPlatform != stdenv.buildPlatform)
+                      { _PYTHON_HOST_PLATFORM = stdenv.hostPlatform.config; };
+
+  # Build the basic Python interpreter without modules that have
+  # external dependencies.
+
+in with passthru; stdenv.mkDerivation ({
+    pname = "python";
+    inherit version;
+
+    inherit src patches buildInputs nativeBuildInputs preConfigure configureFlags;
+
+    LDFLAGS = stdenv.lib.optionalString (!stdenv.isDarwin) "-lgcc_s";
+    inherit (mkPaths buildInputs) C_INCLUDE_PATH LIBRARY_PATH;
+
+    NIX_CFLAGS_COMPILE = optionalString stdenv.isDarwin "-msse2"
+      + optionalString stdenv.hostPlatform.isMusl " -DTHREAD_STACK_SIZE=0x100000";
+    DETERMINISTIC_BUILD = 1;
+
+    setupHook = python-setup-hook sitePackages;
+
+    postPatch = optionalString (x11Support && (tix != null)) ''
+          substituteInPlace "Lib/lib-tk/Tix.py" --replace "os.environ.get('TIX_LIBRARY')" "os.environ.get('TIX_LIBRARY') or '${tix}/lib'"
+    '';
+
+    postInstall =
+      ''
+        # needed for some packages, especially packages that backport
+        # functionality to 2.x from 3.x
+        for item in $out/lib/${libPrefix}/test/*; do
+          if [[ "$item" != */test_support.py*
+             && "$item" != */test/support
+             && "$item" != */test/regrtest.py* ]]; then
+            rm -rf "$item"
+          else
+            echo $item
+          fi
+        done
+        touch $out/lib/${libPrefix}/test/__init__.py
+        ln -s $out/lib/${libPrefix}/pdb.py $out/bin/pdb
+        ln -s $out/lib/${libPrefix}/pdb.py $out/bin/pdb${sourceVersion.major}.${sourceVersion.minor}
+        ln -s $out/share/man/man1/{python2.7.1.gz,python.1.gz}
+
+        rm "$out"/lib/python*/plat-*/regen # refers to glibc.dev
+
+        # Determinism: Windows installers were not deterministic.
+        # We're also not interested in building Windows installers.
+        find "$out" -name 'wininst*.exe' | xargs -r rm -f
+      '' + optionalString (stdenv.hostPlatform == stdenv.buildPlatform)
+      ''
+        # Determinism: rebuild all bytecode
+        # We exclude lib2to3 because that's Python 2 code which fails
+        # We rebuild three times, once for each optimization level
+        find $out -name "*.py" | $out/bin/python -m compileall -q -f -x "lib2to3" -i -
+        find $out -name "*.py" | $out/bin/python -O -m compileall -q -f -x "lib2to3" -i -
+        find $out -name "*.py" | $out/bin/python -OO -m compileall -q -f -x "lib2to3" -i -
+      '' + optionalString stdenv.hostPlatform.isCygwin ''
+        cp libpython2.7.dll.a $out/lib
+      '';
+
+    inherit passthru;
+
+    postFixup = ''
+      # Include a sitecustomize.py file. Note it causes an error when it's in postInstall with 2.7.
+      cp ${../../sitecustomize.py} $out/${sitePackages}/sitecustomize.py
+    '';
+
+    enableParallelBuilding = true;
+
+    doCheck = false; # expensive, and fails
+
+    meta = {
+      homepage = "http://python.org";
+      description = "A high-level dynamically-typed programming language";
+      longDescription = ''
+        Python is a remarkably powerful dynamic programming language that
+        is used in a wide variety of application domains. Some of its key
+        distinguishing features include: clear, readable syntax; strong
+        introspection capabilities; intuitive object orientation; natural
+        expression of procedural code; full modularity, supporting
+        hierarchical packages; exception-based error handling; and very
+        high level dynamic data types.
+      '';
+      license = stdenv.lib.licenses.psfl;
+      platforms = stdenv.lib.platforms.all;
+      maintainers = with stdenv.lib.maintainers; [ fridh ];
+      # Higher priority than Python 3.x so that `/bin/python` points to `/bin/python2`
+      # in case both 2 and 3 are installed.
+      priority = -100;
+    };
+  } // crossCompileEnv)
diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/deterministic-build.patch b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/deterministic-build.patch
new file mode 100644
index 000000000000..98d9d339fa11
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/deterministic-build.patch
@@ -0,0 +1,36 @@
+diff -ur orig/Lib/py_compile.py new/Lib/py_compile.py
+--- orig/Lib/py_compile.py
++++ new/Lib/py_compile.py
+@@ -122,7 +122,10 @@
+         cfile = file + (__debug__ and 'c' or 'o')
+     with open(cfile, 'wb') as fc:
+         fc.write('\0\0\0\0')
+-        wr_long(fc, timestamp)
++        if "DETERMINISTIC_BUILD" in os.environ:
++            fc.write('\0\0\0\0')
++        else:
++            wr_long(fc, timestamp)
+         marshal.dump(codeobject, fc)
+         fc.flush()
+         fc.seek(0, 0)
+diff -ur orig/Python/import.c new/Python/import.c
+--- orig/Python/import.c
++++ new/Python/import.c
+@@ -939,10 +939,12 @@
+         return;
+     }
+     /* Now write the true mtime (as a 32-bit field) */
+-    fseek(fp, 4L, 0);
+-    assert(mtime <= 0xFFFFFFFF);
+-    PyMarshal_WriteLongToFile((long)mtime, fp, Py_MARSHAL_VERSION);
+-    fflush(fp);
++    if (Py_GETENV("DETERMINISTIC_BUILD") == NULL) {
++        fseek(fp, 4L, 0);
++        assert(mtime <= 0xFFFFFFFF);
++        PyMarshal_WriteLongToFile((long)mtime, fp, Py_MARSHAL_VERSION);
++        fflush(fp);
++    }
+     fclose(fp);
+     if (Py_VerboseFlag)
+         PySys_WriteStderr("# wrote %s\n", cpathname);
+
diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/nix-store-mtime.patch b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/nix-store-mtime.patch
new file mode 100644
index 000000000000..83f3fea1931b
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/nix-store-mtime.patch
@@ -0,0 +1,12 @@
+diff -ru -x '*~' Python-2.7.1-orig/Python/import.c Python-2.7.1/Python/import.c
+--- Python-2.7.1-orig/Python/import.c	2010-05-20 20:37:55.000000000 +0200
++++ Python-2.7.1/Python/import.c	2011-01-04 15:55:11.000000000 +0100
+@@ -751,7 +751,7 @@
+         return NULL;
+     }
+     pyc_mtime = PyMarshal_ReadLongFromFile(fp);
+-    if (pyc_mtime != mtime) {
++    if (pyc_mtime != mtime && mtime != 1) {
+         if (Py_VerboseFlag)
+             PySys_WriteStderr("# %s has bad mtime\n", cpathname);
+         fclose(fp);
diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/no-ldconfig.patch b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/no-ldconfig.patch
new file mode 100644
index 000000000000..2a6b2a20dd19
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/no-ldconfig.patch
@@ -0,0 +1,117 @@
+From 6b0f329a9f37110020ca02b35c8125391ef282b7 Mon Sep 17 00:00:00 2001
+From: Frederik Rietdijk <fridh@fridh.nl>
+Date: Sat, 24 Dec 2016 15:56:10 +0100
+Subject: [PATCH] no ldconfig
+
+---
+ Lib/ctypes/util.py | 35 +----------------------------------
+ Lib/uuid.py        | 47 -----------------------------------------------
+ 2 files changed, 1 insertion(+), 81 deletions(-)
+
+diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py
+index ab10ec5..f253e34 100644
+--- a/Lib/ctypes/util.py
++++ b/Lib/ctypes/util.py
+@@ -235,40 +235,7 @@ elif os.name == "posix":
+     else:
+ 
+         def _findSoname_ldconfig(name):
+-            import struct
+-            if struct.calcsize('l') == 4:
+-                machine = os.uname()[4] + '-32'
+-            else:
+-                machine = os.uname()[4] + '-64'
+-            mach_map = {
+-                'x86_64-64': 'libc6,x86-64',
+-                'ppc64-64': 'libc6,64bit',
+-                'sparc64-64': 'libc6,64bit',
+-                's390x-64': 'libc6,64bit',
+-                'ia64-64': 'libc6,IA-64',
+-                }
+-            abi_type = mach_map.get(machine, 'libc6')
+-
+-            # XXX assuming GLIBC's ldconfig (with option -p)
+-            expr = r'\s+(lib%s\.[^\s]+)\s+\(%s' % (re.escape(name), abi_type)
+-
+-            env = dict(os.environ)
+-            env['LC_ALL'] = 'C'
+-            env['LANG'] = 'C'
+-            null = open(os.devnull, 'wb')
+-            try:
+-                with null:
+-                    p = subprocess.Popen(['/sbin/ldconfig', '-p'],
+-                                          stderr=null,
+-                                          stdout=subprocess.PIPE,
+-                                          env=env)
+-            except OSError:  # E.g. command not found
+-                return None
+-            [data, _] = p.communicate()
+-            res = re.search(expr, data)
+-            if not res:
+-                return None
+-            return res.group(1)
++            return None
+ 
+         def find_library(name):
+             return _findSoname_ldconfig(name) or _get_soname(_findLib_gcc(name))
+diff --git a/Lib/uuid.py b/Lib/uuid.py
+index 7432032..05eeee5 100644
+--- a/Lib/uuid.py
++++ b/Lib/uuid.py
+@@ -441,53 +441,6 @@ def _netbios_getnode():
+ 
+ # If ctypes is available, use it to find system routines for UUID generation.
+ _uuid_generate_time = _UuidCreate = None
+-try:
+-    import ctypes, ctypes.util
+-    import sys
+-
+-    # The uuid_generate_* routines are provided by libuuid on at least
+-    # Linux and FreeBSD, and provided by libc on Mac OS X.
+-    _libnames = ['uuid']
+-    if not sys.platform.startswith('win'):
+-        _libnames.append('c')
+-    for libname in _libnames:
+-        try:
+-            lib = ctypes.CDLL(ctypes.util.find_library(libname))
+-        except:
+-            continue
+-        if hasattr(lib, 'uuid_generate_time'):
+-            _uuid_generate_time = lib.uuid_generate_time
+-            break
+-    del _libnames
+-
+-    # The uuid_generate_* functions are broken on MacOS X 10.5, as noted
+-    # in issue #8621 the function generates the same sequence of values
+-    # in the parent process and all children created using fork (unless
+-    # those children use exec as well).
+-    #
+-    # Assume that the uuid_generate functions are broken from 10.5 onward,
+-    # the test can be adjusted when a later version is fixed.
+-    if sys.platform == 'darwin':
+-        import os
+-        if int(os.uname()[2].split('.')[0]) >= 9:
+-            _uuid_generate_time = None
+-
+-    # On Windows prior to 2000, UuidCreate gives a UUID containing the
+-    # hardware address.  On Windows 2000 and later, UuidCreate makes a
+-    # random UUID and UuidCreateSequential gives a UUID containing the
+-    # hardware address.  These routines are provided by the RPC runtime.
+-    # NOTE:  at least on Tim's WinXP Pro SP2 desktop box, while the last
+-    # 6 bytes returned by UuidCreateSequential are fixed, they don't appear
+-    # to bear any relationship to the MAC address of any network device
+-    # on the box.
+-    try:
+-        lib = ctypes.windll.rpcrt4
+-    except:
+-        lib = None
+-    _UuidCreate = getattr(lib, 'UuidCreateSequential',
+-                          getattr(lib, 'UuidCreate', None))
+-except:
+-    pass
+ 
+ def _unixdll_getnode():
+     """Get the hardware address on Unix using ctypes."""
+-- 
+2.11.0
+
diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/python-2.7-distutils-C++.patch b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/python-2.7-distutils-C++.patch
new file mode 100644
index 000000000000..78d9272d098a
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/python-2.7-distutils-C++.patch
@@ -0,0 +1,259 @@
+--- a/Lib/distutils/cygwinccompiler.py
++++ b/Lib/distutils/cygwinccompiler.py
+@@ -117,8 +117,10 @@
+         # dllwrap 2.10.90 is buggy
+         if self.ld_version >= "2.10.90":
+             self.linker_dll = "gcc"
++            self.linker_dll_cxx = "g++"
+         else:
+             self.linker_dll = "dllwrap"
++            self.linker_dll_cxx = "dllwrap"
+ 
+         # ld_version >= "2.13" support -shared so use it instead of
+         # -mdll -static
+@@ -132,9 +134,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_cxx, shared_option)))
+ 
+         # cygwin and mingw32 need different sets of libraries
+         if self.gcc_version == "2.91.57":
+@@ -160,8 +166,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
+ 
+@@ -327,9 +337,14 @@
+         self.set_executables(compiler='gcc%s -O -Wall' % no_cygwin,
+                              compiler_so='gcc%s -mdll -O -Wall' % no_cygwin,
+                              compiler_cxx='g++%s -O -Wall' % no_cygwin,
++                             compiler_so_cxx='g++%s -mdll -O -Wall' % no_cygwin,
+                              linker_exe='gcc%s' % no_cygwin,
+                              linker_so='%s%s %s %s'
+                                     % (self.linker_dll, no_cygwin,
++                                       shared_option, entry_point),
++                             linker_exe_cxx='g++%s' % no_cygwin,
++                             linker_so_cxx='%s%s %s %s'
++                                    % (self.linker_dll_cxx, no_cygwin,
+                                        shared_option, entry_point))
+         # Maybe we should also append -mthreads, but then the finished
+         # dlls need another dll (mingwm10.dll see Mingw32 docs)
+--- a/Lib/distutils/emxccompiler.py
++++ b/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
+ 
+--- a/Lib/distutils/sysconfig.py
++++ b/Lib/distutils/sysconfig.py
+@@ -170,10 +170,12 @@
+                 _osx_support.customize_compiler(_config_vars)
+                 _config_vars['CUSTOMIZED_OSX_COMPILER'] = 'True'
+ 
+-        (cc, cxx, cflags, ccshared, ldshared, so_ext, ar, ar_flags) = \
+-            get_config_vars('CC', 'CXX', 'CFLAGS',
+-                            'CCSHARED', 'LDSHARED', 'SO', 'AR',
+-                            'ARFLAGS')
++        (cc, cxx, ccshared, ldshared, ldcxxshared, so_ext, ar, ar_flags) = \
++            get_config_vars('CC', 'CXX', 'CCSHARED', 'LDSHARED', 'LDCXXSHARED',
++                            'SO', 'AR', 'ARFLAGS')
++
++        cflags = ''
++        cxxflags = ''
+ 
+         if 'CC' in os.environ:
+             newcc = os.environ['CC']
+@@ -188,19 +190,27 @@
+             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 = 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']
+         if 'AR' in os.environ:
+             ar = os.environ['AR']
+         if 'ARFLAGS' in os.environ:
+@@ -209,13 +219,17 @@
+             archiver = ar + ' ' + ar_flags
+ 
+         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_so_cxx=ldcxxshared,
++            linker_exe_cxx=cxx,
+             archiver=archiver)
+ 
+         compiler.shared_lib_extension = so_ext
+--- a/Lib/distutils/unixccompiler.py
++++ b/Lib/distutils/unixccompiler.py
+@@ -55,14 +55,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":
+@@ -112,12 +115,19 @@
+ 
+     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 = _osx_support.compiler_fixup(compiler_so,
+                                                     cc_args + extra_postargs)
++            compiler_so_cxx = _osx_support.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
+ 
+@@ -174,23 +184,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 = _osx_support.compiler_fixup(linker, ld_args)
+--- a/Lib/_osx_support.py
++++ b/Lib/_osx_support.py
+@@ -14,13 +14,13 @@
+ # configuration variables that may contain universal build flags,
+ # like "-arch" or "-isdkroot", that may need customization for
+ # the user environment
+-_UNIVERSAL_CONFIG_VARS = ('CFLAGS', 'LDFLAGS', 'CPPFLAGS', 'BASECFLAGS',
+-                            'BLDSHARED', 'LDSHARED', 'CC', 'CXX',
+-                            'PY_CFLAGS', 'PY_LDFLAGS', 'PY_CPPFLAGS',
+-                            'PY_CORE_CFLAGS')
++_UNIVERSAL_CONFIG_VARS = ('CFLAGS', 'CXXFLAGS', 'LDFLAGS', 'CPPFLAGS',
++                          'BASECFLAGS', 'BLDSHARED', 'LDSHARED', 'LDCXXSHARED',
++                          'CC', 'CXX', 'PY_CFLAGS', 'PY_LDFLAGS',
++                          'PY_CPPFLAGS', 'PY_CORE_CFLAGS')
+ 
+ # configuration variables that may contain compiler calls
+-_COMPILER_CONFIG_VARS = ('BLDSHARED', 'LDSHARED', 'CC', 'CXX')
++_COMPILER_CONFIG_VARS = ('BLDSHARED', 'LDSHARED', 'LDCXXSHARED', 'CC', 'CXX')
+ 
+ # prefix added to original configuration variable names
+ _INITPRE = '_OSX_SUPPORT_INITIAL_'
\ No newline at end of file
diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/search-path.patch b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/search-path.patch
new file mode 100644
index 000000000000..2e7b7526c0ce
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/search-path.patch
@@ -0,0 +1,27 @@
+diff -rc Python-2.4.4-orig/setup.py Python-2.4.4/setup.py
+*** Python-2.4.4-orig/setup.py	2006-10-08 19:41:25.000000000 +0200
+--- Python-2.4.4/setup.py	2007-05-27 16:04:54.000000000 +0200
+***************
+*** 279,288 ****
+          # Check for AtheOS which has libraries in non-standard locations
+          if platform == 'atheos':
+              lib_dirs += ['/system/libs', '/atheos/autolnk/lib']
+-             lib_dirs += os.getenv('LIBRARY_PATH', '').split(os.pathsep)
+              inc_dirs += ['/system/include', '/atheos/autolnk/include']
+-             inc_dirs += os.getenv('C_INCLUDE_PATH', '').split(os.pathsep)
+  
+          # OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb)
+          if platform in ['osf1', 'unixware7', 'openunix8']:
+              lib_dirs += ['/usr/ccs/lib']
+--- 279,289 ----
+          # Check for AtheOS which has libraries in non-standard locations
+          if platform == 'atheos':
+              lib_dirs += ['/system/libs', '/atheos/autolnk/lib']
+              inc_dirs += ['/system/include', '/atheos/autolnk/include']
+  
++         lib_dirs += os.getenv('LIBRARY_PATH', '').split(os.pathsep)
++         inc_dirs += os.getenv('C_INCLUDE_PATH', '').split(os.pathsep)
++         
+          # OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb)
+          if platform in ['osf1', 'unixware7', 'openunix8']:
+              lib_dirs += ['/usr/ccs/lib']
diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/use-correct-tcl-tk-on-darwin.patch b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/use-correct-tcl-tk-on-darwin.patch
new file mode 100644
index 000000000000..b73f62b97ec5
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/use-correct-tcl-tk-on-darwin.patch
@@ -0,0 +1,48 @@
+diff --git a/setup.py b/setup.py
+index 2779658..902d0eb 100644
+--- a/setup.py
++++ b/setup.py
+@@ -1699,9 +1699,6 @@ class PyBuildExt(build_ext):
+         # Rather than complicate the code below, detecting and building
+         # AquaTk is a separate method. Only one Tkinter will be built on
+         # Darwin - either AquaTk, if it is found, or X11 based Tk.
+-        if (host_platform == 'darwin' and
+-            self.detect_tkinter_darwin(inc_dirs, lib_dirs)):
+-            return
+
+         # Assume we haven't found any of the libraries or include files
+         # The versions with dots are used on Unix, and the versions without
+@@ -1747,22 +1744,6 @@ class PyBuildExt(build_ext):
+             if dir not in include_dirs:
+                 include_dirs.append(dir)
+
+-        # Check for various platform-specific directories
+-        if host_platform == 'sunos5':
+-            include_dirs.append('/usr/openwin/include')
+-            added_lib_dirs.append('/usr/openwin/lib')
+-        elif os.path.exists('/usr/X11R6/include'):
+-            include_dirs.append('/usr/X11R6/include')
+-            added_lib_dirs.append('/usr/X11R6/lib64')
+-            added_lib_dirs.append('/usr/X11R6/lib')
+-        elif os.path.exists('/usr/X11R5/include'):
+-            include_dirs.append('/usr/X11R5/include')
+-            added_lib_dirs.append('/usr/X11R5/lib')
+-        else:
+-            # Assume default location for X11
+-            include_dirs.append('/usr/X11/include')
+-            added_lib_dirs.append('/usr/X11/lib')
+-
+         # If Cygwin, then verify that X is installed before proceeding
+         if host_platform == 'cygwin':
+             x11_inc = find_file('X11/Xlib.h', [], include_dirs)
+@@ -1786,10 +1767,6 @@ class PyBuildExt(build_ext):
+         if host_platform in ['aix3', 'aix4']:
+             libs.append('ld')
+
+-        # Finally, link with the X11 libraries (not appropriate on cygwin)
+-        if host_platform != "cygwin":
+-            libs.append('X11')
+-
+         ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
+                         define_macros=[('WITH_APPINIT', 1)] + defs,
+                         include_dirs = include_dirs,