1#!/usr/bin/env python 2import os 3import sys 4import commands 5 6 7if not hasattr(sys, 'version_info') or not sys.version_info[1] >= 2: 8 print '********* You must have Python version 2.2 or higher to run configure ***********' 9 print '* Python is easy to install for end users or sys-admin. We urge you to upgrade *' 10 print '* http://www.python.org/download/ *' 11 print '* *' 12 print '* You can configure PETSc manually BUT please, please consider upgrading python *' 13 print '* http://www.mcs.anl.gov/petsc/petsc-2/documentation/installation.html#Manual *' 14 print '*********************************************************************************' 15 sys.exit(4) 16 17def getarch(): 18 if os.path.basename(sys.argv[0]).startswith('configure'): return '' 19 else: return os.path.basename(sys.argv[0])[:-3] 20 21def fixWin32Flinker(filename): 22 '''Change CXX_FLINKER back to f90 for win32 (from cl)''' 23 import fileinput 24 import re 25 26 reglink = re.compile('CXX_FLINKER ') 27 regwin32fe = re.compile('win32fe',re.I) 28 regcl = re.compile('cl',re.I) 29 30 for line in fileinput.input(filename,inplace=1): 31 fl = reglink.search(line) 32 fw = regwin32fe.search(line) 33 if fl and fw: 34 line = regcl.sub('f90',line) 35 print line, 36 return 37 38def petsc_configure(configure_options): 39 # use the name of the config/configure_arch.py to determine the arch 40 if getarch(): configure_options.append('-PETSC_ARCH='+getarch()) 41 42 # Should be run from the toplevel 43 pythonDir = os.path.abspath(os.path.join('python')) 44 bsDir = os.path.join(pythonDir, 'BuildSystem') 45 if not os.path.isdir(pythonDir): 46 raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.')) 47 if not os.path.isdir(bsDir): 48 print '''++ Could not locate BuildSystem in $PETSC_DIR/python.''' 49 print '''++ Downloading it using "bk clone bk://sidl.bkbits.net/BuildSystem $PETSC_DIR/python/BuildSystem"''' 50 (status,output) = commands.getstatusoutput('bk clone bk://sidl.bkbits.net/BuildSystem python/BuildSystem') 51 if status: 52 if output.find('ommand not found') >= 0: 53 print '''** Unable to locate bk (Bitkeeper) to download BuildSystem; make sure bk is in your path''' 54 print '''** or manually copy BuildSystem to $PETSC_DIR/python/BuildSystem from a machine where''' 55 print '''** you do have bk installed and can clone BuildSystem. ''' 56 elif output.find('Cannot resolve host') >= 0: 57 print '''** Unable to download BuildSystem. You must be off the network.''' 58 print '''** Connect to the internet and run config/configure.py again.''' 59 else: 60 print '''** Unable to download BuildSystem. Please send this message to petsc-maint@mcs.anl.gov''' 61 print output 62 sys.exit(3) 63 64 sys.path.insert(0, bsDir) 65 sys.path.insert(0, pythonDir) 66 import config.framework 67 import cPickle 68 69 framework = config.framework.Framework(sys.argv[1:]+['-configModules=PETSc.Configure']+configure_options, loadArgDB = 0) 70 try: 71 framework.configure(out = sys.stdout) 72 framework.storeSubstitutions(framework.argDB) 73 framework.argDB['configureCache'] = cPickle.dumps(framework) 74 fixWin32Flinker('bmake/'+framework.argDB['PETSC_ARCH']+'/variables') 75 return 0 76 except RuntimeError, e: 77 msg = '***** Unable to configure with given options ***** (see configure.log for full details):\n' \ 78 +str(e)+'\n******************************************************\n' 79 se = '' 80 except TypeError, e: 81 msg = '***** Error in command line argument to configure.py *****\n' \ 82 +str(e)+'\n******************************************************\n' 83 se = '' 84 except SystemExit, e: 85 if e.code is None or e.code == 0: 86 return 87 msg = '*** CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n' 88 se = str(e) 89 except Exception, e: 90 msg = '*** CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n' 91 se = str(e) 92 93 print msg 94 if hasattr(framework, 'log'): 95 import traceback 96 framework.log.write(msg+se) 97 traceback.print_tb(sys.exc_info()[2], file = framework.log) 98 sys.exit(1) 99 100if __name__ == '__main__': 101 petsc_configure([]) 102 103