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