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 configure ***********' 9 print '* Python is easy to install for end users or sys-admin. We urge you to upgrade *' 10 print '* http://www.python.org/download/ *' 11 print '* *' 12 print '* You can configure PETSc manually BUT please, please consider upgrading python *' 13 print '* http://www.mcs.anl.gov/petsc/petsc-2/documentation/installation.html#Manual *' 14 print '*********************************************************************************' 15 sys.exit(4) 16 17def check_petsc_arch(opts): 18 # Check for PETSC_ARCH in the following order: 19 # 1. command-line (first occurance) 20 # 2. specified in configure_options(in script) 21 # 3. script name (if not configure.py) 22 23 useName = '' 24 for name in opts: 25 if name.startswith('-PETSC_ARCH'): 26 useName = name 27 break 28 # look for duplicates - and remove them 29 dupnames = [] 30 if useName: 31 for name in opts: 32 if name.startswith('-PETSC_ARCH') and name != useName: 33 opts.remove(name) 34 dupnames.append(name) 35 # print warning for duplicates 36 if dupnames: 37 print '*********************************************************************************' 38 print 'Warning: The following duplicate PETSC_ARCH options are removed:', dupnames 39 print 'Warning: Using the option:', useName 40 print '*********************************************************************************' 41 # If not yet specified - use the filename of script 42 if not useName: 43 filename = os.path.basename(sys.argv[0]) 44 if not filename.startswith('configure'): 45 useName = '-PETSC_ARCH='+os.path.splitext(os.path.basename(sys.argv[0]))[0] 46 opts.append(useName) 47 return 48 49def chkcygwin(): 50 if os.path.exists('/usr/bin/cygcheck.exe'): 51 buf = os.popen('/usr/bin/cygcheck.exe -c cygwin').read() 52 if buf.find('1.5.11-1') > -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 sys.argv += configure_options 80 # check PETSC_ARCH 81 check_petsc_arch(sys.argv) 82 83 # support a few standard configure option types 84 for l in range(0,len(sys.argv)-1): 85 name = sys.argv[l] 86 if name.startswith('--enable'): 87 sys.argv[l] = name.replace('--enable','--with') 88 if name.find('=') == -1: sys.argv[l] += '=1' 89 if name.startswith('--disable'): 90 sys.argv[l] = name.replace('--disable','--with') 91 if name.find('=') == -1: sys.argv[l] += '=0' 92 elif name.endswith('=1'): sys.argv[l].replace('=1','=0') 93 if name.startswith('--without'): 94 sys.argv[l] = name.replace('--without','--with') 95 if name.find('=') == -1: sys.argv[l] += '=0' 96 elif name.endswith('=1'): sys.argv[l].replace('=1','=0') 97 98 # Disable threads on RHL9 99 if rhl9(): 100 sys.argv.append('--useThreads=0') 101 print ' *** RHL9 detected. Disabling threads in configure *****' 102 103 # Check for broken cygwin 104 if chkcygwin(): 105 print ' *** cygwin-1.5.11-1 detected. configure fails with this version ***' 106 print ' *** Please upgrade to cygwin-1.5.12-1 or newer version. This can ***' 107 print ' *** be done by running cygwin-setup, selecting "next" all the way.***' 108 sys.exit(3) 109 110 # Should be run from the toplevel 111 pythonDir = os.path.abspath(os.path.join('python')) 112 bsDir = os.path.join(pythonDir, 'BuildSystem') 113 if not os.path.isdir(pythonDir): 114 raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.')) 115 if not os.path.isdir(bsDir): 116 print '''++ Could not locate BuildSystem in $PETSC_DIR/python.''' 117 print '''++ Downloading it using "bk clone bk://sidl.bkbits.net/BuildSystem $PETSC_DIR/python/BuildSystem"''' 118 (status,output) = commands.getstatusoutput('bk clone bk://sidl.bkbits.net/BuildSystem python/BuildSystem') 119 if status: 120 if output.find('ommand not found') >= 0: 121 print '''** Unable to locate bk (Bitkeeper) to download BuildSystem; make sure bk is in your path''' 122 print '''** or manually copy BuildSystem to $PETSC_DIR/python/BuildSystem from a machine where''' 123 print '''** you do have bk installed and can clone BuildSystem. ''' 124 elif output.find('Cannot resolve host') >= 0: 125 print '''** Unable to download BuildSystem. You must be off the network.''' 126 print '''** Connect to the internet and run config/configure.py again.''' 127 else: 128 print '''** Unable to download BuildSystem. Please send this message to petsc-maint@mcs.anl.gov''' 129 print output 130 sys.exit(3) 131 132 sys.path.insert(0, bsDir) 133 sys.path.insert(0, pythonDir) 134 import config.framework 135 import cPickle 136 137 framework = config.framework.Framework(sys.argv[1:]+['-configModules=PETSc.Configure'], loadArgDB = 0) 138 try: 139 framework.configure(out = sys.stdout) 140 framework.storeSubstitutions(framework.argDB) 141 framework.argDB['configureCache'] = cPickle.dumps(framework) 142 return 0 143 except RuntimeError, e: 144 msg = '***** Unable to configure with given options ***** (see configure.log for full details):\n' \ 145 +str(e)+'\n******************************************************\n' 146 se = '' 147 except TypeError, e: 148 msg = '***** Error in command line argument to configure.py *****\n' \ 149 +str(e)+'\n******************************************************\n' 150 se = '' 151 except ImportError, e: 152 msg = '******* Unable to find module for configure.py *******\n' \ 153 +str(e)+'\n******************************************************\n' 154 se = '' 155 except SystemExit, e: 156 if e.code is None or e.code == 0: 157 return 158 msg = '*** CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n' 159 se = str(e) 160 except Exception, e: 161 msg = '*** CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n' 162 se = str(e) 163 164 print msg 165 if hasattr(framework, 'log'): 166 import traceback 167 framework.log.write(msg+se) 168 traceback.print_tb(sys.exc_info()[2], file = framework.log) 169 sys.exit(1) 170 171if __name__ == '__main__': 172 petsc_configure([]) 173 174