1from __future__ import generators 2import config.base 3 4class Configure(config.base.Configure): 5 def __init__(self, framework): 6 config.base.Configure.__init__(self, framework) 7 self.headerPrefix = '' 8 self.substPrefix = '' 9 self.useShared = 0 10 return 11 12 def __str1__(self): 13 txt = ' Single library: %s\n' % ('yes' if self.framework.argDB['with-single-library'] else 'no') 14 txt += ' Shared libraries: %s\n' % ('yes' if self.useShared else 'no') 15 return txt 16 17 def setupHelp(self, help): 18 import nargs 19 help.addArgument('PETSc', '-with-shared-libraries=<bool>', nargs.ArgBool(None, 1, 'Make PETSc libraries shared -- libpetsc.so (Unix/Linux) or libpetsc.dylib (Mac)')) 20 help.addArgument('PETSc', '-with-serialize-functions=<bool>', nargs.ArgBool(None, 0, 'Allows function pointers to be serialized to binary files with string representations')) 21 return 22 23 def setupDependencies(self, framework): 24 config.base.Configure.setupDependencies(self, framework) 25 self.arch = framework.require('PETSc.options.arch', self) 26 self.debuggers = framework.require('config.utilities.debuggers', self) 27 self.setCompilers = framework.require('config.setCompilers', self) 28 self.headers = framework.require('config.headers', self) 29 self.functions = framework.require('config.functions', self) 30 self.ftm = framework.require('config.utilities.featureTestMacros', self) 31 return 32 33 def checkSharedDynamicPicOptions(self): 34 '''if user specified out-dated 'with-shared' or 'with-dynamic' - flag an error''' 35 if 'with-shared' in self.framework.argDB: 36 raise RuntimeError('Option "--with-shared" no longer exists. Use "--with-shared-libraries".') 37 if 'with-dynamic' in self.framework.argDB or 'with-dynamic-loading' in self.framework.argDB: 38 raise RuntimeError('Option "--with-dynamic" and "--with-dynamic-loading" no longer exist.') 39 if self.framework.argDB['with-shared-libraries'] and not self.framework.argDB['with-pic'] and 'with-pic' in self.framework.clArgDB: 40 raise RuntimeError('If you use --with-shared-libraries you cannot disable --with-pic') 41 42 # default with-shared-libraries=1 => --with-pic=1 43 # Note: there is code in setCompilers.py that uses this as default. 44 if self.framework.argDB['with-shared-libraries'] and not self.framework.argDB['with-pic']: self.framework.argDB['with-pic'] = 1 45 return 46 47 def configureSharedLibraries(self): 48 '''Checks whether shared libraries should be used, for which you must 49 - Specify --with-shared-libraries 50 - Have found a working shared linker 51 Defines PETSC_USE_SHARED_LIBRARIES if they are used''' 52 import sys 53 54 self.useShared = self.framework.argDB['with-shared-libraries'] and not self.setCompilers.staticLibraries 55 56 if self.useShared: 57 #if config.setCompilers.Configure.isSolaris(self.log) and config.setCompilers.Configure.isGNU(self.framework.getCompiler(),self.log): 58 # self.addMakeRule('shared_arch','shared_'+self.arch.hostOsBase+'gnu') 59 #elif '-qmkshrobj' in self.setCompilers.sharedLibraryFlags: 60 # self.addMakeRule('shared_arch','shared_linux_ibm') 61 #else: 62 # self.addMakeRule('shared_arch','shared_'+self.arch.hostOsBase) 63 64 # Linux is the default 65 if self.setCompilers.isDarwin(self.log): 66 self.addMakeRule('shared_arch','shared_darwin') 67 self.addMakeMacro('SONAME_FUNCTION', '$(1).$(2).dylib') 68 self.addMakeMacro('SONAME_SFX_FUNCTION', '$(1)$(LIB_NAME_SUFFIX).$(2).dylib') 69 self.addMakeMacro('SL_LINKER_FUNCTION', '-dynamiclib -install_name $(call SONAME_FUNCTION,$(1),$(2)) -compatibility_version $(2) -current_version $(3) -undefined dynamic_lookup') 70 elif self.setCompilers.CC.find('win32fe') >=0: 71 self.addMakeMacro('SONAME_FUNCTION', '$(1).dll') 72 self.addMakeMacro('SONAME_SFX_FUNCTION', '$(1)$(LIB_NAME_SUFFIX).dll') 73 self.addMakeMacro('SL_LINKER_FUNCTION', '-LD') 74 self.addMakeMacro('PETSC_DLL_EXPORTS', '1') 75 else: 76 # TODO: check that -Wl,-soname,${LIBNAME}.${SL_LINKER_SUFFIX} can be passed (might fail on Intel) 77 # TODO: check whether we need to specify dependent libraries on the link line (long test) 78 self.addMakeRule('shared_arch','shared_linux') 79 self.addMakeMacro('SONAME_FUNCTION', '$(1).$(SL_LINKER_SUFFIX).$(2)') 80 self.addMakeMacro('SONAME_SFX_FUNCTION', '$(1)$(LIB_NAME_SUFFIX).$(SL_LINKER_SUFFIX).$(2)') 81 self.addMakeMacro('SL_LINKER_FUNCTION', self.framework.getSharedLinkerFlags() + ' -Wl,-soname,$(call SONAME_FUNCTION,$(notdir $(1)),$(2))') 82 if config.setCompilers.Configure.isMINGW(self.framework.getCompiler(),self.log): 83 self.addMakeMacro('PETSC_DLL_EXPORTS', '1') 84 self.addMakeMacro('BUILDSHAREDLIB','yes') 85 else: 86 self.addMakeRule('shared_arch','') 87 self.addMakeMacro('BUILDSHAREDLIB','no') 88 if self.useShared: 89 self.addDefine('USE_SHARED_LIBRARIES', 1) 90 else: 91 self.logPrint('Shared libraries - disabled') 92 return 93 94 def configureDynamicLibraries(self): 95 '''Checks whether dynamic loading is available (with dlfcn.h and libdl)''' 96 if self.setCompilers.dynamicLibraries: 97 self.addDefine('HAVE_DYNAMIC_LIBRARIES', 1) 98 return 99 100 def configureSerializedFunctions(self): 101 ''' 102 Defines PETSC_SERIALIZE_FUNCTIONS if they are used 103 Requires shared libraries''' 104 import sys 105 106 if self.framework.argDB['with-serialize-functions'] and self.setCompilers.dynamicLibraries: 107 self.addDefine('SERIALIZE_FUNCTIONS', 1) 108 109 def checkSymbolResolution(self): 110 '''Checks that dladdr() works''' 111 if self.headers.haveHeader('dlfcn.h') and self.functions.haveFunction('dlerror'): 112 ftm = '' 113 if self.ftm.defines.get('_GNU_SOURCE'): ftm = '#define _GNU_SOURCE\n' 114 if self.checkCompile('%s#include<stdlib.h>\n#include <dlfcn.h>\n' % ftm, 'Dl_info info;\nif (dladdr(*(void **)&exit, &info) == 0) return 1;\n'): 115 self.addDefine('HAVE_DLADDR', 1) 116 if hasattr(self.headers.setCompilers, 'CXX'): 117 self.headers.pushLanguage('C++') 118 self.headers.check('cxxabi.h') 119 self.headers.popLanguage() 120 121 def configure(self): 122 self.executeTest(self.checkSharedDynamicPicOptions) 123 self.executeTest(self.configureSharedLibraries) 124 self.executeTest(self.configureDynamicLibraries) 125 self.executeTest(self.configureSerializedFunctions) 126 self.executeTest(self.checkSymbolResolution) 127 return 128