[Numpy-svn] r4028 - trunk/numpy/distutils/fcompiler

numpy-svn@scip... numpy-svn@scip...
Mon Sep 10 15:23:28 CDT 2007


Author: cookedm
Date: 2007-09-10 15:23:25 -0500 (Mon, 10 Sep 2007)
New Revision: 4028

Modified:
   trunk/numpy/distutils/fcompiler/gnu.py
Log:
Add support for universal GCC Fortran compilers on OS X (#571)


Modified: trunk/numpy/distutils/fcompiler/gnu.py
===================================================================
--- trunk/numpy/distutils/fcompiler/gnu.py	2007-09-09 04:44:11 UTC (rev 4027)
+++ trunk/numpy/distutils/fcompiler/gnu.py	2007-09-10 20:23:25 UTC (rev 4028)
@@ -317,6 +317,51 @@
 
     g2c = 'gfortran'
 
+    # Note that this is here instead of GnuFCompiler as gcc < 4 uses a
+    # different output format (which isn't as useful) than gcc >= 4,
+    # and we don't have to worry about g77 being universal (as it can't be).
+    def target_architecture(self, extra_opts=()):
+        """Return the architecture that the compiler will build for.
+        This is most useful for detecting universal compilers in OS X."""
+        extra_opts = list(extra_opts)
+        status, output = exec_command(self.compiler_f90 + ['-v'] + extra_opts,
+                                      use_tee=False)
+        if status == 0:
+            m = re.match(r'(?m)^Target: (.*)$', output)
+            if m:
+                return m.group(1)
+        return None
+
+    def is_universal_compiler(self):
+        """Return True if this compiler can compile universal binaries
+        (for OS X).
+
+        Currently only checks for i686 and powerpc architectures (no 64-bit
+        support yet).
+        """
+        if sys.platform != 'darwin':
+            return False
+        i686_arch = self.target_architecture(extra_opts=['-arch', 'i686'])
+        if not i686_arch or not i686_arch.startswith('i686-'):
+            return False
+        ppc_arch = self.target_architecture(extra_opts=['-arch', 'ppc'])
+        if not ppc_arch or not ppc_arch.startswith('powerpc-'):
+            return False
+        return True
+
+    def _add_arches_for_universal_build(self, flags):
+        if self.is_universal_compiler():
+            flags[:0] = ['-arch', 'i686', '-arch', 'ppc']
+        return flags
+
+    def get_flags(self):
+        flags = GnuFCompiler.get_flags(self)
+        return self._add_arches_for_universal_build(flags)
+
+    def get_flags_linker_so(self):
+        flags = GnuFCompiler.get_flags_linker_so(self)
+        return self._add_arches_for_universal_build(flags)
+
     def get_libraries(self):
         opt = GnuFCompiler.get_libraries(self)
         if sys.platform == 'darwin':



More information about the Numpy-svn mailing list