1 | #!/usr/bin/env python
|
---|
2 | from __future__ import generators
|
---|
3 | import user
|
---|
4 | import config.base
|
---|
5 |
|
---|
6 | class Configure(config.base.Configure):
|
---|
7 | def __init__(self, framework):
|
---|
8 | config.base.Configure.__init__(self, framework)
|
---|
9 | self.headerPrefix = ''
|
---|
10 | self.substPrefix = ''
|
---|
11 | self.useShared = 0
|
---|
12 | self.useDynamic = 0
|
---|
13 | return
|
---|
14 |
|
---|
15 | def __str1__(self):
|
---|
16 | if not hasattr(self, 'useShared') or not hasattr(self, 'useDynamic'):
|
---|
17 | return ''
|
---|
18 | txt = ''
|
---|
19 | if self.useShared:
|
---|
20 | txt += ' shared libraries: enabled\n'
|
---|
21 | else:
|
---|
22 | txt += ' shared libraries: disabled\n'
|
---|
23 | if self.useDynamic:
|
---|
24 | txt += ' dynamic loading: enabled\n'
|
---|
25 | else:
|
---|
26 | txt += ' dynamic loading: disabled\n'
|
---|
27 | return txt
|
---|
28 |
|
---|
29 | def setupHelp(self, help):
|
---|
30 | import nargs
|
---|
31 | help.addArgument('PETSc', '-with-shared-libraries=<bool>', nargs.ArgBool(None, 0, 'Make PETSc libraries shared -- libpetsc.so (Unix/Linux) or libpetsc.dylib (Mac)'))
|
---|
32 | help.addArgument('PETSc', '-with-dynamic-loading=<bool>', nargs.ArgBool(None, 0, 'Make PETSc libraries dynamic -- uses dlopen() to access libraries, rarely needed'))
|
---|
33 | return
|
---|
34 |
|
---|
35 | def setupDependencies(self, framework):
|
---|
36 | config.base.Configure.setupDependencies(self, framework)
|
---|
37 | self.arch = framework.require('PETSc.utilities.arch', self)
|
---|
38 | self.debuggers = framework.require('PETSc.utilities.debuggers', self)
|
---|
39 | self.setCompilers = framework.require('config.setCompilers', self)
|
---|
40 | return
|
---|
41 |
|
---|
42 | def checkSharedDynamicPicOptions(self):
|
---|
43 | # uf user specified 'with-shared' or 'with-dynamic' - flag an error
|
---|
44 | if 'with-shared' in self.framework.argDB:
|
---|
45 | raise RuntimeError('Option "--with-shared" no longer exists. Use "--with-shared-libraries".')
|
---|
46 | if 'with-dynamic' in self.framework.argDB:
|
---|
47 | raise RuntimeError('Option "--with-dynamic" no longer exists. Use "--with-dynamic-loading".')
|
---|
48 | # if user specifies inconsistant 'with-dynamic-loading with-shared-libraries with-pic' options - flag error
|
---|
49 | if self.framework.argDB['with-dynamic-loading'] and not self.framework.argDB['with-shared-libraries'] and 'with-shared-libraries' in self.framework.clArgDB:
|
---|
50 | raise RuntimeError('If you use --with-dynamic-loading you cannot disable --with-shared-libraries')
|
---|
51 | if self.framework.argDB['with-dynamic-loading'] and not self.framework.argDB['with-pic'] and 'with-pic' in self.framework.clArgDB:
|
---|
52 | raise RuntimeError('If you use --with-dynamic-loading you cannot disable --with-pic')
|
---|
53 | if self.framework.argDB['with-shared-libraries'] and not self.framework.argDB['with-pic'] and 'with-pic' in self.framework.clArgDB:
|
---|
54 | raise RuntimeError('If you use --with-shared-libraries you cannot disable --with-pic')
|
---|
55 |
|
---|
56 | # default with-dynamic-loading=1 => with-shared-libraries=1 --with-pic=1
|
---|
57 | # default with-shared-libraries=1 => --with-pic=1
|
---|
58 | # Note: there is code in setCompilers.py that uses this as default.
|
---|
59 | if self.framework.argDB['with-dynamic-loading'] and not self.framework.argDB['with-shared-libraries']: self.framework.argDB['with-shared-libraries'] = 1
|
---|
60 | if self.framework.argDB['with-shared-libraries'] and not self.framework.argDB['with-pic']: self.framework.argDB['with-pic'] = 1
|
---|
61 | return
|
---|
62 |
|
---|
63 | def configureSharedLibraries(self):
|
---|
64 | '''Checks whether shared libraries should be used, for which you must
|
---|
65 | - Specify --with-shared-libraries
|
---|
66 | - Have found a working shared linker
|
---|
67 | Defines PETSC_USE_SHARED_LIBRARIES if they are used'''
|
---|
68 | import sys
|
---|
69 |
|
---|
70 | self.useShared = self.framework.argDB['with-shared-libraries'] and not self.setCompilers.staticLibraries
|
---|
71 |
|
---|
72 | if self.useShared:
|
---|
73 | #if config.setCompilers.Configure.isSolaris() and config.setCompilers.Configure.isGNU(self.framework.getCompiler()):
|
---|
74 | # self.addMakeRule('shared_arch','shared_'+self.arch.hostOsBase+'gnu')
|
---|
75 | #elif '-qmkshrobj' in self.setCompilers.sharedLibraryFlags:
|
---|
76 | # self.addMakeRule('shared_arch','shared_linux_ibm')
|
---|
77 | #else:
|
---|
78 | # self.addMakeRule('shared_arch','shared_'+self.arch.hostOsBase)
|
---|
79 |
|
---|
80 | # Linux is the default
|
---|
81 | if hasattr(self.debuggers, 'dsymutil'):
|
---|
82 | # Check for Mac OSX by the presence of dsymutil
|
---|
83 | # could also check flags: -dynamiclib -single_module -multiply_defined suppress -undefined dynamic_lookup
|
---|
84 | self.addMakeRule('shared_arch','shared_darwin')
|
---|
85 | else:
|
---|
86 | # TODO: check that -Wl,-soname,${LIBNAME}.${SL_LINKER_SUFFIX} can be passed (might fail on Intel)
|
---|
87 | # TODO: check whether to use -qmkshrobj or -shared (maybe we can just use self.setCompilers.sharedLibraryFlags)
|
---|
88 | # TODO: check whether we need to specify dependent libraries on the link line (long test)
|
---|
89 | self.addMakeRule('shared_arch','shared_linux')
|
---|
90 | self.addMakeMacro('BUILDSHAREDLIB','yes')
|
---|
91 | else:
|
---|
92 | self.addMakeRule('shared_arch','')
|
---|
93 | self.addMakeMacro('BUILDSHAREDLIB','no')
|
---|
94 | if self.setCompilers.sharedLibraries:
|
---|
95 | self.addDefine('HAVE_SHARED_LIBRARIES', 1)
|
---|
96 | if self.useShared:
|
---|
97 | self.addDefine('USE_SHARED_LIBRARIES', 1)
|
---|
98 | else:
|
---|
99 | self.logPrint('Shared libraries - disabled')
|
---|
100 | return
|
---|
101 |
|
---|
102 | def configureDynamicLibraries(self):
|
---|
103 | '''Checks whether dynamic loading should be used, for which you must
|
---|
104 | - Specify --with-dynamic-loading
|
---|
105 | - Have found a working dynamic linker (with dlfcn.h and libdl)
|
---|
106 | Defines PETSC_USE_DYNAMIC_LIBRARIES if they are used'''
|
---|
107 | if self.setCompilers.dynamicLibraries:
|
---|
108 | self.addDefine('HAVE_DYNAMIC_LIBRARIES', 1)
|
---|
109 | self.useDynamic = self.framework.argDB['with-dynamic-loading'] and self.useShared and self.setCompilers.dynamicLibraries
|
---|
110 | if self.useDynamic:
|
---|
111 | self.addDefine('USE_DYNAMIC_LIBRARIES', 1)
|
---|
112 | else:
|
---|
113 | self.logPrint('Dynamic loading - disabled')
|
---|
114 | return
|
---|
115 |
|
---|
116 | def configure(self):
|
---|
117 | self.executeTest(self.checkSharedDynamicPicOptions)
|
---|
118 | self.executeTest(self.configureSharedLibraries)
|
---|
119 | self.executeTest(self.configureDynamicLibraries)
|
---|
120 | return
|
---|