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 petsc_configure(configure_options): 47 # If PETSC_ARCH not already defined, check if the script name is different then configure 48 # (if so, use this name). Or else - get a name of the config/configure_arch.py 49 found = 0 50 for name in configure_options: 51 if name.startswith('-PETSC_ARCH'): 52 found = 1 53 break 54 if not found and getarch(): configure_options.append('-PETSC_ARCH='+getarch()) 55 56 # support a few standard configure option types 57 for l in range(0,len(sys.argv)-1): 58 name = sys.argv[l] 59 if name.startswith('--enable'): 60 sys.argv[l] = name.replace('--enable','--with') 61 if name.find('=') == -1: sys.argv[l] += '=1' 62 if name.startswith('--disable'): 63 sys.argv[l] = name.replace('--disable','--with') 64 if name.find('=') == -1: sys.argv[l] += '=0' 65 elif name.endswith('=1'): sys.argv[l].replace('=1','=0') 66 if name.startswith('--without'): 67 sys.argv[l] = name.replace('--without','--with') 68 if name.find('=') == -1: sys.argv[l] += '=0' 69 elif name.endswith('=1'): sys.argv[l].replace('=1','=0') 70 71 # Disable threads on RHL9 72 if rhl9(): 73 sys.argv.append('--useThreads=0') 74 print ' *** RHL9 detected. Threads do not work correctly with this distribution ***' 75 print ' ******** Disabling thread usage for this run of config/configure.py *****' 76 77 # Check for broken cygwin 78 if chkcygwin(): 79 print ' *** cygwin-1.5.11-1 detected. config/configure.py fails with this version ***' 80 print ' *** Please upgrade to cygwin-1.5.12-1 or newer version. This can ***' 81 print ' *** be done by running cygwin-setup, selecting "next" all the way.***' 82 sys.exit(3) 83 84 # Should be run from the toplevel 85 pythonDir = os.path.abspath(os.path.join('python')) 86 bsDir = os.path.join(pythonDir, 'BuildSystem') 87 if not os.path.isdir(pythonDir): 88 raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.')) 89 if not os.path.isdir(bsDir): 90 print '''++ Could not locate BuildSystem in $PETSC_DIR/python.''' 91 print '''++ Downloading it using "bk clone bk://sidl.bkbits.net/BuildSystem $PETSC_DIR/python/BuildSystem"''' 92 (status,output) = commands.getstatusoutput('bk clone bk://sidl.bkbits.net/BuildSystem python/BuildSystem') 93 if status: 94 if output.find('ommand not found') >= 0: 95 print '''** Unable to locate bk (Bitkeeper) to download BuildSystem; make sure bk is in your path''' 96 print '''** or manually copy BuildSystem to $PETSC_DIR/python/BuildSystem from a machine where''' 97 print '''** you do have bk installed and can clone BuildSystem. ''' 98 elif output.find('Cannot resolve host') >= 0: 99 print '''** Unable to download BuildSystem. You must be off the network.''' 100 print '''** Connect to the internet and run config/configure.py again.''' 101 else: 102 print '''** Unable to download BuildSystem. Please send this message to petsc-maint@mcs.anl.gov''' 103 print output 104 sys.exit(3) 105 106 sys.path.insert(0, bsDir) 107 sys.path.insert(0, pythonDir) 108 import config.framework 109 import cPickle 110 111 print '=================================================================================' 112 print ' Configuring PETSc to compile on your system ' 113 print '=================================================================================' 114 framework = config.framework.Framework(sys.argv[1:]+['-configModules=PETSc.Configure']+configure_options, loadArgDB = 0) 115 try: 116 framework.configure(out = sys.stdout) 117 framework.storeSubstitutions(framework.argDB) 118 framework.argDB['configureCache'] = cPickle.dumps(framework) 119 return 0 120 except RuntimeError, e: 121 emsg = str(e) 122 if not emsg.endswith('\n'): emsg += '\n' 123 msg = ' UNABLE to CONFIGURE with GIVEN OPTIONS (see configure.log for details):\n' \ 124 +emsg+'*********************************************************************************\n' 125 se = '' 126 except TypeError, e: 127 emsg = str(e) 128 if not emsg.endswith('\n'): emsg += '\n' 129 msg = ' ERROR in COMMAND LINE ARGUMENT to config/configure.py *****\n' \ 130 +emsg+'*********************************************************************************\n' 131 se = '' 132 except ImportError, e : 133 emsg = str(e) 134 if not emsg.endswith('\n'): emsg += '\n' 135 msg = ' UNABLE to FIND MODULE for config/configure.py *******\n' \ 136 +emsg+'*********************************************************************************\n' 137 se = '' 138 except SystemExit, e: 139 if e.code is None or e.code == 0: 140 return 141 msg = ' CONFIGURATION CRASH (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \ 142 +'\n*********************************************************************************\n' 143 se = str(e) 144 except Exception, e: 145 msg = ' CONFIGURATION CRASH (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \ 146 +'\n*********************************************************************************\n' 147 se = str(e) 148 149 framework.logClear() 150 print msg 151 if hasattr(framework, 'log'): 152 import traceback 153 framework.log.write(msg+se) 154 traceback.print_tb(sys.exc_info()[2], file = framework.log) 155 sys.exit(1) 156 157if __name__ == '__main__': 158 petsc_configure([]) 159 160