summaryrefslogtreecommitdiff
path: root/fcompiler/gnu.py
diff options
context:
space:
mode:
Diffstat (limited to 'fcompiler/gnu.py')
-rw-r--r--fcompiler/gnu.py64
1 files changed, 53 insertions, 11 deletions
diff --git a/fcompiler/gnu.py b/fcompiler/gnu.py
index 2475f61f7..c1353379c 100644
--- a/fcompiler/gnu.py
+++ b/fcompiler/gnu.py
@@ -1,11 +1,9 @@
-
import re
import os
import sys
import warnings
from numpy.distutils.cpuinfo import cpu
-from numpy.distutils.ccompiler import simple_version_match
from numpy.distutils.fcompiler import FCompiler
from numpy.distutils.exec_command import exec_command
from numpy.distutils.misc_util import mingw32, msvc_runtime_library
@@ -13,10 +11,33 @@ from numpy.distutils.misc_util import mingw32, msvc_runtime_library
compilers = ['GnuFCompiler', 'Gnu95FCompiler']
class GnuFCompiler(FCompiler):
-
compiler_type = 'gnu'
description = 'GNU Fortran 77 compiler'
- version_match = simple_version_match(start=r'GNU Fortran (?!95)')
+
+ def gnu_version_match(self, version_string):
+ """Handle the different versions of GNU fortran compilers"""
+ m = re.match(r'GNU Fortran', version_string)
+ if not m:
+ return None
+ m = re.match(r'GNU Fortran\s+95.*?([0-9-.]+)', version_string)
+ if m:
+ return ('gfortran', m.group(1))
+ m = re.match(r'GNU Fortran.*?([0-9-.]+)', version_string)
+ if m:
+ v = m.group(1)
+ if v.startswith('0') or v.startswith('2') or v.startswith('3'):
+ # the '0' is for early g77's
+ return ('g77', v)
+ else:
+ # at some point in the 4.x series, the ' 95' was dropped
+ # from the version string
+ return ('gfortran', v)
+
+ def version_match(self, version_string):
+ v = self.gnu_version_match(version_string)
+ if not v or v[0] != 'g77':
+ return None
+ return v[1]
# 'g77 --version' results
# SunOS: GNU Fortran (GCC 3.2) 3.2 20020814 (release)
@@ -62,13 +83,19 @@ class GnuFCompiler(FCompiler):
def get_flags_linker_so(self):
opt = self.linker_so[1:]
- if sys.platform == 'darwin':
- target = os.environ.get('MACOSX_DEPLOYMENT_TARGET', '10.3')
+ if sys.platform=='darwin':
+ # MACOSX_DEPLOYMENT_TARGET must be at least 10.3. This is
+ # a reasonable default value even when building on 10.4 when using
+ # the official Python distribution and those derived from it (when
+ # not broken).
+ target = os.environ.get('MACOSX_DEPLOYMENT_TARGET', None)
+ if target is None or target == '':
+ target = '10.3'
major, minor = target.split('.')
if int(minor) < 3:
minor = '3'
warnings.warn('Environment variable '
- 'MACOSX_DEPLOYMENT_TARGET reset to 10.3')
+ 'MACOSX_DEPLOYMENT_TARGET reset to %s.%s' % (major, minor))
os.environ['MACOSX_DEPLOYMENT_TARGET'] = '%s.%s' % (major,
minor)
@@ -189,6 +216,8 @@ class GnuFCompiler(FCompiler):
# there's also: athlon-tbird, athlon-4, athlon-xp
elif cpu.is_Nocona():
march_opt = '-march=nocona'
+ elif cpu.is_Core2():
+ march_opt = '-march=nocona'
elif cpu.is_Prescott():
march_opt = '-march=prescott'
elif cpu.is_PentiumIV():
@@ -209,6 +238,10 @@ class GnuFCompiler(FCompiler):
if gnu_ver >= '3.4.4':
if cpu.is_PentiumM():
march_opt = '-march=pentium-m'
+ # Future:
+ # if gnu_ver >= '4.3':
+ # if cpu.is_Core2():
+ # march_opt = '-march=core2'
# Note: gcc 3.2 on win32 has breakage with -march specified
if '3.1.1' <= gnu_ver <= '3.4' and sys.platform=='win32':
@@ -234,22 +267,31 @@ class GnuFCompiler(FCompiler):
return opt
class Gnu95FCompiler(GnuFCompiler):
-
compiler_type = 'gnu95'
description = 'GNU Fortran 95 compiler'
- version_match = simple_version_match(start='GNU Fortran 95')
+
+ def version_match(self, version_string):
+ v = self.gnu_version_match(version_string)
+ if not v or v[0] != 'gfortran':
+ return None
+ return v[1]
# '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>", "--version"],
- 'compiler_f77' : [None, "-Wall", "-ffixed-form", "-fno-second-underscore"],
+ 'compiler_f77' : [None, "-Wall", "-ffixed-form",
+ "-fno-second-underscore"],
'compiler_f90' : [None, "-Wall", "-fno-second-underscore"],
- 'compiler_fix' : [None, "-Wall", "-ffixed-form", "-fno-second-underscore"],
+ 'compiler_fix' : [None, "-Wall", "-ffixed-form",
+ "-fno-second-underscore"],
'linker_so' : ["<F90>", "-Wall"],
'archiver' : ["ar", "-cr"],
'ranlib' : ["ranlib"],