1import config.base 2import os 3import re 4 5class Configure(config.base.Configure): 6 def __init__(self, framework): 7 config.base.Configure.__init__(self, framework) 8 self.headerPrefix = 'PETSC' 9 self.substPrefix = 'PETSC' 10 return 11 12 def __str1__(self): 13 if not hasattr(self, 'arch'): 14 return '' 15 desc = ['PETSc:'] 16 desc.append(' PETSC_ARCH: '+str(self.arch)) 17 return '\n'.join(desc)+'\n' 18 19 def setupHelp(self, help): 20 import nargs 21 help.addArgument('PETSc', '-PETSC_ARCH=<string>', nargs.Arg(None, None, 'The configuration name')) 22 help.addArgument('PETSc', '-with-petsc-arch=<string>',nargs.Arg(None, None, 'The configuration name')) 23 return 24 25 def createArchitecture(self): 26 import sys 27 arch = 'arch-' + sys.platform.replace('cygwin','mswin') 28 # use opt/debug, c/c++ tags.s 29 arch+= '-'+self.framework.argDB['with-clanguage'].lower().replace('+','x') 30 if self.framework.argDB['with-debugging']: 31 arch += '-debug' 32 else: 33 arch += '-opt' 34 return arch 35 36 def configureArchitecture(self): 37 '''Checks PETSC_ARCH and sets if not set''' 38 # Warn if PETSC_ARCH doesnt match env variable 39 if 'PETSC_ARCH' in self.framework.argDB and 'PETSC_ARCH' in os.environ and self.framework.argDB['PETSC_ARCH'] != os.environ['PETSC_ARCH']: 40 self.logPrintBox('''\ 41Warning: PETSC_ARCH from environment does not match command-line or name of script. 42Warning: Using from command-line or name of script: %s, ignoring environment: %s''' % (str(self.framework.argDB['PETSC_ARCH']), str(os.environ['PETSC_ARCH']))) 43 os.environ['PETSC_ARCH'] = self.framework.argDB['PETSC_ARCH'] 44 if 'with-petsc-arch' in self.framework.argDB: 45 self.arch = self.framework.argDB['with-petsc-arch'] 46 msg = 'option -with-petsc-arch='+str(self.arch) 47 elif 'PETSC_ARCH' in self.framework.argDB: 48 self.arch = self.framework.argDB['PETSC_ARCH'] 49 msg = 'option PETSC_ARCH='+str(self.arch) 50 elif 'PETSC_ARCH' in os.environ: 51 self.arch = os.environ['PETSC_ARCH'] 52 msg = 'environment variable PETSC_ARCH='+str(self.arch) 53 else: 54 self.arch = self.createArchitecture() 55 if self.arch.find('/') >= 0 or self.arch.find('\\') >= 0: 56 raise RuntimeError('PETSC_ARCH should not contain path characters, but you have specified with '+msg) 57 if self.arch.startswith('-'): 58 raise RuntimeError('PETSC_ARCH should not start with "-", but you have specified with '+msg) 59 if self.arch.startswith('.'): 60 raise RuntimeError('PETSC_ARCH should not start with ".", but you have specified with '+msg) 61 if not len(self.arch): 62 raise RuntimeError('PETSC_ARCH cannot be empty string. Use a valid string or do not set one. Currently set with '+msg) 63 self.archBase = re.sub(r'^(\w+)[-_]?.*$', r'\1', self.arch) 64 self.addDefine('ARCH', '"'+self.arch+'"') 65 return 66 67 def configure(self): 68 self.executeTest(self.configureArchitecture) 69 # required by top-level configure.py 70 self.framework.arch = self.arch 71 return 72