xref: /petsc/config/configure.py (revision 32077d6df18512e94702c86e7d562481ed0cebd0)
15d5a5a7bSMatthew Knepley#!/usr/bin/env python
25d5a5a7bSMatthew Knepleyimport os
35d5a5a7bSMatthew Knepleyimport sys
44f8a5b45SBarry Smithimport commands
55d5a5a7bSMatthew Knepley
64b8aa89bSBarry Smith
7b26a8723SBarry Smithif not hasattr(sys, 'version_info') or not sys.version_info[1] >= 2:
8*32077d6dSBarry Smith  print '********* You must have Python version 2.2 or higher to run configure ***********'
9*32077d6dSBarry Smith  print '* Python is easy to install for end users or sys-admin. We urge you to upgrade  *'
10*32077d6dSBarry Smith  print '*                   http://www.python.org/download/                             *'
11*32077d6dSBarry Smith  print '*                                                                               *'
12*32077d6dSBarry Smith  print '* You can configure PETSc manually BUT please, please consider upgrading python *'
13*32077d6dSBarry Smith  print '* http://www.mcs.anl.gov/petsc/petsc-2/documentation/installation.html#Manual   *'
14*32077d6dSBarry Smith  print '*********************************************************************************'
15b26a8723SBarry Smith  sys.exit(4)
162fb34ac0SMatthew Knepley
174b8aa89bSBarry Smithdef getarch():
1864382af2SBarry Smith  if os.path.basename(sys.argv[0]).startswith('configure'): return ''
19b88bae4cSBarry Smith  else: return os.path.basename(sys.argv[0])[:-3]
204b8aa89bSBarry Smith
215d5a5a7bSMatthew Knepleydef petsc_configure(configure_options):
225fb2c094SBarry Smith  # use the name of the config/configure_arch.py to determine the arch
235fb2c094SBarry Smith  if getarch(): configure_options.append('-PETSC_ARCH='+getarch())
245fb2c094SBarry Smith
2587282423SMatthew Knepley  # Should be run from the toplevel
265d5a5a7bSMatthew Knepley  pythonDir = os.path.abspath(os.path.join('python'))
2787282423SMatthew Knepley  bsDir     = os.path.join(pythonDir, 'BuildSystem')
2887282423SMatthew Knepley  if not os.path.isdir(pythonDir):
295d5a5a7bSMatthew Knepley    raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.'))
3087282423SMatthew Knepley  if not os.path.isdir(bsDir):
314f8a5b45SBarry Smith    print '''Could not locate BuildSystem in $PETSC_DIR/python.
324f8a5b45SBarry Smith    Downloading it using "bk clone bk://sidl.bkbits.net/BuildSystem $PETSC_DIR/python/BuildSystem"'''
334f8a5b45SBarry Smith    (status,output) = commands.getstatusoutput('bk clone bk://sidl.bkbits.net/BuildSystem python/BuildSystem')
347d7624c9SBarry Smith    if status:
357d7624c9SBarry Smith      if output.find('ommand not found') >= 0:
36b26a8723SBarry Smith        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.******** '''
377d7624c9SBarry Smith      elif output.find('Cannot resolve host') >= 0:
38b26a8723SBarry Smith        print '''******** Unable to download BuildSystem. You must be off the network. Connect to the internet and run config/configure.py again******** '''
397d7624c9SBarry Smith      else:
40b26a8723SBarry Smith        print '''******** Unable to download BuildSystem. Please send this message to petsc-maint@mcs.anl.gov******** '''
417d7624c9SBarry Smith      print output
4287282423SMatthew Knepley      sys.exit(3)
434f8a5b45SBarry Smith
4487282423SMatthew Knepley  sys.path.insert(0, bsDir)
455d5a5a7bSMatthew Knepley  sys.path.insert(0, pythonDir)
465d5a5a7bSMatthew Knepley  import config.framework
47dd50d019SBarry Smith
484f8a5b45SBarry Smith
492c4e8892SMatthew Knepley  framework = config.framework.Framework(sys.argv[1:]+['-configModules=PETSc.Configure']+configure_options, loadArgDB = 0)
505d5a5a7bSMatthew Knepley  framework.argDB['CPPFLAGS'] = ''
515d5a5a7bSMatthew Knepley  framework.argDB['LIBS'] = ''
5270ae1cd5SMatthew Knepley  try:
533e4f49c0SMatthew Knepley    framework.configure(out = sys.stdout)
54358ebc22SMatthew Knepley    framework.storeSubstitutions(framework.argDB)
55dd50d019SBarry Smith    return 0
56e9f3bb17SBarry Smith  except RuntimeError, e:
57e9f3bb17SBarry Smith    msg = '******* Unable to configure with given options ******* (see configure.log for full details):\n'+str(e)+'\n******************************************************\n'
58e9f3bb17SBarry Smith    se = ''
591a02243aSBarry Smith  except TypeError, e:
601a02243aSBarry Smith    msg = '******* Error in command line argument to configure.py ***********\n'+str(e)+'\n******************************************************\n'
611a02243aSBarry Smith    se = ''
62e9f3bb17SBarry Smith  except Exception, e:
63e9f3bb17SBarry Smith    msg = '******* CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n'
64e9f3bb17SBarry Smith    se  = str(e)
65e9f3bb17SBarry Smith
66e9f3bb17SBarry Smith  print msg
67e9f3bb17SBarry Smith  if hasattr(framework, 'log'):
68e9f3bb17SBarry Smith    import traceback
69e9f3bb17SBarry Smith    framework.log.write(msg+se)
70e9f3bb17SBarry Smith    traceback.print_tb(sys.exc_info()[2], file = framework.log)
71e9f3bb17SBarry Smith    sys.exit(1)
725d5a5a7bSMatthew Knepley
735d5a5a7bSMatthew Knepleyif __name__ == '__main__':
74a030c540SBarry Smith  petsc_configure([])
75759acf64SBarry Smith
76