[f2py] Draft: F2PY Users Guide and Reference Manual
Pearu Peterson
pearu@cens.ioc.ee
Fri, 6 Dec 2002 17:25:58 +0200 (EET)
On Fri, 6 Dec 2002, Roman Bertle wrote:
> Another thing, i am not familiar with scipy_distutils, but is it
> possible to pass compiler flags through f2py to the compiler in order to
> have better control of the compilation step?
In the case of a C compiler, scipy_distutils uses standard distutils. This
implies that the same C compiler and compiler flags are used for compiling
C extension modules that were used to compile Pyhton itself.
So, you can control the C compilation step as much as the standard
distutils allows it. See for example
setup.py build_ext --help
In the case of a Fortran compiler, scipy_distutils uses
scipy_distutils/command/build_flib.py where support for different
Fortran compilers are defined. For example,
cd scipy/fftpack
./setup_fftpack.py build_flib --help
shows
Options for 'build_flib' command:
--build-flib (-b) directory to build f77/f90 libraries to
--build-temp (-t) directory to put temporary build by-products
--debug (-g) compile with debugging information
--force (-f) forcibly build everything (ignore filetimestamps)
--fcompiler (-c) specify the compiler type
--fcompiler-exec (-e) specify the path to F77 compiler
--f90compiler-exec (-x) specify the path to F90 compiler
--help-compiler list available compilers
That is, you can explicitely specify which Fortran compiler to use as well
as which executable to use (sometimes one may have different versions of
the same compiler installed).
If you wish to use different compiler flags than provided by
build_flib.py, you can derive your own compiler class, and force
scipy_distutils to use that (similar approach should work also for C
compilers, I think). For example, in the setup.py file of your project,
you can do:
# my setup.py
from scipy_distutils.command import build_flib
class my_gnu_fortran_compiler(build_flib.gnu_fortran_compiler):
# redefine any method in gnu_fortran_compiler
# to suite your needs
..
# force looking my compiler first:
build_flib.all_compilers.insert(0,my_gnu_fortran_compiler)
from scipy_distutils.core import Extension
# define extensions
# you can use .pyf files in sources list, scipy_distutils uses f2py2e
# to process .pyf files.
...
if __name__ == '__main__':
from scipy_distutils.core import setup
setup(...
fortran_libraries = <list of 2-tuples (<name>,<dict>)>,
...
)
#end of my setup.py
For more examples, see the setup.py files of SciPy modules like
linalg, fftpack, etc.
Pearu