xref: /petsc/config/configure.py (revision 4482741e5b2e2bbc854fb1f8dba65221386520f2)
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
30  sys.path.insert(0, os.path.join(pythonDir, 'BuildSystem'))
31  sys.path.insert(0, pythonDir)
32  import config.framework
33
34
35  framework = config.framework.Framework(sys.argv[1:]+['-configModules=PETSc.Configure']+configure_options, loadArgDB = 0)
36  framework.argDB['CPPFLAGS'] = ''
37  framework.argDB['LIBS'] = ''
38  try:
39    framework.configure(out = sys.stdout)
40    framework.storeSubstitutions(framework.argDB)
41    return 0
42  except RuntimeError, e:
43    msg = '******* Unable to configure with given options ******* (see configure.log for full details):\n'+str(e)+'\n******************************************************\n'
44    se = ''
45  except Exception, e:
46    msg = '******* CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n'
47    se  = str(e)
48
49  print msg
50  if hasattr(framework, 'log'):
51    import traceback
52    framework.log.write(msg+se)
53    traceback.print_tb(sys.exc_info()[2], file = framework.log)
54    sys.exit(1)
55
56if __name__ == '__main__':
57  for opt in sys.argv[1:]:
58    if opt.startswith('--prefix') or opt.startswith('-prefix'):
59      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'
60      sys.exit(1)
61  petsc_configure([])
62
63