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