1*9d310bb7SBarry Smithimport config.base 2*9d310bb7SBarry Smithimport os 3*9d310bb7SBarry Smithimport re 4*9d310bb7SBarry Smith 5*9d310bb7SBarry Smithclass Configure(config.base.Configure): 6*9d310bb7SBarry Smith def __init__(self, framework): 7*9d310bb7SBarry Smith config.base.Configure.__init__(self, framework) 8*9d310bb7SBarry Smith self.headerPrefix = 'PETSC' 9*9d310bb7SBarry Smith self.substPrefix = 'PETSC' 10*9d310bb7SBarry Smith self.isPetsc = 1 11*9d310bb7SBarry Smith return 12*9d310bb7SBarry Smith 13*9d310bb7SBarry Smith def __str1__(self): 14*9d310bb7SBarry Smith if hasattr(self, 'dir'): 15*9d310bb7SBarry Smith return ' PETSC_DIR: '+str(self.dir)+'\n' 16*9d310bb7SBarry Smith return '' 17*9d310bb7SBarry Smith 18*9d310bb7SBarry Smith def setupHelp(self, help): 19*9d310bb7SBarry Smith import nargs 20*9d310bb7SBarry Smith help.addArgument('PETSc', '-PETSC_DIR=<root-dir>', nargs.Arg(None, None, 'The root directory of the PETSc installation')) 21*9d310bb7SBarry Smith return 22*9d310bb7SBarry Smith 23*9d310bb7SBarry Smith def configureDirectories(self): 24*9d310bb7SBarry Smith '''Checks PETSC_DIR and sets if not set''' 25*9d310bb7SBarry Smith if 'PETSC_DIR' in self.framework.argDB: 26*9d310bb7SBarry Smith self.dir = self.framework.argDB['PETSC_DIR'] 27*9d310bb7SBarry Smith if self.dir == 'pwd': 28*9d310bb7SBarry Smith raise RuntimeError('You have set -PETSC_DIR=pwd, you need to use back quotes around the pwd\n like -PETSC_DIR=`pwd`') 29*9d310bb7SBarry Smith if not os.path.isdir(self.dir): 30*9d310bb7SBarry Smith raise RuntimeError('The value you set with -PETSC_DIR='+self.dir+' is not a directory') 31*9d310bb7SBarry Smith elif 'PETSC_DIR' in os.environ: 32*9d310bb7SBarry Smith self.dir = os.environ['PETSC_DIR'] 33*9d310bb7SBarry Smith if self.dir == 'pwd': 34*9d310bb7SBarry Smith raise RuntimeError(''' 35*9d310bb7SBarry SmithThe environmental variable PETSC_DIR is set incorrectly. Please use the following: [notice backquotes] 36*9d310bb7SBarry Smith For sh/bash : PETSC_DIR=`pwd`; export PETSC_DIR 37*9d310bb7SBarry Smith for csh/tcsh : setenv PETSC_DIR `pwd`''') 38*9d310bb7SBarry Smith elif not os.path.isdir(self.dir): 39*9d310bb7SBarry Smith raise RuntimeError('The environmental variable PETSC_DIR '+self.dir+' is not a directory') 40*9d310bb7SBarry Smith else: 41*9d310bb7SBarry Smith self.dir = os.getcwd() 42*9d310bb7SBarry Smith if self.isPetsc and not os.path.realpath(self.dir) == os.path.realpath(os.getcwd()): 43*9d310bb7SBarry Smith raise RuntimeError('The environmental variable PETSC_DIR '+self.dir+' MUST be the current directory '+os.getcwd()) 44*9d310bb7SBarry Smith self.version = 'Unknown' 45*9d310bb7SBarry Smith versionHeader = os.path.join(self.dir, 'include', 'petscversion.h') 46*9d310bb7SBarry Smith versionInfo = [] 47*9d310bb7SBarry Smith if os.path.exists(versionHeader): 48*9d310bb7SBarry Smith f = file(versionHeader) 49*9d310bb7SBarry Smith for line in f: 50*9d310bb7SBarry Smith if line.find('define PETSC_VERSION') >= 0: 51*9d310bb7SBarry Smith versionInfo.append(line[:-1]) 52*9d310bb7SBarry Smith f.close() 53*9d310bb7SBarry Smith else: 54*9d310bb7SBarry Smith raise RuntimeError('Invalid PETSc directory '+str(self.dir)+'. Could not locate '+versionHeader) 55*9d310bb7SBarry Smith self.version = '.'.join([line.split(' ')[-1] for line in versionInfo[1:4]]) 56*9d310bb7SBarry Smith self.logPrint('Version Information:') 57*9d310bb7SBarry Smith for line in versionInfo: 58*9d310bb7SBarry Smith self.logPrint(line) 59*9d310bb7SBarry Smith self.addMakeMacro('DIR', self.dir) 60*9d310bb7SBarry Smith self.framework.argDB['search-dirs'].append(os.path.join(self.dir, 'bin', 'win32fe')) 61*9d310bb7SBarry Smith 62*9d310bb7SBarry Smith return 63*9d310bb7SBarry Smith 64*9d310bb7SBarry Smith def configure(self): 65*9d310bb7SBarry Smith self.executeTest(self.configureDirectories) 66*9d310bb7SBarry Smith return 67