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 = [] 8b0b472b0SSatish Balaypetsc_arch = '' 94b8aa89bSBarry Smith 1044b0d7f9SSatish Balay# Use en_US as language so that BuildSystem parses compiler messages in english 1144b0d7f9SSatish Balayos.environ['LANG'] = 'en_US' 1244b0d7f9SSatish Balay 13378f148eSBarry Smithif not hasattr(sys, 'version_info') or not sys.version_info[1] >= 2 or not sys.version_info[0] >= 2: 14495ffa62SBarry Smith print '**** You must have Python version 2.2 or higher to run config/configure.py ******' 15495ffa62SBarry Smith print '* Python is easy to install for end users or sys-admin. *' 1632077d6dSBarry Smith print '* http://www.python.org/download/ *' 1732077d6dSBarry Smith print '* *' 18495ffa62SBarry Smith print '* You CANNOT configure PETSc without Python *' 19495ffa62SBarry Smith print '* http://www.mcs.anl.gov/petsc/petsc-as/documentation/installation.html *' 2032077d6dSBarry Smith print '*********************************************************************************' 21b26a8723SBarry Smith sys.exit(4) 222fb34ac0SMatthew Knepley 2359e9bfd6SSatish Balaydef check_petsc_arch(opts): 24c43ea0feSSatish Balay # If PETSC_ARCH not specified - use script name (if not configure.py) 25b0b472b0SSatish Balay global petsc_arch 26c43ea0feSSatish Balay found = 0 2759e9bfd6SSatish Balay for name in opts: 28c43ea0feSSatish Balay if name.find('PETSC_ARCH=') >= 0: 29b0b472b0SSatish Balay petsc_arch=name.split('=')[1] 30c43ea0feSSatish Balay found = 1 3159e9bfd6SSatish Balay break 3259e9bfd6SSatish Balay # If not yet specified - use the filename of script 33c43ea0feSSatish Balay if not found: 3459e9bfd6SSatish Balay filename = os.path.basename(sys.argv[0]) 357eed1879SBarry Smith if not filename.startswith('configure') and not filename.startswith('reconfigure'): 36b0b472b0SSatish Balay petsc_arch=os.path.splitext(os.path.basename(sys.argv[0]))[0] 37b0b472b0SSatish Balay useName = 'PETSC_ARCH='+petsc_arch 3859e9bfd6SSatish Balay opts.append(useName) 391937db7aSSatish Balay return 0 404b8aa89bSBarry Smith 4185ef4d1eSSatish Balaydef chkbrokencygwin(): 429dabcff0SSatish Balay if os.path.exists('/usr/bin/cygcheck.exe'): 439dabcff0SSatish Balay buf = os.popen('/usr/bin/cygcheck.exe -c cygwin').read() 449dabcff0SSatish Balay if buf.find('1.5.11-1') > -1: 451937db7aSSatish Balay print '=================================================================================' 461937db7aSSatish Balay print ' *** cygwin-1.5.11-1 detected. config/configure.py fails with this version ***' 471937db7aSSatish Balay print ' *** Please upgrade to cygwin-1.5.12-1 or newer version. This can ***' 481937db7aSSatish Balay print ' *** be done by running cygwin-setup, selecting "next" all the way.***' 491937db7aSSatish Balay print '=================================================================================' 501937db7aSSatish Balay sys.exit(3) 519dabcff0SSatish Balay return 0 529dabcff0SSatish Balay 5385ef4d1eSSatish Balaydef chkusingwindowspython(): 541937db7aSSatish Balay if os.path.exists('/usr/bin/cygcheck.exe') and sys.platform != 'cygwin': 551937db7aSSatish Balay print '=================================================================================' 561937db7aSSatish Balay print ' *** Non-cygwin python detected. Please rerun config/configure.py with cygwin-python ***' 571937db7aSSatish Balay print '=================================================================================' 581937db7aSSatish Balay sys.exit(3) 5985ef4d1eSSatish Balay return 0 6085ef4d1eSSatish Balay 6185ef4d1eSSatish Balaydef chkcygwinpythonver(): 6271384062SSatish Balay if os.path.exists('/usr/bin/cygcheck.exe'): 6371384062SSatish Balay buf = os.popen('/usr/bin/cygcheck.exe -c python').read() 64c4b7e894SSatish Balay if (buf.find('2.4') > -1) or (buf.find('2.5') > -1) or (buf.find('2.6') > -1): 651937db7aSSatish Balay sys.argv.append('--useThreads=0') 661937db7aSSatish Balay extraLogs.append('''\ 671937db7aSSatish Balay================================================================================ 681937db7aSSatish Balay** Cygwin-python-2.4/2.5 detected. Threads do not work correctly with this version * 691937db7aSSatish Balay ********* Disabling thread usage for this run of config/configure.py ********** 701937db7aSSatish Balay================================================================================''') 7171384062SSatish Balay return 0 7271384062SSatish Balay 731937db7aSSatish Balaydef chkrhl9(): 741937db7aSSatish Balay if os.path.exists('/etc/redhat-release'): 75836c2c52SSatish Balay try: 76594eb360SSatish Balay file = open('/etc/redhat-release','r') 77836c2c52SSatish Balay buf = file.read() 78836c2c52SSatish Balay file.close() 79836c2c52SSatish Balay except: 80836c2c52SSatish Balay # can't read file - assume dangerous RHL9 811937db7aSSatish Balay buf = 'Shrike' 82836c2c52SSatish Balay if buf.find('Shrike') > -1: 831937db7aSSatish Balay sys.argv.append('--useThreads=0') 841937db7aSSatish Balay extraLogs.append('''\ 851937db7aSSatish Balay================================================================================ 861937db7aSSatish Balay *** RHL9 detected. Threads do not work correctly with this distribution *** 871937db7aSSatish Balay ****** Disabling thread usage for this run of config/configure.py ******* 881937db7aSSatish Balay================================================================================''') 89836c2c52SSatish Balay return 0 90836c2c52SSatish Balay 91da58527dSSatish Balaydef check_broken_configure_log_links(): 92da58527dSSatish Balay '''Sometime symlinks can get broken if the original files are deleted. Delete such broken links''' 93da58527dSSatish Balay import os 94da58527dSSatish Balay for logfile in ['configure.log','configure.log.bkp']: 95da58527dSSatish Balay if os.path.islink(logfile) and not os.path.isfile(logfile): os.remove(logfile) 96da58527dSSatish Balay return 97da58527dSSatish Balay 98da1d79b4SSatish Balaydef move_configure_log(framework): 99da1d79b4SSatish Balay '''Move configure.log to PETSC_ARCH/conf - and update configure.log.bkp in both locations appropriately''' 100b0b472b0SSatish Balay global petsc_arch 101b0b472b0SSatish Balay 102b0b472b0SSatish Balay if hasattr(framework,'arch'): petsc_arch = framework.arch 103b0b472b0SSatish Balay if hasattr(framework,'logName'): curr_file = framework.logName 104b0b472b0SSatish Balay else: curr_file = 'configure.log' 105b0b472b0SSatish Balay 106b0b472b0SSatish Balay if petsc_arch: 107da1d79b4SSatish Balay import shutil 108da1d79b4SSatish Balay import os 109b0b472b0SSatish Balay 110b0b472b0SSatish Balay # Just in case - confdir is not created 111b0b472b0SSatish Balay conf_dir = os.path.join(petsc_arch,'conf') 112b0b472b0SSatish Balay if not os.path.isdir(petsc_arch): os.mkdir(petsc_arch) 113b0b472b0SSatish Balay if not os.path.isdir(conf_dir): os.mkdir(conf_dir) 114b0b472b0SSatish Balay 115da1d79b4SSatish Balay curr_bkp = curr_file + '.bkp' 116b0b472b0SSatish Balay new_file = os.path.join(conf_dir,curr_file) 117da1d79b4SSatish Balay new_bkp = new_file + '.bkp' 118da1d79b4SSatish Balay 119da1d79b4SSatish Balay # Keep backup in $PETSC_ARCH/conf location 120da1d79b4SSatish Balay if os.path.isfile(new_bkp): os.remove(new_bkp) 121da1d79b4SSatish Balay if os.path.isfile(new_file): os.rename(new_file,new_bkp) 122da58527dSSatish Balay if os.path.isfile(curr_file): shutil.move(curr_file,new_file) 123da58527dSSatish Balay if os.path.isfile(new_file): os.symlink(new_file,curr_file) 124da1d79b4SSatish Balay # If the old bkp is using the same PETSC_ARCH/conf - then update bkp link 125da1d79b4SSatish Balay if os.path.realpath(curr_bkp) == os.path.realpath(new_file): 126da58527dSSatish Balay if os.path.isfile(curr_bkp): os.remove(curr_bkp) 127da58527dSSatish Balay if os.path.isfile(new_bkp): os.symlink(new_bkp,curr_bkp) 128da1d79b4SSatish Balay return 129da1d79b4SSatish Balay 1305d5a5a7bSMatthew Knepleydef petsc_configure(configure_options): 13159e9bfd6SSatish Balay print '=================================================================================' 13259e9bfd6SSatish Balay print ' Configuring PETSc to compile on your system ' 13359e9bfd6SSatish Balay print '=================================================================================' 13459e9bfd6SSatish Balay 135c43ea0feSSatish Balay # Command line arguments take precedence (but don't destroy argv[0]) 136c43ea0feSSatish Balay sys.argv = sys.argv[:1] + configure_options + sys.argv[1:] 13759e9bfd6SSatish Balay # check PETSC_ARCH 13859e9bfd6SSatish Balay check_petsc_arch(sys.argv) 139da58527dSSatish Balay check_broken_configure_log_links() 1405fb2c094SBarry Smith 141c22cdea9SBarry Smith # support a few standard configure option types 142ed6a7445SBarry Smith for l in range(0,len(sys.argv)): 143c22cdea9SBarry Smith name = sys.argv[l] 144637cc2ebSSatish Balay if name.find('enable-') >= 0: 145193cd51eSMatthew Knepley if name.find('=') == -1: 146193cd51eSMatthew Knepley sys.argv[l] = name.replace('enable-','with-')+'=1' 147193cd51eSMatthew Knepley else: 148193cd51eSMatthew Knepley head, tail = name.split('=', 1) 149193cd51eSMatthew Knepley sys.argv[l] = head.replace('enable-','with-')+'='+tail 150637cc2ebSSatish Balay if name.find('disable-') >= 0: 151193cd51eSMatthew Knepley if name.find('=') == -1: 152193cd51eSMatthew Knepley sys.argv[l] = name.replace('disable-','with-')+'=0' 153193cd51eSMatthew Knepley else: 154193cd51eSMatthew Knepley head, tail = name.split('=', 1) 155193cd51eSMatthew Knepley if tail == '1': tail = '0' 156193cd51eSMatthew Knepley sys.argv[l] = head.replace('disable-','with-')+'='+tail 157637cc2ebSSatish Balay if name.find('without-') >= 0: 158193cd51eSMatthew Knepley if name.find('=') == -1: 159193cd51eSMatthew Knepley sys.argv[l] = name.replace('without-','with-')+'=0' 160193cd51eSMatthew Knepley else: 161193cd51eSMatthew Knepley head, tail = name.split('=', 1) 162193cd51eSMatthew Knepley if tail == '1': tail = '0' 163193cd51eSMatthew Knepley sys.argv[l] = head.replace('without-','with-')+'='+tail 164adc3e427SMatthew Knepley 1659dabcff0SSatish Balay # Check for broken cygwin 1661937db7aSSatish Balay chkbrokencygwin() 167d65f3bddSMatthew Knepley # Disable threads on RHL9 1681937db7aSSatish Balay chkrhl9() 16985ef4d1eSSatish Balay # Make sure cygwin-python is used on windows 1701937db7aSSatish Balay chkusingwindowspython() 17185ef4d1eSSatish Balay # Threads don't work for cygwin & python-2.4, 2.5 etc.. 1721937db7aSSatish Balay chkcygwinpythonver() 1739dabcff0SSatish Balay 17487282423SMatthew Knepley # Should be run from the toplevel 175dbca6d9dSSatish Balay configDir = os.path.abspath('config') 176f8833479SBarry Smith bsDir = os.path.join(configDir, 'BuildSystem') 177f8833479SBarry Smith if not os.path.isdir(configDir): 1785d5a5a7bSMatthew Knepley raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.')) 17987282423SMatthew Knepley if not os.path.isdir(bsDir): 180ec1ee742SBarry Smith print '=================================================================================' 181dbca6d9dSSatish Balay print '''++ Could not locate BuildSystem in %s.''' % configDir 182*ed2bfab3SMatthew Knepley print '''++ Downloading it using "hg clone http://hg.mcs.anl.gov/petsc/BuildSystem %s"''' % os.path.join(bsDir, 'BuildSystem') 183ec1ee742SBarry Smith print '=================================================================================' 184*ed2bfab3SMatthew Knepley (status,output) = commands.getstatusoutput('hg clone http://petsc.cs.iit.edu/petsc/BuildSystem '+ os.path.join(bsDir, 'BuildSystem')) 1857d7624c9SBarry Smith if status: 1867d7624c9SBarry Smith if output.find('ommand not found') >= 0: 187ec1ee742SBarry Smith print '=================================================================================' 18859dc5438SMatthew Knepley print '''** Unable to locate hg (Mercurial) to download BuildSystem; make sure hg is in your path''' 189ab21cac3SMatthew Knepley print '''** or manually copy BuildSystem to $PETSC_DIR/config/BuildSystem from a machine where''' 19059dc5438SMatthew Knepley print '''** you do have hg installed and can clone BuildSystem. ''' 191ec1ee742SBarry Smith print '=================================================================================' 1927d7624c9SBarry Smith elif output.find('Cannot resolve host') >= 0: 193ec1ee742SBarry Smith print '=================================================================================' 194d688700cSSatish Balay print '''** Unable to download BuildSystem. You must be off the network.''' 195d688700cSSatish Balay print '''** Connect to the internet and run config/configure.py again.''' 196ec1ee742SBarry Smith print '=================================================================================' 1977d7624c9SBarry Smith else: 198ec1ee742SBarry Smith print '=================================================================================' 199d688700cSSatish Balay print '''** Unable to download BuildSystem. Please send this message to petsc-maint@mcs.anl.gov''' 200ec1ee742SBarry Smith print '=================================================================================' 2017d7624c9SBarry Smith print output 20287282423SMatthew Knepley sys.exit(3) 2034f8a5b45SBarry Smith 20487282423SMatthew Knepley sys.path.insert(0, bsDir) 205f8833479SBarry Smith sys.path.insert(0, configDir) 206e69ef9dfSMatthew Knepley import config.base 2075d5a5a7bSMatthew Knepley import config.framework 208f56be888SMatthew Knepley import cPickle 2094f8a5b45SBarry Smith 2102e22a60eSMatthew Knepley # Disable shared libraries by default 2112e22a60eSMatthew Knepley import nargs 2122e22a60eSMatthew Knepley if nargs.Arg.findArgument('with-shared', sys.argv[1:]) is None: 2132e22a60eSMatthew Knepley sys.argv.append('--with-shared=0') 2142e22a60eSMatthew Knepley 2159dd2fdb1SMatthew Knepley framework = None 2169dd2fdb1SMatthew Knepley try: 2171a784507SMatthew Knepley framework = config.framework.Framework(['--configModules=PETSc.Configure','--optionsModule=PETSc.compilerOptions']+sys.argv[1:], loadArgDB = 0) 218d65f3bddSMatthew Knepley framework.setup() 219d65f3bddSMatthew Knepley framework.logPrint('\n'.join(extraLogs)) 220f24f64feSBarry Smith framework.configure(out = sys.stdout) 221358ebc22SMatthew Knepley framework.storeSubstitutions(framework.argDB) 222f56be888SMatthew Knepley framework.argDB['configureCache'] = cPickle.dumps(framework) 2237cfd0b05SBarry Smith import PETSc.packages 2247cfd0b05SBarry Smith for i in framework.packages: 2257cfd0b05SBarry Smith if hasattr(i,'postProcess'): 2267cfd0b05SBarry Smith i.postProcess() 2277cfd0b05SBarry Smith framework.logClear() 228eefa2c0fSBarry Smith framework.closeLog() 229da1d79b4SSatish Balay move_configure_log(framework) 230dd50d019SBarry Smith return 0 231e69ef9dfSMatthew Knepley except (RuntimeError, config.base.ConfigureSetupError), e: 2327d670a3cSBarry Smith emsg = str(e) 23342351d26SSatish Balay if not emsg.endswith('\n'): emsg = emsg+'\n' 234fe09c992SBarry Smith msg ='*********************************************************************************\n'\ 235fe09c992SBarry Smith +' UNABLE to CONFIGURE with GIVEN OPTIONS (see configure.log for details):\n' \ 236fe09c992SBarry Smith +'---------------------------------------------------------------------------------------\n' \ 2377d670a3cSBarry Smith +emsg+'*********************************************************************************\n' 238e9f3bb17SBarry Smith se = '' 2399dd2fdb1SMatthew Knepley except (TypeError, ValueError), e: 2407d670a3cSBarry Smith emsg = str(e) 24142351d26SSatish Balay if not emsg.endswith('\n'): emsg = emsg+'\n' 242fe09c992SBarry Smith msg ='*********************************************************************************\n'\ 243fe09c992SBarry Smith +' ERROR in COMMAND LINE ARGUMENT to config/configure.py \n' \ 244fe09c992SBarry Smith +'---------------------------------------------------------------------------------------\n' \ 2457d670a3cSBarry Smith +emsg+'*********************************************************************************\n' 2461a02243aSBarry Smith se = '' 24796dc2fe8SMatthew Knepley except ImportError, e : 2487d670a3cSBarry Smith emsg = str(e) 24942351d26SSatish Balay if not emsg.endswith('\n'): emsg = emsg+'\n' 250fe09c992SBarry Smith msg ='*********************************************************************************\n'\ 251fe09c992SBarry Smith +' UNABLE to FIND MODULE for config/configure.py \n' \ 252fe09c992SBarry Smith +'---------------------------------------------------------------------------------------\n' \ 2537d670a3cSBarry Smith +emsg+'*********************************************************************************\n' 25496dc2fe8SMatthew Knepley se = '' 25501def6f0SMatthew Knepley except OSError, e : 25601def6f0SMatthew Knepley emsg = str(e) 25701def6f0SMatthew Knepley if not emsg.endswith('\n'): emsg = emsg+'\n' 25801def6f0SMatthew Knepley msg ='*********************************************************************************\n'\ 25901def6f0SMatthew Knepley +' UNABLE to EXECUTE BINARIES for config/configure.py \n' \ 26001def6f0SMatthew Knepley +'---------------------------------------------------------------------------------------\n' \ 26101def6f0SMatthew Knepley +emsg+'*********************************************************************************\n' 26201def6f0SMatthew Knepley se = '' 263d7d3c4beSMatthew Knepley except SystemExit, e: 264d7d3c4beSMatthew Knepley if e.code is None or e.code == 0: 265d7d3c4beSMatthew Knepley return 266fe09c992SBarry Smith msg ='*********************************************************************************\n'\ 267fe09c992SBarry Smith +' CONFIGURATION CRASH (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \ 268fe09c992SBarry Smith +'*********************************************************************************\n' 269d7d3c4beSMatthew Knepley se = str(e) 270e9f3bb17SBarry Smith except Exception, e: 271fe09c992SBarry Smith msg ='*********************************************************************************\n'\ 272fe09c992SBarry Smith +' CONFIGURATION CRASH (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \ 273fe09c992SBarry Smith +'*********************************************************************************\n' 274e9f3bb17SBarry Smith se = str(e) 275e9f3bb17SBarry Smith 276e9f3bb17SBarry Smith print msg 2779dd2fdb1SMatthew Knepley if not framework is None: 2789dd2fdb1SMatthew Knepley framework.logClear() 279e9f3bb17SBarry Smith if hasattr(framework, 'log'): 280f6614063SBarry Smith import traceback 281f24f64feSBarry Smith framework.log.write(msg+se) 282f24f64feSBarry Smith traceback.print_tb(sys.exc_info()[2], file = framework.log) 283da1d79b4SSatish Balay move_configure_log(framework) 284e9f3bb17SBarry Smith sys.exit(1) 2855a74f024SMatthew Knepley else: 2865a74f024SMatthew Knepley print se 2875a74f024SMatthew Knepley import traceback 2885a74f024SMatthew Knepley traceback.print_tb(sys.exc_info()[2]) 289da1d79b4SSatish Balay move_configure_log(framework) 2905d5a5a7bSMatthew Knepley 2915d5a5a7bSMatthew Knepleyif __name__ == '__main__': 292a030c540SBarry Smith petsc_configure([]) 293759acf64SBarry Smith 294