setup: disable -mno-cygwin if building under mingw32
authorBryan O'Sullivan <bryano@fb.com>
Fri, 06 Jul 2012 20:19:55 -0700
changeset 17121 d13f47c800fd
parent 17069 2b1c78674230
child 17122 5d6cbfa975bf
setup: disable -mno-cygwin if building under mingw32 This gcc option has been deprecated since at least 2009 (gcc 4.4), and it causes compilations to fail entirely with gcc 4.6.x. Upstream distutils bug: http://bugs.python.org/issue12641
setup.py
--- a/setup.py	Thu Jun 28 08:45:38 2012 -0500
+++ b/setup.py	Fri Jul 06 20:19:55 2012 -0700
@@ -65,6 +65,7 @@
 from distutils.command.install_scripts import install_scripts
 from distutils.spawn import spawn, find_executable
 from distutils.ccompiler import new_compiler
+from distutils import cygwinccompiler
 from distutils.errors import CCompilerError, DistutilsExecError
 from distutils.sysconfig import get_python_inc
 from distutils.version import StrictVersion
@@ -429,6 +430,20 @@
     extmodules.append(Extension('mercurial.osutil', ['mercurial/osutil.c'],
                                 extra_link_args=osutil_ldflags))
 
+# the -mno-cygwin option has been deprecated for years
+Mingw32CCompiler = cygwinccompiler.Mingw32CCompiler
+
+class HackedMingw32CCompiler(cygwinccompiler.Mingw32CCompiler):
+    def __init__(self, *args, **kwargs):
+        Mingw32CCompiler.__init__(self, *args, **kwargs)
+        for i in 'compiler compiler_so linker_exe linker_so'.split():
+            try:
+                getattr(self, i).remove('-mno-cygwin')
+            except ValueError:
+                pass
+
+cygwinccompiler.Mingw32CCompiler = HackedMingw32CCompiler
+
 if sys.platform.startswith('linux') and os.uname()[2] > '2.6':
     # The inotify extension is only usable with Linux 2.6 kernels.
     # You also need a reasonably recent C library.