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