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