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(): 1164382af2SBarry Smith if os.path.basename(sys.argv[0]).startswith('configure'): return '' 12b88bae4cSBarry Smith else: return os.path.basename(sys.argv[0])[:-3] 134b8aa89bSBarry Smith 145d5a5a7bSMatthew Knepleydef petsc_configure(configure_options): 155fb2c094SBarry Smith # use the name of the config/configure_arch.py to determine the arch 165fb2c094SBarry Smith if getarch(): configure_options.append('-PETSC_ARCH='+getarch()) 175fb2c094SBarry Smith 185d5a5a7bSMatthew Knepley # Should be run from the toplevel or from ./config 195d5a5a7bSMatthew Knepley pythonDir = os.path.abspath(os.path.join('..', 'python')) 205d5a5a7bSMatthew Knepley if not os.path.exists(pythonDir): 215d5a5a7bSMatthew Knepley pythonDir = os.path.abspath(os.path.join('python')) 225d5a5a7bSMatthew Knepley if not os.path.exists(pythonDir): 235d5a5a7bSMatthew Knepley raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.')) 244f8a5b45SBarry Smith 254f8a5b45SBarry Smith if not os.path.isdir('python/BuildSystem'): 264f8a5b45SBarry Smith print '''Could not locate BuildSystem in $PETSC_DIR/python. 274f8a5b45SBarry Smith Downloading it using "bk clone bk://sidl.bkbits.net/BuildSystem $PETSC_DIR/python/BuildSystem"''' 284f8a5b45SBarry Smith (status,output) = commands.getstatusoutput('bk clone bk://sidl.bkbits.net/BuildSystem python/BuildSystem') 294f8a5b45SBarry Smith 305d5a5a7bSMatthew Knepley sys.path.insert(0, os.path.join(pythonDir, 'BuildSystem')) 315d5a5a7bSMatthew Knepley sys.path.insert(0, pythonDir) 325d5a5a7bSMatthew Knepley import config.framework 33dd50d019SBarry Smith 344f8a5b45SBarry Smith 352c4e8892SMatthew Knepley framework = config.framework.Framework(sys.argv[1:]+['-configModules=PETSc.Configure']+configure_options, loadArgDB = 0) 365d5a5a7bSMatthew Knepley framework.argDB['CPPFLAGS'] = '' 375d5a5a7bSMatthew Knepley framework.argDB['LIBS'] = '' 3870ae1cd5SMatthew Knepley try: 393e4f49c0SMatthew Knepley framework.configure(out = sys.stdout) 40358ebc22SMatthew Knepley framework.storeSubstitutions(framework.argDB) 41dd50d019SBarry Smith return 0 42*e9f3bb17SBarry Smith except RuntimeError, e: 43*e9f3bb17SBarry Smith msg = '******* Unable to configure with given options ******* (see configure.log for full details):\n'+str(e)+'\n******************************************************\n' 44*e9f3bb17SBarry Smith se = '' 45*e9f3bb17SBarry Smith except Exception, e: 46*e9f3bb17SBarry Smith msg = '******* CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n' 47*e9f3bb17SBarry Smith se = str(e) 48*e9f3bb17SBarry Smith 49*e9f3bb17SBarry Smith print msg 50*e9f3bb17SBarry Smith if hasattr(framework, 'log'): 51*e9f3bb17SBarry Smith import traceback 52*e9f3bb17SBarry Smith framework.log.write(msg+se) 53*e9f3bb17SBarry Smith traceback.print_tb(sys.exc_info()[2], file = framework.log) 54*e9f3bb17SBarry Smith sys.exit(1) 555d5a5a7bSMatthew Knepley 565d5a5a7bSMatthew Knepleyif __name__ == '__main__': 5755ca06a9SBarry Smith for opt in sys.argv[1:]: 5855ca06a9SBarry Smith if opt.startswith('--prefix') or opt.startswith('-prefix'): 5955ca06a9SBarry 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' 6055ca06a9SBarry Smith sys.exit(1) 61a030c540SBarry Smith petsc_configure([]) 62759acf64SBarry Smith 63