1#!/usr/bin/env python 2import os 3import sys 4import commands 5# to load ~/.pythonrc.py before inserting correct BuildSystem to path 6import user 7 8 9if not hasattr(sys, 'version_info') or not sys.version_info[1] >= 2 or not sys.version_info[0] >= 2: 10 print '**** You must have Python version 2.2 or higher to run config/configure.py ******' 11 print '* Python is easy to install for end users or sys-admin. *' 12 print '* http://www.python.org/download/ *' 13 print '* *' 14 print '* You CANNOT configure PETSc without Python *' 15 print '* http://www.mcs.anl.gov/petsc/petsc-as/documentation/installation.html *' 16 print '*********************************************************************************' 17 sys.exit(4) 18 19def check_petsc_arch(opts): 20 # If PETSC_ARCH not specified - use script name (if not configure.py) 21 found = 0 22 for name in opts: 23 if name.find('PETSC_ARCH=') >= 0: 24 found = 1 25 break 26 # If not yet specified - use the filename of script 27 if not found: 28 filename = os.path.basename(sys.argv[0]) 29 if not filename.startswith('configure') and not filename.startswith('reconfigure'): 30 useName = 'PETSC_ARCH='+os.path.splitext(os.path.basename(sys.argv[0]))[0] 31 opts.append(useName) 32 return 33 34def chkcygwin(): 35 if os.path.exists('/usr/bin/cygcheck.exe'): 36 buf = os.popen('/usr/bin/cygcheck.exe -c cygwin').read() 37 if buf.find('1.5.11-1') > -1: 38 return 1 39 else: 40 return 0 41 return 0 42 43def chkcygwinpython(): 44 if os.path.exists('/usr/bin/cygcheck.exe'): 45 buf = os.popen('/usr/bin/cygcheck.exe -c python').read() 46 if buf.find('2.4') > -1: 47 return 1 48 else: 49 return 0 50 return 0 51 52def rhl9(): 53 try: 54 file = open('/etc/redhat-release','r') 55 except: 56 return 0 57 try: 58 buf = file.read() 59 file.close() 60 except: 61 # can't read file - assume dangerous RHL9 62 return 1 63 if buf.find('Shrike') > -1: 64 return 1 65 else: 66 return 0 67 68def petsc_configure(configure_options): 69 print '=================================================================================' 70 print ' Configuring PETSc to compile on your system ' 71 print '=================================================================================' 72 73 # Command line arguments take precedence (but don't destroy argv[0]) 74 sys.argv = sys.argv[:1] + configure_options + sys.argv[1:] 75 # check PETSC_ARCH 76 check_petsc_arch(sys.argv) 77 extraLogs = [] 78 79 # support a few standard configure option types 80 for l in range(0,len(sys.argv)): 81 name = sys.argv[l] 82 if name.find('enable-') >= 0: 83 sys.argv[l] = name.replace('enable-','with-') 84 if name.find('=') == -1: sys.argv[l] = sys.argv[l]+'=1' 85 if name.find('disable-') >= 0: 86 sys.argv[l] = name.replace('disable-','with-') 87 if name.find('=') == -1: sys.argv[l] = sys.argv[l]+'=0' 88 elif name.endswith('=1'): sys.argv[l].replace('=1','=0') 89 if name.find('without-') >= 0: 90 sys.argv[l] = name.replace('without-','with-') 91 if name.find('=') == -1: sys.argv[l] = sys.argv[l]+'=0' 92 elif name.endswith('=1'): sys.argv[l].replace('=1','=0') 93 94 # Check for broken cygwin 95 if chkcygwin(): 96 print '=================================================================================' 97 print ' *** cygwin-1.5.11-1 detected. config/configure.py fails with this version ***' 98 print ' *** Please upgrade to cygwin-1.5.12-1 or newer version. This can ***' 99 print ' *** be done by running cygwin-setup, selecting "next" all the way.***' 100 print '=================================================================================' 101 sys.exit(3) 102 103 # Disable threads on RHL9 104 if rhl9(): 105 sys.argv.append('--useThreads=0') 106 extraLogs.append('''\ 107================================================================================ 108 *** RHL9 detected. Threads do not work correctly with this distribution *** 109 ****** Disabling thread usage for this run of config/configure.py ******* 110================================================================================''') 111 112 # Threads don't work for cygwin & python-2.4 113 if chkcygwinpython(): 114 sys.argv.append('--useThreads=0') 115 extraLogs.append('''\ 116================================================================================ 117** Cygwin-python-2.4 detected. Threads do not work correctly with this version * 118 ********* Disabling thread usage for this run of config/configure.py ********** 119================================================================================''') 120 121 # Should be run from the toplevel 122 pythonDir = os.path.abspath(os.path.join('python')) 123 bsDir = os.path.join(pythonDir, 'BuildSystem') 124 if not os.path.isdir(pythonDir): 125 raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.')) 126 if not os.path.isdir(bsDir): 127 print '=================================================================================' 128 print '''++ Could not locate BuildSystem in %s/python.''' % os.getcwd() 129 print '''++ Downloading it using "bk clone http://sidl.bkbits.net/BuildSystem %s/python/BuildSystem"''' % os.getcwd() 130 print '=================================================================================' 131 (status,output) = commands.getstatusoutput('bk clone http://sidl.bkbits.net/BuildSystem python/BuildSystem') 132 if status: 133 if output.find('ommand not found') >= 0: 134 print '=================================================================================' 135 print '''** Unable to locate bk (Bitkeeper) to download BuildSystem; make sure bk is in your path''' 136 print '''** or manually copy BuildSystem to $PETSC_DIR/python/BuildSystem from a machine where''' 137 print '''** you do have bk installed and can clone BuildSystem. ''' 138 print '=================================================================================' 139 elif output.find('Cannot resolve host') >= 0: 140 print '=================================================================================' 141 print '''** Unable to download BuildSystem. You must be off the network.''' 142 print '''** Connect to the internet and run config/configure.py again.''' 143 print '=================================================================================' 144 else: 145 print '=================================================================================' 146 print '''** Unable to download BuildSystem. Please send this message to petsc-maint@mcs.anl.gov''' 147 print '=================================================================================' 148 print output 149 sys.exit(3) 150 151 sys.path.insert(0, bsDir) 152 sys.path.insert(0, pythonDir) 153 import config.framework 154 import cPickle 155 156 # Disable shared libraries by default 157 import nargs 158 if nargs.Arg.findArgument('with-shared', sys.argv[1:]) is None: 159 sys.argv.append('--with-shared=0') 160 161 framework = None 162 try: 163 framework = config.framework.Framework(sys.argv[1:]+['--configModules=PETSc.Configure','--optionsModule=PETSc.compilerOptions'], loadArgDB = 0) 164 framework.setup() 165 framework.logPrint('\n'.join(extraLogs)) 166 framework.configure(out = sys.stdout) 167 framework.storeSubstitutions(framework.argDB) 168 framework.argDB['configureCache'] = cPickle.dumps(framework) 169 import PETSc.packages 170 for i in framework.packages: 171 if hasattr(i,'postProcess'): 172 i.postProcess() 173 framework.logClear() 174 return 0 175 except RuntimeError, e: 176 emsg = str(e) 177 if not emsg.endswith('\n'): emsg = emsg+'\n' 178 msg ='*********************************************************************************\n'\ 179 +' UNABLE to CONFIGURE with GIVEN OPTIONS (see configure.log for details):\n' \ 180 +'---------------------------------------------------------------------------------------\n' \ 181 +emsg+'*********************************************************************************\n' 182 se = '' 183 except (TypeError, ValueError), e: 184 emsg = str(e) 185 if not emsg.endswith('\n'): emsg = emsg+'\n' 186 msg ='*********************************************************************************\n'\ 187 +' ERROR in COMMAND LINE ARGUMENT to config/configure.py \n' \ 188 +'---------------------------------------------------------------------------------------\n' \ 189 +emsg+'*********************************************************************************\n' 190 se = '' 191 except ImportError, e : 192 emsg = str(e) 193 if not emsg.endswith('\n'): emsg = emsg+'\n' 194 msg ='*********************************************************************************\n'\ 195 +' UNABLE to FIND MODULE for config/configure.py \n' \ 196 +'---------------------------------------------------------------------------------------\n' \ 197 +emsg+'*********************************************************************************\n' 198 se = '' 199 except SystemExit, e: 200 if e.code is None or e.code == 0: 201 return 202 msg ='*********************************************************************************\n'\ 203 +' CONFIGURATION CRASH (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \ 204 +'*********************************************************************************\n' 205 se = str(e) 206 except Exception, e: 207 msg ='*********************************************************************************\n'\ 208 +' CONFIGURATION CRASH (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \ 209 +'*********************************************************************************\n' 210 se = str(e) 211 212 print msg 213 if not framework is None: 214 framework.logClear() 215 if hasattr(framework, 'log'): 216 import traceback 217 framework.log.write(msg+se) 218 traceback.print_tb(sys.exc_info()[2], file = framework.log) 219 if os.path.isfile(framework.logName+'.bkp'): 220 framework.logPrintDivider() 221 framework.logPrintBox('Previous configure logs below', debugSection = None) 222 f = file(framework.logName+'.bkp') 223 framework.log.write(f.read()) 224 f.close() 225 sys.exit(1) 226 227if __name__ == '__main__': 228 petsc_configure([]) 229 230