xref: /petsc/config/configure.py (revision 584f652fec6ad367a5246661b4c75ebdf64b507f)
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
17def getarch():
18  if os.path.basename(sys.argv[0]).startswith('configure'): return ''
19  else: return os.path.basename(sys.argv[0])[:-3]
20
21def petsc_configure(configure_options):
22  # use the name of the config/configure_arch.py to determine the arch
23  if getarch(): configure_options.append('-PETSC_ARCH='+getarch())
24
25  # Should be run from the toplevel
26  pythonDir = os.path.abspath(os.path.join('python'))
27  bsDir     = os.path.join(pythonDir, 'BuildSystem')
28  if not os.path.isdir(pythonDir):
29    raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.'))
30  if not os.path.isdir(bsDir):
31    print '''++ Could not locate BuildSystem in $PETSC_DIR/python.'''
32    print '''++ Downloading it using "bk clone bk://sidl.bkbits.net/BuildSystem $PETSC_DIR/python/BuildSystem"'''
33    (status,output) = commands.getstatusoutput('bk clone bk://sidl.bkbits.net/BuildSystem python/BuildSystem')
34    if status:
35      if output.find('ommand not found') >= 0:
36        print '''** Unable to locate bk (Bitkeeper) to download BuildSystem; make sure bk is in your path'''
37        print '''** or manually copy BuildSystem to $PETSC_DIR/python/BuildSystem from a machine where'''
38        print '''** you do have bk installed and can clone BuildSystem. '''
39      elif output.find('Cannot resolve host') >= 0:
40        print '''** Unable to download BuildSystem. You must be off the network.'''
41        print '''** Connect to the internet and run config/configure.py again.'''
42      else:
43        print '''** Unable to download BuildSystem. Please send this message to petsc-maint@mcs.anl.gov'''
44      print output
45      sys.exit(3)
46
47  sys.path.insert(0, bsDir)
48  sys.path.insert(0, pythonDir)
49  import config.framework
50  import cPickle
51
52  framework = config.framework.Framework(sys.argv[1:]+['-configModules=PETSc.Configure']+configure_options, loadArgDB = 0)
53  try:
54    framework.configure(out = sys.stdout)
55    framework.storeSubstitutions(framework.argDB)
56    framework.argDB['configureCache'] = cPickle.dumps(framework)
57    return 0
58  except RuntimeError, e:
59    msg = '***** Unable to configure with given options ***** (see configure.log for full details):\n' \
60    +str(e)+'\n******************************************************\n'
61    se = ''
62  except TypeError, e:
63    msg = '***** Error in command line argument to configure.py *****\n' \
64    +str(e)+'\n******************************************************\n'
65    se = ''
66  except ImportError, e:
67    msg = '******* Unable to find module for configure.py *******\n' \
68    +str(e)+'\n******************************************************\n'
69    se = ''
70  except SystemExit, e:
71    if e.code is None or e.code == 0:
72      return
73    msg = '*** CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n'
74    se  = str(e)
75  except Exception, e:
76    msg = '*** CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n'
77    se  = str(e)
78
79  print msg
80  if hasattr(framework, 'log'):
81    import traceback
82    framework.log.write(msg+se)
83    traceback.print_tb(sys.exc_info()[2], file = framework.log)
84    sys.exit(1)
85
86if __name__ == '__main__':
87  petsc_configure([])
88
89