summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPearu Peterson <pearu.peterson@gmail.com>2006-10-08 09:30:17 +0000
committerPearu Peterson <pearu.peterson@gmail.com>2006-10-08 09:30:17 +0000
commit45e92465815e16d02a611005b61abc6a65f6b91c (patch)
tree7cb75b38697c04be28bac4a388a5c8b71db5373c
parentcc7fd3d7d62f4bc6ee17456d282475781204f98e (diff)
downloadnumpy-45e92465815e16d02a611005b61abc6a65f6b91c.tar.gz
numpy.distutils: use language flag or source file extension to select default f77 or f90 compiler.
-rw-r--r--numpy/distutils/command/build_clib.py12
-rw-r--r--numpy/distutils/command/build_ext.py10
-rw-r--r--numpy/distutils/fcompiler/__init__.py27
-rw-r--r--numpy/distutils/fcompiler/gnu.py4
-rw-r--r--numpy/distutils/misc_util.py29
5 files changed, 70 insertions, 12 deletions
diff --git a/numpy/distutils/command/build_clib.py b/numpy/distutils/command/build_clib.py
index 3319c6a75..de1781991 100644
--- a/numpy/distutils/command/build_clib.py
+++ b/numpy/distutils/command/build_clib.py
@@ -46,9 +46,12 @@ class build_clib(old_build_clib):
return
# Make sure that library sources are complete.
+ languages = []
for (lib_name, build_info) in self.libraries:
if not all_strings(build_info.get('sources',[])):
self.run_command('build_src')
+ l = build_info.get('language',None)
+ if l and l not in languages: languages.append(l)
from distutils.ccompiler import new_compiler
self.compiler = new_compiler(compiler=self.compiler,
@@ -69,7 +72,8 @@ class build_clib(old_build_clib):
self.fcompiler = new_fcompiler(compiler=self.fcompiler,
verbose=self.verbose,
dry_run=self.dry_run,
- force=self.force)
+ force=self.force,
+ requiref90='f90' in languages)
self.fcompiler.customize(self.distribution)
libraries = self.libraries
@@ -124,12 +128,14 @@ class build_clib(old_build_clib):
'for fortran compiler: %s' \
% (config_fc))
from numpy.distutils.fcompiler import new_fcompiler
+ requiref90 = build_info.get('language','c')=='f90'
fcompiler = new_fcompiler(compiler=self.fcompiler.compiler_type,
verbose=self.verbose,
dry_run=self.dry_run,
- force=self.force)
+ force=self.force,
+ requiref90=requiref90)
fcompiler.customize(config_fc)
-
+
macros = build_info.get('macros')
include_dirs = build_info.get('include_dirs')
extra_postargs = build_info.get('extra_compiler_args') or []
diff --git a/numpy/distutils/command/build_ext.py b/numpy/distutils/command/build_ext.py
index 9958f5d8b..5f09ea1e3 100644
--- a/numpy/distutils/command/build_ext.py
+++ b/numpy/distutils/command/build_ext.py
@@ -75,6 +75,13 @@ class build_ext (old_build_ext):
need_f_compiler = 1
break
+ requiref90 = 0
+ if need_f_compiler:
+ for ext in self.extensions:
+ if getattr(ext,'language','c')=='f90':
+ requiref90 = 1
+ break
+
# Determine if C++ compiler is needed.
need_cxx_compiler = 0
for ext in self.extensions:
@@ -100,7 +107,8 @@ class build_ext (old_build_ext):
self.fcompiler = new_fcompiler(compiler=self.fcompiler,
verbose=self.verbose,
dry_run=self.dry_run,
- force=self.force)
+ force=self.force,
+ requiref90=requiref90)
if self.fcompiler.get_version():
self.fcompiler.customize(self.distribution)
self.fcompiler.customize_cmd(self)
diff --git a/numpy/distutils/fcompiler/__init__.py b/numpy/distutils/fcompiler/__init__.py
index 2974f5693..9dc8114a4 100644
--- a/numpy/distutils/fcompiler/__init__.py
+++ b/numpy/distutils/fcompiler/__init__.py
@@ -104,6 +104,11 @@ class FCompiler(CCompiler):
shared_lib_format = "%s%s"
exe_extension = ""
+ # If compiler does not support compiling Fortran 90 then it can
+ # suggest using another compiler. For example, gnu would suggest
+ # gnu95 compiler type when there are F90 sources.
+ suggested_f90_compiler = None
+
######################################################################
## Methods that subclasses may redefine. But don't call these methods!
## They are private to FCompiler class and may return unexpected
@@ -589,13 +594,23 @@ _default_compilers = (
('mac',('gnu','gnu95',)),
)
-def _find_existing_fcompiler(compilers, osname=None, platform=None):
+def _find_existing_fcompiler(compilers, osname=None, platform=None, requiref90=None):
for compiler in compilers:
v = None
try:
c = new_fcompiler(plat=platform, compiler=compiler)
c.customize()
v = c.get_version()
+ if requiref90 and c.compiler_f90 is None:
+ v = None
+ new_compiler = c.suggested_f90_compiler
+ if new_compiler:
+ c = new_fcompiler(plat=platform, compiler=new_compiler)
+ c.customize()
+ v = c.get_version()
+ if requiref90 and c.compiler_f90 is None:
+ raise ValueError,'%s does not support compiling f90 codes, skipping.' \
+ % (c.__class__.__name__)
except DistutilsModuleError:
pass
except Exception, msg:
@@ -604,7 +619,7 @@ def _find_existing_fcompiler(compilers, osname=None, platform=None):
return compiler
return
-def get_default_fcompiler(osname=None, platform=None):
+def get_default_fcompiler(osname=None, platform=None, requiref90=None):
""" Determine the default Fortran compiler to use for the given platform. """
if osname is None:
osname = os.name
@@ -622,7 +637,8 @@ def get_default_fcompiler(osname=None, platform=None):
matching_compilers.append('gnu')
compiler = _find_existing_fcompiler(matching_compilers,
osname=osname,
- platform=platform)
+ platform=platform,
+ requiref90=requiref90)
if compiler is not None:
return compiler
return matching_compilers[0]
@@ -631,7 +647,8 @@ def new_fcompiler(plat=None,
compiler=None,
verbose=0,
dry_run=0,
- force=0):
+ force=0,
+ requiref90=0):
""" Generate an instance of some FCompiler subclass for the supplied
platform/compiler combination.
"""
@@ -639,7 +656,7 @@ def new_fcompiler(plat=None,
plat = os.name
try:
if compiler is None:
- compiler = get_default_fcompiler(plat)
+ compiler = get_default_fcompiler(plat,requiref90=requiref90)
(module_name, class_name, long_description) = fcompiler_class[compiler]
except KeyError:
msg = "don't know how to compile Fortran code on platform '%s'" % plat
diff --git a/numpy/distutils/fcompiler/gnu.py b/numpy/distutils/fcompiler/gnu.py
index cd272b885..6e0f1895d 100644
--- a/numpy/distutils/fcompiler/gnu.py
+++ b/numpy/distutils/fcompiler/gnu.py
@@ -28,7 +28,7 @@ class GnuFCompiler(FCompiler):
executables = {
'version_cmd' : [fc_exe,"--version"],
'compiler_f77' : [fc_exe, "-g", "-Wall","-fno-second-underscore"],
- 'compiler_f90' : None,
+ 'compiler_f90' : None, # Use --fcompiler=gnu95 for f90 codes
'compiler_fix' : None,
'linker_so' : [fc_exe, "-g", "-Wall"],
'archiver' : ["ar", "-cr"],
@@ -50,6 +50,8 @@ class GnuFCompiler(FCompiler):
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.
diff --git a/numpy/distutils/misc_util.py b/numpy/distutils/misc_util.py
index 48fbe335a..384d7f2d7 100644
--- a/numpy/distutils/misc_util.py
+++ b/numpy/distutils/misc_util.py
@@ -19,7 +19,7 @@ __all__ = ['Configuration', 'get_numpy_include_dirs', 'default_config_dict',
'get_dependencies', 'is_local_src_dir', 'get_ext_source_files',
'get_script_files', 'get_lib_source_files', 'get_data_files',
'dot_join', 'get_frame', 'minrelpath','njoin',
- 'is_sequence', 'is_string', 'as_list', 'gpaths']
+ 'is_sequence', 'is_string', 'as_list', 'gpaths', 'get_language']
def allpath(name):
"Convert a /-separated pathname to one using the OS's path separator."
@@ -308,6 +308,18 @@ def as_list(seq):
else:
return [seq]
+def get_language(sources):
+ """ Determine language value (c,f77,f90) from sources """
+ language = 'c'
+ for source in sources:
+ if isinstance(source, str):
+ if f90_ext_match(source):
+ language = 'f90'
+ break
+ elif fortran_ext_match(source):
+ language = 'f77'
+ return language
+
def has_f_sources(sources):
""" Return True if sources contains Fortran files """
for source in sources:
@@ -1018,6 +1030,10 @@ class Configuration(object):
ext_args['name'] = dot_join(self.name,name)
ext_args['sources'] = sources
+ language = ext_args.get('language',None)
+ if language is None:
+ ext_args['language'] = get_language(sources)
+
if ext_args.has_key('extra_info'):
extra_info = ext_args['extra_info']
del ext_args['extra_info']
@@ -1076,11 +1092,16 @@ class Configuration(object):
include_dirs
extra_compiler_args
f2py_options
+ language
"""
build_info = copy.copy(build_info)
name = name #+ '__OF__' + self.name
build_info['sources'] = sources
+ language = build_info.get('language',None)
+ if language is None:
+ build_info['language'] = get_language(sources)
+
self._fix_paths_dict(build_info)
self.libraries.append((name,build_info))
@@ -1379,7 +1400,11 @@ def default_config_dict(name = None, parent_name = None, local_path=None):
def dict_append(d, **kws):
for k, v in kws.items():
if d.has_key(k):
- d[k].extend(v)
+ ov = d[k]
+ if isinstance(ov,str):
+ d[k] = v
+ else:
+ d[k].extend(v)
else:
d[k] = v