247 | | def _can_target(self, cmd, arch): |
248 | | """Return true is the compiler support the -arch flag for the given |
249 | | architecture.""" |
250 | | newcmd = cmd[:] |
251 | | newcmd.extend(["-arch", arch, "-v"]) |
252 | | st, out = exec_command(" ".join(newcmd)) |
253 | | if st == 0: |
254 | | for line in out.splitlines(): |
255 | | m = re.search(_R_ARCHS[arch], line) |
256 | | if m: |
257 | | return True |
258 | | return False |
259 | | |
260 | | def _universal_flags(self, cmd): |
261 | | """Return a list of -arch flags for every supported architecture.""" |
262 | | if not sys.platform == 'darwin': |
263 | | return [] |
264 | | arch_flags = [] |
265 | | for arch in ["ppc", "i686"]: |
266 | | if self._can_target(cmd, arch): |
267 | | arch_flags.extend(["-arch", arch]) |
268 | | return arch_flags |
| 239 | def target_architecture(self, extra_opts=()): |
| 240 | """Return the architecture that the compiler will build for. |
| 241 | This is most useful for detecting universal compilers in OS X.""" |
| 242 | extra_opts = list(extra_opts) |
| 243 | status, output = exec_command(self.compiler_f90 + ['-v'] + extra_opts, |
| 244 | use_tee=False) |
| 245 | if status == 0: |
| 246 | m = re.match(r'(?m)^Target: (.*)$', output) |
| 247 | if m: |
| 248 | return m.group(1) |
| 249 | return None |
| 250 | |
| 251 | def is_universal_compiler(self): |
| 252 | """Return True if this compiler can compile universal binaries |
| 253 | (for OS X). |
| 254 | |
| 255 | Currently only checks for i686 and powerpc architectures (no 64-bit |
| 256 | support yet). |
| 257 | """ |
| 258 | if sys.platform != 'darwin': |
| 259 | return False |
| 260 | i686_arch = self.target_architecture(extra_opts=['-arch', 'i686']) |
| 261 | if not i686_arch or not i686_arch.startswith('i686-'): |
| 262 | return False |
| 263 | ppc_arch = self.target_architecture(extra_opts=['-arch', 'ppc']) |
| 264 | if not ppc_arch or not ppc_arch.startswith('powerpc-'): |
| 265 | return False |
| 266 | return True |
| 267 | |
| 268 | def _add_arches_for_universal_build(self, flags): |
| 269 | if self.is_universal_compiler(): |
| 270 | flags[:0] = ['-arch', 'i686', '-arch', 'ppc'] |
| 271 | return flags |