xref: /petsc/config/configure.py (revision 5582bec17b042ee1c19decb9d092fe7ad142b625)
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    print '''++ 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'''
54        print '''** or manually copy BuildSystem to $PETSC_DIR/python/BuildSystem from a machine where'''
55        print '''** you do have bk installed and can clone BuildSystem. '''
56      elif output.find('Cannot resolve host') >= 0:
57        print '''** Unable to download BuildSystem. You must be off the network.'''
58        print '''** Connect to the internet and run config/configure.py again.'''
59      else:
60        print '''** Unable to download BuildSystem. Please send this message to petsc-maint@mcs.anl.gov'''
61      print output
62      sys.exit(3)
63
64  sys.path.insert(0, bsDir)
65  sys.path.insert(0, pythonDir)
66  import config.framework
67
68
69  framework = config.framework.Framework(sys.argv[1:]+['-configModules=PETSc.Configure']+configure_options, loadArgDB = 0)
70  try:
71    framework.configure(out = sys.stdout)
72    framework.storeSubstitutions(framework.argDB)
73    fixWin32Flinker('bmake/'+framework.argDB['PETSC_ARCH']+'/variables')
74    return 0
75  except RuntimeError, e:
76    msg = '***** Unable to configure with given options ***** (see configure.log for full details):\n' \
77    +str(e)+'\n******************************************************\n'
78    se = ''
79  except TypeError, e:
80    msg = '***** Error in command line argument to configure.py *****\n' \
81    +str(e)+'\n******************************************************\n'
82    se = ''
83  except SystemExit, e:
84    if e.code is None or e.code == 0:
85      return
86    msg = '*** CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n'
87    se  = str(e)
88  except Exception, e:
89    msg = '*** CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n'
90    se  = str(e)
91
92  print msg
93  if hasattr(framework, 'log'):
94    import traceback
95    framework.log.write(msg+se)
96    traceback.print_tb(sys.exc_info()[2], file = framework.log)
97    sys.exit(1)
98
99if __name__ == '__main__':
100  petsc_configure([])
101
102