xref: /petsc/config/configure.py (revision 0fd7313001ea7fe3f39e4e1ae07530194f56d65b)
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 ImportError, e:
72    msg = '******* Unable to find module for configure.py *******\n' \
73    +str(e)+'\n******************************************************\n'
74    se = ''
75  except SystemExit, e:
76    if e.code is None or e.code == 0:
77      return
78    msg = '*** CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n'
79    se  = str(e)
80  except Exception, e:
81    msg = '*** CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n'
82    se  = str(e)
83
84  print msg
85  if hasattr(framework, 'log'):
86    framework.log.write(msg+se)
87    file = framework.log
88  else:
89    print se
90    file = sys.stdout
91  import traceback
92  traceback.print_tb(sys.exc_info()[2], file = file)
93  sys.exit(1)
94
95
96def while_petsc_configure(args):
97  import config.framework
98  while 1:
99    framework = config.framework.Framework(args, loadArgDB = 0)
100    try:
101      framework.configure(out = sys.stdout)
102      break
103    except RestartException, e:
104      # ugly crap; merge additional args
105      for j in e.args:
106        found = 0
107        for i in len(args):
108          if args[i].startswith(j):
109            args[i] += ' '+e.args[j]
110            found = 1
111            break
112        if not found:
113          args.append(j+'='+e.args[j])
114      args.append('-logAppend=1')
115  return framework
116
117if __name__ == '__main__':
118  petsc_configure([])
119
120