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): 14*e8e972b2SVaclav Hapla txt = ' Single library: %s\n' % ('yes' if self.framework.argDB['with-single-library'] else 'no') 15*e8e972b2SVaclav 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) 299d310bb7SBarry Smith return 309d310bb7SBarry Smith 319d310bb7SBarry Smith def checkSharedDynamicPicOptions(self): 329d310bb7SBarry Smith # uf user specified 'with-shared' or 'with-dynamic' - flag an error 339d310bb7SBarry Smith if 'with-shared' in self.framework.argDB: 349d310bb7SBarry Smith raise RuntimeError('Option "--with-shared" no longer exists. Use "--with-shared-libraries".') 359d310bb7SBarry Smith if 'with-dynamic' in self.framework.argDB or 'with-dynamic-loading' in self.framework.argDB: 369d310bb7SBarry Smith raise RuntimeError('Option "--with-dynamic" and "--with-dynamic-loading" no longer exist.') 379d310bb7SBarry Smith # if user specifies inconsistant 'with-dynamic-loading with-shared-libraries with-pic' options - flag error 389d310bb7SBarry Smith if self.framework.argDB['with-shared-libraries'] and not self.framework.argDB['with-pic'] and 'with-pic' in self.framework.clArgDB: 399d310bb7SBarry Smith raise RuntimeError('If you use --with-shared-libraries you cannot disable --with-pic') 409d310bb7SBarry Smith 419d310bb7SBarry Smith # default with-shared-libraries=1 => --with-pic=1 429d310bb7SBarry Smith # Note: there is code in setCompilers.py that uses this as default. 439d310bb7SBarry Smith if self.framework.argDB['with-shared-libraries'] and not self.framework.argDB['with-pic']: self.framework.argDB['with-pic'] = 1 449d310bb7SBarry Smith return 459d310bb7SBarry Smith 469d310bb7SBarry Smith 479d310bb7SBarry Smith def configureSharedLibraries(self): 489d310bb7SBarry Smith '''Checks whether shared libraries should be used, for which you must 499d310bb7SBarry Smith - Specify --with-shared-libraries 509d310bb7SBarry Smith - Have found a working shared linker 519d310bb7SBarry Smith Defines PETSC_USE_SHARED_LIBRARIES if they are used''' 529d310bb7SBarry Smith import sys 539d310bb7SBarry Smith 549d310bb7SBarry Smith self.useShared = self.framework.argDB['with-shared-libraries'] and not self.setCompilers.staticLibraries 559d310bb7SBarry Smith 569d310bb7SBarry Smith if self.useShared: 577fca349cSMatthew G. Knepley #if config.setCompilers.Configure.isSolaris(self.log) and config.setCompilers.Configure.isGNU(self.framework.getCompiler(),self.log): 589d310bb7SBarry Smith # self.addMakeRule('shared_arch','shared_'+self.arch.hostOsBase+'gnu') 599d310bb7SBarry Smith #elif '-qmkshrobj' in self.setCompilers.sharedLibraryFlags: 609d310bb7SBarry Smith # self.addMakeRule('shared_arch','shared_linux_ibm') 619d310bb7SBarry Smith #else: 629d310bb7SBarry Smith # self.addMakeRule('shared_arch','shared_'+self.arch.hostOsBase) 639d310bb7SBarry Smith 649d310bb7SBarry Smith # Linux is the default 65af521b60SSatish Balay if self.setCompilers.isDarwin(self.log): 669d310bb7SBarry Smith self.addMakeRule('shared_arch','shared_darwin') 679d310bb7SBarry Smith self.addMakeMacro('SONAME_FUNCTION', '$(1).$(2).dylib') 689d310bb7SBarry 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') 691b8cab44SSatish Balay elif self.setCompilers.CC.find('win32fe') >=0: 701b8cab44SSatish Balay self.addMakeMacro('SONAME_FUNCTION', '$(1).dll') 711b8cab44SSatish Balay self.addMakeMacro('SL_LINKER_FUNCTION', '-LD') 72aa11c055SSatish Balay self.addMakeMacro('PETSC_DLL_EXPORTS', '1') 739d310bb7SBarry Smith else: 749d310bb7SBarry Smith # TODO: check that -Wl,-soname,${LIBNAME}.${SL_LINKER_SUFFIX} can be passed (might fail on Intel) 759d310bb7SBarry Smith # TODO: check whether to use -qmkshrobj or -shared (maybe we can just use self.setCompilers.sharedLibraryFlags) 769d310bb7SBarry Smith # TODO: check whether we need to specify dependent libraries on the link line (long test) 779d310bb7SBarry Smith self.addMakeRule('shared_arch','shared_linux') 789d310bb7SBarry Smith self.addMakeMacro('SONAME_FUNCTION', '$(1).so.$(2)') 799d310bb7SBarry Smith self.addMakeMacro('SL_LINKER_FUNCTION', '-shared -Wl,-soname,$(call SONAME_FUNCTION,$(notdir $(1)),$(2))') 80aa11c055SSatish Balay if config.setCompilers.Configure.isMINGW(self.framework.getCompiler(),self.log): 81aa11c055SSatish Balay self.addMakeMacro('PETSC_DLL_EXPORTS', '1') 829d310bb7SBarry Smith self.addMakeMacro('BUILDSHAREDLIB','yes') 839d310bb7SBarry Smith else: 849d310bb7SBarry Smith self.addMakeRule('shared_arch','') 859d310bb7SBarry Smith self.addMakeMacro('BUILDSHAREDLIB','no') 869d310bb7SBarry Smith if self.useShared: 879d310bb7SBarry Smith self.addDefine('USE_SHARED_LIBRARIES', 1) 889d310bb7SBarry Smith else: 899d310bb7SBarry Smith self.logPrint('Shared libraries - disabled') 909d310bb7SBarry Smith return 919d310bb7SBarry Smith 929d310bb7SBarry Smith def configureDynamicLibraries(self): 939d310bb7SBarry Smith '''Checks whether dynamic loading is available (with dlfcn.h and libdl)''' 949d310bb7SBarry Smith if self.setCompilers.dynamicLibraries: 959d310bb7SBarry Smith self.addDefine('HAVE_DYNAMIC_LIBRARIES', 1) 969d310bb7SBarry Smith return 979d310bb7SBarry Smith 989d310bb7SBarry Smith def configureSerializedFunctions(self): 999d310bb7SBarry Smith ''' 1009d310bb7SBarry Smith Defines PETSC_SERIALIZE_FUNCTIONS if they are used 1019d310bb7SBarry Smith Requires shared libraries''' 1029d310bb7SBarry Smith import sys 1039d310bb7SBarry Smith 1049d310bb7SBarry Smith if self.framework.argDB['with-serialize-functions'] and self.setCompilers.dynamicLibraries: 1059d310bb7SBarry Smith self.addDefine('SERIALIZE_FUNCTIONS', 1) 1069d310bb7SBarry Smith 1079d310bb7SBarry Smith 1089d310bb7SBarry Smith def configure(self): 1099d310bb7SBarry Smith self.executeTest(self.checkSharedDynamicPicOptions) 1109d310bb7SBarry Smith self.executeTest(self.configureSharedLibraries) 1119d310bb7SBarry Smith self.executeTest(self.configureDynamicLibraries) 1129d310bb7SBarry Smith self.executeTest(self.configureSerializedFunctions) 1139d310bb7SBarry Smith return 114