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 os.environ['PETSC_ARCH'] = self.framework.argDB['PETSC_ARCH'] 35 if 'with-petsc-arch' in self.framework.argDB: 36 self.arch = self.framework.argDB['with-petsc-arch'] 37 elif 'PETSC_ARCH' in self.framework.argDB: 38 self.arch = self.framework.argDB['PETSC_ARCH'] 39 else: 40 if 'PETSC_ARCH' in os.environ: 41 if not len(os.environ['PETSC_ARCH']): 42 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.') 43 self.arch = os.environ['PETSC_ARCH'] 44 else: 45 import sys 46 self.arch = 'arch-' + sys.platform.replace('cygwin','mswin') 47 # use opt/debug, c/c++ tags.s 48 self.arch+= '-'+self.framework.argDB['with-clanguage'].lower().replace('+','x') 49 if self.framework.argDB['with-debugging']: 50 self.arch += '-debug' 51 else: 52 self.arch += '-opt' 53 if self.arch.find('/') >= 0 or self.arch.find('\\') >= 0: 54 raise RuntimeError('PETSC_ARCH should not contain path characters, but you have specified: '+str(self.arch)) 55 if self.arch.startswith('-'): 56 raise RuntimeError('PETSC_ARCH should not start with "-", but you have specified: '+str(self.arch)) 57 self.archBase = re.sub(r'^(\w+)[-_]?.*$', r'\1', self.arch) 58 self.addDefine('ARCH', '"'+self.arch+'"') 59 return 60 61 def configure(self): 62 self.executeTest(self.configureArchitecture) 63 # required by top-level configure.py 64 self.framework.arch = self.arch 65 return 66