~jtaylor/ubuntu/precise/python-numpy/multiarch-fix-818867

« back to all changes in this revision

Viewing changes to numpy/distutils/fcompiler/gnu.py

  • Committer: Bazaar Package Importer
  • Author(s): Sandro Tosi
  • Date: 2010-10-07 10:19:13 UTC
  • mfrom: (7.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20101007101913-8b1kmt8ho4upcl9s
Tags: 1:1.4.1-5
* debian/patches/10_use_local_python.org_object.inv_sphinx.diff
  - fixed small typo in description
* debian/patches/changeset_r8364.diff
  - fix memory corruption (double free); thanks to Joseph Barillari for the
    report and to Michael Gilbert for pushing resolution; Closes: #581058

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
import os
3
3
import sys
4
4
import warnings
 
5
import platform
 
6
import tempfile
 
7
from subprocess import Popen, PIPE, STDOUT
5
8
 
6
9
from numpy.distutils.cpuinfo import cpu
7
10
from numpy.distutils.fcompiler import FCompiler
12
15
 
13
16
TARGET_R = re.compile("Target: ([a-zA-Z0-9_\-]*)")
14
17
 
15
 
# XXX: do we really need to check for target ? If the arch is not supported,
16
 
# the return code should be != 0
17
 
_R_ARCHS = {"ppc": r"^Target: (powerpc-.*)$",
18
 
    "i686": r"^Target: (i686-.*)$",
19
 
    "x86_64": r"^Target: (i686-.*)$",
20
 
    "ppc64": r"^Target: (powerpc-.*)$",}
 
18
# XXX: handle cross compilation
 
19
def is_win64():
 
20
    return sys.platform == "win32" and platform.architecture()[0] == "64bit"
 
21
 
 
22
if is_win64():
 
23
    #_EXTRAFLAGS = ["-fno-leading-underscore"]
 
24
    _EXTRAFLAGS = []
 
25
else:
 
26
    _EXTRAFLAGS = []
21
27
 
22
28
class GnuFCompiler(FCompiler):
23
29
    compiler_type = 'gnu'
220
226
    executables = {
221
227
        'version_cmd'  : ["<F90>", "--version"],
222
228
        'compiler_f77' : [None, "-Wall", "-ffixed-form",
223
 
                          "-fno-second-underscore"],
224
 
        'compiler_f90' : [None, "-Wall", "-fno-second-underscore"],
 
229
                "-fno-second-underscore"] + _EXTRAFLAGS,
 
230
        'compiler_f90' : [None, "-Wall", "-fno-second-underscore"] + _EXTRAFLAGS,
225
231
        'compiler_fix' : [None, "-Wall", "-ffixed-form",
226
 
                          "-fno-second-underscore"],
 
232
                          "-fno-second-underscore"] + _EXTRAFLAGS,
227
233
        'linker_so'    : ["<F90>", "-Wall"],
228
234
        'archiver'     : ["ar", "-cr"],
229
235
        'ranlib'       : ["ranlib"],
241
247
 
242
248
    g2c = 'gfortran'
243
249
 
244
 
    # Note that this is here instead of GnuFCompiler as gcc < 4 uses a
245
 
    # different output format (which isn't as useful) than gcc >= 4,
246
 
    # and we don't have to worry about g77 being universal (as it can't be).
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
250
    def _universal_flags(self, cmd):
261
251
        """Return a list of -arch flags for every supported architecture."""
262
252
        if not sys.platform == 'darwin':
263
253
            return []
264
254
        arch_flags = []
265
 
        for arch in ["ppc", "i686"]:
266
 
            if self._can_target(cmd, arch):
 
255
        for arch in ["ppc", "i686", "x86_64"]:
 
256
            if _can_target(cmd, arch):
267
257
                arch_flags.extend(["-arch", arch])
268
258
        return arch_flags
269
259
 
307
297
                    i = opt.index("gcc")
308
298
                    opt.insert(i+1, "mingwex")
309
299
                    opt.insert(i+1, "mingw32")
 
300
            # XXX: fix this mess, does not work for mingw
 
301
            if is_win64():
 
302
                c_compiler = self.c_compiler
 
303
                if c_compiler and c_compiler.compiler_type == "msvc":
 
304
                    return []
 
305
                else:
 
306
                    raise NotImplementedError("Only MS compiler supported with gfortran on win64")
310
307
        return opt
311
308
 
312
309
    def get_target(self):
319
316
                return m.group(1)
320
317
        return ""
321
318
 
 
319
    def get_flags_opt(self):
 
320
        if is_win64():
 
321
            return ['-O0']
 
322
        else:
 
323
            return GnuFCompiler.get_flags_opt(self)
 
324
 
 
325
def _can_target(cmd, arch):
 
326
    """Return true is the command supports the -arch flag for the given
 
327
    architecture."""
 
328
    newcmd = cmd[:]
 
329
    fid, filename = tempfile.mkstemp(suffix=".f")
 
330
    try:
 
331
        d = os.path.dirname(filename)
 
332
        output = os.path.splitext(filename)[0] + ".o"
 
333
        try:
 
334
            newcmd.extend(["-arch", arch, "-c", filename])
 
335
            p = Popen(newcmd, stderr=STDOUT, stdout=PIPE, cwd=d)
 
336
            p.communicate()
 
337
            return p.returncode == 0
 
338
        finally:
 
339
            if os.path.exists(output):
 
340
                os.remove(output)
 
341
    finally:
 
342
        os.remove(filename)
 
343
    return False
 
344
 
322
345
if __name__ == '__main__':
323
346
    from distutils import log
324
347
    log.set_verbosity(2)