xref: /petsc/config/configure.py (revision 2fc52814d27bf1f4e71021c1c3ebb532b583ed60)
1#!/usr/bin/env python
2import os
3import sys
4import commands
5
6if not hasattr(sys, 'version_info'):
7  raise RuntimeError('You must have Python version 2.2 or higher to run configure')
8
9def petsc_configure(configure_options):
10  # Should be run from the toplevel or from ./config
11  pythonDir = os.path.abspath(os.path.join('..', 'python'))
12  if not os.path.exists(pythonDir):
13    pythonDir = os.path.abspath(os.path.join('python'))
14    if not os.path.exists(pythonDir):
15      raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.'))
16
17  if not os.path.isdir('python/BuildSystem'):
18    print '''Could not locate BuildSystem in $PETSC_DIR/python.
19    Downloading it using "bk clone bk://sidl.bkbits.net/BuildSystem $PETSC_DIR/python/BuildSystem"'''
20    (status,output) = commands.getstatusoutput('bk clone bk://sidl.bkbits.net/BuildSystem python/BuildSystem')
21
22  sys.path.insert(0, os.path.join(pythonDir, 'BuildSystem'))
23  sys.path.insert(0, pythonDir)
24  import config.framework
25  import PETSc.packages.update
26
27
28  framework = config.framework.Framework(sys.argv[1:]+['-configModules=PETSc.Configure']+configure_options, loadArgDB = 0)
29  framework.argDB['CPPFLAGS'] = ''
30  framework.argDB['LIBS'] = ''
31  try:
32    framework.configure(out = sys.stdout)
33  except PETSc.packages.update.UpdateException, e:
34    return 1
35  except Exception, e:
36    import traceback
37
38    msg = 'CONFIGURATION FAILURE (see configure.log for full details):\n'+str(e)+'\n'
39    print msg
40    if hasattr(framework, 'log'):
41      framework.log.write(msg)
42      traceback.print_tb(sys.exc_info()[2], file = framework.log)
43    sys.exit(1)
44  framework.storeSubstitutions(framework.argDB)
45  return 0
46
47if __name__ == '__main__':
48  for opt in sys.argv[1:]:
49    if opt.startswith('--prefix') or opt.startswith('-prefix'):
50      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'
51      sys.exit(1)
52  if petsc_configure([]):
53    print 'Updated the source code, rerunning configure'
54    petsc_configure([])
55