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