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