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 from numpy.distutils.unixccompiler import UnixCCompiler 9 try: # Python 2 10 meth = UnixCCompiler.runtime_library_dir_option.im_func 11 except AttributeError: # Python 3 12 meth = UnixCCompiler.runtime_library_dir_option 13 FCompiler.runtime_library_dir_option = meth 14except Exception: 15 pass 16 17 18def configuration(parent_package='',top_path=None): 19 INCLUDE_DIRS = [] 20 LIBRARY_DIRS = [] 21 LIBRARIES = [] 22 23 # PETSc 24 import os 25 PETSC_DIR = os.environ['PETSC_DIR'] 26 PETSC_ARCH = os.environ.get('PETSC_ARCH', '') 27 from os.path import join, isdir 28 if PETSC_ARCH and isdir(join(PETSC_DIR, PETSC_ARCH)): 29 INCLUDE_DIRS += [join(PETSC_DIR, PETSC_ARCH, 'include'), 30 join(PETSC_DIR, 'include')] 31 LIBRARY_DIRS += [join(PETSC_DIR, PETSC_ARCH, 'lib')] 32 else: 33 if PETSC_ARCH: pass # XXX should warn ... 34 INCLUDE_DIRS += [join(PETSC_DIR, 'include')] 35 LIBRARY_DIRS += [join(PETSC_DIR, 'lib')] 36 LIBRARIES += [#'petscts', 'petscsnes', 'petscksp', 37 #'petscdm', 'petscmat', 'petscvec', 38 'petsc'] 39 40 # PETSc for Python 41 import petsc4py 42 INCLUDE_DIRS += [petsc4py.get_include()] 43 44 # Configuration 45 from numpy.distutils.misc_util import Configuration 46 config = Configuration('', parent_package, top_path) 47 config.add_extension('_Bratu3D', 48 sources = ['Bratu3D.i', 49 'Bratu3D.c'], 50 depends = ['Bratu3D.h'], 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