Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a90754d

Browse files
pearucharris
authored andcommitted
ENH: Introduce new options extra_f77_compile_args and extra_f90_compile_args to
Configuration.add_extension. Configuration.add_library, and Extension. These options allow specifying extra compile options for compiling Fortran sources within a setup.py file.
1 parent ea529d4 commit a90754d

6 files changed

Lines changed: 40 additions & 8 deletions

File tree

doc/DISTUTILS.rst.txt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ in writing setup scripts:
226226
``define_macros``, ``undef_macros``, ``library_dirs``, ``libraries``,
227227
``runtime_library_dirs``, ``extra_objects``, ``extra_compile_args``,
228228
``extra_link_args``, ``export_symbols``, ``swig_opts``, ``depends``,
229-
``language``, ``f2py_options``, ``module_dirs``, ``extra_info``.
229+
``language``, ``f2py_options``, ``module_dirs``, ``extra_info``,
230+
``extra_f77_compile_args``, ``extra_compile_f90_args``.
230231

231232
Note that ``config.paths`` method is applied to all lists that
232233
may contain paths. ``extra_info`` is a dictionary or a list
@@ -261,11 +262,12 @@ in writing setup scripts:
261262
The second argument gives a path to a build directory that must
262263
be used when creating files to a disk.
263264

264-
+ ``config.add_library(name, sources, **build_info)`` --- add
265-
a library to ``libraries`` list. Allowed keywords arguments
266-
are ``depends``, ``macros``, ``include_dirs``,
267-
``extra_compiler_args``, ``f2py_options``. See ``.add_extension()``
268-
method for more information on arguments.
265+
+ ``config.add_library(name, sources, **build_info)`` --- add a
266+
library to ``libraries`` list. Allowed keywords arguments are
267+
``depends``, ``macros``, ``include_dirs``, ``extra_compiler_args``,
268+
``f2py_options``, ``extra_f77_compile_args``,
269+
``extra_compile_f90_args``. See ``.add_extension()`` method for
270+
more information on arguments.
269271

270272
+ ``config.have_f77c()`` --- return True if Fortran 77 compiler is
271273
available (read: a simple Fortran 77 code compiled succesfully).

numpy/distutils/command/build_clib.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ def build_a_library(self, build_info, lib_name, libraries):
177177
raise DistutilsError("library %s has Fortran sources"\
178178
" but no Fortran compiler found" % (lib_name))
179179

180+
if fcompiler is not None:
181+
fcompiler.extra_f77_compile_args = build_info.get('extra_f77_compile_args') or []
182+
fcompiler.extra_f90_compile_args = build_info.get('extra_f90_compile_args') or []
183+
180184
macros = build_info.get('macros')
181185
include_dirs = build_info.get('include_dirs')
182186
if include_dirs is None:

numpy/distutils/command/build_ext.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,9 @@ def build_extension(self, ext):
299299
fcompiler = self._f77_compiler
300300
else: # in case ext.language is c++, for instance
301301
fcompiler = self._f90_compiler or self._f77_compiler
302+
if fcompiler is not None:
303+
fcompiler.extra_f77_compile_args = ext.extra_f77_compile_args or []
304+
fcompiler.extra_f90_compile_args = ext.extra_f90_compile_args or []
302305
cxx_compiler = self._cxx_compiler
303306

304307
# check for the availability of required compilers

numpy/distutils/extension.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ def __init__ (self, name, sources,
3131
language=None,
3232
f2py_options=None,
3333
module_dirs=None,
34+
extra_f77_compile_args=None,
35+
extra_f90_compile_args=None,
3436
):
3537
old_Extension.__init__(self,name, [],
3638
include_dirs,
@@ -63,7 +65,9 @@ def __init__ (self, name, sources,
6365
# numpy_distutils features
6466
self.f2py_options = f2py_options or []
6567
self.module_dirs = module_dirs or []
66-
68+
self.extra_f77_compile_args = extra_f77_compile_args or []
69+
self.extra_f90_compile_args = extra_f90_compile_args or []
70+
6771
return
6872

6973
def has_cxx_sources(self):

numpy/distutils/fcompiler/__init__.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ class FCompiler(CCompiler):
213213
# command/{build_ext.py, build_clib.py, config.py} files.
214214
c_compiler = None
215215

216+
# extra_{f77,f90}_compile_args are set by build_ext.build_extension method
217+
extra_f77_compile_args = []
218+
extra_f90_compile_args = []
219+
216220
def __init__(self, *args, **kw):
217221
CCompiler.__init__(self, *args, **kw)
218222
self.distutils_vars = self.distutils_vars.clone(self._environment_hook)
@@ -560,18 +564,21 @@ def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
560564
flavor = ':f77'
561565
compiler = self.compiler_f77
562566
src_flags = get_f77flags(src)
567+
extra_compile_args = self.extra_f77_compile_args or []
563568
elif is_free_format(src):
564569
flavor = ':f90'
565570
compiler = self.compiler_f90
566571
if compiler is None:
567572
raise DistutilsExecError('f90 not supported by %s needed for %s'\
568573
% (self.__class__.__name__,src))
574+
extra_compile_args = self.extra_f90_compile_args or []
569575
else:
570576
flavor = ':fix'
571577
compiler = self.compiler_fix
572578
if compiler is None:
573579
raise DistutilsExecError('f90 (fixed) not supported by %s needed for %s'\
574580
% (self.__class__.__name__,src))
581+
extra_compile_args = self.extra_f90_compile_args or []
575582
if self.object_switch[-1]==' ':
576583
o_args = [self.object_switch.strip(),obj]
577584
else:
@@ -580,13 +587,17 @@ def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
580587
assert self.compile_switch.strip()
581588
s_args = [self.compile_switch, src]
582589

590+
if extra_compile_args:
591+
log.info('extra %s options: %r' \
592+
% (flavor[1:], ' '.join(extra_compile_args)))
593+
583594
extra_flags = src_flags.get(self.compiler_type,[])
584595
if extra_flags:
585596
log.info('using compile options from source: %r' \
586597
% ' '.join(extra_flags))
587598

588599
command = compiler + cc_args + extra_flags + s_args + o_args \
589-
+ extra_postargs
600+
+ extra_postargs + extra_compile_args
590601

591602
display = '%s: %s' % (os.path.basename(compiler[0]) + flavor,
592603
src)
@@ -961,5 +972,7 @@ def get_f77flags(src):
961972
f.close()
962973
return flags
963974

975+
# TODO: implement get_f90flags and use it in _compile similarly to get_f77flags
976+
964977
if __name__ == '__main__':
965978
show_fcompilers()

numpy/distutils/misc_util.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,6 +1403,8 @@ def add_extension(self,name,sources,**kw):
14031403
extra_objects:
14041404
extra_compile_args:
14051405
extra_link_args:
1406+
extra_f77_compile_args:
1407+
extra_f90_compile_args:
14061408
export_symbols:
14071409
swig_opts:
14081410
depends:
@@ -1497,6 +1499,8 @@ def add_library(self,name,sources,**build_info):
14971499
* macros
14981500
* include_dirs
14991501
* extra_compiler_args
1502+
* extra_f77_compiler_args
1503+
* extra_f90_compiler_args
15001504
* f2py_options
15011505
* language
15021506
@@ -1548,6 +1552,8 @@ def add_installed_library(self, name, sources, install_dir, build_info=None):
15481552
* macros
15491553
* include_dirs
15501554
* extra_compiler_args
1555+
* extra_f77_compiler_args
1556+
* extra_f90_compiler_args
15511557
* f2py_options
15521558
* language
15531559

0 commit comments

Comments
 (0)