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 chkcygwin(): 22 if os.path.exists('/usr/bin/cygcheck.exe'): 23 buf = os.popen('/usr/bin/cygcheck.exe -c cygwin').read() 24 if buf.find('1.5.11-1') > -1: 25 return 1 26 else: 27 return 0 28 return 0 29 30def rhl9(): 31 try: 32 file = open('/etc/redhat-release','r') 33 except: 34 return 0 35 try: 36 buf = file.read() 37 file.close() 38 except: 39 # can't read file - assume dangerous RHL9 40 return 1 41 if buf.find('Shrike') > -1: 42 return 1 43 else: 44 return 0 45 46def fixWin32Flinker(filename): 47 '''Change CXX_FLINKER back to f90 for win32 (from cl)''' 48 import fileinput 49 import re 50 51 reglink = re.compile('CXX_FLINKER ') 52 regwin32fe = re.compile('win32fe',re.I) 53 regcl = re.compile('cl',re.I) 54 55 for line in fileinput.input(filename,inplace=1): 56 fl = reglink.search(line) 57 fw = regwin32fe.search(line) 58 if fl and fw: 59 line = regcl.sub('f90',line) 60 print line, 61 return 62 63def petsc_configure(configure_options): 64 # use the name of the config/configure_arch.py to determine the arch 65 if getarch(): configure_options.append('-PETSC_ARCH='+getarch()) 66 67 # Disable threads on RHL9 68 if rhl9(): 69 sys.argv.append('--useThreads=0') 70 print ' *** RHL9 detected. Disabling threads in configure *****' 71 72 # Check for broken cygwin 73 if chkcygwin(): 74 print ' *** cygwin-1.5.11-1 detected. configure fails with this version ***' 75 print ' *** Please downgrade to cygwin-1.5.10-3. This can be done by ***' 76 print ' *** running cygwin setup, and in "up to date" view - click on the ***' 77 print ' *** "cirular arrow" next to "cygwin" until it changes to 1.5.10-3.***' 78 sys.exit(3) 79 80 # Should be run from the toplevel 81 pythonDir = os.path.abspath(os.path.join('python')) 82 bsDir = os.path.join(pythonDir, 'BuildSystem') 83 if not os.path.isdir(pythonDir): 84 raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.')) 85 if not os.path.isdir(bsDir): 86 print '''++ Could not locate BuildSystem in $PETSC_DIR/python.''' 87 print '''++ Downloading it using "bk clone bk://sidl.bkbits.net/BuildSystem $PETSC_DIR/python/BuildSystem"''' 88 (status,output) = commands.getstatusoutput('bk clone bk://sidl.bkbits.net/BuildSystem python/BuildSystem') 89 if status: 90 if output.find('ommand not found') >= 0: 91 print '''** Unable to locate bk (Bitkeeper) to download BuildSystem; make sure bk is in your path''' 92 print '''** or manually copy BuildSystem to $PETSC_DIR/python/BuildSystem from a machine where''' 93 print '''** you do have bk installed and can clone BuildSystem. ''' 94 elif output.find('Cannot resolve host') >= 0: 95 print '''** Unable to download BuildSystem. You must be off the network.''' 96 print '''** Connect to the internet and run config/configure.py again.''' 97 else: 98 print '''** Unable to download BuildSystem. Please send this message to petsc-maint@mcs.anl.gov''' 99 print output 100 sys.exit(3) 101 102 sys.path.insert(0, bsDir) 103 sys.path.insert(0, pythonDir) 104 import config.framework 105 106 107 framework = config.framework.Framework(sys.argv[1:]+['-configModules=PETSc.Configure']+configure_options, loadArgDB = 0) 108 try: 109 framework.configure(out = sys.stdout) 110 framework.storeSubstitutions(framework.argDB) 111 fixWin32Flinker('bmake/'+framework.argDB['PETSC_ARCH']+'/variables') 112 return 0 113 except RuntimeError, e: 114 msg = '***** Unable to configure with given options ***** (see configure.log for full details):\n' \ 115 +str(e)+'\n******************************************************\n' 116 se = '' 117 except TypeError, e: 118 msg = '***** Error in command line argument to configure.py *****\n' \ 119 +str(e)+'\n******************************************************\n' 120 se = '' 121 except SystemExit, e: 122 if e.code is None or e.code == 0: 123 return 124 msg = '*** CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n' 125 se = str(e) 126 except Exception, e: 127 msg = '*** CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n' 128 se = str(e) 129 130 print msg 131 if hasattr(framework, 'log'): 132 import traceback 133 framework.log.write(msg+se) 134 traceback.print_tb(sys.exc_info()[2], file = framework.log) 135 sys.exit(1) 136 137if __name__ == '__main__': 138 petsc_configure([]) 139 140