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