1 | import config.base
|
---|
2 |
|
---|
3 | import os
|
---|
4 | import re
|
---|
5 |
|
---|
6 | # The sorted() builtin is not available with python-2.3
|
---|
7 | try: sorted
|
---|
8 | except NameError:
|
---|
9 | def sorted(lst):
|
---|
10 | lst.sort()
|
---|
11 | return lst
|
---|
12 |
|
---|
13 | class Configure(config.base.Configure):
|
---|
14 | def __init__(self, framework):
|
---|
15 | config.base.Configure.__init__(self, framework)
|
---|
16 | self.headerPrefix = 'PETSC'
|
---|
17 | self.substPrefix = 'PETSC'
|
---|
18 | return
|
---|
19 |
|
---|
20 | def __str2__(self):
|
---|
21 | desc = []
|
---|
22 | desc.append('xxx=========================================================================xxx')
|
---|
23 | if self.getMakeMacro('PETSC_BUILD_USING_CMAKE'):
|
---|
24 | build_type = 'cmake build'
|
---|
25 | else:
|
---|
26 | build_type = 'legacy build'
|
---|
27 | desc.append(' Configure stage complete. Now build PETSc libraries with (%s):' % build_type)
|
---|
28 | desc.append(' make PETSC_DIR='+self.petscdir.dir+' PETSC_ARCH='+self.arch.arch+' all')
|
---|
29 | desc.append(' or (experimental with python):')
|
---|
30 | desc.append(' PETSC_DIR='+self.petscdir.dir+' PETSC_ARCH='+self.arch.arch+' ./config/builder.py')
|
---|
31 | desc.append('xxx=========================================================================xxx')
|
---|
32 | return '\n'.join(desc)+'\n'
|
---|
33 |
|
---|
34 | def setupHelp(self, help):
|
---|
35 | import nargs
|
---|
36 | help.addArgument('PETSc', '-prefix=<dir>', nargs.Arg(None, '', 'Specifiy location to install PETSc (eg. /usr/local)'))
|
---|
37 | help.addArgument('Windows','-with-windows-graphics=<bool>', nargs.ArgBool(None, 1,'Enable check for Windows Graphics'))
|
---|
38 | help.addArgument('PETSc', '-with-default-arch=<bool>', nargs.ArgBool(None, 1, 'Allow using the last configured arch without setting PETSC_ARCH'))
|
---|
39 | help.addArgument('PETSc','-with-single-library=<bool>', nargs.ArgBool(None, 1,'Put all PETSc code into the single -lpetsc library'))
|
---|
40 | help.addArgument('PETSc', '-with-iphone=<bool>', nargs.ArgBool(None, 0, 'Build an iPhone version of PETSc'))
|
---|
41 | return
|
---|
42 |
|
---|
43 | def setupDependencies(self, framework):
|
---|
44 | config.base.Configure.setupDependencies(self, framework)
|
---|
45 | self.setCompilers = framework.require('config.setCompilers', self)
|
---|
46 | self.arch = framework.require('PETSc.utilities.arch', self.setCompilers)
|
---|
47 | self.petscdir = framework.require('PETSc.utilities.petscdir', self.setCompilers)
|
---|
48 | self.languages = framework.require('PETSc.utilities.languages',self.setCompilers)
|
---|
49 | self.debugging = framework.require('PETSc.utilities.debugging',self.setCompilers)
|
---|
50 | self.CHUD = framework.require('PETSc.utilities.CHUD', self)
|
---|
51 | self.compilers = framework.require('config.compilers', self)
|
---|
52 | self.types = framework.require('config.types', self)
|
---|
53 | self.headers = framework.require('config.headers', self)
|
---|
54 | self.functions = framework.require('config.functions', self)
|
---|
55 | self.libraries = framework.require('config.libraries', self)
|
---|
56 | if os.path.isdir(os.path.join('config', 'PETSc')):
|
---|
57 | for d in ['utilities', 'packages']:
|
---|
58 | for utility in os.listdir(os.path.join('config', 'PETSc', d)):
|
---|
59 | (utilityName, ext) = os.path.splitext(utility)
|
---|
60 | if not utilityName.startswith('.') and not utilityName.startswith('#') and ext == '.py' and not utilityName == '__init__':
|
---|
61 | utilityObj = self.framework.require('PETSc.'+d+'.'+utilityName, self)
|
---|
62 | utilityObj.headerPrefix = self.headerPrefix
|
---|
63 | utilityObj.archProvider = self.arch
|
---|
64 | utilityObj.languageProvider = self.languages
|
---|
65 | utilityObj.installDirProvider = self.petscdir
|
---|
66 | setattr(self, utilityName.lower(), utilityObj)
|
---|
67 |
|
---|
68 | for package in config.packages.all:
|
---|
69 | if not package == 'PETSc':
|
---|
70 | packageObj = framework.require('config.packages.'+package, self)
|
---|
71 | packageObj.archProvider = self.arch
|
---|
72 | packageObj.languageProvider = self.languages
|
---|
73 | packageObj.installDirProvider = self.petscdir
|
---|
74 | setattr(self, package.lower(), packageObj)
|
---|
75 | # Force blaslapack to depend on scalarType so precision is set before BlasLapack is built
|
---|
76 | framework.require('PETSc.utilities.scalarTypes', self.f2cblaslapack)
|
---|
77 | self.f2cblaslapack.precisionProvider = self.scalartypes
|
---|
78 | framework.require('PETSc.utilities.scalarTypes', self.blaslapack)
|
---|
79 | self.blaslapack.precisionProvider = self.scalartypes
|
---|
80 |
|
---|
81 | self.compilers.headerPrefix = self.headerPrefix
|
---|
82 | self.types.headerPrefix = self.headerPrefix
|
---|
83 | self.headers.headerPrefix = self.headerPrefix
|
---|
84 | self.functions.headerPrefix = self.headerPrefix
|
---|
85 | self.libraries.headerPrefix = self.headerPrefix
|
---|
86 | self.blaslapack.headerPrefix = self.headerPrefix
|
---|
87 | self.mpi.headerPrefix = self.headerPrefix
|
---|
88 | headersC = map(lambda name: name+'.h', ['dos', 'endian', 'fcntl', 'float', 'io', 'limits', 'malloc', 'pwd', 'search', 'strings',
|
---|
89 | 'unistd', 'sys/sysinfo', 'machine/endian', 'sys/param', 'sys/procfs', 'sys/resource',
|
---|
90 | 'sys/systeminfo', 'sys/times', 'sys/utsname','string', 'stdlib','memory',
|
---|
91 | 'sys/socket','sys/wait','netinet/in','netdb','Direct','time','Ws2tcpip','sys/types',
|
---|
92 | 'WindowsX', 'cxxabi','float','ieeefp','stdint','fenv','sched','pthread'])
|
---|
93 | functions = ['access', '_access', 'clock', 'drand48', 'getcwd', '_getcwd', 'getdomainname', 'gethostname', 'getpwuid',
|
---|
94 | 'gettimeofday', 'getwd', 'memalign', 'memmove', 'mkstemp', 'popen', 'PXFGETARG', 'rand', 'getpagesize',
|
---|
95 | 'readlink', 'realpath', 'sigaction', 'signal', 'sigset', 'usleep', 'sleep', '_sleep', 'socket',
|
---|
96 | 'times', 'gethostbyname', 'uname','snprintf','_snprintf','_fullpath','lseek','_lseek','time','fork','stricmp',
|
---|
97 | 'strcasecmp', 'bzero', 'dlopen', 'dlsym', 'dlclose', 'dlerror',
|
---|
98 | '_intel_fast_memcpy','_intel_fast_memset']
|
---|
99 | libraries1 = [(['socket', 'nsl'], 'socket'), (['fpe'], 'handle_sigfpes')]
|
---|
100 | self.headers.headers.extend(headersC)
|
---|
101 | self.functions.functions.extend(functions)
|
---|
102 | self.libraries.libraries.extend(libraries1)
|
---|
103 |
|
---|
104 | return
|
---|
105 |
|
---|
106 | def Dump(self):
|
---|
107 | ''' Actually put the values into the configuration files '''
|
---|
108 | # eventually everything between -- should be gone
|
---|
109 | #-----------------------------------------------------------------------------------------------------
|
---|
110 |
|
---|
111 | # Sometimes we need C compiler, even if built with C++
|
---|
112 | self.setCompilers.pushLanguage('C')
|
---|
113 | self.addMakeMacro('CC_FLAGS',self.setCompilers.getCompilerFlags())
|
---|
114 | self.setCompilers.popLanguage()
|
---|
115 |
|
---|
116 | # C preprocessor values
|
---|
117 | self.addMakeMacro('CPP_FLAGS',self.setCompilers.CPPFLAGS+self.CHUD.CPPFLAGS)
|
---|
118 |
|
---|
119 | # compiler values
|
---|
120 | self.setCompilers.pushLanguage(self.languages.clanguage)
|
---|
121 | self.addMakeMacro('PCC',self.setCompilers.getCompiler())
|
---|
122 | self.addMakeMacro('PCC_FLAGS',self.setCompilers.getCompilerFlags())
|
---|
123 | self.setCompilers.popLanguage()
|
---|
124 | # .o or .obj
|
---|
125 | self.addMakeMacro('CC_SUFFIX','o')
|
---|
126 |
|
---|
127 | # executable linker values
|
---|
128 | self.setCompilers.pushLanguage(self.languages.clanguage)
|
---|
129 | pcc_linker = self.setCompilers.getLinker()
|
---|
130 | self.addMakeMacro('PCC_LINKER',pcc_linker)
|
---|
131 | self.addMakeMacro('PCC_LINKER_FLAGS',self.setCompilers.getLinkerFlags())
|
---|
132 | self.setCompilers.popLanguage()
|
---|
133 | # '' for Unix, .exe for Windows
|
---|
134 | self.addMakeMacro('CC_LINKER_SUFFIX','')
|
---|
135 |
|
---|
136 | if hasattr(self.compilers, 'FC'):
|
---|
137 | self.setCompilers.pushLanguage('FC')
|
---|
138 | # need FPPFLAGS in config/setCompilers
|
---|
139 | self.addDefine('HAVE_FORTRAN','1')
|
---|
140 | self.addMakeMacro('FPP_FLAGS',self.setCompilers.CPPFLAGS)
|
---|
141 |
|
---|
142 | # compiler values
|
---|
143 | self.addMakeMacro('FC_FLAGS',self.setCompilers.getCompilerFlags())
|
---|
144 | self.setCompilers.popLanguage()
|
---|
145 | # .o or .obj
|
---|
146 | self.addMakeMacro('FC_SUFFIX','o')
|
---|
147 |
|
---|
148 | # executable linker values
|
---|
149 | self.setCompilers.pushLanguage('FC')
|
---|
150 | # Cannot have NAG f90 as the linker - so use pcc_linker as fc_linker
|
---|
151 | fc_linker = self.setCompilers.getLinker()
|
---|
152 | if config.setCompilers.Configure.isNAG(fc_linker):
|
---|
153 | self.addMakeMacro('FC_LINKER',pcc_linker)
|
---|
154 | else:
|
---|
155 | self.addMakeMacro('FC_LINKER',fc_linker)
|
---|
156 | self.addMakeMacro('FC_LINKER_FLAGS',self.setCompilers.getLinkerFlags())
|
---|
157 | # apple requires this shared library linker flag on SOME versions of the os
|
---|
158 | if self.setCompilers.getLinkerFlags().find('-Wl,-commons,use_dylibs') > -1:
|
---|
159 | self.addMakeMacro('DARWIN_COMMONS_USE_DYLIBS',' -Wl,-commons,use_dylibs ')
|
---|
160 | self.setCompilers.popLanguage()
|
---|
161 |
|
---|
162 | # F90 Modules
|
---|
163 | if self.setCompilers.fortranModuleIncludeFlag:
|
---|
164 | self.addMakeMacro('FC_MODULE_FLAG', self.setCompilers.fortranModuleIncludeFlag)
|
---|
165 | else: # for non-f90 compilers like g77
|
---|
166 | self.addMakeMacro('FC_MODULE_FLAG', '-I')
|
---|
167 | if self.setCompilers.fortranModuleIncludeFlag:
|
---|
168 | self.addMakeMacro('FC_MODULE_OUTPUT_FLAG', self.setCompilers.fortranModuleOutputFlag)
|
---|
169 | else:
|
---|
170 | self.addMakeMacro('FC','')
|
---|
171 |
|
---|
172 | if hasattr(self.compilers, 'CUDAC'):
|
---|
173 | self.setCompilers.pushLanguage('CUDA')
|
---|
174 | self.addMakeMacro('CUDAC_FLAGS',self.setCompilers.getCompilerFlags())
|
---|
175 | self.setCompilers.popLanguage()
|
---|
176 |
|
---|
177 | # shared library linker values
|
---|
178 | self.setCompilers.pushLanguage(self.languages.clanguage)
|
---|
179 | # need to fix BuildSystem to collect these separately
|
---|
180 | self.addMakeMacro('SL_LINKER',self.setCompilers.getLinker())
|
---|
181 | self.addMakeMacro('SL_LINKER_FLAGS','${PCC_LINKER_FLAGS}')
|
---|
182 | self.setCompilers.popLanguage()
|
---|
183 | # One of 'a', 'so', 'lib', 'dll', 'dylib' (perhaps others also?) depending on the library generator and architecture
|
---|
184 | # Note: . is not included in this macro, consistent with AR_LIB_SUFFIX
|
---|
185 | if self.setCompilers.sharedLibraryExt == self.setCompilers.AR_LIB_SUFFIX:
|
---|
186 | self.addMakeMacro('SL_LINKER_SUFFIX', '')
|
---|
187 | self.addDefine('SLSUFFIX','""')
|
---|
188 | else:
|
---|
189 | self.addMakeMacro('SL_LINKER_SUFFIX', self.setCompilers.sharedLibraryExt)
|
---|
190 | self.addDefine('SLSUFFIX','"'+self.setCompilers.sharedLibraryExt+'"')
|
---|
191 |
|
---|
192 | self.addMakeMacro('SL_LINKER_LIBS','${PETSC_EXTERNAL_LIB_BASIC}')
|
---|
193 |
|
---|
194 | #-----------------------------------------------------------------------------------------------------
|
---|
195 |
|
---|
196 | # CONLY or CPP. We should change the PETSc makefiles to do this better
|
---|
197 | if self.languages.clanguage == 'C': lang = 'CONLY'
|
---|
198 | else: lang = 'CXXONLY'
|
---|
199 | self.addMakeMacro('PETSC_LANGUAGE',lang)
|
---|
200 |
|
---|
201 | # real or complex
|
---|
202 | self.addMakeMacro('PETSC_SCALAR',self.scalartypes.scalartype)
|
---|
203 | # double or float
|
---|
204 | self.addMakeMacro('PETSC_PRECISION',self.scalartypes.precision)
|
---|
205 |
|
---|
206 | if self.framework.argDB['with-batch']:
|
---|
207 | self.addMakeMacro('PETSC_WITH_BATCH','1')
|
---|
208 |
|
---|
209 | # Test for compiler-specific macros that need to be defined.
|
---|
210 | if self.setCompilers.isCrayVector('CC'):
|
---|
211 | self.addDefine('HAVE_CRAY_VECTOR','1')
|
---|
212 |
|
---|
213 | #-----------------------------------------------------------------------------------------------------
|
---|
214 | if self.functions.haveFunction('gethostbyname') and self.functions.haveFunction('socket') and self.headers.haveHeader('netinet/in.h'):
|
---|
215 | self.addDefine('USE_SOCKET_VIEWER','1')
|
---|
216 | if self.checkCompile('#include <sys/socket.h>','setsockopt(0,SOL_SOCKET,SO_REUSEADDR,0,0)'):
|
---|
217 | self.addDefine('HAVE_SO_REUSEADDR','1')
|
---|
218 |
|
---|
219 | #-----------------------------------------------------------------------------------------------------
|
---|
220 | # print include and lib for makefiles
|
---|
221 | self.framework.packages.reverse()
|
---|
222 | includes = [os.path.join(self.petscdir.dir,'include'),os.path.join(self.petscdir.dir,self.arch.arch,'include')]
|
---|
223 | libs = []
|
---|
224 | for i in self.framework.packages:
|
---|
225 | if i.useddirectly:
|
---|
226 | self.addDefine('HAVE_'+i.PACKAGE, 1) # ONLY list package if it is used directly by PETSc (and not only by another package)
|
---|
227 | if not isinstance(i.lib, list):
|
---|
228 | i.lib = [i.lib]
|
---|
229 | libs.extend(i.lib)
|
---|
230 | self.addMakeMacro(i.PACKAGE+'_LIB', self.libraries.toStringNoDupes(i.lib))
|
---|
231 | if hasattr(i,'include'):
|
---|
232 | if not isinstance(i.include,list):
|
---|
233 | i.include = [i.include]
|
---|
234 | if not i.PACKAGE.lower() == 'valgrind':
|
---|
235 | includes.extend(i.include)
|
---|
236 | self.addMakeMacro(i.PACKAGE+'_INCLUDE',self.headers.toStringNoDupes(i.include))
|
---|
237 | if self.framework.argDB['with-single-library']:
|
---|
238 | self.addMakeMacro('PETSC_WITH_EXTERNAL_LIB',self.libraries.toStringNoDupes(['-L'+os.path.join(self.petscdir.dir,self.arch.arch,'lib'),' -lpetsc']+libs+self.libraries.math+self.compilers.flibs+self.compilers.cxxlibs+self.compilers.LIBS.split(' '))+self.CHUD.LIBS)
|
---|
239 | self.addMakeMacro('PETSC_EXTERNAL_LIB_BASIC',self.libraries.toStringNoDupes(libs+self.libraries.math+self.compilers.flibs+self.compilers.cxxlibs+self.compilers.LIBS.split(' '))+self.CHUD.LIBS)
|
---|
240 | self.PETSC_EXTERNAL_LIB_BASIC = self.libraries.toStringNoDupes(libs+self.libraries.math+self.compilers.flibs+self.compilers.cxxlibs+self.compilers.LIBS.split(' '))+self.CHUD.LIBS
|
---|
241 | self.addMakeMacro('PETSC_CC_INCLUDES',self.headers.toStringNoDupes(includes))
|
---|
242 | self.PETSC_CC_INCLUDES = self.headers.toStringNoDupes(includes)
|
---|
243 | if hasattr(self.compilers, 'FC'):
|
---|
244 | if self.compilers.fortranIsF90:
|
---|
245 | self.addMakeMacro('PETSC_FC_INCLUDES',self.headers.toStringNoDupes(includes,includes))
|
---|
246 | else:
|
---|
247 | self.addMakeMacro('PETSC_FC_INCLUDES',self.headers.toStringNoDupes(includes))
|
---|
248 |
|
---|
249 | self.addMakeMacro('DESTDIR',self.installdir)
|
---|
250 | self.addDefine('LIB_DIR','"'+os.path.join(self.installdir,'lib')+'"')
|
---|
251 |
|
---|
252 | if self.framework.argDB['with-single-library']:
|
---|
253 | # overrides the values set in conf/variables
|
---|
254 | self.addMakeMacro('LIBNAME','${INSTALL_LIB_DIR}/libpetsc.${AR_LIB_SUFFIX}')
|
---|
255 | self.addMakeMacro('SHLIBS','libpetsc')
|
---|
256 | self.addMakeMacro('PETSC_LIB_BASIC','-lpetsc')
|
---|
257 | self.addMakeMacro('PETSC_KSP_LIB_BASIC','-lpetsc')
|
---|
258 | self.addMakeMacro('PETSC_TS_LIB_BASIC','-lpetsc')
|
---|
259 | self.addDefine('USE_SINGLE_LIBRARY', '1')
|
---|
260 | if self.sharedlibraries.useShared:
|
---|
261 | self.addMakeMacro('PETSC_SYS_LIB','${C_SH_LIB_PATH} ${PETSC_WITH_EXTERNAL_LIB}')
|
---|
262 | self.addMakeMacro('PETSC_VEC_LIB','${C_SH_LIB_PATH} ${PETSC_WITH_EXTERNAL_LIB}')
|
---|
263 | self.addMakeMacro('PETSC_MAT_LIB','${C_SH_LIB_PATH} ${PETSC_WITH_EXTERNAL_LIB}')
|
---|
264 | self.addMakeMacro('PETSC_DM_LIB','${C_SH_LIB_PATH} ${PETSC_WITH_EXTERNAL_LIB}')
|
---|
265 | self.addMakeMacro('PETSC_KSP_LIB','${C_SH_LIB_PATH} ${PETSC_WITH_EXTERNAL_LIB}')
|
---|
266 | self.addMakeMacro('PETSC_SNES_LIB','${C_SH_LIB_PATH} ${PETSC_WITH_EXTERNAL_LIB}')
|
---|
267 | self.addMakeMacro('PETSC_TS_LIB','${C_SH_LIB_PATH} ${PETSC_WITH_EXTERNAL_LIB}')
|
---|
268 | self.addMakeMacro('PETSC_CHARACTERISTIC_LIB','${C_SH_LIB_PATH} ${PETSC_WITH_EXTERNAL_LIB}')
|
---|
269 | self.addMakeMacro('PETSC_LIB','${C_SH_LIB_PATH} ${PETSC_WITH_EXTERNAL_LIB}')
|
---|
270 | self.addMakeMacro('PETSC_CONTRIB','${C_SH_LIB_PATH} ${PETSC_WITH_EXTERNAL_LIB}')
|
---|
271 | else:
|
---|
272 | self.addMakeMacro('PETSC_SYS_LIB','${PETSC_WITH_EXTERNAL_LIB}')
|
---|
273 | self.addMakeMacro('PETSC_VEC_LIB','${PETSC_WITH_EXTERNAL_LIB}')
|
---|
274 | self.addMakeMacro('PETSC_MAT_LIB','${PETSC_WITH_EXTERNAL_LIB}')
|
---|
275 | self.addMakeMacro('PETSC_DM_LIB','${PETSC_WITH_EXTERNAL_LIB}')
|
---|
276 | self.addMakeMacro('PETSC_KSP_LIB','${PETSC_WITH_EXTERNAL_LIB}')
|
---|
277 | self.addMakeMacro('PETSC_SNES_LIB','${PETSC_WITH_EXTERNAL_LIB}')
|
---|
278 | self.addMakeMacro('PETSC_TS_LIB','${PETSC_WITH_EXTERNAL_LIB}')
|
---|
279 | self.addMakeMacro('PETSC_CHARACTERISTIC_LIB','${PETSC_WITH_EXTERNAL_LIB}')
|
---|
280 | self.addMakeMacro('PETSC_LIB','${PETSC_WITH_EXTERNAL_LIB}')
|
---|
281 | self.addMakeMacro('PETSC_CONTRIB','${PETSC_WITH_EXTERNAL_LIB}')
|
---|
282 |
|
---|
283 | if not os.path.exists(os.path.join(self.petscdir.dir,self.arch.arch,'lib')):
|
---|
284 | os.makedirs(os.path.join(self.petscdir.dir,self.arch.arch,'lib'))
|
---|
285 |
|
---|
286 | # add a makefile entry for configure options
|
---|
287 | self.addMakeMacro('CONFIGURE_OPTIONS', self.framework.getOptionsString(['configModules', 'optionsModule']).replace('\"','\\"'))
|
---|
288 | return
|
---|
289 |
|
---|
290 | def dumpConfigInfo(self):
|
---|
291 | import time
|
---|
292 | fd = file(os.path.join(self.arch.arch,'include','petscconfiginfo.h'),'w')
|
---|
293 | fd.write('static const char *petscconfigureruntime = "'+time.ctime(time.time())+'";\n')
|
---|
294 | fd.write('static const char *petscconfigureoptions = "'+self.framework.getOptionsString(['configModules', 'optionsModule']).replace('\"','\\"')+'";\n')
|
---|
295 | fd.close()
|
---|
296 | return
|
---|
297 |
|
---|
298 | def dumpMachineInfo(self):
|
---|
299 | import platform
|
---|
300 | import time
|
---|
301 | import script
|
---|
302 | fd = file(os.path.join(self.arch.arch,'include','petscmachineinfo.h'),'w')
|
---|
303 | fd.write('static const char *petscmachineinfo = \"\\n\"\n')
|
---|
304 | fd.write('\"-----------------------------------------\\n\"\n')
|
---|
305 | fd.write('\"Libraries compiled on %s on %s \\n\"\n' % (time.ctime(time.time()), platform.node()))
|
---|
306 | fd.write('\"Machine characteristics: %s\\n\"\n' % (platform.platform()))
|
---|
307 | fd.write('\"Using PETSc directory: %s\\n\"\n' % (self.petscdir.dir))
|
---|
308 | fd.write('\"Using PETSc arch: %s\\n\"\n' % (self.arch.arch))
|
---|
309 | fd.write('\"-----------------------------------------\\n\";\n')
|
---|
310 | fd.write('static const char *petsccompilerinfo = \"\\n\"\n')
|
---|
311 | self.setCompilers.pushLanguage(self.languages.clanguage)
|
---|
312 | fd.write('\"Using C compiler: %s %s ${COPTFLAGS} ${CFLAGS}\\n\"\n' % (self.setCompilers.getCompiler(), self.setCompilers.getCompilerFlags()))
|
---|
313 | self.setCompilers.popLanguage()
|
---|
314 | if hasattr(self.compilers, 'FC'):
|
---|
315 | self.setCompilers.pushLanguage('FC')
|
---|
316 | fd.write('\"Using Fortran compiler: %s %s ${FOPTFLAGS} ${FFLAGS} %s\\n\"\n' % (self.setCompilers.getCompiler(), self.setCompilers.getCompilerFlags(), self.setCompilers.CPPFLAGS))
|
---|
317 | self.setCompilers.popLanguage()
|
---|
318 | fd.write('\"-----------------------------------------\\n\";\n')
|
---|
319 | fd.write('static const char *petsccompilerflagsinfo = \"\\n\"\n')
|
---|
320 | fd.write('\"Using include paths: %s %s %s\\n\"\n' % ('-I'+os.path.join(self.petscdir.dir, self.arch.arch, 'include'), '-I'+os.path.join(self.petscdir.dir, 'include'), self.PETSC_CC_INCLUDES.replace('\\ ','\\\\ ')))
|
---|
321 | fd.write('\"-----------------------------------------\\n\";\n')
|
---|
322 | fd.write('static const char *petsclinkerinfo = \"\\n\"\n')
|
---|
323 | self.setCompilers.pushLanguage(self.languages.clanguage)
|
---|
324 | fd.write('\"Using C linker: %s\\n\"\n' % (self.setCompilers.getLinker()))
|
---|
325 | self.setCompilers.popLanguage()
|
---|
326 | if hasattr(self.compilers, 'FC'):
|
---|
327 | self.setCompilers.pushLanguage('FC')
|
---|
328 | fd.write('\"Using Fortran linker: %s\\n\"\n' % (self.setCompilers.getLinker()))
|
---|
329 | self.setCompilers.popLanguage()
|
---|
330 | if self.framework.argDB['with-single-library']:
|
---|
331 | petsclib = '-lpetsc'
|
---|
332 | else:
|
---|
333 | petsclib = '-lpetscts -lpetscsnes -lpetscksp -lpetscdm -lpetscmat -lpetscvec -lpetscsys'
|
---|
334 | fd.write('\"Using libraries: %s%s -L%s %s %s\\n\"\n' % (self.setCompilers.CSharedLinkerFlag, os.path.join(self.petscdir.dir, self.arch.arch, 'lib'), os.path.join(self.petscdir.dir, self.arch.arch, 'lib'), petsclib, self.PETSC_EXTERNAL_LIB_BASIC.replace('\\ ','\\\\ ')))
|
---|
335 | fd.write('\"-----------------------------------------\\n\";\n')
|
---|
336 | fd.close()
|
---|
337 | return
|
---|
338 |
|
---|
339 | def dumpCMakeConfig(self):
|
---|
340 | '''
|
---|
341 | Writes configuration-specific values to ${PETSC_ARCH}/conf/PETScConfig.cmake.
|
---|
342 | This file is private to PETSc and should not be included by third parties
|
---|
343 | (a suitable file can be produced later by CMake, but this is not it).
|
---|
344 | '''
|
---|
345 | def cmakeset(fd,key,val=True):
|
---|
346 | if val == True: val = 'YES'
|
---|
347 | if val == False: val = 'NO'
|
---|
348 | fd.write('set (' + key + ' ' + val + ')\n')
|
---|
349 | def ensurelist(a):
|
---|
350 | if isinstance(a,list):
|
---|
351 | return a
|
---|
352 | else:
|
---|
353 | return [a]
|
---|
354 | def libpath(lib):
|
---|
355 | 'Returns a search path if that is what this item provides, else "" which will be cleaned out later'
|
---|
356 | if not isinstance(lib,str): return ''
|
---|
357 | if lib.startswith('-L'): return lib[2:]
|
---|
358 | if lib.startswith('-R'): return lib[2:]
|
---|
359 | if lib.startswith('-Wl,-rpath,'):
|
---|
360 | # This case occurs when an external package needs a specific system library that is normally provided by the compiler.
|
---|
361 | # In other words, the -L path is builtin to the wrapper or compiler, here we provide it so that CMake can locate the
|
---|
362 | # corresponding library.
|
---|
363 | return lib[len('-Wl,-rpath,'):]
|
---|
364 | if lib.startswith('-'): return ''
|
---|
365 | return os.path.dirname(lib)
|
---|
366 | def cleanlib(lib):
|
---|
367 | 'Returns a library name if that is what this item provides, else "" which will be cleaned out later'
|
---|
368 | if not isinstance(lib,str): return ''
|
---|
369 | if lib.startswith('-l'): return lib[2:]
|
---|
370 | if lib.startswith('-Wl') or lib.startswith('-L'): return ''
|
---|
371 | lib = os.path.splitext(os.path.basename(lib))[0]
|
---|
372 | if lib.startswith('lib'): return lib[3:]
|
---|
373 | return lib
|
---|
374 | def nub(lst):
|
---|
375 | 'Return a list containing the first occurrence of each unique element'
|
---|
376 | unique = []
|
---|
377 | for elem in lst:
|
---|
378 | if elem not in unique and elem != '':
|
---|
379 | unique.append(elem)
|
---|
380 | return unique
|
---|
381 | try: reversed # reversed was added in Python-2.4
|
---|
382 | except NameError:
|
---|
383 | def reversed(lst): return lst[::-1]
|
---|
384 | def nublast(lst):
|
---|
385 | 'Return a list containing the last occurrence of each unique entry in a list'
|
---|
386 | return reversed(nub(reversed(lst)))
|
---|
387 | def cmakeexpand(varname):
|
---|
388 | return r'"${' + varname + r'}"'
|
---|
389 | def uniqextend(lst,new):
|
---|
390 | for x in ensurelist(new):
|
---|
391 | if x not in lst:
|
---|
392 | lst.append(x)
|
---|
393 | def notstandardinclude(path):
|
---|
394 | return path not in '/usr/include'.split() # /usr/local/include is not automatically included on FreeBSD
|
---|
395 | def writeMacroDefinitions(fd):
|
---|
396 | if self.mpi.usingMPIUni:
|
---|
397 | cmakeset(fd,'PETSC_HAVE_MPIUNI')
|
---|
398 | for pkg in self.framework.packages:
|
---|
399 | if pkg.useddirectly:
|
---|
400 | cmakeset(fd,'PETSC_HAVE_' + pkg.PACKAGE)
|
---|
401 | for name,val in self.functions.defines.items():
|
---|
402 | cmakeset(fd,'PETSC_'+name,val)
|
---|
403 | for dct in [self.defines, self.libraryoptions.defines]:
|
---|
404 | for k,v in dct.items():
|
---|
405 | if k.startswith('USE_'):
|
---|
406 | cmakeset(fd,'PETSC_' + k, v)
|
---|
407 | cmakeset(fd,'PETSC_USE_COMPLEX', self.scalartypes.scalartype == 'complex')
|
---|
408 | cmakeset(fd,'PETSC_USE_REAL_' + self.scalartypes.precision.upper())
|
---|
409 | cmakeset(fd,'PETSC_CLANGUAGE_'+self.languages.clanguage)
|
---|
410 | if hasattr(self.compilers, 'FC'):
|
---|
411 | cmakeset(fd,'PETSC_HAVE_FORTRAN')
|
---|
412 | if self.compilers.fortranIsF90:
|
---|
413 | cmakeset(fd,'PETSC_USING_F90')
|
---|
414 | if self.sharedlibraries.useShared:
|
---|
415 | cmakeset(fd,'BUILD_SHARED_LIBS')
|
---|
416 | def writeBuildFlags(fd):
|
---|
417 | def extendby(lib):
|
---|
418 | libs = ensurelist(lib)
|
---|
419 | lib_paths.extend(map(libpath,libs))
|
---|
420 | lib_libs.extend(map(cleanlib,libs))
|
---|
421 | lib_paths = []
|
---|
422 | lib_libs = []
|
---|
423 | includes = []
|
---|
424 | libvars = []
|
---|
425 | for pkg in self.framework.packages:
|
---|
426 | extendby(pkg.lib)
|
---|
427 | uniqextend(includes,pkg.include)
|
---|
428 | extendby(self.libraries.math)
|
---|
429 | extendby(self.libraries.rt)
|
---|
430 | extendby(self.compilers.flibs)
|
---|
431 | extendby(self.compilers.cxxlibs)
|
---|
432 | extendby(self.compilers.LIBS.split())
|
---|
433 | for libname in nublast(lib_libs):
|
---|
434 | libvar = 'PETSC_' + libname.upper() + '_LIB'
|
---|
435 | addpath = ''
|
---|
436 | for lpath in nublast(lib_paths):
|
---|
437 | addpath += '"' + str(lpath) + '" '
|
---|
438 | fd.write('find_library (' + libvar + ' ' + libname + ' HINTS ' + addpath + ')\n')
|
---|
439 | libvars.append(libvar)
|
---|
440 | fd.write('mark_as_advanced (' + ' '.join(libvars) + ')\n')
|
---|
441 | fd.write('set (PETSC_PACKAGE_LIBS ' + ' '.join(map(cmakeexpand,libvars)) + ')\n')
|
---|
442 | includes = filter(notstandardinclude,includes)
|
---|
443 | fd.write('set (PETSC_PACKAGE_INCLUDES ' + ' '.join(map(lambda i: '"'+i+'"',includes)) + ')\n')
|
---|
444 | fd = open(os.path.join(self.arch.arch,'conf','PETScConfig.cmake'), 'w')
|
---|
445 | writeMacroDefinitions(fd)
|
---|
446 | writeBuildFlags(fd)
|
---|
447 | fd.close()
|
---|
448 | return
|
---|
449 |
|
---|
450 | def dumpCMakeLists(self):
|
---|
451 | import sys
|
---|
452 | if sys.version_info >= (2,5):
|
---|
453 | import cmakegen
|
---|
454 | try:
|
---|
455 | cmakegen.main(self.petscdir.dir, log=self.framework.log)
|
---|
456 | except (OSError), e:
|
---|
457 | self.framework.logPrint('Generating CMakeLists.txt failed:\n' + str(e))
|
---|
458 | else:
|
---|
459 | self.framework.logPrint('Skipping cmakegen due to old python version: ' +str(sys.version_info) )
|
---|
460 |
|
---|
461 | def cmakeBoot(self):
|
---|
462 | import sys
|
---|
463 | self.cmakeboot_success = False
|
---|
464 | if sys.version_info >= (2,5) and hasattr(self.cmake,'cmake'):
|
---|
465 | try:
|
---|
466 | import cmakeboot
|
---|
467 | self.cmakeboot_success = cmakeboot.main(petscdir=self.petscdir.dir,petscarch=self.arch.arch,argDB=self.argDB,framework=self.framework,log=self.framework.log)
|
---|
468 | except (OSError), e:
|
---|
469 | self.framework.logPrint('Booting CMake in PETSC_ARCH failed:\n' + str(e))
|
---|
470 | except (ImportError, KeyError), e:
|
---|
471 | self.framework.logPrint('Importing cmakeboot failed:\n' + str(e))
|
---|
472 | if self.cmakeboot_success:
|
---|
473 | if self.framework.argDB['with-cuda']: # Our CMake build does not support CUDA at this time
|
---|
474 | self.framework.logPrint('CMake configured successfully, but could not be used by default because --with-cuda was used\n')
|
---|
475 | elif hasattr(self.compilers, 'FC') and not self.setCompilers.fortranModuleOutputFlag:
|
---|
476 | self.framework.logPrint('CMake configured successfully, but could not be used by default because of missing fortranModuleOutputFlag\n')
|
---|
477 | else:
|
---|
478 | self.framework.logPrint('CMake configured successfully, using as default build\n')
|
---|
479 | self.addMakeMacro('PETSC_BUILD_USING_CMAKE',1)
|
---|
480 | else:
|
---|
481 | self.framework.logPrint('CMake configuration was unsuccessful\n')
|
---|
482 | else:
|
---|
483 | self.framework.logPrint('Skipping cmakeboot due to old python version: ' +str(sys.version_info) )
|
---|
484 | return
|
---|
485 |
|
---|
486 | def configurePrefetch(self):
|
---|
487 | '''Sees if there are any prefetch functions supported'''
|
---|
488 | if config.setCompilers.Configure.isSolaris() or self.framework.argDB['with-iphone']:
|
---|
489 | self.addDefine('Prefetch(a,b,c)', ' ')
|
---|
490 | return
|
---|
491 | self.pushLanguage(self.languages.clanguage)
|
---|
492 | if self.checkLink('#include <xmmintrin.h>', 'void *v = 0;_mm_prefetch((const char*)v,_MM_HINT_NTA);\n'):
|
---|
493 | # The Intel Intrinsics manual [1] specifies the prototype
|
---|
494 | #
|
---|
495 | # void _mm_prefetch(char const *a, int sel);
|
---|
496 | #
|
---|
497 | # but other vendors seem to insist on using subtly different
|
---|
498 | # prototypes, including void* for the pointer, and an enum for
|
---|
499 | # sel. These are both reasonable changes, but negatively impact
|
---|
500 | # portability.
|
---|
501 | #
|
---|
502 | # [1] http://software.intel.com/file/6373
|
---|
503 | self.addDefine('HAVE_XMMINTRIN_H', 1)
|
---|
504 | self.addDefine('Prefetch(a,b,c)', '_mm_prefetch((const char*)(a),(c))')
|
---|
505 | self.addDefine('PREFETCH_HINT_NTA', '_MM_HINT_NTA')
|
---|
506 | self.addDefine('PREFETCH_HINT_T0', '_MM_HINT_T0')
|
---|
507 | self.addDefine('PREFETCH_HINT_T1', '_MM_HINT_T1')
|
---|
508 | self.addDefine('PREFETCH_HINT_T2', '_MM_HINT_T2')
|
---|
509 | elif self.checkLink('#include <xmmintrin.h>', 'void *v = 0;_mm_prefetch(v,_MM_HINT_NTA);\n'):
|
---|
510 | self.addDefine('HAVE_XMMINTRIN_H', 1)
|
---|
511 | self.addDefine('Prefetch(a,b,c)', '_mm_prefetch((const void*)(a),(c))')
|
---|
512 | self.addDefine('PREFETCH_HINT_NTA', '_MM_HINT_NTA')
|
---|
513 | self.addDefine('PREFETCH_HINT_T0', '_MM_HINT_T0')
|
---|
514 | self.addDefine('PREFETCH_HINT_T1', '_MM_HINT_T1')
|
---|
515 | self.addDefine('PREFETCH_HINT_T2', '_MM_HINT_T2')
|
---|
516 | elif self.checkLink('', 'void *v = 0;__builtin_prefetch(v,0,0);\n'):
|
---|
517 | # From GCC docs: void __builtin_prefetch(const void *addr,int rw,int locality)
|
---|
518 | #
|
---|
519 | # The value of rw is a compile-time constant one or zero; one
|
---|
520 | # means that the prefetch is preparing for a write to the memory
|
---|
521 | # address and zero, the default, means that the prefetch is
|
---|
522 | # preparing for a read. The value locality must be a compile-time
|
---|
523 | # constant integer between zero and three. A value of zero means
|
---|
524 | # that the data has no temporal locality, so it need not be left
|
---|
525 | # in the cache after the access. A value of three means that the
|
---|
526 | # data has a high degree of temporal locality and should be left
|
---|
527 | # in all levels of cache possible. Values of one and two mean,
|
---|
528 | # respectively, a low or moderate degree of temporal locality.
|
---|
529 | #
|
---|
530 | # Here we adopt Intel's x86/x86-64 naming scheme for the locality
|
---|
531 | # hints. Using macros for these values in necessary since some
|
---|
532 | # compilers require an enum.
|
---|
533 | self.addDefine('Prefetch(a,b,c)', '__builtin_prefetch((a),(b),(c))')
|
---|
534 | self.addDefine('PREFETCH_HINT_NTA', '0')
|
---|
535 | self.addDefine('PREFETCH_HINT_T0', '3')
|
---|
536 | self.addDefine('PREFETCH_HINT_T1', '2')
|
---|
537 | self.addDefine('PREFETCH_HINT_T2', '1')
|
---|
538 | else:
|
---|
539 | self.addDefine('Prefetch(a,b,c)', ' ')
|
---|
540 | self.popLanguage()
|
---|
541 |
|
---|
542 | def configureFeatureTestMacros(self):
|
---|
543 | '''Checks if certain feature test macros are support'''
|
---|
544 | if self.checkCompile('#define _POSIX_C_SOURCE 200112L\n#include <stdlib.h>',''):
|
---|
545 | self.addDefine('_POSIX_C_SOURCE_200112L', '1')
|
---|
546 | if self.checkCompile('#define _BSD_SOURCE\n#include<stdlib.h>',''):
|
---|
547 | self.addDefine('_BSD_SOURCE', '1')
|
---|
548 |
|
---|
549 | def configureAtoll(self):
|
---|
550 | '''Checks if atoll exists'''
|
---|
551 | if self.checkCompile('#define _POSIX_C_SOURCE 200112L\n#include <stdlib.h>','long v = atoll("25")') or self.checkCompile ('#include <stdlib.h>','long v = atoll("25")'):
|
---|
552 | self.addDefine('HAVE_ATOLL', '1')
|
---|
553 |
|
---|
554 | def configureUnused(self):
|
---|
555 | '''Sees if __attribute((unused)) is supported'''
|
---|
556 | if self.framework.argDB['with-iphone'] or self.framework.argDB['with-cuda']:
|
---|
557 | self.addDefine('UNUSED', ' ')
|
---|
558 | return
|
---|
559 | self.pushLanguage(self.languages.clanguage)
|
---|
560 | if self.checkLink('__attribute((unused)) static int myfunc(void){ return 1;}', 'int i = myfunc();\ntypedef void* atype;\n__attribute((unused)) atype a;\n'):
|
---|
561 | self.addDefine('UNUSED', '__attribute((unused))')
|
---|
562 | else:
|
---|
563 | self.addDefine('UNUSED', ' ')
|
---|
564 | self.popLanguage()
|
---|
565 |
|
---|
566 | def configureExpect(self):
|
---|
567 | '''Sees if the __builtin_expect directive is supported'''
|
---|
568 | self.pushLanguage(self.languages.clanguage)
|
---|
569 | if self.checkLink('', 'if (__builtin_expect(0,1)) return 1;'):
|
---|
570 | self.addDefine('HAVE_BUILTIN_EXPECT', 1)
|
---|
571 | self.popLanguage()
|
---|
572 |
|
---|
573 | def configureFunctionName(self):
|
---|
574 | '''Sees if the compiler supports __func__ or a variant. Falls back
|
---|
575 | on __FUNCT__ which PETSc source defines, but most users do not, thus
|
---|
576 | stack traces through user code are better when the compiler's
|
---|
577 | variant is used.'''
|
---|
578 | def getFunctionName(lang):
|
---|
579 | name = '__FUNCT__'
|
---|
580 | self.pushLanguage(lang)
|
---|
581 | if self.checkLink('', "if (__func__[0] != 'm') return 1;"):
|
---|
582 | name = '__func__'
|
---|
583 | elif self.checkLink('', "if (__FUNCTION__[0] != 'm') return 1;"):
|
---|
584 | name = '__FUNCTION__'
|
---|
585 | self.popLanguage()
|
---|
586 | return name
|
---|
587 | langs = []
|
---|
588 |
|
---|
589 | self.addDefine('FUNCTION_NAME_C', getFunctionName('C'))
|
---|
590 | if hasattr(self.compilers, 'CXX'):
|
---|
591 | self.addDefine('FUNCTION_NAME_CXX', getFunctionName('Cxx'))
|
---|
592 | else:
|
---|
593 | self.addDefine('FUNCTION_NAME_CXX', '__FUNCT__')
|
---|
594 |
|
---|
595 | def configureIntptrt(self):
|
---|
596 | '''Determine what to use for uintptr_t'''
|
---|
597 | def staticAssertSizeMatchesVoidStar(inc,typename):
|
---|
598 | # The declaration is an error if either array size is negative.
|
---|
599 | # It should be okay to use an int that is too large, but it would be very unlikely for this to be the case
|
---|
600 | return self.checkCompile(inc, ('#define STATIC_ASSERT(cond) char negative_length_if_false[2*(!!(cond))-1]\n'
|
---|
601 | + 'STATIC_ASSERT(sizeof(void*) == sizeof(%s));'%typename))
|
---|
602 | self.pushLanguage(self.languages.clanguage)
|
---|
603 | if self.checkCompile('#include <stdint.h>', 'int x; uintptr_t i = (uintptr_t)&x;'):
|
---|
604 | self.addDefine('UINTPTR_T', 'uintptr_t')
|
---|
605 | elif staticAssertSizeMatchesVoidStar('','unsigned long long'):
|
---|
606 | self.addDefine('UINTPTR_T', 'unsigned long long')
|
---|
607 | elif staticAssertSizeMatchesVoidStar('#include <stdlib.h>','size_t') or staticAssertSizeMatchesVoidStar('#include <string.h>', 'size_t'):
|
---|
608 | self.addDefine('UINTPTR_T', 'size_t')
|
---|
609 | elif staticAssertSizeMatchesVoidStar('','unsigned long'):
|
---|
610 | self.addDefine('UINTPTR_T', 'unsigned long')
|
---|
611 | elif staticAssertSizeMatchesVoidStar('','unsigned'):
|
---|
612 | self.addDefine('UINTPTR_T', 'unsigned')
|
---|
613 | else:
|
---|
614 | raise RuntimeError('Could not find any unsigned integer type matching void*')
|
---|
615 | self.popLanguage()
|
---|
616 |
|
---|
617 | def configureInline(self):
|
---|
618 | '''Get a generic inline keyword, depending on the language'''
|
---|
619 | if self.languages.clanguage == 'C':
|
---|
620 | self.addDefine('STATIC_INLINE', self.compilers.cStaticInlineKeyword)
|
---|
621 | self.addDefine('RESTRICT', self.compilers.cRestrict)
|
---|
622 | elif self.languages.clanguage == 'Cxx':
|
---|
623 | self.addDefine('STATIC_INLINE', self.compilers.cxxStaticInlineKeyword)
|
---|
624 | self.addDefine('RESTRICT', self.compilers.cxxRestrict)
|
---|
625 |
|
---|
626 | if self.checkCompile('#include <dlfcn.h>\n void *ptr = RTLD_DEFAULT;'):
|
---|
627 | self.addDefine('RTLD_DEFAULT','1')
|
---|
628 | return
|
---|
629 |
|
---|
630 | def configureSolaris(self):
|
---|
631 | '''Solaris specific stuff'''
|
---|
632 | if os.path.isdir(os.path.join('/usr','ucblib')):
|
---|
633 | try:
|
---|
634 | flag = getattr(self.setCompilers, self.language[-1]+'SharedLinkerFlag')
|
---|
635 | except AttributeError:
|
---|
636 | flag = None
|
---|
637 | if flag is None:
|
---|
638 | self.compilers.LIBS += ' -L/usr/ucblib'
|
---|
639 | else:
|
---|
640 | self.compilers.LIBS += ' '+flag+'/usr/ucblib'
|
---|
641 | return
|
---|
642 |
|
---|
643 | def configureLinux(self):
|
---|
644 | '''Linux specific stuff'''
|
---|
645 | # TODO: Test for this by mallocing an odd number of floats and checking the address
|
---|
646 | self.addDefine('HAVE_DOUBLE_ALIGN_MALLOC', 1)
|
---|
647 | return
|
---|
648 |
|
---|
649 | def configureWin32(self):
|
---|
650 | '''Win32 non-cygwin specific stuff'''
|
---|
651 | kernel32=0
|
---|
652 | if self.libraries.add('Kernel32.lib','GetComputerName',prototype='#include <Windows.h>', call='GetComputerName(NULL,NULL);'):
|
---|
653 | self.addDefine('HAVE_WINDOWS_H',1)
|
---|
654 | self.addDefine('HAVE_GETCOMPUTERNAME',1)
|
---|
655 | kernel32=1
|
---|
656 | elif self.libraries.add('kernel32','GetComputerName',prototype='#include <Windows.h>', call='GetComputerName(NULL,NULL);'):
|
---|
657 | self.addDefine('HAVE_WINDOWS_H',1)
|
---|
658 | self.addDefine('HAVE_GETCOMPUTERNAME',1)
|
---|
659 | kernel32=1
|
---|
660 | if kernel32:
|
---|
661 | if self.framework.argDB['with-windows-graphics']:
|
---|
662 | self.addDefine('USE_WINDOWS_GRAPHICS',1)
|
---|
663 | if self.checkLink('#include <Windows.h>','LoadLibrary(0)'):
|
---|
664 | self.addDefine('HAVE_LOADLIBRARY',1)
|
---|
665 | if self.checkLink('#include <Windows.h>','GetProcAddress(0,0)'):
|
---|
666 | self.addDefine('HAVE_GETPROCADDRESS',1)
|
---|
667 | if self.checkLink('#include <Windows.h>','FreeLibrary(0)'):
|
---|
668 | self.addDefine('HAVE_FREELIBRARY',1)
|
---|
669 | if self.checkLink('#include <Windows.h>','GetLastError()'):
|
---|
670 | self.addDefine('HAVE_GETLASTERROR',1)
|
---|
671 | if self.checkLink('#include <Windows.h>','SetLastError(0)'):
|
---|
672 | self.addDefine('HAVE_SETLASTERROR',1)
|
---|
673 | if self.checkLink('#include <Windows.h>\n','QueryPerformanceCounter(0);\n'):
|
---|
674 | self.addDefine('USE_NT_TIME',1)
|
---|
675 | if self.libraries.add('Advapi32.lib','GetUserName',prototype='#include <Windows.h>', call='GetUserName(NULL,NULL);'):
|
---|
676 | self.addDefine('HAVE_GET_USER_NAME',1)
|
---|
677 | elif self.libraries.add('advapi32','GetUserName',prototype='#include <Windows.h>', call='GetUserName(NULL,NULL);'):
|
---|
678 | self.addDefine('HAVE_GET_USER_NAME',1)
|
---|
679 |
|
---|
680 | if not self.libraries.add('User32.lib','GetDC',prototype='#include <Windows.h>',call='GetDC(0);'):
|
---|
681 | self.libraries.add('user32','GetDC',prototype='#include <Windows.h>',call='GetDC(0);')
|
---|
682 | if not self.libraries.add('Gdi32.lib','CreateCompatibleDC',prototype='#include <Windows.h>',call='CreateCompatibleDC(0);'):
|
---|
683 | self.libraries.add('gdi32','CreateCompatibleDC',prototype='#include <Windows.h>',call='CreateCompatibleDC(0);')
|
---|
684 |
|
---|
685 | self.types.check('int32_t', 'int')
|
---|
686 | if not self.checkCompile('#include <sys/types.h>\n','uid_t u;\n'):
|
---|
687 | self.addTypedef('int', 'uid_t')
|
---|
688 | self.addTypedef('int', 'gid_t')
|
---|
689 | if not self.checkLink('#if defined(PETSC_HAVE_UNISTD_H)\n#include <unistd.h>\n#endif\n','int a=R_OK;\n'):
|
---|
690 | self.framework.addDefine('R_OK', '04')
|
---|
691 | self.framework.addDefine('W_OK', '02')
|
---|
692 | self.framework.addDefine('X_OK', '01')
|
---|
693 | if not self.checkLink('#include <sys/stat.h>\n','int a=0;\nif (S_ISDIR(a)){}\n'):
|
---|
694 | self.framework.addDefine('S_ISREG(a)', '(((a)&_S_IFMT) == _S_IFREG)')
|
---|
695 | self.framework.addDefine('S_ISDIR(a)', '(((a)&_S_IFMT) == _S_IFDIR)')
|
---|
696 | if self.checkCompile('#include <Windows.h>\n','LARGE_INTEGER a;\nDWORD b=a.u.HighPart;\n'):
|
---|
697 | self.addDefine('HAVE_LARGE_INTEGER_U',1)
|
---|
698 |
|
---|
699 | # Windows requires a Binary file creation flag when creating/opening binary files. Is a better test in order?
|
---|
700 | if self.checkCompile('#include <Windows.h>\n#include <fcntl.h>\n', 'int flags = O_BINARY;'):
|
---|
701 | self.addDefine('HAVE_O_BINARY',1)
|
---|
702 |
|
---|
703 | if self.compilers.CC.find('win32fe') >= 0:
|
---|
704 | self.addDefine('PATH_SEPARATOR','\';\'')
|
---|
705 | self.addDefine('DIR_SEPARATOR','\'\\\\\'')
|
---|
706 | self.addDefine('REPLACE_DIR_SEPARATOR','\'/\'')
|
---|
707 | self.addDefine('CANNOT_START_DEBUGGER',1)
|
---|
708 | else:
|
---|
709 | self.addDefine('PATH_SEPARATOR','\':\'')
|
---|
710 | self.addDefine('REPLACE_DIR_SEPARATOR','\'\\\\\'')
|
---|
711 | self.addDefine('DIR_SEPARATOR','\'/\'')
|
---|
712 |
|
---|
713 | return
|
---|
714 |
|
---|
715 | #-----------------------------------------------------------------------------------------------------
|
---|
716 | def configureDefaultArch(self):
|
---|
717 | conffile = os.path.join('conf', 'petscvariables')
|
---|
718 | if self.framework.argDB['with-default-arch']:
|
---|
719 | fd = file(conffile, 'w')
|
---|
720 | fd.write('PETSC_ARCH='+self.arch.arch+'\n')
|
---|
721 | fd.write('PETSC_DIR='+self.petscdir.dir+'\n')
|
---|
722 | fd.write('include '+os.path.join(self.petscdir.dir,self.arch.arch,'conf','petscvariables')+'\n')
|
---|
723 | fd.close()
|
---|
724 | self.framework.actions.addArgument('PETSc', 'Build', 'Set default architecture to '+self.arch.arch+' in '+conffile)
|
---|
725 | elif os.path.isfile(conffile):
|
---|
726 | try:
|
---|
727 | os.unlink(conffile)
|
---|
728 | except:
|
---|
729 | raise RuntimeError('Unable to remove file '+conffile+'. Did a different user create it?')
|
---|
730 | return
|
---|
731 |
|
---|
732 | #-----------------------------------------------------------------------------------------------------
|
---|
733 | def configureScript(self):
|
---|
734 | '''Output a script in the conf directory which will reproduce the configuration'''
|
---|
735 | import nargs
|
---|
736 | import sys
|
---|
737 | scriptName = os.path.join(self.arch.arch,'conf', 'reconfigure-'+self.arch.arch+'.py')
|
---|
738 | args = dict([(nargs.Arg.parseArgument(arg)[0], arg) for arg in self.framework.clArgs])
|
---|
739 | if 'configModules' in args:
|
---|
740 | if nargs.Arg.parseArgument(args['configModules'])[1] == 'PETSc.Configure':
|
---|
741 | del args['configModules']
|
---|
742 | if 'optionsModule' in args:
|
---|
743 | if nargs.Arg.parseArgument(args['optionsModule'])[1] == 'PETSc.compilerOptions':
|
---|
744 | del args['optionsModule']
|
---|
745 | if not 'PETSC_ARCH' in args:
|
---|
746 | args['PETSC_ARCH'] = 'PETSC_ARCH='+str(self.arch.arch)
|
---|
747 | f = file(scriptName, 'w')
|
---|
748 | f.write('#!'+sys.executable+'\n')
|
---|
749 | f.write('if __name__ == \'__main__\':\n')
|
---|
750 | f.write(' import sys\n')
|
---|
751 | f.write(' import os\n')
|
---|
752 | f.write(' sys.path.insert(0, os.path.abspath(\'config\'))\n')
|
---|
753 | f.write(' import configure\n')
|
---|
754 | # pretty print repr(args.values())
|
---|
755 | f.write(' configure_options = [\n')
|
---|
756 | for itm in sorted(args.values()):
|
---|
757 | f.write(' \''+str(itm)+'\',\n')
|
---|
758 | f.write(' ]\n')
|
---|
759 | f.write(' configure.petsc_configure(configure_options)\n')
|
---|
760 | f.close()
|
---|
761 | try:
|
---|
762 | os.chmod(scriptName, 0775)
|
---|
763 | except OSError, e:
|
---|
764 | self.framework.logPrint('Unable to make reconfigure script executable:\n'+str(e))
|
---|
765 | self.framework.actions.addArgument('PETSc', 'File creation', 'Created '+scriptName+' for automatic reconfiguration')
|
---|
766 | return
|
---|
767 |
|
---|
768 | def configureInstall(self):
|
---|
769 | '''Setup the directories for installation'''
|
---|
770 | if self.framework.argDB['prefix']:
|
---|
771 | self.installdir = self.framework.argDB['prefix']
|
---|
772 | self.addMakeRule('shared_install','',['-@echo "Now to install the libraries do:"',\
|
---|
773 | '-@echo "make PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} install"',\
|
---|
774 | '-@echo "========================================="'])
|
---|
775 | else:
|
---|
776 | self.installdir = os.path.join(self.petscdir.dir,self.arch.arch)
|
---|
777 | self.addMakeRule('shared_install','',['-@echo "Now to check if the libraries are working do:"',\
|
---|
778 | '-@echo "make PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} test"',\
|
---|
779 | '-@echo "========================================="'])
|
---|
780 | return
|
---|
781 |
|
---|
782 | def configureGCOV(self):
|
---|
783 | if self.framework.argDB['with-gcov']:
|
---|
784 | self.addDefine('USE_GCOV','1')
|
---|
785 | return
|
---|
786 |
|
---|
787 | def configureFortranFlush(self):
|
---|
788 | if hasattr(self.compilers, 'FC'):
|
---|
789 | for baseName in ['flush','flush_']:
|
---|
790 | if self.libraries.check('', baseName, otherLibs = self.compilers.flibs, fortranMangle = 1):
|
---|
791 | self.addDefine('HAVE_'+baseName.upper(), 1)
|
---|
792 | return
|
---|
793 |
|
---|
794 | def postProcessPackages(self):
|
---|
795 | postPackages=[]
|
---|
796 | for i in self.framework.packages:
|
---|
797 | if hasattr(i,'postProcess'): postPackages.append(i)
|
---|
798 | if postPackages:
|
---|
799 | # prometheus needs petsc conf files. so attempt to create them early
|
---|
800 | self.framework.dumpConfFiles()
|
---|
801 | for i in postPackages: i.postProcess()
|
---|
802 | return
|
---|
803 |
|
---|
804 | def configure(self):
|
---|
805 | if not os.path.samefile(self.petscdir.dir, os.getcwd()):
|
---|
806 | raise RuntimeError('Wrong PETSC_DIR option specified: '+str(self.petscdir.dir) + '\n Configure invoked in: '+os.path.realpath(os.getcwd()))
|
---|
807 | if self.framework.argDB['prefix'] and os.path.isdir(self.framework.argDB['prefix']) and os.path.samefile(self.framework.argDB['prefix'],self.petscdir.dir):
|
---|
808 | raise RuntimeError('Incorrect option --prefix='+self.framework.argDB['prefix']+' specified. It cannot be same as PETSC_DIR!')
|
---|
809 | if self.framework.argDB['prefix'] and os.path.isdir(self.framework.argDB['prefix']) and os.path.samefile(self.framework.argDB['prefix'],os.path.join(self.petscdir.dir,self.arch.arch)):
|
---|
810 | raise RuntimeError('Incorrect option --prefix='+self.framework.argDB['prefix']+' specified. It cannot be same as PETSC_DIR/PETSC_ARCH!')
|
---|
811 | self.framework.header = os.path.join(self.arch.arch,'include','petscconf.h')
|
---|
812 | self.framework.cHeader = os.path.join(self.arch.arch,'include','petscfix.h')
|
---|
813 | self.framework.makeMacroHeader = os.path.join(self.arch.arch,'conf','petscvariables')
|
---|
814 | self.framework.makeRuleHeader = os.path.join(self.arch.arch,'conf','petscrules')
|
---|
815 | if self.libraries.math is None:
|
---|
816 | raise RuntimeError('PETSc requires a functional math library. Please send configure.log to petsc-maint@mcs.anl.gov.')
|
---|
817 | if self.languages.clanguage == 'Cxx' and not hasattr(self.compilers, 'CXX'):
|
---|
818 | raise RuntimeError('Cannot set C language to C++ without a functional C++ compiler.')
|
---|
819 | self.executeTest(self.configureInline)
|
---|
820 | self.executeTest(self.configurePrefetch)
|
---|
821 | self.executeTest(self.configureUnused)
|
---|
822 | self.executeTest(self.configureExpect);
|
---|
823 | self.executeTest(self.configureFunctionName);
|
---|
824 | self.executeTest(self.configureIntptrt);
|
---|
825 | self.executeTest(self.configureSolaris)
|
---|
826 | self.executeTest(self.configureLinux)
|
---|
827 | self.executeTest(self.configureWin32)
|
---|
828 | self.executeTest(self.configureDefaultArch)
|
---|
829 | self.executeTest(self.configureScript)
|
---|
830 | self.executeTest(self.configureInstall)
|
---|
831 | self.executeTest(self.configureGCOV)
|
---|
832 | self.executeTest(self.configureFortranFlush)
|
---|
833 | self.executeTest(self.configureFeatureTestMacros)
|
---|
834 | self.executeTest(self.configureAtoll)
|
---|
835 | # dummy rules, always needed except for remote builds
|
---|
836 | self.addMakeRule('remote','')
|
---|
837 | self.addMakeRule('remoteclean','')
|
---|
838 |
|
---|
839 | self.Dump()
|
---|
840 | self.dumpConfigInfo()
|
---|
841 | self.dumpMachineInfo()
|
---|
842 | self.postProcessPackages()
|
---|
843 | self.dumpCMakeConfig()
|
---|
844 | self.dumpCMakeLists()
|
---|
845 | self.cmakeBoot()
|
---|
846 | self.framework.log.write('================================================================================\n')
|
---|
847 | self.logClear()
|
---|
848 | return
|
---|