15d5a5a7bSMatthew Knepley#!/usr/bin/env python 25d5a5a7bSMatthew Knepleyimport os 35d5a5a7bSMatthew Knepleyimport sys 44f8a5b45SBarry Smithimport commands 5a1eda5bfSSatish Balay# to load ~/.pythonrc.py before inserting correct BuildSystem to path 6a1eda5bfSSatish Balayimport user 75d5a5a7bSMatthew Knepley 84b8aa89bSBarry Smith 9378f148eSBarry Smithif not hasattr(sys, 'version_info') or not sys.version_info[1] >= 2 or not sys.version_info[0] >= 2: 10495ffa62SBarry Smith print '**** You must have Python version 2.2 or higher to run config/configure.py ******' 11495ffa62SBarry Smith print '* Python is easy to install for end users or sys-admin. *' 1232077d6dSBarry Smith print '* http://www.python.org/download/ *' 1332077d6dSBarry Smith print '* *' 14495ffa62SBarry Smith print '* You CANNOT configure PETSc without Python *' 15495ffa62SBarry Smith print '* http://www.mcs.anl.gov/petsc/petsc-as/documentation/installation.html *' 1632077d6dSBarry Smith print '*********************************************************************************' 17b26a8723SBarry Smith sys.exit(4) 182fb34ac0SMatthew Knepley 1959e9bfd6SSatish Balaydef check_petsc_arch(opts): 20c43ea0feSSatish Balay # If PETSC_ARCH not specified - use script name (if not configure.py) 21c43ea0feSSatish Balay found = 0 2259e9bfd6SSatish Balay for name in opts: 23c43ea0feSSatish Balay if name.find('PETSC_ARCH=') >= 0: 24c43ea0feSSatish Balay found = 1 2559e9bfd6SSatish Balay break 2659e9bfd6SSatish Balay # If not yet specified - use the filename of script 27c43ea0feSSatish Balay if not found: 2859e9bfd6SSatish Balay filename = os.path.basename(sys.argv[0]) 297eed1879SBarry Smith if not filename.startswith('configure') and not filename.startswith('reconfigure'): 30637cc2ebSSatish Balay useName = 'PETSC_ARCH='+os.path.splitext(os.path.basename(sys.argv[0]))[0] 3159e9bfd6SSatish Balay opts.append(useName) 3259e9bfd6SSatish Balay return 334b8aa89bSBarry Smith 349dabcff0SSatish Balaydef chkcygwin(): 359dabcff0SSatish Balay if os.path.exists('/usr/bin/cygcheck.exe'): 369dabcff0SSatish Balay buf = os.popen('/usr/bin/cygcheck.exe -c cygwin').read() 379dabcff0SSatish Balay if buf.find('1.5.11-1') > -1: 389dabcff0SSatish Balay return 1 399dabcff0SSatish Balay else: 409dabcff0SSatish Balay return 0 419dabcff0SSatish Balay return 0 429dabcff0SSatish Balay 4371384062SSatish Balaydef chkcygwinpython(): 4471384062SSatish Balay if os.path.exists('/usr/bin/cygcheck.exe'): 4571384062SSatish Balay buf = os.popen('/usr/bin/cygcheck.exe -c python').read() 4671384062SSatish Balay if buf.find('2.4') > -1: 4771384062SSatish Balay return 1 4871384062SSatish Balay else: 4971384062SSatish Balay return 0 5071384062SSatish Balay return 0 5171384062SSatish Balay 52836c2c52SSatish Balaydef rhl9(): 53836c2c52SSatish Balay try: 54594eb360SSatish Balay file = open('/etc/redhat-release','r') 55836c2c52SSatish Balay except: 56836c2c52SSatish Balay return 0 57836c2c52SSatish Balay try: 58836c2c52SSatish Balay buf = file.read() 59836c2c52SSatish Balay file.close() 60836c2c52SSatish Balay except: 61836c2c52SSatish Balay # can't read file - assume dangerous RHL9 62836c2c52SSatish Balay return 1 63836c2c52SSatish Balay if buf.find('Shrike') > -1: 64836c2c52SSatish Balay return 1 65836c2c52SSatish Balay else: 66836c2c52SSatish Balay return 0 67836c2c52SSatish Balay 685d5a5a7bSMatthew Knepleydef petsc_configure(configure_options): 6959e9bfd6SSatish Balay print '=================================================================================' 7059e9bfd6SSatish Balay print ' Configuring PETSc to compile on your system ' 7159e9bfd6SSatish Balay print '=================================================================================' 7259e9bfd6SSatish Balay 73c43ea0feSSatish Balay # Command line arguments take precedence (but don't destroy argv[0]) 74c43ea0feSSatish Balay sys.argv = sys.argv[:1] + configure_options + sys.argv[1:] 7559e9bfd6SSatish Balay # check PETSC_ARCH 7659e9bfd6SSatish Balay check_petsc_arch(sys.argv) 77d65f3bddSMatthew Knepley extraLogs = [] 785fb2c094SBarry Smith 79c22cdea9SBarry Smith # support a few standard configure option types 80ed6a7445SBarry Smith for l in range(0,len(sys.argv)): 81c22cdea9SBarry Smith name = sys.argv[l] 82637cc2ebSSatish Balay if name.find('enable-') >= 0: 83637cc2ebSSatish Balay sys.argv[l] = name.replace('enable-','with-') 8442351d26SSatish Balay if name.find('=') == -1: sys.argv[l] = sys.argv[l]+'=1' 85637cc2ebSSatish Balay if name.find('disable-') >= 0: 86637cc2ebSSatish Balay sys.argv[l] = name.replace('disable-','with-') 8742351d26SSatish Balay if name.find('=') == -1: sys.argv[l] = sys.argv[l]+'=0' 88c22cdea9SBarry Smith elif name.endswith('=1'): sys.argv[l].replace('=1','=0') 89637cc2ebSSatish Balay if name.find('without-') >= 0: 90637cc2ebSSatish Balay sys.argv[l] = name.replace('without-','with-') 9142351d26SSatish Balay if name.find('=') == -1: sys.argv[l] = sys.argv[l]+'=0' 92c22cdea9SBarry Smith elif name.endswith('=1'): sys.argv[l].replace('=1','=0') 93c22cdea9SBarry Smith 94adc3e427SMatthew Knepley # Check for sudo 95adc3e427SMatthew Knepley if os.getuid() == 0: 96adc3e427SMatthew Knepley print '=================================================================================' 97adc3e427SMatthew Knepley print ' *** Do not run configure as root, or using sudo. ***' 98adc3e427SMatthew Knepley print ' ***** That should be reserved for installation *****' 99adc3e427SMatthew Knepley print '=================================================================================' 100adc3e427SMatthew Knepley sys.exit(3) 101adc3e427SMatthew Knepley 1029dabcff0SSatish Balay # Check for broken cygwin 1039dabcff0SSatish Balay if chkcygwin(): 104ec1ee742SBarry Smith print '=================================================================================' 1057d670a3cSBarry Smith print ' *** cygwin-1.5.11-1 detected. config/configure.py fails with this version ***' 1061e42869aSSatish Balay print ' *** Please upgrade to cygwin-1.5.12-1 or newer version. This can ***' 1071e42869aSSatish Balay print ' *** be done by running cygwin-setup, selecting "next" all the way.***' 108ec1ee742SBarry Smith print '=================================================================================' 1099dabcff0SSatish Balay sys.exit(3) 110d65f3bddSMatthew Knepley 111d65f3bddSMatthew Knepley # Disable threads on RHL9 112d65f3bddSMatthew Knepley if rhl9(): 113d65f3bddSMatthew Knepley sys.argv.append('--useThreads=0') 114d65f3bddSMatthew Knepley extraLogs.append('''\ 115d65f3bddSMatthew Knepley================================================================================ 116d65f3bddSMatthew Knepley *** RHL9 detected. Threads do not work correctly with this distribution *** 117d65f3bddSMatthew Knepley ****** Disabling thread usage for this run of config/configure.py ******* 118d65f3bddSMatthew Knepley================================================================================''') 119d65f3bddSMatthew Knepley 12071384062SSatish Balay # Threads don't work for cygwin & python-2.4 12171384062SSatish Balay if chkcygwinpython(): 12271384062SSatish Balay sys.argv.append('--useThreads=0') 123d65f3bddSMatthew Knepley extraLogs.append('''\ 124d65f3bddSMatthew Knepley================================================================================ 125d65f3bddSMatthew Knepley** Cygwin-python-2.4 detected. Threads do not work correctly with this version * 126d65f3bddSMatthew Knepley ********* Disabling thread usage for this run of config/configure.py ********** 127d65f3bddSMatthew Knepley================================================================================''') 1289dabcff0SSatish Balay 12987282423SMatthew Knepley # Should be run from the toplevel 1305d5a5a7bSMatthew Knepley pythonDir = os.path.abspath(os.path.join('python')) 13187282423SMatthew Knepley bsDir = os.path.join(pythonDir, 'BuildSystem') 13287282423SMatthew Knepley if not os.path.isdir(pythonDir): 1335d5a5a7bSMatthew Knepley raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.')) 13487282423SMatthew Knepley if not os.path.isdir(bsDir): 135ec1ee742SBarry Smith print '=================================================================================' 1369c4310d5SMatthew Knepley print '''++ Could not locate BuildSystem in %s/python.''' % os.getcwd() 1379c4310d5SMatthew Knepley print '''++ Downloading it using "bk clone http://sidl.bkbits.net/BuildSystem %s/python/BuildSystem"''' % os.getcwd() 138ec1ee742SBarry Smith print '=================================================================================' 1399c4310d5SMatthew Knepley (status,output) = commands.getstatusoutput('bk clone http://sidl.bkbits.net/BuildSystem python/BuildSystem') 1407d7624c9SBarry Smith if status: 1417d7624c9SBarry Smith if output.find('ommand not found') >= 0: 142ec1ee742SBarry Smith print '=================================================================================' 143d688700cSSatish Balay print '''** Unable to locate bk (Bitkeeper) to download BuildSystem; make sure bk is in your path''' 144d688700cSSatish Balay print '''** or manually copy BuildSystem to $PETSC_DIR/python/BuildSystem from a machine where''' 145d688700cSSatish Balay print '''** you do have bk installed and can clone BuildSystem. ''' 146ec1ee742SBarry Smith print '=================================================================================' 1477d7624c9SBarry Smith elif output.find('Cannot resolve host') >= 0: 148ec1ee742SBarry Smith print '=================================================================================' 149d688700cSSatish Balay print '''** Unable to download BuildSystem. You must be off the network.''' 150d688700cSSatish Balay print '''** Connect to the internet and run config/configure.py again.''' 151ec1ee742SBarry Smith print '=================================================================================' 1527d7624c9SBarry Smith else: 153ec1ee742SBarry Smith print '=================================================================================' 154d688700cSSatish Balay print '''** Unable to download BuildSystem. Please send this message to petsc-maint@mcs.anl.gov''' 155ec1ee742SBarry Smith print '=================================================================================' 1567d7624c9SBarry Smith print output 15787282423SMatthew Knepley sys.exit(3) 1584f8a5b45SBarry Smith 15987282423SMatthew Knepley sys.path.insert(0, bsDir) 1605d5a5a7bSMatthew Knepley sys.path.insert(0, pythonDir) 161*e69ef9dfSMatthew Knepley import config.base 1625d5a5a7bSMatthew Knepley import config.framework 163f56be888SMatthew Knepley import cPickle 1644f8a5b45SBarry Smith 1652e22a60eSMatthew Knepley # Disable shared libraries by default 1662e22a60eSMatthew Knepley import nargs 1672e22a60eSMatthew Knepley if nargs.Arg.findArgument('with-shared', sys.argv[1:]) is None: 1682e22a60eSMatthew Knepley sys.argv.append('--with-shared=0') 1692e22a60eSMatthew Knepley 1709dd2fdb1SMatthew Knepley framework = None 1719dd2fdb1SMatthew Knepley try: 172637cc2ebSSatish Balay framework = config.framework.Framework(sys.argv[1:]+['--configModules=PETSc.Configure','--optionsModule=PETSc.compilerOptions'], loadArgDB = 0) 173d65f3bddSMatthew Knepley framework.setup() 174d65f3bddSMatthew Knepley framework.logPrint('\n'.join(extraLogs)) 175f24f64feSBarry Smith framework.configure(out = sys.stdout) 176358ebc22SMatthew Knepley framework.storeSubstitutions(framework.argDB) 177f56be888SMatthew Knepley framework.argDB['configureCache'] = cPickle.dumps(framework) 1787cfd0b05SBarry Smith import PETSc.packages 1797cfd0b05SBarry Smith for i in framework.packages: 1807cfd0b05SBarry Smith if hasattr(i,'postProcess'): 1817cfd0b05SBarry Smith i.postProcess() 1827cfd0b05SBarry Smith framework.logClear() 183dd50d019SBarry Smith return 0 184*e69ef9dfSMatthew Knepley except (RuntimeError, config.base.ConfigureSetupError), e: 1857d670a3cSBarry Smith emsg = str(e) 18642351d26SSatish Balay if not emsg.endswith('\n'): emsg = emsg+'\n' 187fe09c992SBarry Smith msg ='*********************************************************************************\n'\ 188fe09c992SBarry Smith +' UNABLE to CONFIGURE with GIVEN OPTIONS (see configure.log for details):\n' \ 189fe09c992SBarry Smith +'---------------------------------------------------------------------------------------\n' \ 1907d670a3cSBarry Smith +emsg+'*********************************************************************************\n' 191e9f3bb17SBarry Smith se = '' 1929dd2fdb1SMatthew Knepley except (TypeError, ValueError), e: 1937d670a3cSBarry Smith emsg = str(e) 19442351d26SSatish Balay if not emsg.endswith('\n'): emsg = emsg+'\n' 195fe09c992SBarry Smith msg ='*********************************************************************************\n'\ 196fe09c992SBarry Smith +' ERROR in COMMAND LINE ARGUMENT to config/configure.py \n' \ 197fe09c992SBarry Smith +'---------------------------------------------------------------------------------------\n' \ 1987d670a3cSBarry Smith +emsg+'*********************************************************************************\n' 1991a02243aSBarry Smith se = '' 20096dc2fe8SMatthew Knepley except ImportError, e : 2017d670a3cSBarry Smith emsg = str(e) 20242351d26SSatish Balay if not emsg.endswith('\n'): emsg = emsg+'\n' 203fe09c992SBarry Smith msg ='*********************************************************************************\n'\ 204fe09c992SBarry Smith +' UNABLE to FIND MODULE for config/configure.py \n' \ 205fe09c992SBarry Smith +'---------------------------------------------------------------------------------------\n' \ 2067d670a3cSBarry Smith +emsg+'*********************************************************************************\n' 20796dc2fe8SMatthew Knepley se = '' 208d7d3c4beSMatthew Knepley except SystemExit, e: 209d7d3c4beSMatthew Knepley if e.code is None or e.code == 0: 210d7d3c4beSMatthew Knepley return 211fe09c992SBarry Smith msg ='*********************************************************************************\n'\ 212fe09c992SBarry Smith +' CONFIGURATION CRASH (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \ 213fe09c992SBarry Smith +'*********************************************************************************\n' 214d7d3c4beSMatthew Knepley se = str(e) 215e9f3bb17SBarry Smith except Exception, e: 216fe09c992SBarry Smith msg ='*********************************************************************************\n'\ 217fe09c992SBarry Smith +' CONFIGURATION CRASH (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \ 218fe09c992SBarry Smith +'*********************************************************************************\n' 219e9f3bb17SBarry Smith se = str(e) 220e9f3bb17SBarry Smith 221e9f3bb17SBarry Smith print msg 2229dd2fdb1SMatthew Knepley if not framework is None: 2239dd2fdb1SMatthew Knepley framework.logClear() 224e9f3bb17SBarry Smith if hasattr(framework, 'log'): 225f6614063SBarry Smith import traceback 226f24f64feSBarry Smith framework.log.write(msg+se) 227f24f64feSBarry Smith traceback.print_tb(sys.exc_info()[2], file = framework.log) 2282418bae5SMatthew Knepley if os.path.isfile(framework.logName+'.bkp'): 2295a74f024SMatthew Knepley if framework.debugIndent is None: 2305a74f024SMatthew Knepley framework.debugIndent = ' ' 2312418bae5SMatthew Knepley framework.logPrintDivider() 2322418bae5SMatthew Knepley framework.logPrintBox('Previous configure logs below', debugSection = None) 2332418bae5SMatthew Knepley f = file(framework.logName+'.bkp') 2342418bae5SMatthew Knepley framework.log.write(f.read()) 2352418bae5SMatthew Knepley f.close() 236e9f3bb17SBarry Smith sys.exit(1) 2375a74f024SMatthew Knepley else: 2385a74f024SMatthew Knepley print se 2395a74f024SMatthew Knepley import traceback 2405a74f024SMatthew Knepley traceback.print_tb(sys.exc_info()[2]) 2415d5a5a7bSMatthew Knepley 2425d5a5a7bSMatthew Knepleyif __name__ == '__main__': 243a030c540SBarry Smith petsc_configure([]) 244759acf64SBarry Smith 245