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 77c9abfe7SSatish BalayextraLogs = [] 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) 321937db7aSSatish Balay return 0 334b8aa89bSBarry Smith 3485ef4d1eSSatish Balaydef chkbrokencygwin(): 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: 381937db7aSSatish Balay print '=================================================================================' 391937db7aSSatish Balay print ' *** cygwin-1.5.11-1 detected. config/configure.py fails with this version ***' 401937db7aSSatish Balay print ' *** Please upgrade to cygwin-1.5.12-1 or newer version. This can ***' 411937db7aSSatish Balay print ' *** be done by running cygwin-setup, selecting "next" all the way.***' 421937db7aSSatish Balay print '=================================================================================' 431937db7aSSatish Balay sys.exit(3) 449dabcff0SSatish Balay return 0 459dabcff0SSatish Balay 4685ef4d1eSSatish Balaydef chkusingwindowspython(): 471937db7aSSatish Balay if os.path.exists('/usr/bin/cygcheck.exe') and sys.platform != 'cygwin': 481937db7aSSatish Balay print '=================================================================================' 491937db7aSSatish Balay print ' *** Non-cygwin python detected. Please rerun config/configure.py with cygwin-python ***' 501937db7aSSatish Balay print '=================================================================================' 511937db7aSSatish Balay sys.exit(3) 5285ef4d1eSSatish Balay return 0 5385ef4d1eSSatish Balay 5485ef4d1eSSatish Balaydef chkcygwinpythonver(): 5571384062SSatish Balay if os.path.exists('/usr/bin/cygcheck.exe'): 5671384062SSatish Balay buf = os.popen('/usr/bin/cygcheck.exe -c python').read() 57c4b7e894SSatish Balay if (buf.find('2.4') > -1) or (buf.find('2.5') > -1) or (buf.find('2.6') > -1): 581937db7aSSatish Balay sys.argv.append('--useThreads=0') 591937db7aSSatish Balay extraLogs.append('''\ 601937db7aSSatish Balay================================================================================ 611937db7aSSatish Balay** Cygwin-python-2.4/2.5 detected. Threads do not work correctly with this version * 621937db7aSSatish Balay ********* Disabling thread usage for this run of config/configure.py ********** 631937db7aSSatish Balay================================================================================''') 6471384062SSatish Balay return 0 6571384062SSatish Balay 661937db7aSSatish Balaydef chkrhl9(): 671937db7aSSatish Balay if os.path.exists('/etc/redhat-release'): 68836c2c52SSatish Balay try: 69594eb360SSatish Balay file = open('/etc/redhat-release','r') 70836c2c52SSatish Balay buf = file.read() 71836c2c52SSatish Balay file.close() 72836c2c52SSatish Balay except: 73836c2c52SSatish Balay # can't read file - assume dangerous RHL9 741937db7aSSatish Balay buf = 'Shrike' 75836c2c52SSatish Balay if buf.find('Shrike') > -1: 761937db7aSSatish Balay sys.argv.append('--useThreads=0') 771937db7aSSatish Balay extraLogs.append('''\ 781937db7aSSatish Balay================================================================================ 791937db7aSSatish Balay *** RHL9 detected. Threads do not work correctly with this distribution *** 801937db7aSSatish Balay ****** Disabling thread usage for this run of config/configure.py ******* 811937db7aSSatish Balay================================================================================''') 82836c2c52SSatish Balay return 0 83836c2c52SSatish Balay 84*da1d79b4SSatish Balaydef move_configure_log(framework): 85*da1d79b4SSatish Balay '''Move configure.log to PETSC_ARCH/conf - and update configure.log.bkp in both locations appropriately''' 86*da1d79b4SSatish Balay if hasattr(framework, 'arch'): 87*da1d79b4SSatish Balay import shutil 88*da1d79b4SSatish Balay import os 89*da1d79b4SSatish Balay curr_file = framework.logName 90*da1d79b4SSatish Balay curr_bkp = curr_file + '.bkp' 91*da1d79b4SSatish Balay new_file = os.path.join(framework.arch,'conf',curr_file) 92*da1d79b4SSatish Balay new_bkp = new_file + '.bkp' 93*da1d79b4SSatish Balay 94*da1d79b4SSatish Balay # Keep backup in $PETSC_ARCH/conf location 95*da1d79b4SSatish Balay if os.path.isfile(new_bkp): os.remove(new_bkp) 96*da1d79b4SSatish Balay if os.path.isfile(new_file): os.rename(new_file,new_bkp) 97*da1d79b4SSatish Balay shutil.move(curr_file,new_file) 98*da1d79b4SSatish Balay os.symlink(new_file,curr_file) 99*da1d79b4SSatish Balay # If the old bkp is using the same PETSC_ARCH/conf - then update bkp link 100*da1d79b4SSatish Balay if os.path.realpath(curr_bkp) == os.path.realpath(new_file): 101*da1d79b4SSatish Balay os.remove(curr_bkp) 102*da1d79b4SSatish Balay os.symlink(new_bkp,curr_bkp) 103*da1d79b4SSatish Balay return 104*da1d79b4SSatish Balay 1055d5a5a7bSMatthew Knepleydef petsc_configure(configure_options): 10659e9bfd6SSatish Balay print '=================================================================================' 10759e9bfd6SSatish Balay print ' Configuring PETSc to compile on your system ' 10859e9bfd6SSatish Balay print '=================================================================================' 10959e9bfd6SSatish Balay 110c43ea0feSSatish Balay # Command line arguments take precedence (but don't destroy argv[0]) 111c43ea0feSSatish Balay sys.argv = sys.argv[:1] + configure_options + sys.argv[1:] 11259e9bfd6SSatish Balay # check PETSC_ARCH 11359e9bfd6SSatish Balay check_petsc_arch(sys.argv) 1145fb2c094SBarry Smith 115c22cdea9SBarry Smith # support a few standard configure option types 116ed6a7445SBarry Smith for l in range(0,len(sys.argv)): 117c22cdea9SBarry Smith name = sys.argv[l] 118637cc2ebSSatish Balay if name.find('enable-') >= 0: 119193cd51eSMatthew Knepley if name.find('=') == -1: 120193cd51eSMatthew Knepley sys.argv[l] = name.replace('enable-','with-')+'=1' 121193cd51eSMatthew Knepley else: 122193cd51eSMatthew Knepley head, tail = name.split('=', 1) 123193cd51eSMatthew Knepley sys.argv[l] = head.replace('enable-','with-')+'='+tail 124637cc2ebSSatish Balay if name.find('disable-') >= 0: 125193cd51eSMatthew Knepley if name.find('=') == -1: 126193cd51eSMatthew Knepley sys.argv[l] = name.replace('disable-','with-')+'=0' 127193cd51eSMatthew Knepley else: 128193cd51eSMatthew Knepley head, tail = name.split('=', 1) 129193cd51eSMatthew Knepley if tail == '1': tail = '0' 130193cd51eSMatthew Knepley sys.argv[l] = head.replace('disable-','with-')+'='+tail 131637cc2ebSSatish Balay if name.find('without-') >= 0: 132193cd51eSMatthew Knepley if name.find('=') == -1: 133193cd51eSMatthew Knepley sys.argv[l] = name.replace('without-','with-')+'=0' 134193cd51eSMatthew Knepley else: 135193cd51eSMatthew Knepley head, tail = name.split('=', 1) 136193cd51eSMatthew Knepley if tail == '1': tail = '0' 137193cd51eSMatthew Knepley sys.argv[l] = head.replace('without-','with-')+'='+tail 138adc3e427SMatthew Knepley 1399dabcff0SSatish Balay # Check for broken cygwin 1401937db7aSSatish Balay chkbrokencygwin() 141d65f3bddSMatthew Knepley # Disable threads on RHL9 1421937db7aSSatish Balay chkrhl9() 14385ef4d1eSSatish Balay # Make sure cygwin-python is used on windows 1441937db7aSSatish Balay chkusingwindowspython() 14585ef4d1eSSatish Balay # Threads don't work for cygwin & python-2.4, 2.5 etc.. 1461937db7aSSatish Balay chkcygwinpythonver() 1479dabcff0SSatish Balay 14887282423SMatthew Knepley # Should be run from the toplevel 149dbca6d9dSSatish Balay configDir = os.path.abspath('config') 150f8833479SBarry Smith bsDir = os.path.join(configDir, 'BuildSystem') 151f8833479SBarry Smith if not os.path.isdir(configDir): 1525d5a5a7bSMatthew Knepley raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.')) 15387282423SMatthew Knepley if not os.path.isdir(bsDir): 154ec1ee742SBarry Smith print '=================================================================================' 155dbca6d9dSSatish Balay print '''++ Could not locate BuildSystem in %s.''' % configDir 156dbca6d9dSSatish Balay print '''++ Downloading it using "hg clone http://hg.mcs.anl.gov/petsc/BuildSystem %s"''' % bsDir 157ec1ee742SBarry Smith print '=================================================================================' 158dbca6d9dSSatish Balay (status,output) = commands.getstatusoutput('hg clone http://petsc.cs.iit.edu/petsc/BuildSystem '+ bsDir) 1597d7624c9SBarry Smith if status: 1607d7624c9SBarry Smith if output.find('ommand not found') >= 0: 161ec1ee742SBarry Smith print '=================================================================================' 16259dc5438SMatthew Knepley print '''** Unable to locate hg (Mercurial) to download BuildSystem; make sure hg is in your path''' 163ab21cac3SMatthew Knepley print '''** or manually copy BuildSystem to $PETSC_DIR/config/BuildSystem from a machine where''' 16459dc5438SMatthew Knepley print '''** you do have hg installed and can clone BuildSystem. ''' 165ec1ee742SBarry Smith print '=================================================================================' 1667d7624c9SBarry Smith elif output.find('Cannot resolve host') >= 0: 167ec1ee742SBarry Smith print '=================================================================================' 168d688700cSSatish Balay print '''** Unable to download BuildSystem. You must be off the network.''' 169d688700cSSatish Balay print '''** Connect to the internet and run config/configure.py again.''' 170ec1ee742SBarry Smith print '=================================================================================' 1717d7624c9SBarry Smith else: 172ec1ee742SBarry Smith print '=================================================================================' 173d688700cSSatish Balay print '''** Unable to download BuildSystem. Please send this message to petsc-maint@mcs.anl.gov''' 174ec1ee742SBarry Smith print '=================================================================================' 1757d7624c9SBarry Smith print output 17687282423SMatthew Knepley sys.exit(3) 1774f8a5b45SBarry Smith 17887282423SMatthew Knepley sys.path.insert(0, bsDir) 179f8833479SBarry Smith sys.path.insert(0, configDir) 180e69ef9dfSMatthew Knepley import config.base 1815d5a5a7bSMatthew Knepley import config.framework 182f56be888SMatthew Knepley import cPickle 1834f8a5b45SBarry Smith 1842e22a60eSMatthew Knepley # Disable shared libraries by default 1852e22a60eSMatthew Knepley import nargs 1862e22a60eSMatthew Knepley if nargs.Arg.findArgument('with-shared', sys.argv[1:]) is None: 1872e22a60eSMatthew Knepley sys.argv.append('--with-shared=0') 1882e22a60eSMatthew Knepley 1899dd2fdb1SMatthew Knepley framework = None 1909dd2fdb1SMatthew Knepley try: 1911a784507SMatthew Knepley framework = config.framework.Framework(['--configModules=PETSc.Configure','--optionsModule=PETSc.compilerOptions']+sys.argv[1:], loadArgDB = 0) 192d65f3bddSMatthew Knepley framework.setup() 193d65f3bddSMatthew Knepley framework.logPrint('\n'.join(extraLogs)) 194f24f64feSBarry Smith framework.configure(out = sys.stdout) 195358ebc22SMatthew Knepley framework.storeSubstitutions(framework.argDB) 196f56be888SMatthew Knepley framework.argDB['configureCache'] = cPickle.dumps(framework) 1977cfd0b05SBarry Smith import PETSc.packages 1987cfd0b05SBarry Smith for i in framework.packages: 1997cfd0b05SBarry Smith if hasattr(i,'postProcess'): 2007cfd0b05SBarry Smith i.postProcess() 2017cfd0b05SBarry Smith framework.logClear() 202eefa2c0fSBarry Smith framework.closeLog() 203*da1d79b4SSatish Balay move_configure_log(framework) 204dd50d019SBarry Smith return 0 205e69ef9dfSMatthew Knepley except (RuntimeError, config.base.ConfigureSetupError), e: 2067d670a3cSBarry Smith emsg = str(e) 20742351d26SSatish Balay if not emsg.endswith('\n'): emsg = emsg+'\n' 208fe09c992SBarry Smith msg ='*********************************************************************************\n'\ 209fe09c992SBarry Smith +' UNABLE to CONFIGURE with GIVEN OPTIONS (see configure.log for details):\n' \ 210fe09c992SBarry Smith +'---------------------------------------------------------------------------------------\n' \ 2117d670a3cSBarry Smith +emsg+'*********************************************************************************\n' 212e9f3bb17SBarry Smith se = '' 2139dd2fdb1SMatthew Knepley except (TypeError, ValueError), e: 2147d670a3cSBarry Smith emsg = str(e) 21542351d26SSatish Balay if not emsg.endswith('\n'): emsg = emsg+'\n' 216fe09c992SBarry Smith msg ='*********************************************************************************\n'\ 217fe09c992SBarry Smith +' ERROR in COMMAND LINE ARGUMENT to config/configure.py \n' \ 218fe09c992SBarry Smith +'---------------------------------------------------------------------------------------\n' \ 2197d670a3cSBarry Smith +emsg+'*********************************************************************************\n' 2201a02243aSBarry Smith se = '' 22196dc2fe8SMatthew Knepley except ImportError, e : 2227d670a3cSBarry Smith emsg = str(e) 22342351d26SSatish Balay if not emsg.endswith('\n'): emsg = emsg+'\n' 224fe09c992SBarry Smith msg ='*********************************************************************************\n'\ 225fe09c992SBarry Smith +' UNABLE to FIND MODULE for config/configure.py \n' \ 226fe09c992SBarry Smith +'---------------------------------------------------------------------------------------\n' \ 2277d670a3cSBarry Smith +emsg+'*********************************************************************************\n' 22896dc2fe8SMatthew Knepley se = '' 22901def6f0SMatthew Knepley except OSError, e : 23001def6f0SMatthew Knepley emsg = str(e) 23101def6f0SMatthew Knepley if not emsg.endswith('\n'): emsg = emsg+'\n' 23201def6f0SMatthew Knepley msg ='*********************************************************************************\n'\ 23301def6f0SMatthew Knepley +' UNABLE to EXECUTE BINARIES for config/configure.py \n' \ 23401def6f0SMatthew Knepley +'---------------------------------------------------------------------------------------\n' \ 23501def6f0SMatthew Knepley +emsg+'*********************************************************************************\n' 23601def6f0SMatthew Knepley se = '' 237d7d3c4beSMatthew Knepley except SystemExit, e: 238d7d3c4beSMatthew Knepley if e.code is None or e.code == 0: 239d7d3c4beSMatthew Knepley return 240fe09c992SBarry Smith msg ='*********************************************************************************\n'\ 241fe09c992SBarry Smith +' CONFIGURATION CRASH (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \ 242fe09c992SBarry Smith +'*********************************************************************************\n' 243d7d3c4beSMatthew Knepley se = str(e) 244e9f3bb17SBarry Smith except Exception, e: 245fe09c992SBarry Smith msg ='*********************************************************************************\n'\ 246fe09c992SBarry Smith +' CONFIGURATION CRASH (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \ 247fe09c992SBarry Smith +'*********************************************************************************\n' 248e9f3bb17SBarry Smith se = str(e) 249e9f3bb17SBarry Smith 250e9f3bb17SBarry Smith print msg 2519dd2fdb1SMatthew Knepley if not framework is None: 2529dd2fdb1SMatthew Knepley framework.logClear() 253e9f3bb17SBarry Smith if hasattr(framework, 'log'): 254f6614063SBarry Smith import traceback 255f24f64feSBarry Smith framework.log.write(msg+se) 256f24f64feSBarry Smith traceback.print_tb(sys.exc_info()[2], file = framework.log) 257*da1d79b4SSatish Balay move_configure_log(framework) 258e9f3bb17SBarry Smith sys.exit(1) 2595a74f024SMatthew Knepley else: 2605a74f024SMatthew Knepley print se 2615a74f024SMatthew Knepley import traceback 2625a74f024SMatthew Knepley traceback.print_tb(sys.exc_info()[2]) 263*da1d79b4SSatish Balay move_configure_log(framework) 2645d5a5a7bSMatthew Knepley 2655d5a5a7bSMatthew Knepleyif __name__ == '__main__': 266a030c540SBarry Smith petsc_configure([]) 267759acf64SBarry Smith 268