1#!/usr/bin/env python 2import os 3import sys 4import commands 5# to load ~/.pythonrc.py before inserting correct BuildSystem to path 6import user 7extraLogs = [] 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 0 33 34def chkbrokencygwin(): 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 print '=================================================================================' 39 print ' *** cygwin-1.5.11-1 detected. config/configure.py fails with this version ***' 40 print ' *** Please upgrade to cygwin-1.5.12-1 or newer version. This can ***' 41 print ' *** be done by running cygwin-setup, selecting "next" all the way.***' 42 print '=================================================================================' 43 sys.exit(3) 44 return 0 45 46def chkusingwindowspython(): 47 if os.path.exists('/usr/bin/cygcheck.exe') and sys.platform != 'cygwin': 48 print '=================================================================================' 49 print ' *** Non-cygwin python detected. Please rerun config/configure.py with cygwin-python ***' 50 print '=================================================================================' 51 sys.exit(3) 52 return 0 53 54def chkcygwinpythonver(): 55 if os.path.exists('/usr/bin/cygcheck.exe'): 56 buf = os.popen('/usr/bin/cygcheck.exe -c python').read() 57 if (buf.find('2.4') > -1) or (buf.find('2.5') > -1) or (buf.find('2.6') > -1): 58 sys.argv.append('--useThreads=0') 59 extraLogs.append('''\ 60================================================================================ 61** Cygwin-python-2.4/2.5 detected. Threads do not work correctly with this version * 62 ********* Disabling thread usage for this run of config/configure.py ********** 63================================================================================''') 64 return 0 65 66def chkrhl9(): 67 if os.path.exists('/etc/redhat-release'): 68 try: 69 file = open('/etc/redhat-release','r') 70 buf = file.read() 71 file.close() 72 except: 73 # can't read file - assume dangerous RHL9 74 buf = 'Shrike' 75 if buf.find('Shrike') > -1: 76 sys.argv.append('--useThreads=0') 77 extraLogs.append('''\ 78================================================================================ 79 *** RHL9 detected. Threads do not work correctly with this distribution *** 80 ****** Disabling thread usage for this run of config/configure.py ******* 81================================================================================''') 82 return 0 83 84def petsc_configure(configure_options): 85 print '=================================================================================' 86 print ' Configuring PETSc to compile on your system ' 87 print '=================================================================================' 88 89 # Command line arguments take precedence (but don't destroy argv[0]) 90 sys.argv = sys.argv[:1] + configure_options + sys.argv[1:] 91 # check PETSC_ARCH 92 check_petsc_arch(sys.argv) 93 94 # support a few standard configure option types 95 for l in range(0,len(sys.argv)): 96 name = sys.argv[l] 97 if name.find('enable-') >= 0: 98 if name.find('=') == -1: 99 sys.argv[l] = name.replace('enable-','with-')+'=1' 100 else: 101 head, tail = name.split('=', 1) 102 sys.argv[l] = head.replace('enable-','with-')+'='+tail 103 if name.find('disable-') >= 0: 104 if name.find('=') == -1: 105 sys.argv[l] = name.replace('disable-','with-')+'=0' 106 else: 107 head, tail = name.split('=', 1) 108 if tail == '1': tail = '0' 109 sys.argv[l] = head.replace('disable-','with-')+'='+tail 110 if name.find('without-') >= 0: 111 if name.find('=') == -1: 112 sys.argv[l] = name.replace('without-','with-')+'=0' 113 else: 114 head, tail = name.split('=', 1) 115 if tail == '1': tail = '0' 116 sys.argv[l] = head.replace('without-','with-')+'='+tail 117 118 # Check for broken cygwin 119 chkbrokencygwin() 120 # Disable threads on RHL9 121 chkrhl9() 122 # Make sure cygwin-python is used on windows 123 chkusingwindowspython() 124 # Threads don't work for cygwin & python-2.4, 2.5 etc.. 125 chkcygwinpythonver() 126 127 # Should be run from the toplevel 128 configDir = os.path.abspath('config') 129 bsDir = os.path.join(configDir, 'BuildSystem') 130 if not os.path.isdir(configDir): 131 raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.')) 132 if not os.path.isdir(bsDir): 133 print '=================================================================================' 134 print '''++ Could not locate BuildSystem in %s.''' % configDir 135 print '''++ Downloading it using "hg clone http://hg.mcs.anl.gov/petsc/BuildSystem %s"''' % bsDir 136 print '=================================================================================' 137 (status,output) = commands.getstatusoutput('hg clone http://petsc.cs.iit.edu/petsc/BuildSystem '+ bsDir) 138 if status: 139 if output.find('ommand not found') >= 0: 140 print '=================================================================================' 141 print '''** Unable to locate hg (Mercurial) to download BuildSystem; make sure hg is in your path''' 142 print '''** or manually copy BuildSystem to $PETSC_DIR/config/BuildSystem from a machine where''' 143 print '''** you do have hg installed and can clone BuildSystem. ''' 144 print '=================================================================================' 145 elif output.find('Cannot resolve host') >= 0: 146 print '=================================================================================' 147 print '''** Unable to download BuildSystem. You must be off the network.''' 148 print '''** Connect to the internet and run config/configure.py again.''' 149 print '=================================================================================' 150 else: 151 print '=================================================================================' 152 print '''** Unable to download BuildSystem. Please send this message to petsc-maint@mcs.anl.gov''' 153 print '=================================================================================' 154 print output 155 sys.exit(3) 156 157 sys.path.insert(0, bsDir) 158 sys.path.insert(0, configDir) 159 import config.base 160 import config.framework 161 import cPickle 162 163 # Disable shared libraries by default 164 import nargs 165 if nargs.Arg.findArgument('with-shared', sys.argv[1:]) is None: 166 sys.argv.append('--with-shared=0') 167 168 framework = None 169 try: 170 framework = config.framework.Framework(['--configModules=PETSc.Configure','--optionsModule=PETSc.compilerOptions']+sys.argv[1:], loadArgDB = 0) 171 framework.setup() 172 framework.logPrint('\n'.join(extraLogs)) 173 framework.configure(out = sys.stdout) 174 framework.storeSubstitutions(framework.argDB) 175 framework.argDB['configureCache'] = cPickle.dumps(framework) 176 import PETSc.packages 177 for i in framework.packages: 178 if hasattr(i,'postProcess'): 179 i.postProcess() 180 framework.logClear() 181 framework.closeLog() 182 if hasattr(framework, 'arch'): 183 import shutil 184 shutil.move(framework.logName,os.path.join(framework.arch,'conf',framework.logName)) 185 return 0 186 except (RuntimeError, config.base.ConfigureSetupError), e: 187 emsg = str(e) 188 if not emsg.endswith('\n'): emsg = emsg+'\n' 189 msg ='*********************************************************************************\n'\ 190 +' UNABLE to CONFIGURE with GIVEN OPTIONS (see configure.log for details):\n' \ 191 +'---------------------------------------------------------------------------------------\n' \ 192 +emsg+'*********************************************************************************\n' 193 se = '' 194 except (TypeError, ValueError), e: 195 emsg = str(e) 196 if not emsg.endswith('\n'): emsg = emsg+'\n' 197 msg ='*********************************************************************************\n'\ 198 +' ERROR in COMMAND LINE ARGUMENT to config/configure.py \n' \ 199 +'---------------------------------------------------------------------------------------\n' \ 200 +emsg+'*********************************************************************************\n' 201 se = '' 202 except ImportError, e : 203 emsg = str(e) 204 if not emsg.endswith('\n'): emsg = emsg+'\n' 205 msg ='*********************************************************************************\n'\ 206 +' UNABLE to FIND MODULE for config/configure.py \n' \ 207 +'---------------------------------------------------------------------------------------\n' \ 208 +emsg+'*********************************************************************************\n' 209 se = '' 210 except OSError, e : 211 emsg = str(e) 212 if not emsg.endswith('\n'): emsg = emsg+'\n' 213 msg ='*********************************************************************************\n'\ 214 +' UNABLE to EXECUTE BINARIES for config/configure.py \n' \ 215 +'---------------------------------------------------------------------------------------\n' \ 216 +emsg+'*********************************************************************************\n' 217 se = '' 218 except SystemExit, e: 219 if e.code is None or e.code == 0: 220 return 221 msg ='*********************************************************************************\n'\ 222 +' CONFIGURATION CRASH (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \ 223 +'*********************************************************************************\n' 224 se = str(e) 225 except Exception, e: 226 msg ='*********************************************************************************\n'\ 227 +' CONFIGURATION CRASH (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \ 228 +'*********************************************************************************\n' 229 se = str(e) 230 231 print msg 232 if not framework is None: 233 framework.logClear() 234 if hasattr(framework, 'log'): 235 import traceback 236 framework.log.write(msg+se) 237 traceback.print_tb(sys.exc_info()[2], file = framework.log) 238 sys.exit(1) 239 else: 240 print se 241 import traceback 242 traceback.print_tb(sys.exc_info()[2]) 243 244if __name__ == '__main__': 245 petsc_configure([]) 246 247