1import config.base 2 3import os 4import sys 5import re 6import pickle 7 8class Configure(config.base.Configure): 9 def __init__(self, framework): 10 config.base.Configure.__init__(self, framework) 11 self.headerPrefix = 'PETSC' 12 self.substPrefix = 'PETSC' 13 self.installed = 0 # 1 indicates that Configure itself has already compiled and installed PETSc 14 return 15 16 def __str2__(self): 17 desc = [' Using GNU make: ' + self.make.make] 18 if not self.installed: 19 desc.append('xxx=========================================================================xxx') 20 desc.append(' Configure stage complete. Now build PETSc libraries with:') 21 desc.append(' %s PETSC_DIR=%s PETSC_ARCH=%s all' % (self.make.make_user, self.petscdir.dir, self.arch.arch)) 22 desc.append('xxx=========================================================================xxx') 23 else: 24 desc.append('xxx=========================================================================xxx') 25 desc.append(' Installation complete. You do not need to run make to compile or install the software') 26 desc.append('xxx=========================================================================xxx') 27 return '\n'.join(desc)+'\n' 28 29 def setupHelp(self, help): 30 import nargs 31 help.addArgument('PETSc', '-prefix=<dir>', nargs.Arg(None, '', 'Specifiy location to install PETSc (eg. /usr/local)')) 32 help.addArgument('PETSc', '-with-prefetch=<bool>', nargs.ArgBool(None, 1,'Enable checking for prefetch instructions')) 33 help.addArgument('Windows','-with-windows-graphics=<bool>', nargs.ArgBool(None, 1,'Enable check for Windows Graphics')) 34 help.addArgument('PETSc', '-with-default-arch=<bool>', nargs.ArgBool(None, 1, 'Allow using the last configured arch without setting PETSC_ARCH')) 35 help.addArgument('PETSc','-with-single-library=<bool>', nargs.ArgBool(None, 1,'Put all PETSc code into the single -lpetsc library')) 36 help.addArgument('PETSc','-with-fortran-bindings=<bool>', nargs.ArgBool(None, 1,'Build PETSc fortran bindings in the library and corresponding module files')) 37 help.addArgument('PETSc', '-with-ios=<bool>', nargs.ArgBool(None, 0, 'Build an iPhone/iPad version of PETSc library')) 38 help.addArgument('PETSc', '-with-xsdk-defaults', nargs.ArgBool(None, 0, 'Set the following as defaults for the xSDK standard: --enable-debug=1, --enable-shared=1, --with-precision=double, --with-index-size=32, locate blas/lapack automatically')) 39 help.addArgument('PETSc', '-with-display=<x11display>', nargs.Arg(None, '', 'Specifiy DISPLAY env variable for use with matlab test)')) 40 help.addArgument('PETSc', '-with-package-scripts=<pyscripts>',nargs.ArgFileList(None,None,'Specify configure package scripts for user provided packages')) 41 return 42 43 def registerPythonFile(self,filename,directory): 44 ''' Add a python file to the framework and registers its headerprefix, ... externalpackagedir 45 directory is the directory where the file relative to the BuildSystem or config path in python notation with . ''' 46 (utilityName, ext) = os.path.splitext(filename) 47 if not utilityName.startswith('.') and not utilityName.startswith('#') and ext == '.py' and not utilityName == '__init__': 48 if directory: directory = directory+'.' 49 utilityObj = self.framework.require(directory+utilityName, self) 50 utilityObj.headerPrefix = self.headerPrefix 51 utilityObj.archProvider = self.arch 52 utilityObj.languageProvider = self.languages 53 utilityObj.installDirProvider = self.installdir 54 utilityObj.externalPackagesDirProvider = self.externalpackagesdir 55 utilityObj.precisionProvider = self.scalartypes 56 utilityObj.indexProvider = self.indexTypes 57 setattr(self, utilityName.lower(), utilityObj) 58 return utilityObj 59 return None 60 61 def setupDependencies(self, framework): 62 config.base.Configure.setupDependencies(self, framework) 63 self.programs = framework.require('config.programs', self) 64 self.setCompilers = framework.require('config.setCompilers', self) 65 self.compilers = framework.require('config.compilers', self) 66 self.arch = framework.require('PETSc.options.arch', self.setCompilers) 67 self.petscdir = framework.require('PETSc.options.petscdir', self.arch) 68 self.installdir = framework.require('PETSc.options.installDir', self) 69 self.dataFilesPath = framework.require('PETSc.options.dataFilesPath',self) 70 self.scalartypes = framework.require('PETSc.options.scalarTypes', self) 71 self.indexTypes = framework.require('PETSc.options.indexTypes', self) 72 self.languages = framework.require('PETSc.options.languages', self.setCompilers) 73 self.indexTypes = framework.require('PETSc.options.indexTypes', self.compilers) 74 self.types = framework.require('config.types', self) 75 self.headers = framework.require('config.headers', self) 76 self.functions = framework.require('config.functions', self) 77 self.libraries = framework.require('config.libraries', self) 78 self.atomics = framework.require('config.atomics', self) 79 self.make = framework.require('config.packages.make', self) 80 self.blasLapack = framework.require('config.packages.BlasLapack',self) 81 self.mpi = framework.require('config.packages.MPI', self) 82 self.fortran = framework.require('config.compilersFortran', self) 83 self.externalpackagesdir = framework.require('PETSc.options.externalpackagesdir',self) 84 85 for utility in sorted(os.listdir(os.path.join('config','PETSc','options'))): 86 self.registerPythonFile(utility,'PETSc.options') 87 88 for utility in sorted(os.listdir(os.path.join('config','BuildSystem','config','utilities'))): 89 self.registerPythonFile(utility,'config.utilities') 90 91 for package in sorted(os.listdir(os.path.join('config', 'BuildSystem', 'config', 'packages'))): 92 obj = self.registerPythonFile(package,'config.packages') 93 if obj: 94 obj.archProvider = self.framework.requireModule(obj.archProvider, obj) 95 obj.languageProvider = self.framework.requireModule(obj.languageProvider, obj) 96 obj.installDirProvider = self.framework.requireModule(obj.installDirProvider, obj) 97 obj.externalPackagesDirProvider = self.framework.requireModule(obj.externalPackagesDirProvider, obj) 98 obj.precisionProvider = self.framework.requireModule(obj.precisionProvider, obj) 99 obj.indexProvider = self.framework.requireModule(obj.indexProvider, obj) 100 101 # Force blaslapack and opencl to depend on scalarType so precision is set before BlasLapack is built 102 framework.require('PETSc.options.scalarTypes', self.f2cblaslapack) 103 framework.require('PETSc.options.scalarTypes', self.fblaslapack) 104 framework.require('PETSc.options.scalarTypes', self.blaslapack) 105 framework.require('PETSc.options.scalarTypes', self.opencl) 106 107 self.programs.headerPrefix = self.headerPrefix 108 self.compilers.headerPrefix = self.headerPrefix 109 self.fortran.headerPrefix = self.headerPrefix 110 self.types.headerPrefix = self.headerPrefix 111 self.headers.headerPrefix = self.headerPrefix 112 self.functions.headerPrefix = self.headerPrefix 113 self.libraries.headerPrefix = self.headerPrefix 114 115 # Register user provided package scripts 116 if 'with-package-scripts' in self.framework.argDB: 117 for script in self.framework.argDB['with-package-scripts']: 118 if os.path.splitext(script)[1] != '.py': 119 raise RuntimeError('Only python scripts compatible with configure package script format should be specified! Invalid option -with-package-scripts='+script) 120 self.framework.logPrint('User is registering a new package script: '+script) 121 dname,fname = os.path.split(script) 122 if dname: sys.path.append(dname) 123 self.registerPythonFile(fname,'') 124 125 # test for a variety of basic headers and functions 126 headersC = map(lambda name: name+'.h',['setjmp','dos','fcntl','float','io','malloc','pwd','strings', 127 'unistd','sys/sysinfo','machine/endian','sys/param','sys/procfs','sys/resource', 128 'sys/systeminfo','sys/times','sys/utsname', 129 'sys/socket','sys/wait','netinet/in','netdb','direct','time','Ws2tcpip','sys/types', 130 'WindowsX','float','ieeefp','stdint','pthread','inttypes','immintrin','zmmintrin']) 131 functions = ['access','_access','clock','drand48','getcwd','_getcwd','getdomainname','gethostname', 132 'getwd','memalign','popen','PXFGETARG','rand','getpagesize', 133 'readlink','realpath','usleep','sleep','_sleep', 134 'uname','snprintf','_snprintf','lseek','_lseek','time','fork','stricmp', 135 'strcasecmp','bzero','dlopen','dlsym','dlclose','dlerror', 136 '_set_output_format','_mkdir','socket','gethostbyname','_pipe','fpresetsticky','fpsetsticky'] 137 libraries = [(['fpe'],'handle_sigfpes')] 138 librariessock = [(['socket','nsl'],'socket')] 139 self.headers.headers.extend(headersC) 140 self.functions.functions.extend(functions) 141 self.libraries.libraries.extend(libraries) 142 if not hasattr(self,'socket'): 143 self.libraries.libraries.extend(librariessock) 144 return 145 146 def DumpPkgconfig(self, petsc_pc): 147 ''' Create a pkg-config file ''' 148 if not os.path.exists(os.path.join(self.petscdir.dir,self.arch.arch,'lib','pkgconfig')): 149 os.makedirs(os.path.join(self.petscdir.dir,self.arch.arch,'lib','pkgconfig')) 150 with open(os.path.join(self.petscdir.dir,self.arch.arch,'lib','pkgconfig',petsc_pc),'w') as fd: 151 cflags_inc = ['-I${includedir}'] 152 if self.framework.argDB['prefix']: 153 fd.write('prefix='+self.installdir.dir+'\n') 154 else: 155 fd.write('prefix='+os.path.join(self.petscdir.dir, self.arch.arch)+'\n') 156 cflags_inc.append('-I' + os.path.join(self.petscdir.dir, 'include')) 157 fd.write('exec_prefix=${prefix}\n') 158 fd.write('includedir=${prefix}/include\n') 159 fd.write('libdir=${prefix}/lib\n') 160 161 with self.setCompilers.Language('C'): 162 fd.write('ccompiler='+self.setCompilers.getCompiler()+'\n') 163 fd.write('cflags_extra='+self.setCompilers.getCompilerFlags().strip()+'\n') 164 fd.write('cflags_dep='+self.compilers.dependenciesGenerationFlag.get('C','')+'\n') 165 fd.write('ldflag_rpath='+self.setCompilers.CSharedLinkerFlag+'\n') 166 if hasattr(self.compilers, 'CXX'): 167 with self.setCompilers.Language('C++'): 168 fd.write('cxxcompiler='+self.setCompilers.getCompiler()+'\n') 169 fd.write('cxxflags_extra='+self.setCompilers.getCompilerFlags().strip()+'\n') 170 if hasattr(self.compilers, 'FC'): 171 with self.setCompilers.Language('FC'): 172 fd.write('fcompiler='+self.setCompilers.getCompiler()+'\n') 173 fd.write('fflags_extra='+self.setCompilers.getCompilerFlags().strip()+'\n') 174 if hasattr(self.compilers, 'CUDAC'): 175 with self.setCompilers.Language('CUDA'): 176 fd.write('cudacompiler='+self.setCompilers.getCompiler()+'\n') 177 fd.write('cudaflags_extra='+self.setCompilers.getCompilerFlags().strip()+'\n') 178 p = self.framework.require('config.packages.cuda') 179 fd.write('cudalib='+self.libraries.toStringNoDupes(p.lib)+'\n') 180 fd.write('cudainclude='+self.headers.toStringNoDupes(p.include)+'\n') 181 182 fd.write('\n') 183 fd.write('Name: PETSc\n') 184 fd.write('Description: Library to solve ODEs and algebraic equations\n') 185 fd.write('Version: %s\n' % self.petscdir.version) 186 fd.write('Cflags: ' + ' '.join([self.setCompilers.CPPFLAGS] + cflags_inc) + '\n') 187 fd.write('Libs: '+self.libraries.toStringNoDupes(['-L${libdir}', self.petsclib], with_rpath=False)+'\n') 188 # Remove RPATH flags from library list. User can add them using 189 # pkg-config --variable=ldflag_rpath and pkg-config --libs-only-L 190 fd.write('Libs.private: '+self.libraries.toStringNoDupes([f for f in self.packagelibs+self.complibs if not f.startswith(self.setCompilers.CSharedLinkerFlag)], with_rpath=False)+'\n') 191 return 192 193 def DumpModule(self): 194 ''' Create a module file ''' 195 if not os.path.exists(os.path.join(self.petscdir.dir,self.arch.arch,'lib','petsc','conf','modules')): 196 os.makedirs(os.path.join(self.petscdir.dir,self.arch.arch,'lib','petsc','conf','modules')) 197 if not os.path.exists(os.path.join(self.petscdir.dir,self.arch.arch,'lib','petsc','conf','modules','petsc')): 198 os.makedirs(os.path.join(self.petscdir.dir,self.arch.arch,'lib','petsc','conf','modules','petsc')) 199 if self.framework.argDB['prefix']: 200 installdir = self.installdir.dir 201 installarch = '' 202 installpath = os.path.join(installdir,'bin') 203 else: 204 installdir = self.petscdir.dir 205 installarch = self.arch.arch 206 installpath = os.path.join(installdir,installarch,'bin')+':'+os.path.join(installdir,'bin') 207 fd = open(os.path.join(self.petscdir.dir,self.arch.arch,'lib','petsc','conf','modules','petsc',self.petscdir.version),'w') 208 fd.write('''\ 209#%%Module 210 211proc ModulesHelp { } { 212 puts stderr "This module sets the path and environment variables for petsc-%s" 213 puts stderr " see https://www.mcs.anl.gov/petsc/ for more information " 214 puts stderr "" 215} 216module-whatis "PETSc - Portable, Extensible Toolkit for Scientific Computation" 217 218set petsc_dir "%s" 219set petsc_arch "%s" 220 221setenv PETSC_ARCH "$petsc_arch" 222setenv PETSC_DIR "$petsc_dir" 223prepend-path PATH "%s" 224''' % (self.petscdir.version, installdir, installarch, installpath)) 225 fd.close() 226 return 227 228 def Dump(self): 229 ''' Actually put the values into the configuration files ''' 230 # eventually everything between -- should be gone 231 if self.mpi.usingMPIUni: 232 # 233 # Remove any MPI/MPICH include files that may have been put here by previous runs of ./configure 234 self.executeShellCommand('rm -rf '+os.path.join(self.petscdir.dir,self.arch.arch,'include','mpi*')+' '+os.path.join(self.petscdir.dir,self.arch.arch,'include','opa*'), log = self.log) 235 236 self.logPrintDivider() 237 # Test for compiler-specific macros that need to be defined. 238 if self.setCompilers.isCrayVector('CC', self.log): 239 self.addDefine('HAVE_CRAY_VECTOR','1') 240 241 if self.functions.haveFunction('gethostbyname') and self.functions.haveFunction('socket') and self.headers.haveHeader('netinet/in.h'): 242 self.addDefine('USE_SOCKET_VIEWER','1') 243 if self.checkCompile('#include <sys/socket.h>','setsockopt(0,SOL_SOCKET,SO_REUSEADDR,0,0)'): 244 self.addDefine('HAVE_SO_REUSEADDR','1') 245 246 self.logPrintDivider() 247 self.setCompilers.pushLanguage('C') 248 compiler = self.setCompilers.getCompiler() 249 if compiler.endswith('mpicc') or compiler.endswith('mpiicc'): 250 try: 251 output = self.executeShellCommand(compiler + ' -show', log = self.log)[0] 252 compiler = output.split(' ')[0] 253 self.addDefine('MPICC_SHOW','"'+output.strip().replace('\n','\\\\n')+'"') 254 except: 255 self.addDefine('MPICC_SHOW','"Unavailable"') 256 else: 257 self.addDefine('MPICC_SHOW','"Unavailable"') 258 self.setCompilers.popLanguage() 259#----------------------------------------------------------------------------------------------------- 260 261 # Sometimes we need C compiler, even if built with C++ 262 self.setCompilers.pushLanguage('C') 263 self.addMakeMacro('CC_FLAGS',self.setCompilers.getCompilerFlags()) 264 self.setCompilers.popLanguage() 265 266 # And sometimes we need a C++ compiler even when PETSc is built with C 267 if hasattr(self.compilers, 'CXX'): 268 self.setCompilers.pushLanguage('Cxx') 269 self.addDefine('HAVE_CXX','1') 270 self.addMakeMacro('CXXPP_FLAGS',self.setCompilers.CXXPPFLAGS) 271 self.addMakeMacro('CXX_FLAGS',self.setCompilers.getCompilerFlags()) 272 cxx_linker = self.setCompilers.getLinker() 273 self.addMakeMacro('CXX_LINKER',cxx_linker) 274 self.addMakeMacro('CXX_LINKER_FLAGS',self.setCompilers.getLinkerFlags()) 275 self.setCompilers.popLanguage() 276 277 # C preprocessor values 278 self.addMakeMacro('CPP_FLAGS',self.setCompilers.CPPFLAGS) 279 280 # compiler values 281 self.setCompilers.pushLanguage(self.languages.clanguage) 282 self.addMakeMacro('PCC',self.setCompilers.getCompiler()) 283 self.addMakeMacro('PCC_FLAGS',self.setCompilers.getCompilerFlags()) 284 self.addMakeMacro('PCPP_FLAGS',getattr(self.setCompilers,self.languages.clanguage.upper()+'PPFLAGS')) 285 self.addMakeMacro('PFLAGS','${'+self.languages.clanguage.upper()+'FLAGS}') 286 self.addMakeMacro('PPPFLAGS','${'+self.languages.clanguage.upper()+'PPFLAGS}') 287 # ugly work-around for python3 distutils parse_makefile() issue with the above 2 lines 288 self.addMakeMacro('PY_'+self.languages.clanguage.upper()+'FLAGS','') 289 self.addMakeMacro('PY_'+self.languages.clanguage.upper()+'PPFLAGS','') 290 self.setCompilers.popLanguage() 291 # .o or .obj 292 self.addMakeMacro('CC_SUFFIX','o') 293 294 # executable linker values 295 self.setCompilers.pushLanguage(self.languages.clanguage) 296 pcc_linker = self.setCompilers.getLinker() 297 self.addMakeMacro('PCC_LINKER',pcc_linker) 298 self.addMakeMacro('PCC_LINKER_FLAGS',self.setCompilers.getLinkerFlags()) 299 self.setCompilers.popLanguage() 300 # '' for Unix, .exe for Windows 301 self.addMakeMacro('CC_LINKER_SUFFIX','') 302 303 if hasattr(self.compilers, 'FC'): 304 if self.framework.argDB['with-fortran-bindings']: 305 if not self.fortran.fortranIsF90: 306 raise RuntimeError('Error! Fortran compiler "'+self.compilers.FC+'" does not support F90! PETSc fortran bindings require a F90 compiler') 307 self.addDefine('HAVE_FORTRAN','1') 308 self.setCompilers.pushLanguage('FC') 309 # need FPPFLAGS in config/setCompilers 310 self.addMakeMacro('FPP_FLAGS',self.setCompilers.FPPFLAGS) 311 312 # compiler values 313 self.addMakeMacro('FC_FLAGS',self.setCompilers.getCompilerFlags()) 314 self.setCompilers.popLanguage() 315 # .o or .obj 316 self.addMakeMacro('FC_SUFFIX','o') 317 318 # executable linker values 319 self.setCompilers.pushLanguage('FC') 320 self.addMakeMacro('FC_LINKER',self.setCompilers.getLinker()) 321 self.addMakeMacro('FC_LINKER_FLAGS',self.setCompilers.getLinkerFlags()) 322 # apple requires this shared library linker flag on SOME versions of the os 323 if self.setCompilers.getLinkerFlags().find('-Wl,-commons,use_dylibs') > -1: 324 self.addMakeMacro('DARWIN_COMMONS_USE_DYLIBS',' -Wl,-commons,use_dylibs ') 325 self.setCompilers.popLanguage() 326 327 # F90 Modules 328 if self.setCompilers.fortranModuleIncludeFlag: 329 self.addMakeMacro('FC_MODULE_FLAG', self.setCompilers.fortranModuleIncludeFlag) 330 else: # for non-f90 compilers like g77 331 self.addMakeMacro('FC_MODULE_FLAG', '-I') 332 if self.setCompilers.fortranModuleIncludeFlag: 333 self.addMakeMacro('FC_MODULE_OUTPUT_FLAG', self.setCompilers.fortranModuleOutputFlag) 334 else: 335 self.addMakeMacro('FC','') 336 337 if hasattr(self.compilers, 'CUDAC'): 338 self.setCompilers.pushLanguage('CUDA') 339 self.addMakeMacro('CUDAC_FLAGS',self.setCompilers.getCompilerFlags()) 340 self.setCompilers.popLanguage() 341 342 if hasattr(self.compilers, 'HIPCC'): 343 self.setCompilers.pushLanguage('HIP') 344 self.addMakeMacro('HIPCC_FLAGS',self.setCompilers.getCompilerFlags()) 345 self.setCompilers.popLanguage() 346 347 if hasattr(self.compilers, 'SYCLCXX'): 348 self.setCompilers.pushLanguage('SYCL') 349 self.addMakeMacro('SYCLCXX_FLAGS',self.setCompilers.getCompilerFlags()) 350 self.setCompilers.popLanguage() 351 352 # shared library linker values 353 self.setCompilers.pushLanguage(self.languages.clanguage) 354 # need to fix BuildSystem to collect these separately 355 self.addMakeMacro('SL_LINKER',self.setCompilers.getLinker()) 356 self.addMakeMacro('SL_LINKER_FLAGS','${PCC_LINKER_FLAGS}') 357 self.setCompilers.popLanguage() 358 # One of 'a', 'so', 'lib', 'dll', 'dylib' (perhaps others also?) depending on the library generator and architecture 359 # Note: . is not included in this macro, consistent with AR_LIB_SUFFIX 360 if self.setCompilers.sharedLibraryExt == self.setCompilers.AR_LIB_SUFFIX: 361 self.addMakeMacro('SL_LINKER_SUFFIX', '') 362 self.addDefine('SLSUFFIX','""') 363 else: 364 self.addMakeMacro('SL_LINKER_SUFFIX', self.setCompilers.sharedLibraryExt) 365 self.addDefine('SLSUFFIX','"'+self.setCompilers.sharedLibraryExt+'"') 366 367 self.addMakeMacro('SL_LINKER_LIBS','${PETSC_EXTERNAL_LIB_BASIC}') 368 369#----------------------------------------------------------------------------------------------------- 370 371 # CONLY or CPP. We should change the PETSc makefiles to do this better 372 if self.languages.clanguage == 'C': lang = 'CONLY' 373 else: lang = 'CXXONLY' 374 self.addMakeMacro('PETSC_LANGUAGE',lang) 375 376 # real or complex 377 self.addMakeMacro('PETSC_SCALAR',self.scalartypes.scalartype) 378 # double or float 379 self.addMakeMacro('PETSC_PRECISION',self.scalartypes.precision) 380 381 if self.framework.argDB['with-batch']: 382 self.addMakeMacro('PETSC_WITH_BATCH','1') 383 384#----------------------------------------------------------------------------------------------------- 385 # print include and lib for makefiles 386 self.logPrintDivider() 387 self.framework.packages.reverse() 388 petscincludes = [os.path.join(self.petscdir.dir,'include'),os.path.join(self.petscdir.dir,self.arch.arch,'include')] 389 petscincludes_install = [os.path.join(self.installdir.dir, 'include')] if self.framework.argDB['prefix'] else petscincludes 390 includes = [] 391 self.packagelibs = [] 392 for i in self.framework.packages: 393 if not i.required: 394 self.addDefine('HAVE_'+i.PACKAGE.replace('-','_'), 1) # ONLY list package if it is used directly by PETSc (and not only by another package) 395 if not isinstance(i.lib, list): 396 i.lib = [i.lib] 397 if i.linkedbypetsc: self.packagelibs.extend(i.lib) 398 self.addMakeMacro(i.PACKAGE.replace('-','_')+'_LIB', self.libraries.toStringNoDupes(i.lib)) 399 if hasattr(i,'include'): 400 if not isinstance(i.include,list): 401 i.include = [i.include] 402 includes.extend(i.include) 403 self.addMakeMacro(i.PACKAGE.replace('-','_')+'_INCLUDE',self.headers.toStringNoDupes(i.include)) 404 if self.framework.argDB['with-single-library']: 405 self.petsclib = '-lpetsc' 406 else: 407 self.petsclib = '-lpetscts -lpetscsnes -lpetscksp -lpetscdm -lpetscmat -lpetscvec -lpetscsys' 408 self.complibs = self.compilers.flibs+self.compilers.cxxlibs+self.compilers.LIBS.split() 409 self.PETSC_WITH_EXTERNAL_LIB = self.libraries.toStringNoDupes(['-L${PETSC_DIR}/${PETSC_ARCH}/lib', self.petsclib]+self.packagelibs+self.complibs) 410 self.PETSC_EXTERNAL_LIB_BASIC = self.libraries.toStringNoDupes(self.packagelibs+self.complibs) 411 412 self.addMakeMacro('PETSC_EXTERNAL_LIB_BASIC',self.PETSC_EXTERNAL_LIB_BASIC) 413 allincludes = petscincludes + includes 414 allincludes_install = petscincludes_install + includes 415 self.PETSC_CC_INCLUDES = self.headers.toStringNoDupes(allincludes) 416 self.PETSC_CC_INCLUDES_INSTALL = self.headers.toStringNoDupes(allincludes_install) 417 self.addMakeMacro('PETSC_CC_INCLUDES',self.PETSC_CC_INCLUDES) 418 self.addMakeMacro('PETSC_CC_INCLUDES_INSTALL', self.PETSC_CC_INCLUDES_INSTALL) 419 if hasattr(self.compilers, 'FC'): 420 def modinc(includes): 421 return includes if self.fortran.fortranIsF90 else [] 422 self.addMakeMacro('PETSC_FC_INCLUDES',self.headers.toStringNoDupes(allincludes,modinc(allincludes))) 423 self.addMakeMacro('PETSC_FC_INCLUDES_INSTALL',self.headers.toStringNoDupes(allincludes_install,modinc(allincludes_install))) 424 425 self.addDefine('LIB_DIR','"'+os.path.join(self.installdir.dir,'lib')+'"') 426 427 if self.framework.argDB['with-single-library']: 428 # overrides the values set in conf/variables 429 self.addMakeMacro('LIBNAME','${INSTALL_LIB_DIR}/libpetsc.${AR_LIB_SUFFIX}') 430 self.addMakeMacro('SHLIBS','libpetsc') 431 self.addMakeMacro('PETSC_LIB_BASIC','-lpetsc') 432 self.addMakeMacro('PETSC_KSP_LIB_BASIC','-lpetsc') 433 self.addMakeMacro('PETSC_TS_LIB_BASIC','-lpetsc') 434 self.addMakeMacro('PETSC_TAO_LIB_BASIC','-lpetsc') 435 self.addMakeMacro('PETSC_WITH_EXTERNAL_LIB',self.PETSC_WITH_EXTERNAL_LIB) 436 self.addDefine('USE_SINGLE_LIBRARY', '1') 437 if self.sharedlibraries.useShared: 438 self.addMakeMacro('PETSC_SYS_LIB','${C_SH_LIB_PATH} ${PETSC_WITH_EXTERNAL_LIB}') 439 self.addMakeMacro('PETSC_VEC_LIB','${C_SH_LIB_PATH} ${PETSC_WITH_EXTERNAL_LIB}') 440 self.addMakeMacro('PETSC_MAT_LIB','${C_SH_LIB_PATH} ${PETSC_WITH_EXTERNAL_LIB}') 441 self.addMakeMacro('PETSC_DM_LIB','${C_SH_LIB_PATH} ${PETSC_WITH_EXTERNAL_LIB}') 442 self.addMakeMacro('PETSC_KSP_LIB','${C_SH_LIB_PATH} ${PETSC_WITH_EXTERNAL_LIB}') 443 self.addMakeMacro('PETSC_SNES_LIB','${C_SH_LIB_PATH} ${PETSC_WITH_EXTERNAL_LIB}') 444 self.addMakeMacro('PETSC_TS_LIB','${C_SH_LIB_PATH} ${PETSC_WITH_EXTERNAL_LIB}') 445 self.addMakeMacro('PETSC_TAO_LIB','${C_SH_LIB_PATH} ${PETSC_WITH_EXTERNAL_LIB}') 446 self.addMakeMacro('PETSC_CHARACTERISTIC_LIB','${C_SH_LIB_PATH} ${PETSC_WITH_EXTERNAL_LIB}') 447 self.addMakeMacro('PETSC_LIB','${C_SH_LIB_PATH} ${PETSC_WITH_EXTERNAL_LIB}') 448 self.addMakeMacro('PETSC_CONTRIB','${C_SH_LIB_PATH} ${PETSC_WITH_EXTERNAL_LIB}') 449 else: 450 self.addMakeMacro('PETSC_SYS_LIB','${PETSC_WITH_EXTERNAL_LIB}') 451 self.addMakeMacro('PETSC_VEC_LIB','${PETSC_WITH_EXTERNAL_LIB}') 452 self.addMakeMacro('PETSC_MAT_LIB','${PETSC_WITH_EXTERNAL_LIB}') 453 self.addMakeMacro('PETSC_DM_LIB','${PETSC_WITH_EXTERNAL_LIB}') 454 self.addMakeMacro('PETSC_KSP_LIB','${PETSC_WITH_EXTERNAL_LIB}') 455 self.addMakeMacro('PETSC_SNES_LIB','${PETSC_WITH_EXTERNAL_LIB}') 456 self.addMakeMacro('PETSC_TS_LIB','${PETSC_WITH_EXTERNAL_LIB}') 457 self.addMakeMacro('PETSC_TAO_LIB','${PETSC_WITH_EXTERNAL_LIB}') 458 self.addMakeMacro('PETSC_CHARACTERISTIC_LIB','${PETSC_WITH_EXTERNAL_LIB}') 459 self.addMakeMacro('PETSC_LIB','${PETSC_WITH_EXTERNAL_LIB}') 460 self.addMakeMacro('PETSC_CONTRIB','${PETSC_WITH_EXTERNAL_LIB}') 461 462 if not os.path.exists(os.path.join(self.petscdir.dir,self.arch.arch,'lib')): 463 os.makedirs(os.path.join(self.petscdir.dir,self.arch.arch,'lib')) 464 465# add a makefile endtry for display 466 if self.framework.argDB['with-display']: 467 self.addMakeMacro('DISPLAY',self.framework.argDB['with-display']) 468 469 # add a makefile entry for configure options 470 self.addMakeMacro('CONFIGURE_OPTIONS', self.framework.getOptionsString(['configModules', 'optionsModule']).replace('\"','\\"')) 471 return 472 473 def dumpConfigInfo(self): 474 import time 475 fd = open(os.path.join(self.arch.arch,'include','petscconfiginfo.h'),'w') 476 fd.write('static const char *petscconfigureoptions = "'+self.framework.getOptionsString(['configModules', 'optionsModule']).replace('\"','\\"').replace('\\ ','\\\\ ')+'";\n') 477 fd.close() 478 return 479 480 def dumpMachineInfo(self): 481 import platform 482 import datetime 483 import time 484 import script 485 def escape(s): 486 return s.replace('"',r'\"').replace(r'\ ',r'\\ ') # novermin 487 fd = open(os.path.join(self.arch.arch,'include','petscmachineinfo.h'),'w') 488 fd.write('static const char *petscmachineinfo = \"\\n\"\n') 489 fd.write('\"-----------------------------------------\\n\"\n') 490 buildhost = platform.node() 491 if os.environ.get('SOURCE_DATE_EPOCH'): 492 buildhost = "reproducible" 493 buildtime = datetime.datetime.utcfromtimestamp(int(os.environ.get('SOURCE_DATE_EPOCH', time.time()))) 494 fd.write('\"Libraries compiled on %s on %s \\n\"\n' % (buildtime, buildhost)) 495 fd.write('\"Machine characteristics: %s\\n\"\n' % (platform.platform())) 496 fd.write('\"Using PETSc directory: %s\\n\"\n' % (escape(self.installdir.petscDir))) 497 fd.write('\"Using PETSc arch: %s\\n\"\n' % (escape(self.installdir.petscArch))) 498 fd.write('\"-----------------------------------------\\n\";\n') 499 fd.write('static const char *petsccompilerinfo = \"\\n\"\n') 500 self.setCompilers.pushLanguage(self.languages.clanguage) 501 fd.write('\"Using C compiler: %s %s \\n\"\n' % (escape(self.setCompilers.getCompiler()), escape(self.setCompilers.getCompilerFlags()))) 502 self.setCompilers.popLanguage() 503 if hasattr(self.compilers, 'FC'): 504 self.setCompilers.pushLanguage('FC') 505 fd.write('\"Using Fortran compiler: %s %s %s\\n\"\n' % (escape(self.setCompilers.getCompiler()), escape(self.setCompilers.getCompilerFlags()), escape(self.setCompilers.CPPFLAGS))) 506 self.setCompilers.popLanguage() 507 fd.write('\"-----------------------------------------\\n\";\n') 508 fd.write('static const char *petsccompilerflagsinfo = \"\\n\"\n') 509 fd.write('\"Using include paths: %s\\n\"\n' % (escape(self.PETSC_CC_INCLUDES_INSTALL.replace('${PETSC_DIR}', self.installdir.petscDir)))) 510 fd.write('\"-----------------------------------------\\n\";\n') 511 fd.write('static const char *petsclinkerinfo = \"\\n\"\n') 512 self.setCompilers.pushLanguage(self.languages.clanguage) 513 fd.write('\"Using C linker: %s\\n\"\n' % (escape(self.setCompilers.getLinker()))) 514 self.setCompilers.popLanguage() 515 if hasattr(self.compilers, 'FC'): 516 self.setCompilers.pushLanguage('FC') 517 fd.write('\"Using Fortran linker: %s\\n\"\n' % (escape(self.setCompilers.getLinker()))) 518 self.setCompilers.popLanguage() 519 fd.write('\"Using libraries: %s%s -L%s %s %s\\n\"\n' % (escape(self.setCompilers.CSharedLinkerFlag), escape(os.path.join(self.installdir.petscDir, self.installdir.petscArch, 'lib')), escape(os.path.join(self.installdir.petscDir, self.installdir.petscArch, 'lib')), escape(self.petsclib), escape(self.PETSC_EXTERNAL_LIB_BASIC))) 520 fd.write('\"-----------------------------------------\\n\";\n') 521 fd.close() 522 return 523 524 def configurePrefetch(self): 525 '''Sees if there are any prefetch functions supported''' 526 if config.setCompilers.Configure.isSolaris(self.log) or self.framework.argDB['with-ios'] or not self.framework.argDB['with-prefetch']: 527 self.addDefine('Prefetch(a,b,c)', ' ') 528 return 529 self.pushLanguage(self.languages.clanguage) 530 if self.checkLink('#include <xmmintrin.h>', 'void *v = 0;_mm_prefetch((const char*)v,_MM_HINT_NTA);\n'): 531 # The Intel Intrinsics manual [1] specifies the prototype 532 # 533 # void _mm_prefetch(char const *a, int sel); 534 # 535 # but other vendors seem to insist on using subtly different 536 # prototypes, including void* for the pointer, and an enum for 537 # sel. These are both reasonable changes, but negatively impact 538 # portability. 539 # 540 # [1] https://software.intel.com/file/6373 541 self.addDefine('HAVE_XMMINTRIN_H', 1) 542 self.addDefine('Prefetch(a,b,c)', '_mm_prefetch((const char*)(a),(c))') 543 self.addDefine('PREFETCH_HINT_NTA', '_MM_HINT_NTA') 544 self.addDefine('PREFETCH_HINT_T0', '_MM_HINT_T0') 545 self.addDefine('PREFETCH_HINT_T1', '_MM_HINT_T1') 546 self.addDefine('PREFETCH_HINT_T2', '_MM_HINT_T2') 547 elif self.checkLink('#include <xmmintrin.h>', 'void *v = 0;_mm_prefetch(v,_MM_HINT_NTA);\n'): 548 self.addDefine('HAVE_XMMINTRIN_H', 1) 549 self.addDefine('Prefetch(a,b,c)', '_mm_prefetch((const void*)(a),(c))') 550 self.addDefine('PREFETCH_HINT_NTA', '_MM_HINT_NTA') 551 self.addDefine('PREFETCH_HINT_T0', '_MM_HINT_T0') 552 self.addDefine('PREFETCH_HINT_T1', '_MM_HINT_T1') 553 self.addDefine('PREFETCH_HINT_T2', '_MM_HINT_T2') 554 elif self.checkLink('', 'void *v = 0;__builtin_prefetch(v,0,0);\n'): 555 # From GCC docs: void __builtin_prefetch(const void *addr,int rw,int locality) 556 # 557 # The value of rw is a compile-time constant one or zero; one 558 # means that the prefetch is preparing for a write to the memory 559 # address and zero, the default, means that the prefetch is 560 # preparing for a read. The value locality must be a compile-time 561 # constant integer between zero and three. A value of zero means 562 # that the data has no temporal locality, so it need not be left 563 # in the cache after the access. A value of three means that the 564 # data has a high degree of temporal locality and should be left 565 # in all levels of cache possible. Values of one and two mean, 566 # respectively, a low or moderate degree of temporal locality. 567 # 568 # Here we adopt Intel's x86/x86-64 naming scheme for the locality 569 # hints. Using macros for these values in necessary since some 570 # compilers require an enum. 571 self.addDefine('Prefetch(a,b,c)', '__builtin_prefetch((a),(b),(c))') 572 self.addDefine('PREFETCH_HINT_NTA', '0') 573 self.addDefine('PREFETCH_HINT_T0', '3') 574 self.addDefine('PREFETCH_HINT_T1', '2') 575 self.addDefine('PREFETCH_HINT_T2', '1') 576 else: 577 self.addDefine('Prefetch(a,b,c)', ' ') 578 self.popLanguage() 579 580 def configureAtoll(self): 581 '''Checks if atoll exists''' 582 if self.checkLink('#define _POSIX_C_SOURCE 200112L\n#include <stdlib.h>','long v = atoll("25")') or self.checkLink ('#include <stdlib.h>','long v = atoll("25")'): 583 self.addDefine('HAVE_ATOLL', '1') 584 585 def configureUnused(self): 586 '''Sees if __attribute((unused)) is supported''' 587 if self.framework.argDB['with-ios']: 588 self.addDefine('UNUSED', ' ') 589 return 590 self.pushLanguage(self.languages.clanguage) 591 if self.checkLink('__attribute((unused)) static int myfunc(__attribute((unused)) void *name){ return 1;}', 'int i = 0;\nint j = myfunc(&i);\ntypedef void* atype;\n__attribute((unused)) atype a;\n'): 592 self.addDefine('UNUSED', '__attribute((unused))') 593 else: 594 self.addDefine('UNUSED', ' ') 595 self.popLanguage() 596 597 def configureIsatty(self): 598 '''Check if the Unix C function isatty() works correctly 599 Actually just assumes it does not work correctly on batch systems''' 600 if not self.framework.argDB['with-batch']: 601 self.addDefine('USE_ISATTY',1) 602 603 def configureDeprecated(self): 604 '''Check if __attribute((deprecated)) is supported''' 605 self.pushLanguage(self.languages.clanguage) 606 ## Recent versions of gcc and clang support __attribute((deprecated("string argument"))), which is very useful, but 607 ## Intel has conspired to make a supremely environment-sensitive compiler. The Intel compiler looks at the gcc 608 ## executable in the environment to determine the language compatibility that it should attempt to emulate. Some 609 ## important Cray installations have built PETSc using the Intel compiler, but with a newer gcc module loaded (e.g., 610 ## 4.7). Thus at PETSc configure time, the Intel compiler decides to support the string argument, but the gcc 611 ## found in the default user environment is older and does not support the argument. If GCC and Intel were cool 612 ## like Clang and supported __has_attribute, we could avoid configure tests entirely, but they don't. And that is 613 ## why we can't have nice things. 614 # 615 # if self.checkCompile("""__attribute((deprecated("Why you shouldn't use myfunc"))) static int myfunc(void) { return 1;}""", ''): 616 # self.addDefine('DEPRECATED_FUNCTION(why)', '__attribute((deprecated(why)))') 617 # self.addDefine('DEPRECATED_TYPEDEF(why)', '__attribute((deprecated(why)))') 618 if self.checkCompile("""__attribute((deprecated)) static int myfunc(void) { return 1;}""", ''): 619 self.addDefine('DEPRECATED_FUNCTION(why)', '__attribute((deprecated))') 620 self.addDefine('DEPRECATED_TYPEDEF(why)', '__attribute((deprecated))') 621 else: 622 self.addDefine('DEPRECATED_FUNCTION(why)', ' ') 623 self.addDefine('DEPRECATED_TYPEDEF(why)', ' ') 624 if self.checkCompile("""enum E {oldval __attribute((deprecated)), newval };""", ''): 625 self.addDefine('DEPRECATED_ENUM(why)', '__attribute((deprecated))') 626 else: 627 self.addDefine('DEPRECATED_ENUM(why)', ' ') 628 # I was unable to make a CPP macro that takes the old and new values as separate arguments and builds the message needed by _Pragma 629 # hence the deprecation message is handled as it is 630 if self.checkCompile('#define TEST _Pragma("GCC warning \"Testing _Pragma\"") value'): 631 self.addDefine('DEPRECATED_MACRO(why)', '_Pragma(why)') 632 else: 633 self.addDefine('DEPRECATED_MACRO(why)', ' ') 634 self.popLanguage() 635 636 def configureAlign(self): 637 '''Check if __attribute(aligned) is supported''' 638 code = '''\ 639struct mystruct {int myint;} __attribute((aligned(16))); 640char assert_aligned[(sizeof(struct mystruct)==16)*2-1]; 641''' 642 self.pushLanguage(self.languages.clanguage) 643 if self.checkCompile(code): 644 self.addDefine('ATTRIBUTEALIGNED(size)', '__attribute((aligned(size)))') 645 self.addDefine('HAVE_ATTRIBUTEALIGNED', 1) 646 else: 647 self.framework.logPrint('Incorrect attribute(aligned)') 648 self.addDefine('ATTRIBUTEALIGNED(size)', ' ') 649 self.popLanguage() 650 return 651 652 def configureExpect(self): 653 '''Sees if the __builtin_expect directive is supported''' 654 self.pushLanguage(self.languages.clanguage) 655 if self.checkLink('', 'if (__builtin_expect(0,1)) return 1;'): 656 self.addDefine('HAVE_BUILTIN_EXPECT', 1) 657 self.popLanguage() 658 659 def configureFunctionName(self): 660 '''Sees if the compiler supports __func__ or a variant.''' 661 def getFunctionName(lang): 662 name = '"unknown"' 663 self.pushLanguage(lang) 664 for fname in ['__func__','__FUNCTION__','__extension__ __func__']: 665 code = "if ("+fname+"[0] != 'm') return 1;" 666 if self.checkCompile('',code) and self.checkLink('',code): 667 name = fname 668 break 669 self.popLanguage() 670 return name 671 langs = [] 672 673 self.addDefine('FUNCTION_NAME_C', getFunctionName('C')) 674 if hasattr(self.compilers, 'CXX'): 675 self.addDefine('FUNCTION_NAME_CXX', getFunctionName('Cxx')) 676 677 def configureIntptrt(self): 678 '''Determine what to use for uintptr_t''' 679 def staticAssertSizeMatchesVoidStar(inc,typename): 680 # The declaration is an error if either array size is negative. 681 # It should be okay to use an int that is too large, but it would be very unlikely for this to be the case 682 return self.checkCompile(inc, ('#define STATIC_ASSERT(cond) char negative_length_if_false[2*(!!(cond))-1]\n' 683 + 'STATIC_ASSERT(sizeof(void*) == sizeof(%s));'%typename)) 684 self.pushLanguage(self.languages.clanguage) 685 if self.checkCompile('#include <stdint.h>', 'int x; uintptr_t i = (uintptr_t)&x;'): 686 self.addDefine('UINTPTR_T', 'uintptr_t') 687 elif staticAssertSizeMatchesVoidStar('','unsigned long long'): 688 self.addDefine('UINTPTR_T', 'unsigned long long') 689 elif staticAssertSizeMatchesVoidStar('#include <stdlib.h>','size_t') or staticAssertSizeMatchesVoidStar('#include <string.h>', 'size_t'): 690 self.addDefine('UINTPTR_T', 'size_t') 691 elif staticAssertSizeMatchesVoidStar('','unsigned long'): 692 self.addDefine('UINTPTR_T', 'unsigned long') 693 elif staticAssertSizeMatchesVoidStar('','unsigned'): 694 self.addDefine('UINTPTR_T', 'unsigned') 695 else: 696 raise RuntimeError('Could not find any unsigned integer type matching void*') 697 self.popLanguage() 698 699 def configureRTLDDefault(self): 700 if self.checkCompile('#include <dlfcn.h>\n void *ptr = RTLD_DEFAULT;'): 701 self.addDefine('RTLD_DEFAULT','1') 702 return 703 704 def configureSolaris(self): 705 '''Solaris specific stuff''' 706 if os.path.isdir(os.path.join('/usr','ucblib')): 707 try: 708 flag = getattr(self.setCompilers, self.language[-1]+'SharedLinkerFlag') 709 except AttributeError: 710 flag = None 711 if flag is None: 712 self.compilers.LIBS += ' -L/usr/ucblib' 713 else: 714 self.compilers.LIBS += ' '+flag+'/usr/ucblib' 715 return 716 717 def configureLinux(self): 718 '''Linux specific stuff''' 719 # TODO: Test for this by mallocing an odd number of floats and checking the address 720 self.addDefine('HAVE_DOUBLE_ALIGN_MALLOC', 1) 721 return 722 723 def configureWin32(self): 724 '''Win32 non-cygwin specific stuff''' 725 kernel32=0 726 if self.libraries.add('Kernel32.lib','GetComputerName',prototype='#include <windows.h>', call='GetComputerName(NULL,NULL);'): 727 self.addDefine('HAVE_WINDOWS_H',1) 728 self.addDefine('HAVE_GETCOMPUTERNAME',1) 729 kernel32=1 730 elif self.libraries.add('kernel32','GetComputerName',prototype='#include <windows.h>', call='GetComputerName(NULL,NULL);'): 731 self.addDefine('HAVE_WINDOWS_H',1) 732 self.addDefine('HAVE_GETCOMPUTERNAME',1) 733 kernel32=1 734 if kernel32: 735 if self.framework.argDB['with-windows-graphics']: 736 self.addDefine('USE_WINDOWS_GRAPHICS',1) 737 if self.checkLink('#include <windows.h>','LoadLibrary(0)'): 738 self.addDefine('HAVE_LOADLIBRARY',1) 739 if self.checkLink('#include <windows.h>','GetProcAddress(0,0)'): 740 self.addDefine('HAVE_GETPROCADDRESS',1) 741 if self.checkLink('#include <windows.h>','FreeLibrary(0)'): 742 self.addDefine('HAVE_FREELIBRARY',1) 743 if self.checkLink('#include <windows.h>','GetLastError()'): 744 self.addDefine('HAVE_GETLASTERROR',1) 745 if self.checkLink('#include <windows.h>','SetLastError(0)'): 746 self.addDefine('HAVE_SETLASTERROR',1) 747 if self.checkLink('#include <windows.h>\n','QueryPerformanceCounter(0);\n'): 748 self.addDefine('USE_MICROSOFT_TIME',1) 749 if self.libraries.add('Advapi32.lib','GetUserName',prototype='#include <windows.h>', call='GetUserName(NULL,NULL);'): 750 self.addDefine('HAVE_GET_USER_NAME',1) 751 elif self.libraries.add('advapi32','GetUserName',prototype='#include <windows.h>', call='GetUserName(NULL,NULL);'): 752 self.addDefine('HAVE_GET_USER_NAME',1) 753 754 if not self.libraries.add('User32.lib','GetDC',prototype='#include <windows.h>',call='GetDC(0);'): 755 self.libraries.add('user32','GetDC',prototype='#include <windows.h>',call='GetDC(0);') 756 if not self.libraries.add('Gdi32.lib','CreateCompatibleDC',prototype='#include <windows.h>',call='CreateCompatibleDC(0);'): 757 self.libraries.add('gdi32','CreateCompatibleDC',prototype='#include <windows.h>',call='CreateCompatibleDC(0);') 758 759 self.types.check('int32_t', 'int') 760 if not self.checkCompile('#include <sys/types.h>\n','uid_t u;\n'): 761 self.addTypedef('int', 'uid_t') 762 self.addTypedef('int', 'gid_t') 763 if not self.checkLink('#if defined(PETSC_HAVE_UNISTD_H)\n#include <unistd.h>\n#endif\n','int a=R_OK;\n'): 764 self.framework.addDefine('R_OK', '04') 765 self.framework.addDefine('W_OK', '02') 766 self.framework.addDefine('X_OK', '01') 767 if not self.checkLink('#include <sys/stat.h>\n','int a=0;\nif (S_ISDIR(a)){}\n'): 768 self.framework.addDefine('S_ISREG(a)', '(((a)&_S_IFMT) == _S_IFREG)') 769 self.framework.addDefine('S_ISDIR(a)', '(((a)&_S_IFMT) == _S_IFDIR)') 770 if self.checkCompile('#include <windows.h>\n','LARGE_INTEGER a;\nDWORD b=a.u.HighPart;\n'): 771 self.addDefine('HAVE_LARGE_INTEGER_U',1) 772 773 # Windows requires a Binary file creation flag when creating/opening binary files. Is a better test in order? 774 if self.checkCompile('#include <windows.h>\n#include <fcntl.h>\n', 'int flags = O_BINARY;'): 775 self.addDefine('HAVE_O_BINARY',1) 776 777 if self.compilers.CC.find('win32fe') >= 0: 778 self.addDefine('HAVE_WINDOWS_COMPILERS',1) 779 self.addDefine('DIR_SEPARATOR','\'\\\\\'') 780 self.addDefine('REPLACE_DIR_SEPARATOR','\'/\'') 781 self.addDefine('CANNOT_START_DEBUGGER',1) 782 (petscdir,error,status) = self.executeShellCommand('cygpath -w '+self.installdir.petscDir, log = self.log) 783 self.addDefine('DIR','"'+petscdir.replace('\\','\\\\')+'"') 784 (petscdir,error,status) = self.executeShellCommand('cygpath -m '+self.installdir.petscDir, log = self.log) 785 self.addMakeMacro('wPETSC_DIR',petscdir) 786 if self.dataFilesPath.datafilespath: 787 (datafilespath,error,status) = self.executeShellCommand('cygpath -m '+self.dataFilesPath.datafilespath, log = self.log) 788 self.addMakeMacro('DATAFILESPATH',datafilespath) 789 790 else: 791 self.addDefine('REPLACE_DIR_SEPARATOR','\'\\\\\'') 792 self.addDefine('DIR_SEPARATOR','\'/\'') 793 self.addDefine('DIR','"'+self.installdir.petscDir+'"') 794 self.addMakeMacro('wPETSC_DIR',self.installdir.petscDir) 795 if self.dataFilesPath.datafilespath: 796 self.addMakeMacro('DATAFILESPATH',self.dataFilesPath.datafilespath) 797 self.addDefine('ARCH','"'+self.installdir.petscArch+'"') 798 return 799 800#----------------------------------------------------------------------------------------------------- 801 def configureCygwinBrokenPipe(self): 802 '''Cygwin version <= 1.7.18 had issues with pipes and long commands invoked from gnu-make 803 http://cygwin.com/ml/cygwin/2013-05/msg00340.html ''' 804 if config.setCompilers.Configure.isCygwin(self.log): 805 import platform 806 import re 807 r=re.compile("([0-9]+).([0-9]+).([0-9]+)") 808 m=r.match(platform.release()) 809 major=int(m.group(1)) 810 minor=int(m.group(2)) 811 subminor=int(m.group(3)) 812 if ((major < 1) or (major == 1 and minor < 7) or (major == 1 and minor == 7 and subminor <= 18)): 813 self.addMakeMacro('PETSC_CYGWIN_BROKEN_PIPE','1') 814 return 815 816#----------------------------------------------------------------------------------------------------- 817 def configureDefaultArch(self): 818 conffile = os.path.join('lib','petsc','conf', 'petscvariables') 819 if self.framework.argDB['with-default-arch']: 820 fd = open(conffile, 'w') 821 fd.write('PETSC_ARCH='+self.arch.arch+'\n') 822 fd.write('PETSC_DIR='+self.petscdir.dir+'\n') 823 fd.write('include '+os.path.join('$(PETSC_DIR)','$(PETSC_ARCH)','lib','petsc','conf','petscvariables')+'\n') 824 fd.close() 825 self.framework.actions.addArgument('PETSc', 'Build', 'Set default architecture to '+self.arch.arch+' in '+conffile) 826 elif os.path.isfile(conffile): 827 try: 828 os.unlink(conffile) 829 except: 830 raise RuntimeError('Unable to remove file '+conffile+'. Did a different user create it?') 831 return 832 833#----------------------------------------------------------------------------------------------------- 834 def configureScript(self): 835 '''Output a script in the conf directory which will reproduce the configuration''' 836 import nargs 837 import sys 838 scriptName = os.path.join(self.arch.arch,'lib','petsc','conf', 'reconfigure-'+self.arch.arch+'.py') 839 args = dict([(nargs.Arg.parseArgument(arg)[0], arg) for arg in self.framework.clArgs]) 840 if 'with-clean' in args: 841 del args['with-clean'] 842 if 'force' in args: 843 del args['force'] 844 if 'configModules' in args: 845 if nargs.Arg.parseArgument(args['configModules'])[1] == 'PETSc.Configure': 846 del args['configModules'] 847 if 'optionsModule' in args: 848 if nargs.Arg.parseArgument(args['optionsModule'])[1] == 'config.compilerOptions': 849 del args['optionsModule'] 850 if not 'PETSC_ARCH' in args: 851 args['PETSC_ARCH'] = 'PETSC_ARCH='+str(self.arch.arch) 852 f = open(scriptName, 'w') 853 f.write('#!'+sys.executable+'\n') 854 f.write('if __name__ == \'__main__\':\n') 855 f.write(' import sys\n') 856 f.write(' import os\n') 857 f.write(' sys.path.insert(0, os.path.abspath(\'config\'))\n') 858 f.write(' import configure\n') 859 # pretty print repr(args.values()) 860 f.write(' configure_options = [\n') 861 for itm in sorted(args.values()): 862 f.write(' \''+str(itm)+'\',\n') 863 f.write(' ]\n') 864 f.write(' configure.petsc_configure(configure_options)\n') 865 f.close() 866 try: 867 os.chmod(scriptName, 0o775) 868 except OSError as e: 869 self.framework.logPrint('Unable to make reconfigure script executable:\n'+str(e)) 870 self.framework.actions.addArgument('PETSc', 'File creation', 'Created '+scriptName+' for automatic reconfiguration') 871 return 872 873 def configureInstall(self): 874 '''Setup the directories for installation''' 875 if self.framework.argDB['prefix']: 876 self.addMakeRule('print_mesg_after_build','', 877 ['-@echo "========================================="', 878 '-@echo "Now to install the libraries do:"', 879 '-@echo "%s${MAKE_USER} PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} install"' % self.installdir.installSudo, 880 '-@echo "========================================="']) 881 else: 882 self.addMakeRule('print_mesg_after_build','', 883 ['-@echo "========================================="', 884 '-@echo "Now to check if the libraries are working do:"', 885 '-@echo "${MAKE_USER} PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} check"', 886 '-@echo "========================================="']) 887 return 888 889 def configureGCOV(self): 890 if self.framework.argDB['with-gcov']: 891 self.addDefine('USE_GCOV','1') 892 return 893 894 def postProcessPackages(self): 895 postPackages=[] 896 for i in self.framework.packages: 897 if hasattr(i,'postProcess'): postPackages.append(i) 898 if postPackages: 899 # ctetgen needs petsc conf files. so attempt to create them early 900 self.framework.dumpConfFiles() 901 # tacky fix for dependency of Aluimia on Pflotran; requested via petsc-dev Matt provide a correct fix 902 for i in postPackages: 903 if i.name.upper() in ['PFLOTRAN']: 904 i.postProcess() 905 postPackages.remove(i) 906 for i in postPackages: i.postProcess() 907 for i in postPackages: 908 if i.installedpetsc: 909 self.installed = 1 910 break 911 return 912 913 def configure(self): 914 if 'package-prefix-hash' in self.argDB: 915 # turn off prefix if it was only used to for installing external packages. 916 self.framework.argDB['prefix'] = '' 917 self.dir = os.path.abspath(os.path.join(self.petscdir.dir, self.arch.arch)) 918 self.installdir.dir = self.dir 919 self.installdir.petscDir = self.petscdir.dir 920 self.petscDir = self.petscdir.dir 921 self.petscArch = self.arch.arch 922 self.addMakeMacro('PREFIXDIR',self.dir) 923 self.confDir = os.path.abspath(os.path.join(self.petscdir.dir, self.arch.arch)) 924 925 if not os.path.samefile(self.petscdir.dir, os.getcwd()): 926 raise RuntimeError('Wrong PETSC_DIR option specified: '+str(self.petscdir.dir) + '\n Configure invoked in: '+os.path.realpath(os.getcwd())) 927 if self.framework.argDB['prefix'] and os.path.isdir(self.framework.argDB['prefix']) and os.path.samefile(self.framework.argDB['prefix'],self.petscdir.dir): 928 raise RuntimeError('Incorrect option --prefix='+self.framework.argDB['prefix']+' specified. It cannot be same as PETSC_DIR!') 929 if self.framework.argDB['prefix'] and self.framework.argDB['prefix'].find(' ') > -1: 930 raise RuntimeError('Your --prefix '+self.framework.argDB['prefix']+' has spaces in it; this is not allowed.\n Use a --prefix that does not have spaces in it') 931 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)): 932 raise RuntimeError('Incorrect option --prefix='+self.framework.argDB['prefix']+' specified. It cannot be same as PETSC_DIR/PETSC_ARCH!') 933 self.framework.header = os.path.join(self.arch.arch,'include','petscconf.h') 934 self.framework.cHeader = os.path.join(self.arch.arch,'include','petscfix.h') 935 self.framework.pkgheader = os.path.join(self.arch.arch,'include','petscpkg_version.h') 936 self.framework.makeMacroHeader = os.path.join(self.arch.arch,'lib','petsc','conf','petscvariables') 937 self.framework.makeRuleHeader = os.path.join(self.arch.arch,'lib','petsc','conf','petscrules') 938 if self.libraries.math is None: 939 raise RuntimeError('PETSc requires a functional math library. Please send configure.log to petsc-maint@mcs.anl.gov.') 940 if self.languages.clanguage == 'Cxx' and not hasattr(self.compilers, 'CXX'): 941 raise RuntimeError('Cannot set C language to C++ without a functional C++ compiler.') 942 self.executeTest(self.configureRTLDDefault) 943 self.executeTest(self.configurePrefetch) 944 self.executeTest(self.configureUnused) 945 self.executeTest(self.configureDeprecated) 946 self.executeTest(self.configureIsatty) 947 self.executeTest(self.configureExpect) 948 self.executeTest(self.configureAlign) 949 self.executeTest(self.configureFunctionName) 950 self.executeTest(self.configureIntptrt) 951 self.executeTest(self.configureSolaris) 952 self.executeTest(self.configureLinux) 953 self.executeTest(self.configureWin32) 954 self.executeTest(self.configureCygwinBrokenPipe) 955 self.executeTest(self.configureDefaultArch) 956 self.executeTest(self.configureScript) 957 self.executeTest(self.configureInstall) 958 self.executeTest(self.configureGCOV) 959 self.executeTest(self.configureAtoll) 960 961 self.Dump() 962 self.dumpConfigInfo() 963 self.dumpMachineInfo() 964 # need to save the current state of BuildSystem so that postProcess() packages can read it in and perhaps run make install 965 self.framework.storeSubstitutions(self.framework.argDB) 966 self.framework.argDB['configureCache'] = pickle.dumps(self.framework) 967 self.framework.argDB.save(force = True) 968 self.DumpPkgconfig('PETSc.pc') 969 self.DumpPkgconfig('petsc.pc') 970 self.DumpModule() 971 self.postProcessPackages() 972 self.framework.log.write('================================================================================\n') 973 self.logClear() 974 return 975