summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/distutils/fcompiler/__init__.py30
-rw-r--r--numpy/doc/DISTUTILS.txt34
2 files changed, 63 insertions, 1 deletions
diff --git a/numpy/distutils/fcompiler/__init__.py b/numpy/distutils/fcompiler/__init__.py
index d3b0ad7e8..e7f41330c 100644
--- a/numpy/distutils/fcompiler/__init__.py
+++ b/numpy/distutils/fcompiler/__init__.py
@@ -380,9 +380,11 @@ class FCompiler(CCompiler):
def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
"""Compile 'src' to product 'obj'."""
+ src_flags = {}
if is_f_file(src) and not has_f90_header(src):
flavor = ':f77'
compiler = self.compiler_f77
+ src_flags = get_f77flags(src)
elif is_free_format(src):
flavor = ':f90'
compiler = self.compiler_f90
@@ -403,9 +405,14 @@ class FCompiler(CCompiler):
assert self.compile_switch.strip()
s_args = [self.compile_switch, src]
+ extra_flags = src_flags.get(self.compiler_type,[])
+ if extra_flags:
+ log.info('using compile options from source: %r' \
+ % ' '.join(extra_flags))
+
if os.name == 'nt':
compiler = _nt_quote_args(compiler)
- command = compiler + cc_args + s_args + o_args + extra_postargs
+ command = compiler + cc_args + extra_flags + s_args + o_args + extra_postargs
display = '%s: %s' % (os.path.basename(compiler[0]) + flavor,
src)
@@ -758,5 +765,26 @@ def has_f90_header(src):
f.close()
return _has_f90_header(line) or _has_fix_header(line)
+_f77flags_re = re.compile(r'(c|)f77flags\s*\(\s*(?P<fcname>\w+)\s*\)\s*=\s*(?P<fflags>.*)',re.I)
+def get_f77flags(src):
+ """
+ Search the first 20 lines of fortran 77 code for line pattern
+ `CF77FLAGS(<fcompiler type>)=<f77 flags>`
+ Return a dictionary {<fcompiler type>:<f77 flags>}.
+ """
+ flags = {}
+ f = open(src,'r')
+ i = 0
+ for line in f.readlines():
+ i += 1
+ if i>20: break
+ m = _f77flags_re.match(line)
+ if not m: continue
+ fcname = m.group('fcname').strip()
+ fflags = m.group('fflags').strip()
+ flags[fcname] = split_quoted(fflags)
+ f.close()
+ return flags
+
if __name__ == '__main__':
show_fcompilers()
diff --git a/numpy/doc/DISTUTILS.txt b/numpy/doc/DISTUTILS.txt
index eab331af8..d53107cf4 100644
--- a/numpy/doc/DISTUTILS.txt
+++ b/numpy/doc/DISTUTILS.txt
@@ -535,3 +535,37 @@ To run only tests for ``xxx.yyy`` module, execute:
To take the level and verbosity parameters for tests from
``sys.argv``, use ``NumpyTest.run()`` method (this is supported only
when ``optparse`` is installed).
+
+Extra features in NumPy Distutils
+'''''''''''''''''''''''''''''''''
+
+Specifing config_fc options for libraries in setup.py script
+------------------------------------------------------------
+
+It is possible to specify config_fc options in setup.py scripts.
+For example, using
+
+ config.add_library('library',
+ sources=[...],
+ config_fc={'noopt':(__file__,1)})
+
+will compile the ``library`` sources without optimization flags.
+
+It's recommended to specify only those config_fc options in such a way
+that are compiler independent.
+
+Getting extra Fortran 77 compiler options from source
+-----------------------------------------------------
+
+Some old Fortran codes need special compiler options in order to
+work correctly. In order to specify compiler options per source
+file, ``numpy.distutils`` Fortran compiler looks for the following
+pattern::
+
+ CF77FLAGS(<fcompiler type>) = <fcompiler f77flags>
+
+in the first 20 lines of the source and use the ``f77flags`` for
+specified type of the fcompiler (the first character ``C`` is optional).
+
+TODO: This feature can be easily extended for Fortran 90 codes as
+well. Let us know if you would need such a feature.