1#!/usr/bin/env python3 2 3#$ python setup.py build_ext --inplace 4 5# a bit of monkeypatching ... 6try: 7 from numpy.distutils.fcompiler import FCompiler 8 def runtime_library_dir_option(self, dir): 9 return self.c_compiler.runtime_library_dir_option(dir) 10 FCompiler.runtime_library_dir_option = \ 11 runtime_library_dir_option 12except Exception: 13 pass 14 15 16def configuration(parent_package='',top_path=None): 17 INCLUDE_DIRS = [] 18 LIBRARY_DIRS = [] 19 LIBRARIES = [] 20 21 # PETSc 22 import os 23 PETSC_DIR = os.environ['PETSC_DIR'] 24 PETSC_ARCH = os.environ.get('PETSC_ARCH', '') 25 from os.path import join, isdir 26 if PETSC_ARCH and isdir(join(PETSC_DIR, PETSC_ARCH)): 27 INCLUDE_DIRS += [join(PETSC_DIR, PETSC_ARCH, 'include'), 28 join(PETSC_DIR, 'include')] 29 LIBRARY_DIRS += [join(PETSC_DIR, PETSC_ARCH, 'lib')] 30 else: 31 if PETSC_ARCH: pass # XXX should warn ... 32 INCLUDE_DIRS += [join(PETSC_DIR, 'include')] 33 LIBRARY_DIRS += [join(PETSC_DIR, 'lib')] 34 LIBRARIES += [#'petscts', 'petscsnes', 'petscksp', 35 #'petscdm', 'petscmat', 'petscvec', 36 'petsc'] 37 38 # PETSc for Python 39 import petsc4py 40 INCLUDE_DIRS += [petsc4py.get_include()] 41 42 # Configuration 43 from numpy.distutils.misc_util import Configuration 44 config = Configuration('', parent_package, top_path) 45 config.add_extension('Bratu2D', 46 sources = ['Bratu2D.pyf', 47 'Bratu2D.F90'], 48 depends = ['Bratu2Dmodule.h'], 49 f2py_options=['--quiet'], 50 define_macros=[('F2PY_REPORT_ON_ARRAY_COPY',1)], 51 include_dirs=INCLUDE_DIRS + [os.curdir], 52 libraries=LIBRARIES, 53 library_dirs=LIBRARY_DIRS, 54 runtime_library_dirs=LIBRARY_DIRS) 55 return config 56 57if __name__ == "__main__": 58 from numpy.distutils.core import setup 59 setup(**configuration(top_path='').todict()) 60