summaryrefslogtreecommitdiff
path: root/numpy/distutils/fcompiler/gnu.py
diff options
context:
space:
mode:
authorcookedm <cookedm@localhost>2007-09-10 20:23:25 +0000
committercookedm <cookedm@localhost>2007-09-10 20:23:25 +0000
commit1fa7397150f71565a3cc2735cf005e09d15aa458 (patch)
treeb8bdf21e09bec0344c6f3da70f6ca2a40a136e81 /numpy/distutils/fcompiler/gnu.py
parent208d3c27fe1605644002b270f68177c82a324d01 (diff)
downloadnumpy-1fa7397150f71565a3cc2735cf005e09d15aa458.tar.gz
Add support for universal GCC Fortran compilers on OS X (#571)
Diffstat (limited to 'numpy/distutils/fcompiler/gnu.py')
-rw-r--r--numpy/distutils/fcompiler/gnu.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/numpy/distutils/fcompiler/gnu.py b/numpy/distutils/fcompiler/gnu.py
index 569c0932a..a0aae6144 100644
--- a/numpy/distutils/fcompiler/gnu.py
+++ b/numpy/distutils/fcompiler/gnu.py
@@ -317,6 +317,51 @@ class Gnu95FCompiler(GnuFCompiler):
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':