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 return os.path.basename(sys.argv[0])[10:-3] 12 13def petsc_configure(configure_options): 14 # use the name of the config/configure_arch.py to determine the arch 15 if getarch(): configure_options.append('-PETSC_ARCH='+getarch()) 16 17 # Should be run from the toplevel or from ./config 18 pythonDir = os.path.abspath(os.path.join('..', 'python')) 19 if not os.path.exists(pythonDir): 20 pythonDir = os.path.abspath(os.path.join('python')) 21 if not os.path.exists(pythonDir): 22 raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.')) 23 24 if not os.path.isdir('python/BuildSystem'): 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 29 sys.path.insert(0, os.path.join(pythonDir, 'BuildSystem')) 30 sys.path.insert(0, pythonDir) 31 import config.framework 32 import PETSc.packages.update 33 34 35 framework = config.framework.Framework(sys.argv[1:]+['-configModules=PETSc.Configure']+configure_options, loadArgDB = 0) 36 framework.argDB['CPPFLAGS'] = '' 37 framework.argDB['LIBS'] = '' 38 try: 39 framework.configure(out = sys.stdout) 40 except PETSc.packages.update.UpdateException, e: 41 return 1 42 except Exception, e: 43 import traceback 44 45 msg = 'CONFIGURATION FAILURE (see configure.log for full details):\n'+str(e)+'\n' 46 print msg 47 if hasattr(framework, 'log'): 48 framework.log.write(msg) 49 traceback.print_tb(sys.exc_info()[2], file = framework.log) 50 sys.exit(1) 51 framework.storeSubstitutions(framework.argDB) 52 53 # save the jobs that should be run by the PETSc buildtest 54 fd = open(os.path.abspath(os.path.join('bmake',framework.argDB['PETSC_ARCH'],'jobs')),'w') 55 jobs = [] 56 if framework.usingMPIUni: 57 jobs.append('4') 58 if 'FC' in framework.argDB:jobs.append('9') 59 else: 60 jobs.append('1') 61 if 'FC' in framework.argDB:jobs.append('3') 62 if framework.foundX11:jobs.append('2') 63 fd.write(' '.join(jobs)+'\n') 64 fd.close() 65 fd = open(os.path.abspath(os.path.join('bmake',framework.argDB['PETSC_ARCH'],'ejobs')),'w') 66 fd.write(' ') 67 fd.close() 68 return 0 69 70if __name__ == '__main__': 71 for opt in sys.argv[1:]: 72 if opt.startswith('--prefix') or opt.startswith('-prefix'): 73 print '=====================================================================\nPETSc does NOT support the --prefix options. All installs are done in-place.\nMove your petsc directory to the location you wish it installed, before running configure\n' 74 sys.exit(1) 75 if petsc_configure([]): 76 print 'Updated the source code, rerunning configure' 77 petsc_configure([]) 78