xref: /petsc/config/configure.py (revision 234db7c003d09f14ef3c393142ff87155763a1af)
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  return os.path.basename(sys.argv[0])[10:]
12
13def petsc_configure(configure_options):
14  # Should be run from the toplevel or from ./config
15  pythonDir = os.path.abspath(os.path.join('..', 'python'))
16  if not os.path.exists(pythonDir):
17    pythonDir = os.path.abspath(os.path.join('python'))
18    if not os.path.exists(pythonDir):
19      raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.'))
20
21  if not os.path.isdir('python/BuildSystem'):
22    print '''Could not locate BuildSystem in $PETSC_DIR/python.
23    Downloading it using "bk clone bk://sidl.bkbits.net/BuildSystem $PETSC_DIR/python/BuildSystem"'''
24    (status,output) = commands.getstatusoutput('bk clone bk://sidl.bkbits.net/BuildSystem python/BuildSystem')
25
26  sys.path.insert(0, os.path.join(pythonDir, 'BuildSystem'))
27  sys.path.insert(0, pythonDir)
28  import config.framework
29  import PETSc.packages.update
30
31
32  framework = config.framework.Framework(sys.argv[1:]+['-configModules=PETSc.Configure']+configure_options, loadArgDB = 0)
33  framework.argDB['CPPFLAGS'] = ''
34  framework.argDB['LIBS'] = ''
35  try:
36    framework.configure(out = sys.stdout)
37  except PETSc.packages.update.UpdateException, e:
38    return 1
39  except Exception, e:
40    import traceback
41
42    msg = 'CONFIGURATION FAILURE (see configure.log for full details):\n'+str(e)+'\n'
43    print msg
44    if hasattr(framework, 'log'):
45      framework.log.write(msg)
46      traceback.print_tb(sys.exc_info()[2], file = framework.log)
47    sys.exit(1)
48  framework.storeSubstitutions(framework.argDB)
49
50  # save the jobs that should be run by the PETSc buildtest
51  fd = open(os.path.abspath(os.path.join('bmake',framework.argDB['PETSC_ARCH'],'jobs')),'w')
52  jobs = []
53  if framework.usingMPIUni:
54    jobs.append('4')
55    if 'FC' in framework.argDB:jobs.append('9')
56  else:
57    jobs.append('1')
58    if 'FC' in framework.argDB:jobs.append('3')
59    if framework.foundX11:jobs.append('2')
60  fd.write(' '.join(jobs)+'\n')
61  fd.close()
62  fd = open(os.path.abspath(os.path.join('bmake',framework.argDB['PETSC_ARCH'],'ejobs')),'w')
63  fd.write(' ')
64  fd.close()
65  return 0
66
67if __name__ == '__main__':
68  for opt in sys.argv[1:]:
69    if opt.startswith('--prefix') or opt.startswith('-prefix'):
70      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'
71      sys.exit(1)
72  if petsc_configure([]):
73    print 'Updated the source code, rerunning configure'
74    petsc_configure([])
75