15d5a5a7bSMatthew Knepley#!/usr/bin/env python 25d5a5a7bSMatthew Knepleyimport os 35d5a5a7bSMatthew Knepleyimport sys 44f8a5b45SBarry Smithimport commands 55d5a5a7bSMatthew Knepley 64b8aa89bSBarry Smith 72fb34ac0SMatthew Knepleyif not hasattr(sys, 'version_info'): 82fb34ac0SMatthew Knepley raise RuntimeError('You must have Python version 2.2 or higher to run configure') 92fb34ac0SMatthew Knepley 104b8aa89bSBarry Smithdef getarch(): 114b8aa89bSBarry Smith return os.path.basename(sys.argv[0])[10:] 124b8aa89bSBarry Smith 135d5a5a7bSMatthew Knepleydef petsc_configure(configure_options): 145d5a5a7bSMatthew Knepley # Should be run from the toplevel or from ./config 155d5a5a7bSMatthew Knepley pythonDir = os.path.abspath(os.path.join('..', 'python')) 165d5a5a7bSMatthew Knepley if not os.path.exists(pythonDir): 175d5a5a7bSMatthew Knepley pythonDir = os.path.abspath(os.path.join('python')) 185d5a5a7bSMatthew Knepley if not os.path.exists(pythonDir): 195d5a5a7bSMatthew Knepley raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.')) 204f8a5b45SBarry Smith 214f8a5b45SBarry Smith if not os.path.isdir('python/BuildSystem'): 224f8a5b45SBarry Smith print '''Could not locate BuildSystem in $PETSC_DIR/python. 234f8a5b45SBarry Smith Downloading it using "bk clone bk://sidl.bkbits.net/BuildSystem $PETSC_DIR/python/BuildSystem"''' 244f8a5b45SBarry Smith (status,output) = commands.getstatusoutput('bk clone bk://sidl.bkbits.net/BuildSystem python/BuildSystem') 254f8a5b45SBarry Smith 265d5a5a7bSMatthew Knepley sys.path.insert(0, os.path.join(pythonDir, 'BuildSystem')) 275d5a5a7bSMatthew Knepley sys.path.insert(0, pythonDir) 285d5a5a7bSMatthew Knepley import config.framework 29dd50d019SBarry Smith import PETSc.packages.update 30dd50d019SBarry Smith 314f8a5b45SBarry Smith 322c4e8892SMatthew Knepley framework = config.framework.Framework(sys.argv[1:]+['-configModules=PETSc.Configure']+configure_options, loadArgDB = 0) 335d5a5a7bSMatthew Knepley framework.argDB['CPPFLAGS'] = '' 345d5a5a7bSMatthew Knepley framework.argDB['LIBS'] = '' 3570ae1cd5SMatthew Knepley try: 363e4f49c0SMatthew Knepley framework.configure(out = sys.stdout) 37dd50d019SBarry Smith except PETSc.packages.update.UpdateException, e: 38dd50d019SBarry Smith return 1 3970ae1cd5SMatthew Knepley except Exception, e: 4070ae1cd5SMatthew Knepley import traceback 4170ae1cd5SMatthew Knepley 4243c77886SBarry Smith msg = 'CONFIGURATION FAILURE (see configure.log for full details):\n'+str(e)+'\n' 4370ae1cd5SMatthew Knepley print msg 443bd70c20SMatthew Knepley if hasattr(framework, 'log'): 4570ae1cd5SMatthew Knepley framework.log.write(msg) 4670ae1cd5SMatthew Knepley traceback.print_tb(sys.exc_info()[2], file = framework.log) 4770ae1cd5SMatthew Knepley sys.exit(1) 48358ebc22SMatthew Knepley framework.storeSubstitutions(framework.argDB) 49*234db7c0SBarry Smith 50*234db7c0SBarry Smith # save the jobs that should be run by the PETSc buildtest 51*234db7c0SBarry Smith fd = open(os.path.abspath(os.path.join('bmake',framework.argDB['PETSC_ARCH'],'jobs')),'w') 52*234db7c0SBarry Smith jobs = [] 53*234db7c0SBarry Smith if framework.usingMPIUni: 54*234db7c0SBarry Smith jobs.append('4') 55*234db7c0SBarry Smith if 'FC' in framework.argDB:jobs.append('9') 56*234db7c0SBarry Smith else: 57*234db7c0SBarry Smith jobs.append('1') 58*234db7c0SBarry Smith if 'FC' in framework.argDB:jobs.append('3') 59*234db7c0SBarry Smith if framework.foundX11:jobs.append('2') 60*234db7c0SBarry Smith fd.write(' '.join(jobs)+'\n') 61*234db7c0SBarry Smith fd.close() 62*234db7c0SBarry Smith fd = open(os.path.abspath(os.path.join('bmake',framework.argDB['PETSC_ARCH'],'ejobs')),'w') 63*234db7c0SBarry Smith fd.write(' ') 64*234db7c0SBarry Smith fd.close() 65dd50d019SBarry Smith return 0 665d5a5a7bSMatthew Knepley 675d5a5a7bSMatthew Knepleyif __name__ == '__main__': 6855ca06a9SBarry Smith for opt in sys.argv[1:]: 6955ca06a9SBarry Smith if opt.startswith('--prefix') or opt.startswith('-prefix'): 7055ca06a9SBarry Smith 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' 7155ca06a9SBarry Smith sys.exit(1) 72dd50d019SBarry Smith if petsc_configure([]): 73b186f651SBarry Smith print 'Updated the source code, rerunning configure' 745d5a5a7bSMatthew Knepley petsc_configure([]) 75