19d310bb7SBarry Smith#!/usr/bin/env python 29d310bb7SBarry Smithfrom __future__ import generators 39d310bb7SBarry Smithimport config.base 49d310bb7SBarry Smith 59d310bb7SBarry Smithclass Configure(config.base.Configure): 69d310bb7SBarry Smith def __init__(self, framework): 79d310bb7SBarry Smith config.base.Configure.__init__(self, framework) 89d310bb7SBarry Smith self.headerPrefix = '' 99d310bb7SBarry Smith self.substPrefix = '' 109d310bb7SBarry Smith self.useShared = 0 119d310bb7SBarry Smith return 129d310bb7SBarry Smith 139d310bb7SBarry Smith def __str1__(self): 14e8e972b2SVaclav Hapla txt = ' Single library: %s\n' % ('yes' if self.framework.argDB['with-single-library'] else 'no') 15e8e972b2SVaclav Hapla txt += ' Shared libraries: %s\n' % ('yes' if self.useShared else 'no') 169d310bb7SBarry Smith return txt 179d310bb7SBarry Smith 189d310bb7SBarry Smith def setupHelp(self, help): 199d310bb7SBarry Smith import nargs 209d310bb7SBarry Smith help.addArgument('PETSc', '-with-shared-libraries=<bool>', nargs.ArgBool(None, 1, 'Make PETSc libraries shared -- libpetsc.so (Unix/Linux) or libpetsc.dylib (Mac)')) 219d310bb7SBarry Smith help.addArgument('PETSc', '-with-serialize-functions=<bool>', nargs.ArgBool(None, 0, 'Allows function pointers to be serialized to binary files with string representations')) 229d310bb7SBarry Smith return 239d310bb7SBarry Smith 249d310bb7SBarry Smith def setupDependencies(self, framework): 259d310bb7SBarry Smith config.base.Configure.setupDependencies(self, framework) 269d310bb7SBarry Smith self.arch = framework.require('PETSc.options.arch', self) 279d310bb7SBarry Smith self.debuggers = framework.require('config.utilities.debuggers', self) 289d310bb7SBarry Smith self.setCompilers = framework.require('config.setCompilers', self) 29*184ce1a2SMatthew G. Knepley self.headers = framework.require('config.headers', self) 30*184ce1a2SMatthew G. Knepley self.functions = framework.require('config.functions', self) 31*184ce1a2SMatthew G. Knepley self.ftm = framework.require('config.utilities.featureTestMacros', self) 329d310bb7SBarry Smith return 339d310bb7SBarry Smith 349d310bb7SBarry Smith def checkSharedDynamicPicOptions(self): 359d310bb7SBarry Smith # uf user specified 'with-shared' or 'with-dynamic' - flag an error 369d310bb7SBarry Smith if 'with-shared' in self.framework.argDB: 379d310bb7SBarry Smith raise RuntimeError('Option "--with-shared" no longer exists. Use "--with-shared-libraries".') 389d310bb7SBarry Smith if 'with-dynamic' in self.framework.argDB or 'with-dynamic-loading' in self.framework.argDB: 399d310bb7SBarry Smith raise RuntimeError('Option "--with-dynamic" and "--with-dynamic-loading" no longer exist.') 409d310bb7SBarry Smith if self.framework.argDB['with-shared-libraries'] and not self.framework.argDB['with-pic'] and 'with-pic' in self.framework.clArgDB: 419d310bb7SBarry Smith raise RuntimeError('If you use --with-shared-libraries you cannot disable --with-pic') 429d310bb7SBarry Smith 439d310bb7SBarry Smith # default with-shared-libraries=1 => --with-pic=1 449d310bb7SBarry Smith # Note: there is code in setCompilers.py that uses this as default. 459d310bb7SBarry Smith if self.framework.argDB['with-shared-libraries'] and not self.framework.argDB['with-pic']: self.framework.argDB['with-pic'] = 1 469d310bb7SBarry Smith return 479d310bb7SBarry Smith 489d310bb7SBarry Smith 499d310bb7SBarry Smith def configureSharedLibraries(self): 509d310bb7SBarry Smith '''Checks whether shared libraries should be used, for which you must 519d310bb7SBarry Smith - Specify --with-shared-libraries 529d310bb7SBarry Smith - Have found a working shared linker 539d310bb7SBarry Smith Defines PETSC_USE_SHARED_LIBRARIES if they are used''' 549d310bb7SBarry Smith import sys 559d310bb7SBarry Smith 569d310bb7SBarry Smith self.useShared = self.framework.argDB['with-shared-libraries'] and not self.setCompilers.staticLibraries 579d310bb7SBarry Smith 589d310bb7SBarry Smith if self.useShared: 597fca349cSMatthew G. Knepley #if config.setCompilers.Configure.isSolaris(self.log) and config.setCompilers.Configure.isGNU(self.framework.getCompiler(),self.log): 609d310bb7SBarry Smith # self.addMakeRule('shared_arch','shared_'+self.arch.hostOsBase+'gnu') 619d310bb7SBarry Smith #elif '-qmkshrobj' in self.setCompilers.sharedLibraryFlags: 629d310bb7SBarry Smith # self.addMakeRule('shared_arch','shared_linux_ibm') 639d310bb7SBarry Smith #else: 649d310bb7SBarry Smith # self.addMakeRule('shared_arch','shared_'+self.arch.hostOsBase) 659d310bb7SBarry Smith 669d310bb7SBarry Smith # Linux is the default 67af521b60SSatish Balay if self.setCompilers.isDarwin(self.log): 689d310bb7SBarry Smith self.addMakeRule('shared_arch','shared_darwin') 699d310bb7SBarry Smith self.addMakeMacro('SONAME_FUNCTION', '$(1).$(2).dylib') 709d310bb7SBarry Smith self.addMakeMacro('SL_LINKER_FUNCTION', '-dynamiclib -install_name $(call SONAME_FUNCTION,$(1),$(2)) -compatibility_version $(2) -current_version $(3) -single_module -multiply_defined suppress -undefined dynamic_lookup') 711b8cab44SSatish Balay elif self.setCompilers.CC.find('win32fe') >=0: 721b8cab44SSatish Balay self.addMakeMacro('SONAME_FUNCTION', '$(1).dll') 731b8cab44SSatish Balay self.addMakeMacro('SL_LINKER_FUNCTION', '-LD') 74aa11c055SSatish Balay self.addMakeMacro('PETSC_DLL_EXPORTS', '1') 759d310bb7SBarry Smith else: 769d310bb7SBarry Smith # TODO: check that -Wl,-soname,${LIBNAME}.${SL_LINKER_SUFFIX} can be passed (might fail on Intel) 779d310bb7SBarry Smith # TODO: check whether to use -qmkshrobj or -shared (maybe we can just use self.setCompilers.sharedLibraryFlags) 789d310bb7SBarry Smith # TODO: check whether we need to specify dependent libraries on the link line (long test) 799d310bb7SBarry Smith self.addMakeRule('shared_arch','shared_linux') 809d310bb7SBarry Smith self.addMakeMacro('SONAME_FUNCTION', '$(1).so.$(2)') 819d310bb7SBarry Smith self.addMakeMacro('SL_LINKER_FUNCTION', '-shared -Wl,-soname,$(call SONAME_FUNCTION,$(notdir $(1)),$(2))') 82aa11c055SSatish Balay if config.setCompilers.Configure.isMINGW(self.framework.getCompiler(),self.log): 83aa11c055SSatish Balay self.addMakeMacro('PETSC_DLL_EXPORTS', '1') 849d310bb7SBarry Smith self.addMakeMacro('BUILDSHAREDLIB','yes') 859d310bb7SBarry Smith else: 869d310bb7SBarry Smith self.addMakeRule('shared_arch','') 879d310bb7SBarry Smith self.addMakeMacro('BUILDSHAREDLIB','no') 889d310bb7SBarry Smith if self.useShared: 899d310bb7SBarry Smith self.addDefine('USE_SHARED_LIBRARIES', 1) 909d310bb7SBarry Smith else: 919d310bb7SBarry Smith self.logPrint('Shared libraries - disabled') 929d310bb7SBarry Smith return 939d310bb7SBarry Smith 949d310bb7SBarry Smith def configureDynamicLibraries(self): 959d310bb7SBarry Smith '''Checks whether dynamic loading is available (with dlfcn.h and libdl)''' 969d310bb7SBarry Smith if self.setCompilers.dynamicLibraries: 979d310bb7SBarry Smith self.addDefine('HAVE_DYNAMIC_LIBRARIES', 1) 989d310bb7SBarry Smith return 999d310bb7SBarry Smith 1009d310bb7SBarry Smith def configureSerializedFunctions(self): 1019d310bb7SBarry Smith ''' 1029d310bb7SBarry Smith Defines PETSC_SERIALIZE_FUNCTIONS if they are used 1039d310bb7SBarry Smith Requires shared libraries''' 1049d310bb7SBarry Smith import sys 1059d310bb7SBarry Smith 1069d310bb7SBarry Smith if self.framework.argDB['with-serialize-functions'] and self.setCompilers.dynamicLibraries: 1079d310bb7SBarry Smith self.addDefine('SERIALIZE_FUNCTIONS', 1) 1089d310bb7SBarry Smith 109*184ce1a2SMatthew G. Knepley def checkSymbolResolution(self): 110*184ce1a2SMatthew G. Knepley '''Checks that dladdr() works''' 111*184ce1a2SMatthew G. Knepley if self.headers.haveHeader('dlfcn.h') and self.functions.haveFunction('dlerror'): 112*184ce1a2SMatthew G. Knepley ftm = '' 113*184ce1a2SMatthew G. Knepley if self.ftm.defines.get('_GNU_SOURCE'): ftm = '#define _GNU_SOURCE\n' 114*184ce1a2SMatthew G. Knepley if self.checkCompile('%s#include<stdlib.h>\n#include <dlfcn.h>\n' % ftm, 'Dl_info info;\n\nif (dladdr(exit, &info));\n'): 115*184ce1a2SMatthew G. Knepley self.addDefine('HAVE_DLADDR', 1) 1169d310bb7SBarry Smith 1179d310bb7SBarry Smith def configure(self): 1189d310bb7SBarry Smith self.executeTest(self.checkSharedDynamicPicOptions) 1199d310bb7SBarry Smith self.executeTest(self.configureSharedLibraries) 1209d310bb7SBarry Smith self.executeTest(self.configureDynamicLibraries) 1219d310bb7SBarry Smith self.executeTest(self.configureSerializedFunctions) 122*184ce1a2SMatthew G. Knepley self.executeTest(self.checkSymbolResolution) 1239d310bb7SBarry Smith return 124