xref: /petsc/config/configure.py (revision dcf5cc722893849f9d6a49faec7bb9e7955fb956)
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  print '* Python is easy to install for end users or sys-admin. We urge you to upgrade  *'
10  print '*                   http://www.python.org/download/                             *'
11  print '*                                                                               *'
12  print '* You can configure PETSc manually BUT please, please consider upgrading python *'
13  print '* http://www.mcs.anl.gov/petsc/petsc-2/documentation/installation.html#Manual   *'
14  print '*********************************************************************************'
15  sys.exit(4)
16
17class RestartException:
18  def __init__(self,args):
19    self.args = args
20    return
21
22def getarch():
23  if os.path.basename(sys.argv[0]).startswith('configure'): return ''
24  else: return os.path.basename(sys.argv[0])[:-3]
25
26def petsc_configure(configure_options):
27  # use the name of the config/configure_arch.py to determine the arch
28  if getarch(): configure_options.append('-PETSC_ARCH='+getarch())
29
30  # Should be run from the toplevel
31  pythonDir = os.path.abspath(os.path.join('python'))
32  bsDir     = os.path.join(pythonDir, 'BuildSystem')
33  if not os.path.isdir(pythonDir):
34    raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.'))
35  if not os.path.isdir(bsDir):
36    print '''++ Could not locate BuildSystem in $PETSC_DIR/python.'''
37    print '''++ Downloading it using "bk clone bk://sidl.bkbits.net/BuildSystem $PETSC_DIR/python/BuildSystem"'''
38    (status,output) = commands.getstatusoutput('bk clone bk://sidl.bkbits.net/BuildSystem python/BuildSystem')
39    if status:
40      if output.find('ommand not found') >= 0:
41        print '''** Unable to locate bk (Bitkeeper) to download BuildSystem; make sure bk is in your path'''
42        print '''** or manually copy BuildSystem to $PETSC_DIR/python/BuildSystem from a machine where'''
43        print '''** you do have bk installed and can clone BuildSystem. '''
44      elif output.find('Cannot resolve host') >= 0:
45        print '''** Unable to download BuildSystem. You must be off the network.'''
46        print '''** Connect to the internet and run config/configure.py again.'''
47      else:
48        print '''** Unable to download BuildSystem. Please send this message to petsc-maint@mcs.anl.gov'''
49      print output
50      sys.exit(3)
51
52  sys.path.insert(0, bsDir)
53  sys.path.insert(0, pythonDir)
54  import config.framework
55  import cPickle
56
57  framework = []
58  try:
59    framework = while_petsc_configure(sys.argv[1:]+['-configModules=PETSc.Configure']+configure_options)
60    framework.storeSubstitutions(framework.argDB)
61    framework.argDB['configureCache'] = cPickle.dumps(framework)
62    return 0
63  except RuntimeError, e:
64    msg = '***** Unable to configure with given options ***** (see configure.log for full details):\n' \
65    +str(e)+'\n******************************************************\n'
66    se = ''
67  except TypeError, e:
68    msg = '***** Error in command line argument to configure.py *****\n' \
69    +str(e)+'\n******************************************************\n'
70    se = ''
71  except SystemExit, e:
72    if e.code is None or e.code == 0:
73      return
74    msg = '*** CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n'
75    se  = str(e)
76  except Exception, e:
77    msg = '*** CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n'
78    se  = str(e)
79
80  print msg
81  if hasattr(framework, 'log'):
82    framework.log.write(msg+se)
83    file = framework.log
84  else:
85    print se
86    file = sys.stdout
87  import traceback
88  traceback.print_tb(sys.exc_info()[2], file = file)
89  sys.exit(1)
90
91
92def while_petsc_configure(args):
93  import config.framework
94  while 1:
95    framework = config.framework.Framework(args, loadArgDB = 0)
96    try:
97      framework.configure(out = sys.stdout)
98      break
99    except RestartException, e:
100      # ugly crap; merge additional args
101      for j in e.args:
102        found = 0
103        for i in len(args):
104          if args[i].startswith(j):
105            args[i] += ' '+e.args[j]
106            found = 1
107            break
108        if not found:
109          args.append(j+'='+e.args[j])
110      args.append('-logAppend=1')
111  return framework
112
113if __name__ == '__main__':
114  petsc_configure([])
115
116