Skip to content

Commit

Permalink
Merge pull request #5615 from charris/distutils-style-cleanups
Browse files Browse the repository at this point in the history
STY: Some style cleanups in distutils.
  • Loading branch information
charris committed Mar 2, 2015
2 parents fba3140 + 701dbe1 commit 83b680b
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 109 deletions.
66 changes: 22 additions & 44 deletions numpy/distutils/fcompiler/gnu.py
Expand Up @@ -8,7 +8,6 @@
import tempfile
from subprocess import Popen, PIPE, STDOUT

from numpy.distutils.cpuinfo import cpu
from numpy.distutils.fcompiler import FCompiler
from numpy.distutils.exec_command import exec_command
from numpy.distutils.misc_util import msvc_runtime_library
Expand Down Expand Up @@ -61,19 +60,11 @@ def version_match(self, version_string):
return None
return v[1]

# 'g77 --version' results
# SunOS: GNU Fortran (GCC 3.2) 3.2 20020814 (release)
# Debian: GNU Fortran (GCC) 3.3.3 20040110 (prerelease) (Debian)
# GNU Fortran (GCC) 3.3.3 (Debian 20040401)
# GNU Fortran 0.5.25 20010319 (prerelease)
# Redhat: GNU Fortran (GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
# GNU Fortran (GCC) 3.4.2 (mingw-special)

possible_executables = ['g77', 'f77']
executables = {
'version_cmd' : [None, "-dumpversion"],
'compiler_f77' : [None, "-g", "-Wall", "-fno-second-underscore"],
'compiler_f90' : None, # Use --fcompiler=gnu95 for f90 codes
'compiler_f90' : None, # Use --fcompiler=gnu95 for f90 codes
'compiler_fix' : None,
'linker_so' : [None, "-g", "-Wall"],
'archiver' : ["ar", "-cr"],
Expand All @@ -94,19 +85,11 @@ def version_match(self, version_string):
executables[key].append('-mno-cygwin')

g2c = 'g2c'

suggested_f90_compiler = 'gnu95'

#def get_linker_so(self):
# # win32 linking should be handled by standard linker
# # Darwin g77 cannot be used as a linker.
# #if re.match(r'(darwin)', sys.platform):
# # return
# return FCompiler.get_linker_so(self)

def get_flags_linker_so(self):
opt = self.linker_so[1:]
if sys.platform=='darwin':
if sys.platform == 'darwin':
target = os.environ.get('MACOSX_DEPLOYMENT_TARGET', None)
# If MACOSX_DEPLOYMENT_TARGET is set, we simply trust the value
# and leave it alone. But, distutils will complain if the
Expand Down Expand Up @@ -159,10 +142,12 @@ def get_library_dirs(self):
# if windows and not cygwin, libg2c lies in a different folder
if sys.platform == 'win32' and not d.startswith('/usr/lib'):
d = os.path.normpath(d)
if not os.path.exists(os.path.join(d, "lib%s.a" % self.g2c)):
d2 = os.path.abspath(os.path.join(d,
'../../../../lib'))
if os.path.exists(os.path.join(d2, "lib%s.a" % self.g2c)):
path = os.path.join(d, "lib%s.a" % self.g2c)
if not os.path.exists(path):
root = os.path.join(d, *((os.pardir,)*4))
d2 = os.path.abspath(os.path.join(root, 'lib'))
path = os.path.join(d2, "lib%s.a" % self.g2c)
if os.path.exists(path):
opt.append(d2)
opt.append(d)
return opt
Expand All @@ -182,7 +167,7 @@ def get_libraries(self):
opt.append(g2c)
c_compiler = self.c_compiler
if sys.platform == 'win32' and c_compiler and \
c_compiler.compiler_type=='msvc':
c_compiler.compiler_type == 'msvc':
# the following code is not needed (read: breaks) when using MinGW
# in case want to link F77 compiled code with MSVC
opt.append('gcc')
Expand All @@ -198,21 +183,22 @@ def get_flags_debug(self):

def get_flags_opt(self):
v = self.get_version()
if v and v<='3.3.3':
if v and v <= '3.3.3':
# With this compiler version building Fortran BLAS/LAPACK
# with -O3 caused failures in lib.lapack heevr,syevr tests.
opt = ['-O2']
elif v and v>='4.6.0':
elif v and v >= '4.6.0':
if is_win32():
# use -mincoming-stack-boundary=2
# due to the change to 16 byte stack alignment since GCC 4.6
# but 32 bit Windows ABI defines 4 bytes stack alignment
opt = ['-O2 -march=core2 -mtune=generic -mfpmath=sse -msse2 -mincoming-stack-boundary=2']
opt = ['-O2 -march=core2 -mtune=generic -mfpmath=sse -msse2'
'-mincoming-stack-boundary=2']
else:
opt = ['-O2 -march=x86-64 -DMS_WIN64 -mtune=generic -msse2']
else:
opt = ['-O2']
# opt.append()

return opt

def _c_arch_flags(self):
Expand Down Expand Up @@ -244,25 +230,18 @@ def version_match(self, version_string):
if not v or v[0] != 'gfortran':
return None
v = v[1]
if v>='4.':
if v >= '4.':
# gcc-4 series releases do not support -mno-cygwin option
pass
else:
# use -mno-cygwin flag for gfortran when Python is not Cygwin-Python
# use -mno-cygwin flag for gfortran when Python is not
# Cygwin-Python
if sys.platform == 'win32':
for key in ['version_cmd', 'compiler_f77', 'compiler_f90',
'compiler_fix', 'linker_so', 'linker_exe']:
self.executables[key].append('-mno-cygwin')
return v

# 'gfortran --version' results:
# XXX is the below right?
# Debian: GNU Fortran 95 (GCC 4.0.3 20051023 (prerelease) (Debian 4.0.2-3))
# GNU Fortran 95 (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
# OS X: GNU Fortran 95 (GCC) 4.1.0
# GNU Fortran 95 (GCC) 4.2.0 20060218 (experimental)
# GNU Fortran (GCC) 4.3.0 20070316 (experimental)

possible_executables = ['gfortran', 'f95']
executables = {
'version_cmd' : ["<F90>", "-dumpversion"],
Expand Down Expand Up @@ -321,10 +300,10 @@ def get_library_dirs(self):
target = self.get_target()
if target:
d = os.path.normpath(self.get_libgcc_dir())
root = os.path.join(d, os.pardir, os.pardir, os.pardir, os.pardir)
mingwdir = os.path.normpath(os.path.join(root, target, "lib"))
full = os.path.join(mingwdir, "libmingwex.a")
if os.path.exists(full):
root = os.path.join(d, *((os.pardir,)*4))
path = os.path.join(root, target, "lib")
mingwdir = os.path.normpath(path)
if os.path.exists(os.path.join(mingwdir, "libmingwex.a")):
opt.append(mingwdir)
return opt

Expand Down Expand Up @@ -362,8 +341,7 @@ def get_flags_opt(self):
return GnuFCompiler.get_flags_opt(self)

def _can_target(cmd, arch):
"""Return true is the command supports the -arch flag for the given
architecture."""
"""Return true if the architecture supports the -arch flag"""
newcmd = cmd[:]
fid, filename = tempfile.mkstemp(suffix=".f")
try:
Expand Down

0 comments on commit 83b680b

Please sign in to comment.