File: sharedLibraries.py

package info (click to toggle)
petsc 3.7.5%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 163,864 kB
  • ctags: 618,438
  • sloc: ansic: 515,133; python: 29,793; makefile: 20,458; fortran: 18,998; cpp: 6,515; f90: 3,914; sh: 1,012; xml: 621; objc: 445; csh: 240; java: 13
file content (127 lines) | stat: -rwxr-xr-x 6,178 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env python
from __future__ import generators
import user
import config.base

class Configure(config.base.Configure):
  def __init__(self, framework):
    config.base.Configure.__init__(self, framework)
    self.headerPrefix = ''
    self.substPrefix  = ''
    self.useShared    = 0
    self.petsclibExt  = ''
    return

  def __str1__(self):
    if not hasattr(self, 'useShared'):
      return ''
    txt = ''
    if self.useShared:
      txt += '  shared libraries: enabled\n'
    else:
      txt += '  shared libraries: disabled\n'
    if self.petsclibExt:
      txt += '  shared library extension: ' + self.petsclibExt + '\n'
    return txt

  def setupHelp(self, help):
    import nargs
    help.addArgument('PETSc', '-with-shared-libraries=<bool>', nargs.ArgBool(None, 1, 'Make PETSc libraries shared -- libpetsc.so (Unix/Linux) or libpetsc.dylib (Mac)'))
    help.addArgument('PETSc', '-with-serialize-functions=<bool>', nargs.ArgBool(None, 0, 'Allows function pointers to be serialized to binary files with string representations'))
    help.addArgument('PETSc', '-shared-library-extension=<string>', nargs.Arg(None, None, 'Extension to name of shared library'))
    return

  def setupDependencies(self, framework):
    config.base.Configure.setupDependencies(self, framework)
    self.arch         = framework.require('PETSc.options.arch', self)
    self.debuggers    = framework.require('config.utilities.debuggers', self)
    self.setCompilers = framework.require('config.setCompilers', self)
    return

  def checkSharedDynamicPicOptions(self):
    # uf user specified 'with-shared' or 'with-dynamic' - flag an error
    if 'with-shared' in self.framework.argDB:
      raise RuntimeError('Option "--with-shared" no longer exists. Use "--with-shared-libraries".')
    if 'with-dynamic' in self.framework.argDB or 'with-dynamic-loading' in self.framework.argDB:
      raise RuntimeError('Option "--with-dynamic" and "--with-dynamic-loading" no longer exist.')
    # if user specifies inconsistant 'with-dynamic-loading with-shared-libraries with-pic' options - flag error
    if self.framework.argDB['with-shared-libraries'] and not self.framework.argDB['with-pic'] and 'with-pic' in self.framework.clArgDB:
      raise RuntimeError('If you use --with-shared-libraries you cannot disable --with-pic')

    # default with-shared-libraries=1 => --with-pic=1
    # Note: there is code in setCompilers.py that uses this as default.
    if self.framework.argDB['with-shared-libraries'] and not self.framework.argDB['with-pic']: self.framework.argDB['with-pic'] = 1
    return


  def configureSharedLibraries(self):
    '''Checks whether shared libraries should be used, for which you must
      - Specify --with-shared-libraries
      - Have found a working shared linker
    Defines PETSC_USE_SHARED_LIBRARIES if they are used'''
    import sys

    self.useShared = self.framework.argDB['with-shared-libraries'] and not self.setCompilers.staticLibraries

    if self.useShared:
      #if config.setCompilers.Configure.isSolaris(self.log) and config.setCompilers.Configure.isGNU(self.framework.getCompiler(),self.log):
      #  self.addMakeRule('shared_arch','shared_'+self.arch.hostOsBase+'gnu')
      #elif '-qmkshrobj' in self.setCompilers.sharedLibraryFlags:
      #  self.addMakeRule('shared_arch','shared_linux_ibm')
      #else:
      #  self.addMakeRule('shared_arch','shared_'+self.arch.hostOsBase)

      # define library extension at configure time with --shared-library-extension=<ext>
      # This is added the shared library name and soname to allow for installation multiple configurations
      # e.g. --shared-library-extension=Complex generates libpetscComplex.so instead of libpetsc.so
      if 'shared-library-extension' in self.framework.argDB:
        self.petsclibExt=self.framework.argDB['shared-library-extension']

      # Linux is the default
      if hasattr(self.debuggers, 'dsymutil'):
        # Check for Mac OSX by the presence of dsymutil
        #   could also check flags: -dynamiclib -single_module -multiply_defined suppress -undefined dynamic_lookup
        self.addMakeRule('shared_arch','shared_darwin')
        self.addMakeMacro('SONAME_FUNCTION', '$(1).$(2).dylib')
        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')
      else:
        # TODO: check that -Wl,-soname,${LIBNAME}.${SL_LINKER_SUFFIX} can be passed (might fail on Intel)
        # TODO: check whether to use -qmkshrobj or -shared (maybe we can just use self.setCompilers.sharedLibraryFlags)
        # TODO: check whether we need to specify dependent libraries on the link line (long test)
        self.addMakeRule('shared_arch','shared_linux')
        self.addMakeMacro('SONAME_FUNCTION', '$(1).so.$(2)')
        self.addMakeMacro('SL_LINKER_FUNCTION', '-shared -Wl,-soname,$(call SONAME_FUNCTION,$(notdir $(1)),$(2))')
      self.addMakeMacro('BUILDSHAREDLIB','yes')
    else:
      self.addMakeRule('shared_arch','')
      self.addMakeMacro('BUILDSHAREDLIB','no')
    if self.setCompilers.sharedLibraries:
      self.addDefine('HAVE_SHARED_LIBRARIES', 1)
    if self.useShared:
      self.addDefine('USE_SHARED_LIBRARIES', 1)
    else:
      self.logPrint('Shared libraries - disabled')
    return

  def configureDynamicLibraries(self):
    '''Checks whether dynamic loading is available (with dlfcn.h and libdl)'''
    if self.setCompilers.dynamicLibraries:
      self.addDefine('HAVE_DYNAMIC_LIBRARIES', 1)
    return

  def configureSerializedFunctions(self):
    '''
    Defines PETSC_SERIALIZE_FUNCTIONS if they are used
    Requires shared libraries'''
    import sys

    if self.framework.argDB['with-serialize-functions'] and self.setCompilers.dynamicLibraries:
      self.addDefine('SERIALIZE_FUNCTIONS', 1)


  def configure(self):
    self.executeTest(self.checkSharedDynamicPicOptions)
    self.executeTest(self.configureSharedLibraries)
    self.executeTest(self.configureDynamicLibraries)
    self.executeTest(self.configureSerializedFunctions)
    return