xref: /petsc/config/configure.py (revision 9f95472905e43bbd86a13e9b60bb1eb5a5ab8b35)
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  if os.path.basename(sys.argv[0]).startswith('configure'): return ''
12  else: return os.path.basename(sys.argv[0])[:-3]
13
14def petsc_configure(configure_options):
15  # use the name of the config/configure_arch.py to determine the arch
16  if getarch(): configure_options.append('-PETSC_ARCH='+getarch())
17
18  # Should be run from the toplevel or from ./config
19  pythonDir = os.path.abspath(os.path.join('..', 'python'))
20  if not os.path.exists(pythonDir):
21    pythonDir = os.path.abspath(os.path.join('python'))
22    if not os.path.exists(pythonDir):
23      raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.'))
24
25  if not os.path.isdir('python/BuildSystem'):
26    print '''Could not locate BuildSystem in $PETSC_DIR/python.
27    Downloading it using "bk clone bk://sidl.bkbits.net/BuildSystem $PETSC_DIR/python/BuildSystem"'''
28    (status,output) = commands.getstatusoutput('bk clone bk://sidl.bkbits.net/BuildSystem python/BuildSystem')
29    if status:
30      if output.find('ommand not found') >= 0:
31        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.'''
32      elif output.find('Cannot resolve host') >= 0:
33        print '''Unable to download BuildSystem. You must be off the network. Connect to the internet and run config/configure.py again'''
34      else:
35        print '''Unable to download BuildSystem. Please send this message to petsc-maint@mcs.anl.gov'''
36      print output
37      sys.exit(3);
38
39  sys.path.insert(0, os.path.join(pythonDir, 'BuildSystem'))
40  sys.path.insert(0, pythonDir)
41  import config.framework
42
43
44  framework = config.framework.Framework(sys.argv[1:]+['-configModules=PETSc.Configure']+configure_options, loadArgDB = 0)
45  framework.argDB['CPPFLAGS'] = ''
46  framework.argDB['LIBS'] = ''
47  try:
48    framework.configure(out = sys.stdout)
49    framework.storeSubstitutions(framework.argDB)
50    return 0
51  except RuntimeError, e:
52    msg = '******* Unable to configure with given options ******* (see configure.log for full details):\n'+str(e)+'\n******************************************************\n'
53    se = ''
54  except Exception, e:
55    msg = '******* CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n'
56    se  = str(e)
57
58  print msg
59  if hasattr(framework, 'log'):
60    import traceback
61    framework.log.write(msg+se)
62    traceback.print_tb(sys.exc_info()[2], file = framework.log)
63    sys.exit(1)
64
65if __name__ == '__main__':
66  for opt in sys.argv[1:]:
67    if opt.startswith('--prefix') or opt.startswith('-prefix'):
68      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'
69      sys.exit(1)
70  petsc_configure([])
71
72