xref: /petsc/config/configure.py (revision c7f9034b40a117fec0c00e26d6e2e10075724bfa)
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 downgrade to cygwin-1.5.10-3. This can be done by      ***'
75    print ' *** running cygwin setup, and in "up to date" view - click on the ***'
76    print ' *** "cirular arrow" next to "cygwin" until it changes to 1.5.10-3.***'
77    sys.exit(3)
78
79  # Should be run from the toplevel
80  pythonDir = os.path.abspath(os.path.join('python'))
81  bsDir     = os.path.join(pythonDir, 'BuildSystem')
82  if not os.path.isdir(pythonDir):
83    raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.'))
84  if not os.path.isdir(bsDir):
85    print '''++ Could not locate BuildSystem in $PETSC_DIR/python.'''
86    print '''++ Downloading it using "bk clone bk://sidl.bkbits.net/BuildSystem $PETSC_DIR/python/BuildSystem"'''
87    (status,output) = commands.getstatusoutput('bk clone bk://sidl.bkbits.net/BuildSystem python/BuildSystem')
88    if status:
89      if output.find('ommand not found') >= 0:
90        print '''** Unable to locate bk (Bitkeeper) to download BuildSystem; make sure bk is in your path'''
91        print '''** or manually copy BuildSystem to $PETSC_DIR/python/BuildSystem from a machine where'''
92        print '''** you do have bk installed and can clone BuildSystem. '''
93      elif output.find('Cannot resolve host') >= 0:
94        print '''** Unable to download BuildSystem. You must be off the network.'''
95        print '''** Connect to the internet and run config/configure.py again.'''
96      else:
97        print '''** Unable to download BuildSystem. Please send this message to petsc-maint@mcs.anl.gov'''
98      print output
99      sys.exit(3)
100
101  sys.path.insert(0, bsDir)
102  sys.path.insert(0, pythonDir)
103  import config.framework
104
105
106  framework = config.framework.Framework(sys.argv[1:]+['-configModules=PETSc.Configure']+configure_options, loadArgDB = 0)
107  try:
108    framework.configure(out = sys.stdout)
109    framework.storeSubstitutions(framework.argDB)
110    fixWin32Flinker('bmake/'+framework.argDB['PETSC_ARCH']+'/variables')
111    return 0
112  except RuntimeError, e:
113    msg = '***** Unable to configure with given options ***** (see configure.log for full details):\n' \
114    +str(e)+'\n******************************************************\n'
115    se = ''
116  except TypeError, e:
117    msg = '***** Error in command line argument to configure.py *****\n' \
118    +str(e)+'\n******************************************************\n'
119    se = ''
120  except SystemExit, e:
121    if e.code is None or e.code == 0:
122      return
123    msg = '*** CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n'
124    se  = str(e)
125  except Exception, e:
126    msg = '*** CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n'
127    se  = str(e)
128
129  print msg
130  if hasattr(framework, 'log'):
131    import traceback
132    framework.log.write(msg+se)
133    traceback.print_tb(sys.exc_info()[2], file = framework.log)
134    sys.exit(1)
135
136if __name__ == '__main__':
137  petsc_configure([])
138
139