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