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 configureArchitecture(self): 26 '''Checks PETSC_ARCH and sets if not set''' 27 28 29 # Warn if PETSC_ARCH doesnt match env variable 30 if 'PETSC_ARCH' in self.framework.argDB and 'PETSC_ARCH' in os.environ and self.framework.argDB['PETSC_ARCH'] != os.environ['PETSC_ARCH']: 31 self.logPrintBox('''\ 32Warning: PETSC_ARCH from environment does not match command-line or name of script. 33Warning: Using from command-line or name of script: %s, ignoring environment: %s''' % (str(self.framework.argDB['PETSC_ARCH']), str(os.environ['PETSC_ARCH']))) 34 if 'with-petsc-arch' in self.framework.argDB: 35 self.arch = self.framework.argDB['with-petsc-arch'] 36 elif 'PETSC_ARCH' in self.framework.argDB: 37 self.arch = self.framework.argDB['PETSC_ARCH'] 38 else: 39 if 'PETSC_ARCH' in os.environ: 40 if not len(os.environ['PETSC_ARCH']): 41 raise RuntimeError('PETSC_ARCH is the empty string in your environment. It must either be a valid string, or not be defined in the environment at all.') 42 self.arch = os.environ['PETSC_ARCH'] 43 else: 44 import sys 45 self.arch = 'arch-' + sys.platform.replace('cygwin','mswin') 46 # use opt/debug, c/c++ tags.s 47 self.arch+= '-'+self.framework.argDB['with-clanguage'].lower().replace('+','x') 48 if self.framework.argDB['with-debugging']: 49 self.arch += '-debug' 50 else: 51 self.arch += '-opt' 52 if self.arch.find('/') >= 0 or self.arch.find('\\') >= 0: 53 raise RuntimeError('PETSC_ARCH should not contain path characters, but you have specified: '+str(self.arch)) 54 self.archBase = re.sub(r'^(\w+)[-_]?.*$', r'\1', self.arch) 55 self.addDefine('ARCH', '"'+self.arch+'"') 56 return 57 58 def configure(self): 59 self.executeTest(self.configureArchitecture) 60 # required by top-level configure.py 61 self.framework.arch = self.arch 62 return 63