8

I spent almost an hour googling for the solution, but the documentation for numpy.distutils is very sparse.

I have a f2py-wrapped module. It consists basically of 3 files:

a.f90
a.pyf
lib.a <- this is a static library that contains most of the computational code

The module is well compiled with the following shell-script command.

f2py --build-dir temp -c a.pyf a.f90 lib.a --fcompiler=gnu95   
--fcompiler-flags="Zillions of compiler options"

As a result, I have the python module a.so (the name is specified in the .pyf file).

How do I do that with numpy.distutils (or some other python-oriented building tools)? A less important question is, can I also include the dependence from lib.a (and rebuild it when necessary?)

Ivan Oseledets
  • 2,270
  • 4
  • 23
  • 28
  • Just for the very last part: to add a dependence from `lib.a` you will have to create a separate package (if I am understanding what you mean) and then add it the yours `setup.py`'s dependencies list. – rubik Aug 24 '12 at 20:16
  • @rubik Ok, but how exactly this setup.py will look like? – Ivan Oseledets Aug 25 '12 at 14:03

1 Answers1

5

So, it is not 1 hour of Googling, it took 2 days of Googling, but finally I found the way to do that. Hope, it will be helpful to someone.

  def configuration(parent_package='',top_path=None):
      from numpy.distutils.misc_util import Configuration, get_info
      config = Configuration('a', parent_package, top_path)
      lib = ['./libdir/lib.a']
      src = ['a.f90','a.pyf']
      inc_dir = ['libdir']              
      config.add_extension('mya',sources=src,depends=lib_tt,
                      include_dirs=inc_dir,extra_objects="lib.a")
      #The main trick was to use extra_objects keyword
      return config

  if __name__ == '__main__':
      from numpy.distutils.core import setup
      setup(**configuration(top_path='').todict())
Ivan Oseledets
  • 2,270
  • 4
  • 23
  • 28