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 sys.exit(4) 10 11def getarch(): 12 if os.path.basename(sys.argv[0]).startswith('configure'): return '' 13 else: return os.path.basename(sys.argv[0])[:-3] 14 15def petsc_configure(configure_options): 16 # use the name of the config/configure_arch.py to determine the arch 17 if getarch(): configure_options.append('-PETSC_ARCH='+getarch()) 18 19 # Should be run from the toplevel 20 pythonDir = os.path.abspath(os.path.join('python')) 21 bsDir = os.path.join(pythonDir, 'BuildSystem') 22 if not os.path.isdir(pythonDir): 23 raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.')) 24 if not os.path.isdir(bsDir): 25 print '''Could not locate BuildSystem in $PETSC_DIR/python. 26 Downloading it using "bk clone bk://sidl.bkbits.net/BuildSystem $PETSC_DIR/python/BuildSystem"''' 27 (status,output) = commands.getstatusoutput('bk clone bk://sidl.bkbits.net/BuildSystem python/BuildSystem') 28 if status: 29 if output.find('ommand not found') >= 0: 30 print '''******** Unable to locate bk (Bitkeeper) to download BuildSystem; make sure bk is in your path\nor manually copy BuildSystem to $PETSC_DIR/python/BuildSystem from a machine where you do have bk installed and can clone BuildSystem.******** ''' 31 elif output.find('Cannot resolve host') >= 0: 32 print '''******** Unable to download BuildSystem. You must be off the network. Connect to the internet and run config/configure.py again******** ''' 33 else: 34 print '''******** Unable to download BuildSystem. Please send this message to petsc-maint@mcs.anl.gov******** ''' 35 print output 36 sys.exit(3) 37 38 sys.path.insert(0, bsDir) 39 sys.path.insert(0, pythonDir) 40 import config.framework 41 42 43 framework = config.framework.Framework(sys.argv[1:]+['-configModules=PETSc.Configure']+configure_options, loadArgDB = 0) 44 framework.argDB['CPPFLAGS'] = '' 45 framework.argDB['LIBS'] = '' 46 try: 47 framework.configure(out = sys.stdout) 48 framework.storeSubstitutions(framework.argDB) 49 return 0 50 except RuntimeError, e: 51 msg = '******* Unable to configure with given options ******* (see configure.log for full details):\n'+str(e)+'\n******************************************************\n' 52 se = '' 53 except TypeError, e: 54 msg = '******* Error in command line argument to configure.py ***********\n'+str(e)+'\n******************************************************\n' 55 se = '' 56 except Exception, e: 57 msg = '******* CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n' 58 se = str(e) 59 60 print msg 61 if hasattr(framework, 'log'): 62 import traceback 63 framework.log.write(msg+se) 64 traceback.print_tb(sys.exc_info()[2], file = framework.log) 65 sys.exit(1) 66 67if __name__ == '__main__': 68 petsc_configure([]) 69 70