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 119b436e4bSSatish Balayif 'LC_LOCAL' in os.environ and os.environ['LC_LOCAL'] != '' and os.environ['LC_LOCAL'] != 'en_US' and os.environ['LC_LOCAL']!= 'en_US.UTF-8': os.environ['LC_LOCAL'] = 'en_US.UTF-8' 129b436e4bSSatish Balayif 'LANG' in os.environ and os.environ['LANG'] != '' and os.environ['LANG'] != 'en_US' and os.environ['LANG'] != 'en_US.UTF-8': os.environ['LANG'] = 'en_US.UTF-8' 1344b0d7f9SSatish Balay 14378f148eSBarry Smithif not hasattr(sys, 'version_info') or not sys.version_info[1] >= 2 or not sys.version_info[0] >= 2: 15a0022257SSatish Balay print '*** You must have Python version 2.2 or higher to run config/configure.py *****' 16495ffa62SBarry Smith print '* Python is easy to install for end users or sys-admin. *' 1732077d6dSBarry Smith print '* http://www.python.org/download/ *' 1832077d6dSBarry Smith print '* *' 19495ffa62SBarry Smith print '* You CANNOT configure PETSc without Python *' 20495ffa62SBarry Smith print '* http://www.mcs.anl.gov/petsc/petsc-as/documentation/installation.html *' 21a0022257SSatish Balay print '*******************************************************************************' 22b26a8723SBarry Smith sys.exit(4) 232fb34ac0SMatthew Knepley 24ccb279e1SMatthew Knepleydef check_for_option_mistakes(opts): 2545faeebdSBarry Smith for opt in opts[1:]: 26cda0060aSMatthew Knepley name = opt.split('=')[0] 27ccb279e1SMatthew Knepley if name.find('_') >= 0: 28ccb279e1SMatthew Knepley exception = False 29f3fbd535SBarry Smith for exc in ['superlu_dist', 'PETSC_ARCH', 'PETSC_DIR', 'CXX_CXXFLAGS', 'LD_SHARED', 'CC_LINKER_FLAGS', 'CXX_LINKER_FLAGS', 'FC_LINKER_FLAGS', 'AR_FLAGS', 'C_VERSION', 'CXX_VERSION', 'FC_VERSION', 'size_t', 'MPI_Comm','MPI_Fint']: 30ccb279e1SMatthew Knepley if name.find(exc) >= 0: 31ccb279e1SMatthew Knepley exception = True 32ccb279e1SMatthew Knepley if not exception: 33ccb279e1SMatthew Knepley raise ValueError('The option '+name+' should probably be '+name.replace('_', '-')); 34ccb279e1SMatthew Knepley return 35ccb279e1SMatthew Knepley 3659e9bfd6SSatish Balaydef check_petsc_arch(opts): 37c43ea0feSSatish Balay # If PETSC_ARCH not specified - use script name (if not configure.py) 38b0b472b0SSatish Balay global petsc_arch 39c43ea0feSSatish Balay found = 0 4059e9bfd6SSatish Balay for name in opts: 41c43ea0feSSatish Balay if name.find('PETSC_ARCH=') >= 0: 42b0b472b0SSatish Balay petsc_arch=name.split('=')[1] 43c43ea0feSSatish Balay found = 1 4459e9bfd6SSatish Balay break 4559e9bfd6SSatish Balay # If not yet specified - use the filename of script 46c43ea0feSSatish Balay if not found: 4759e9bfd6SSatish Balay filename = os.path.basename(sys.argv[0]) 487eed1879SBarry Smith if not filename.startswith('configure') and not filename.startswith('reconfigure'): 49b0b472b0SSatish Balay petsc_arch=os.path.splitext(os.path.basename(sys.argv[0]))[0] 50b0b472b0SSatish Balay useName = 'PETSC_ARCH='+petsc_arch 5159e9bfd6SSatish Balay opts.append(useName) 521937db7aSSatish Balay return 0 534b8aa89bSBarry Smith 54*1921852fSSatish Balaydef chkwinf90(): 556a8f6897SSatish Balay for arg in sys.argv: 56*1921852fSSatish Balay if (arg.find('win32fe') >= 0 and (arg.find('f90') >=0 or arg.find('ifort') >=0)): 576a8f6897SSatish Balay return 1 586a8f6897SSatish Balay return 0 596a8f6897SSatish Balay 606a8f6897SSatish Balaydef chkcygwinlink(): 61*1921852fSSatish Balay if os.path.exists('/usr/bin/cygcheck.exe') and os.path.exists('/usr/bin/link.exe') and chkwinf90(): 626a8f6897SSatish Balay if '--ignore-cygwin-link' in sys.argv: return 0 636a8f6897SSatish Balay print '===============================================================================' 64*1921852fSSatish Balay print ' *** Cygwin /usr/bin/link detected! Compiles with CVF/Intel f90 can break! **' 656a8f6897SSatish Balay print ' *** To workarround do: "mv /usr/bin/link.exe /usr/bin/link-cygwin.exe" **' 666a8f6897SSatish Balay print ' *** Or to ignore this check, use configure option: --ignore-cygwin-link **' 676a8f6897SSatish Balay print '===============================================================================' 686a8f6897SSatish Balay sys.exit(3) 696a8f6897SSatish Balay return 0 706a8f6897SSatish Balay 7185ef4d1eSSatish Balaydef chkbrokencygwin(): 729dabcff0SSatish Balay if os.path.exists('/usr/bin/cygcheck.exe'): 739dabcff0SSatish Balay buf = os.popen('/usr/bin/cygcheck.exe -c cygwin').read() 749dabcff0SSatish Balay if buf.find('1.5.11-1') > -1: 75a0022257SSatish Balay print '===============================================================================' 761937db7aSSatish Balay print ' *** cygwin-1.5.11-1 detected. config/configure.py fails with this version ***' 771937db7aSSatish Balay print ' *** Please upgrade to cygwin-1.5.12-1 or newer version. This can ***' 781937db7aSSatish Balay print ' *** be done by running cygwin-setup, selecting "next" all the way.***' 79a0022257SSatish Balay print '===============================================================================' 801937db7aSSatish Balay sys.exit(3) 819dabcff0SSatish Balay return 0 829dabcff0SSatish Balay 8385ef4d1eSSatish Balaydef chkusingwindowspython(): 841937db7aSSatish Balay if os.path.exists('/usr/bin/cygcheck.exe') and sys.platform != 'cygwin': 85a0022257SSatish Balay print '===============================================================================' 86a0022257SSatish Balay print ' *** Non-cygwin python detected. Please rerun config/configure.py **' 87a0022257SSatish Balay print ' *** with cygwin-python. ***' 88a0022257SSatish Balay print '===============================================================================' 891937db7aSSatish Balay sys.exit(3) 9085ef4d1eSSatish Balay return 0 9185ef4d1eSSatish Balay 9285ef4d1eSSatish Balaydef chkcygwinpythonver(): 9371384062SSatish Balay if os.path.exists('/usr/bin/cygcheck.exe'): 9471384062SSatish Balay buf = os.popen('/usr/bin/cygcheck.exe -c python').read() 95c4b7e894SSatish Balay if (buf.find('2.4') > -1) or (buf.find('2.5') > -1) or (buf.find('2.6') > -1): 961937db7aSSatish Balay sys.argv.append('--useThreads=0') 971937db7aSSatish Balay extraLogs.append('''\ 98a0022257SSatish Balay=============================================================================== 99a0022257SSatish Balay** Cygwin-python-2.4/2.5/2.6 detected. Threads do not work correctly with this 100a0022257SSatish Balay** version. Disabling thread usage for this run of config/configure.py ******* 101a0022257SSatish Balay===============================================================================''') 10271384062SSatish Balay return 0 10371384062SSatish Balay 1041937db7aSSatish Balaydef chkrhl9(): 1051937db7aSSatish Balay if os.path.exists('/etc/redhat-release'): 106836c2c52SSatish Balay try: 107594eb360SSatish Balay file = open('/etc/redhat-release','r') 108836c2c52SSatish Balay buf = file.read() 109836c2c52SSatish Balay file.close() 110836c2c52SSatish Balay except: 111836c2c52SSatish Balay # can't read file - assume dangerous RHL9 1121937db7aSSatish Balay buf = 'Shrike' 113836c2c52SSatish Balay if buf.find('Shrike') > -1: 1141937db7aSSatish Balay sys.argv.append('--useThreads=0') 1151937db7aSSatish Balay extraLogs.append('''\ 116a0022257SSatish Balay============================================================================== 1171937db7aSSatish Balay *** RHL9 detected. Threads do not work correctly with this distribution *** 118a0022257SSatish Balay ****** Disabling thread usage for this run of config/configure.py ********* 119a0022257SSatish Balay===============================================================================''') 120836c2c52SSatish Balay return 0 121836c2c52SSatish Balay 122da58527dSSatish Balaydef check_broken_configure_log_links(): 123da58527dSSatish Balay '''Sometime symlinks can get broken if the original files are deleted. Delete such broken links''' 124da58527dSSatish Balay import os 125da58527dSSatish Balay for logfile in ['configure.log','configure.log.bkp']: 126da58527dSSatish Balay if os.path.islink(logfile) and not os.path.isfile(logfile): os.remove(logfile) 127da58527dSSatish Balay return 128da58527dSSatish Balay 129da1d79b4SSatish Balaydef move_configure_log(framework): 130da1d79b4SSatish Balay '''Move configure.log to PETSC_ARCH/conf - and update configure.log.bkp in both locations appropriately''' 131b0b472b0SSatish Balay global petsc_arch 132b0b472b0SSatish Balay 133b0b472b0SSatish Balay if hasattr(framework,'arch'): petsc_arch = framework.arch 134b0b472b0SSatish Balay if hasattr(framework,'logName'): curr_file = framework.logName 135b0b472b0SSatish Balay else: curr_file = 'configure.log' 136b0b472b0SSatish Balay 137b0b472b0SSatish Balay if petsc_arch: 138da1d79b4SSatish Balay import shutil 139da1d79b4SSatish Balay import os 140b0b472b0SSatish Balay 141b0b472b0SSatish Balay # Just in case - confdir is not created 142b0b472b0SSatish Balay conf_dir = os.path.join(petsc_arch,'conf') 143b0b472b0SSatish Balay if not os.path.isdir(petsc_arch): os.mkdir(petsc_arch) 144b0b472b0SSatish Balay if not os.path.isdir(conf_dir): os.mkdir(conf_dir) 145b0b472b0SSatish Balay 146da1d79b4SSatish Balay curr_bkp = curr_file + '.bkp' 147b0b472b0SSatish Balay new_file = os.path.join(conf_dir,curr_file) 148da1d79b4SSatish Balay new_bkp = new_file + '.bkp' 149da1d79b4SSatish Balay 150da1d79b4SSatish Balay # Keep backup in $PETSC_ARCH/conf location 151da1d79b4SSatish Balay if os.path.isfile(new_bkp): os.remove(new_bkp) 152da1d79b4SSatish Balay if os.path.isfile(new_file): os.rename(new_file,new_bkp) 1539e50940cSSatish Balay if os.path.isfile(curr_file): 1549e50940cSSatish Balay shutil.copyfile(curr_file,new_file) 1559e50940cSSatish Balay os.remove(curr_file) 156da58527dSSatish Balay if os.path.isfile(new_file): os.symlink(new_file,curr_file) 157da1d79b4SSatish Balay # If the old bkp is using the same PETSC_ARCH/conf - then update bkp link 158da1d79b4SSatish Balay if os.path.realpath(curr_bkp) == os.path.realpath(new_file): 159da58527dSSatish Balay if os.path.isfile(curr_bkp): os.remove(curr_bkp) 160da58527dSSatish Balay if os.path.isfile(new_bkp): os.symlink(new_bkp,curr_bkp) 161da1d79b4SSatish Balay return 162da1d79b4SSatish Balay 1635d5a5a7bSMatthew Knepleydef petsc_configure(configure_options): 164a0022257SSatish Balay print '===============================================================================' 16559e9bfd6SSatish Balay print ' Configuring PETSc to compile on your system ' 166a0022257SSatish Balay print '===============================================================================' 16759e9bfd6SSatish Balay 168c43ea0feSSatish Balay # Command line arguments take precedence (but don't destroy argv[0]) 169c43ea0feSSatish Balay sys.argv = sys.argv[:1] + configure_options + sys.argv[1:] 170ccb279e1SMatthew Knepley check_for_option_mistakes(sys.argv) 17159e9bfd6SSatish Balay # check PETSC_ARCH 17259e9bfd6SSatish Balay check_petsc_arch(sys.argv) 173da58527dSSatish Balay check_broken_configure_log_links() 1745fb2c094SBarry Smith 175c22cdea9SBarry Smith # support a few standard configure option types 176ed6a7445SBarry Smith for l in range(0,len(sys.argv)): 177c22cdea9SBarry Smith name = sys.argv[l] 178637cc2ebSSatish Balay if name.find('enable-') >= 0: 179193cd51eSMatthew Knepley if name.find('=') == -1: 180193cd51eSMatthew Knepley sys.argv[l] = name.replace('enable-','with-')+'=1' 181193cd51eSMatthew Knepley else: 182193cd51eSMatthew Knepley head, tail = name.split('=', 1) 183193cd51eSMatthew Knepley sys.argv[l] = head.replace('enable-','with-')+'='+tail 184637cc2ebSSatish Balay if name.find('disable-') >= 0: 185193cd51eSMatthew Knepley if name.find('=') == -1: 186193cd51eSMatthew Knepley sys.argv[l] = name.replace('disable-','with-')+'=0' 187193cd51eSMatthew Knepley else: 188193cd51eSMatthew Knepley head, tail = name.split('=', 1) 189193cd51eSMatthew Knepley if tail == '1': tail = '0' 190193cd51eSMatthew Knepley sys.argv[l] = head.replace('disable-','with-')+'='+tail 191637cc2ebSSatish Balay if name.find('without-') >= 0: 192193cd51eSMatthew Knepley if name.find('=') == -1: 193193cd51eSMatthew Knepley sys.argv[l] = name.replace('without-','with-')+'=0' 194193cd51eSMatthew Knepley else: 195193cd51eSMatthew Knepley head, tail = name.split('=', 1) 196193cd51eSMatthew Knepley if tail == '1': tail = '0' 197193cd51eSMatthew Knepley sys.argv[l] = head.replace('without-','with-')+'='+tail 198adc3e427SMatthew Knepley 1999dabcff0SSatish Balay # Check for broken cygwin 2001937db7aSSatish Balay chkbrokencygwin() 201d65f3bddSMatthew Knepley # Disable threads on RHL9 2021937db7aSSatish Balay chkrhl9() 20385ef4d1eSSatish Balay # Make sure cygwin-python is used on windows 2041937db7aSSatish Balay chkusingwindowspython() 20585ef4d1eSSatish Balay # Threads don't work for cygwin & python-2.4, 2.5 etc.. 2061937db7aSSatish Balay chkcygwinpythonver() 2076a8f6897SSatish Balay chkcygwinlink() 2089dabcff0SSatish Balay 20987282423SMatthew Knepley # Should be run from the toplevel 210dbca6d9dSSatish Balay configDir = os.path.abspath('config') 211f8833479SBarry Smith bsDir = os.path.join(configDir, 'BuildSystem') 212f8833479SBarry Smith if not os.path.isdir(configDir): 2135d5a5a7bSMatthew Knepley raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.')) 21487282423SMatthew Knepley if not os.path.isdir(bsDir): 215a0022257SSatish Balay print '===============================================================================' 216dbca6d9dSSatish Balay print '''++ Could not locate BuildSystem in %s.''' % configDir 2174564aff7SMatthew Knepley print '''++ Downloading it using "hg clone http://hg.mcs.anl.gov/petsc/BuildSystem %s"''' % bsDir 218a0022257SSatish Balay print '===============================================================================' 2194564aff7SMatthew Knepley (status,output) = commands.getstatusoutput('hg clone http://petsc.cs.iit.edu/petsc/BuildSystem '+ bsDir) 2207d7624c9SBarry Smith if status: 2217d7624c9SBarry Smith if output.find('ommand not found') >= 0: 222a0022257SSatish Balay print '===============================================================================' 223a0022257SSatish Balay print '''** Unable to locate hg (Mercurial) to download BuildSystem; make sure hg is''' 224a0022257SSatish Balay print '''** in your path or manually copy BuildSystem to $PETSC_DIR/config/BuildSystem''' 225a0022257SSatish Balay print '''** from a machine where you do have hg installed and can clone BuildSystem. ''' 226a0022257SSatish Balay print '===============================================================================' 2277d7624c9SBarry Smith elif output.find('Cannot resolve host') >= 0: 228a0022257SSatish Balay print '===============================================================================' 229d688700cSSatish Balay print '''** Unable to download BuildSystem. You must be off the network.''' 230d688700cSSatish Balay print '''** Connect to the internet and run config/configure.py again.''' 231a0022257SSatish Balay print '===============================================================================' 2327d7624c9SBarry Smith else: 233a0022257SSatish Balay print '===============================================================================' 234d688700cSSatish Balay print '''** Unable to download BuildSystem. Please send this message to petsc-maint@mcs.anl.gov''' 235a0022257SSatish Balay print '===============================================================================' 2367d7624c9SBarry Smith print output 23787282423SMatthew Knepley sys.exit(3) 2384f8a5b45SBarry Smith 23987282423SMatthew Knepley sys.path.insert(0, bsDir) 240f8833479SBarry Smith sys.path.insert(0, configDir) 241e69ef9dfSMatthew Knepley import config.base 2425d5a5a7bSMatthew Knepley import config.framework 243f56be888SMatthew Knepley import cPickle 2444f8a5b45SBarry Smith 2459dd2fdb1SMatthew Knepley framework = None 2469dd2fdb1SMatthew Knepley try: 2471a784507SMatthew Knepley framework = config.framework.Framework(['--configModules=PETSc.Configure','--optionsModule=PETSc.compilerOptions']+sys.argv[1:], loadArgDB = 0) 248d65f3bddSMatthew Knepley framework.setup() 249d65f3bddSMatthew Knepley framework.logPrint('\n'.join(extraLogs)) 250f24f64feSBarry Smith framework.configure(out = sys.stdout) 251358ebc22SMatthew Knepley framework.storeSubstitutions(framework.argDB) 252f56be888SMatthew Knepley framework.argDB['configureCache'] = cPickle.dumps(framework) 2537cfd0b05SBarry Smith import PETSc.packages 2547cfd0b05SBarry Smith for i in framework.packages: 2557cfd0b05SBarry Smith if hasattr(i,'postProcess'): 2567cfd0b05SBarry Smith i.postProcess() 2577c939e48SSatish Balay framework.printSummary() 2587cfd0b05SBarry Smith framework.logClear() 259eefa2c0fSBarry Smith framework.closeLog() 2609e50940cSSatish Balay try: 261da1d79b4SSatish Balay move_configure_log(framework) 2629e50940cSSatish Balay except: 2639e50940cSSatish Balay # perhaps print an error about unable to shuffle logs? 2649e50940cSSatish Balay pass 265dd50d019SBarry Smith return 0 266e69ef9dfSMatthew Knepley except (RuntimeError, config.base.ConfigureSetupError), e: 2677d670a3cSBarry Smith emsg = str(e) 26842351d26SSatish Balay if not emsg.endswith('\n'): emsg = emsg+'\n' 269a0022257SSatish Balay msg ='*******************************************************************************\n'\ 270fe09c992SBarry Smith +' UNABLE to CONFIGURE with GIVEN OPTIONS (see configure.log for details):\n' \ 271a0022257SSatish Balay +'-------------------------------------------------------------------------------\n' \ 272a0022257SSatish Balay +emsg+'*******************************************************************************\n' 273e9f3bb17SBarry Smith se = '' 2749dd2fdb1SMatthew Knepley except (TypeError, ValueError), e: 2757d670a3cSBarry Smith emsg = str(e) 27642351d26SSatish Balay if not emsg.endswith('\n'): emsg = emsg+'\n' 277a0022257SSatish Balay msg ='*******************************************************************************\n'\ 278fe09c992SBarry Smith +' ERROR in COMMAND LINE ARGUMENT to config/configure.py \n' \ 279a0022257SSatish Balay +'-------------------------------------------------------------------------------\n' \ 280a0022257SSatish Balay +emsg+'*******************************************************************************\n' 2811a02243aSBarry Smith se = '' 28296dc2fe8SMatthew Knepley except ImportError, e : 2837d670a3cSBarry Smith emsg = str(e) 28442351d26SSatish Balay if not emsg.endswith('\n'): emsg = emsg+'\n' 285a0022257SSatish Balay msg ='*******************************************************************************\n'\ 286fe09c992SBarry Smith +' UNABLE to FIND MODULE for config/configure.py \n' \ 287a0022257SSatish Balay +'-------------------------------------------------------------------------------\n' \ 288a0022257SSatish Balay +emsg+'*******************************************************************************\n' 28996dc2fe8SMatthew Knepley se = '' 29001def6f0SMatthew Knepley except OSError, e : 29101def6f0SMatthew Knepley emsg = str(e) 29201def6f0SMatthew Knepley if not emsg.endswith('\n'): emsg = emsg+'\n' 293a0022257SSatish Balay msg ='*******************************************************************************\n'\ 29401def6f0SMatthew Knepley +' UNABLE to EXECUTE BINARIES for config/configure.py \n' \ 295a0022257SSatish Balay +'-------------------------------------------------------------------------------\n' \ 296a0022257SSatish Balay +emsg+'*******************************************************************************\n' 29701def6f0SMatthew Knepley se = '' 298d7d3c4beSMatthew Knepley except SystemExit, e: 299d7d3c4beSMatthew Knepley if e.code is None or e.code == 0: 300d7d3c4beSMatthew Knepley return 301a0022257SSatish Balay msg ='*******************************************************************************\n'\ 302b1dada7fSMatthew Knepley +' CONFIGURATION FAILURE (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \ 303a0022257SSatish Balay +'*******************************************************************************\n' 304d7d3c4beSMatthew Knepley se = str(e) 305e9f3bb17SBarry Smith except Exception, e: 306a0022257SSatish Balay msg ='*******************************************************************************\n'\ 307fe09c992SBarry Smith +' CONFIGURATION CRASH (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \ 308a0022257SSatish Balay +'*******************************************************************************\n' 309e9f3bb17SBarry Smith se = str(e) 310e9f3bb17SBarry Smith 311e9f3bb17SBarry Smith print msg 3129dd2fdb1SMatthew Knepley if not framework is None: 3139dd2fdb1SMatthew Knepley framework.logClear() 314e9f3bb17SBarry Smith if hasattr(framework, 'log'): 315f6614063SBarry Smith import traceback 316b1dada7fSMatthew Knepley try: 317f24f64feSBarry Smith framework.log.write(msg+se) 318f24f64feSBarry Smith traceback.print_tb(sys.exc_info()[2], file = framework.log) 319546d5c6fSSatish Balay close(framework.log) 320da1d79b4SSatish Balay move_configure_log(framework) 321b1dada7fSMatthew Knepley except: 322b1dada7fSMatthew Knepley pass 323e9f3bb17SBarry Smith sys.exit(1) 3245a74f024SMatthew Knepley else: 3255a74f024SMatthew Knepley print se 3265a74f024SMatthew Knepley import traceback 3275a74f024SMatthew Knepley traceback.print_tb(sys.exc_info()[2]) 328546d5c6fSSatish Balay close(framework.log) 329da1d79b4SSatish Balay move_configure_log(framework) 3305d5a5a7bSMatthew Knepley 3315d5a5a7bSMatthew Knepleyif __name__ == '__main__': 332a030c540SBarry Smith petsc_configure([]) 333759acf64SBarry Smith 334