xref: /petsc/config/configure.py (revision 8b32f6a42e938bfbc87da6d400cc299b0480291f)
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 chkcygwin():
22  if os.path.exists('/usr/bin/cygcheck.exe'):
23    buf = os.popen('/usr/bin/cygcheck.exe -c cygwin').read()
24    if buf.find('1.5.11-1') > -1:
25      return 1
26    else:
27      return 0
28  return 0
29
30def rhl9():
31  try:
32    file = open('/etc/redhat-release','r')
33  except:
34    return 0
35  try:
36    buf = file.read()
37    file.close()
38  except:
39    # can't read file - assume dangerous RHL9
40    return 1
41  if buf.find('Shrike') > -1:
42    return 1
43  else:
44    return 0
45
46def fixWin32Flinker(filename):
47    '''Change CXX_FLINKER back to C_FLINKER for win32 (from cl or icl)'''
48    import fileinput
49    import re
50
51    reglink    = re.compile('CXX_FLINKER ')
52    regwin32fe = re.compile(r"""\b(win32fe\s+(cl|icl))""",re.I)
53
54    for line in fileinput.input(filename,inplace=1):
55      fl = reglink.search(line)
56      fw = regwin32fe.search(line)
57      if fl and fw:
58        line = 'CXX_FLINKER        = ${C_FLINKER}\n'
59      print line,
60    return
61
62def petsc_configure(configure_options):
63  # use the name of the config/configure_arch.py to determine the arch
64  if getarch(): configure_options.append('-PETSC_ARCH='+getarch())
65
66  # Disable threads on RHL9
67  if rhl9():
68    sys.argv.append('--useThreads=0')
69    print ' *** RHL9 detected. Disabling threads in configure *****'
70
71  # Check for broken cygwin
72  if chkcygwin():
73    print ' *** cygwin-1.5.11-1 detected. configure fails with this version   ***'
74    print ' *** Please upgrade to cygwin-1.5.12-1 or newer version. This can  ***'
75    print ' *** be done by running cygwin-setup, selecting "next" all the way.***'
76    sys.exit(3)
77
78  # Should be run from the toplevel
79  pythonDir = os.path.abspath(os.path.join('python'))
80  bsDir     = os.path.join(pythonDir, 'BuildSystem')
81  if not os.path.isdir(pythonDir):
82    raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.'))
83  if not os.path.isdir(bsDir):
84    print '''++ Could not locate BuildSystem in $PETSC_DIR/python.'''
85    print '''++ Downloading it using "bk clone bk://sidl.bkbits.net/BuildSystem $PETSC_DIR/python/BuildSystem"'''
86    (status,output) = commands.getstatusoutput('bk clone bk://sidl.bkbits.net/BuildSystem python/BuildSystem')
87    if status:
88      if output.find('ommand not found') >= 0:
89        print '''** Unable to locate bk (Bitkeeper) to download BuildSystem; make sure bk is in your path'''
90        print '''** or manually copy BuildSystem to $PETSC_DIR/python/BuildSystem from a machine where'''
91        print '''** you do have bk installed and can clone BuildSystem. '''
92      elif output.find('Cannot resolve host') >= 0:
93        print '''** Unable to download BuildSystem. You must be off the network.'''
94        print '''** Connect to the internet and run config/configure.py again.'''
95      else:
96        print '''** Unable to download BuildSystem. Please send this message to petsc-maint@mcs.anl.gov'''
97      print output
98      sys.exit(3)
99
100  sys.path.insert(0, bsDir)
101  sys.path.insert(0, pythonDir)
102  import config.framework
103
104
105  framework = config.framework.Framework(sys.argv[1:]+['-configModules=PETSc.Configure']+configure_options, loadArgDB = 0)
106  try:
107    framework.configure(out = sys.stdout)
108    framework.storeSubstitutions(framework.argDB)
109    fixWin32Flinker('bmake/'+framework.argDB['PETSC_ARCH']+'/variables')
110    return 0
111  except RuntimeError, e:
112    msg = '***** Unable to configure with given options ***** (see configure.log for full details):\n' \
113    +str(e)+'\n******************************************************\n'
114    se = ''
115  except TypeError, e:
116    msg = '***** Error in command line argument to configure.py *****\n' \
117    +str(e)+'\n******************************************************\n'
118    se = ''
119  except SystemExit, e:
120    if e.code is None or e.code == 0:
121      return
122    msg = '*** CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n'
123    se  = str(e)
124  except Exception, e:
125    msg = '*** CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n'
126    se  = str(e)
127
128  print msg
129  if hasattr(framework, 'log'):
130    import traceback
131    framework.log.write(msg+se)
132    traceback.print_tb(sys.exc_info()[2], file = framework.log)
133    sys.exit(1)
134
135if __name__ == '__main__':
136  petsc_configure([])
137
138