xref: /petsc/config/configure.py (revision d11f3a422a39dc38ef6ea8ba2e6022ac69be8c2b)
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 config/configure.py ******'
9  print '*           Python is easy to install for end users or sys-admin.               *'
10  print '*                   http://www.python.org/download/                             *'
11  print '*                                                                               *'
12  print '*            You CANNOT configure PETSc without Python                          *'
13  print '*    http://www.mcs.anl.gov/petsc/petsc-as/documentation/installation.html      *'
14  print '*********************************************************************************'
15  sys.exit(4)
16
17def check_petsc_arch(opts):
18  # Check for PETSC_ARCH in the following order:
19  # 1. command-line (first occurance)
20  # 2. specified in configure_options(in script)
21  # 3. script name (if not configure.py)
22
23  useName = ''
24  for name in opts:
25    if name.startswith('-PETSC_ARCH'):
26      useName = name
27      break
28  # look for duplicates - and remove them
29  dupnames = []
30  if useName:
31    for name in opts:
32      if name.startswith('-PETSC_ARCH') and name != useName:
33        opts.remove(name)
34        dupnames.append(name)
35  # print warning for duplicates
36  if dupnames:
37    print '*********************************************************************************'
38    print 'Warning: The following duplicate PETSC_ARCH options are removed:', dupnames
39    print 'Warning: Using the option:', useName
40    print '*********************************************************************************'
41  # If not yet specified - use the filename of script
42  if not useName:
43      filename = os.path.basename(sys.argv[0])
44      if not filename.startswith('configure'):
45        useName = '-PETSC_ARCH='+os.path.splitext(os.path.basename(sys.argv[0]))[0]
46        opts.append(useName)
47  return
48
49def chkcygwin():
50  if os.path.exists('/usr/bin/cygcheck.exe'):
51    buf = os.popen('/usr/bin/cygcheck.exe -c cygwin').read()
52    if buf.find('1.5.11-1') > -1:
53      return 1
54    else:
55      return 0
56  return 0
57
58def rhl9():
59  try:
60    file = open('/etc/redhat-release','r')
61  except:
62    return 0
63  try:
64    buf = file.read()
65    file.close()
66  except:
67    # can't read file - assume dangerous RHL9
68    return 1
69  if buf.find('Shrike') > -1:
70    return 1
71  else:
72    return 0
73
74def petsc_configure(configure_options):
75  print '================================================================================='
76  print '             Configuring PETSc to compile on your system                         '
77  print '================================================================================='
78
79  sys.argv += configure_options
80  # check PETSC_ARCH
81  check_petsc_arch(sys.argv)
82
83  # support a few standard configure option types
84  for l in range(0,len(sys.argv)-1):
85    name = sys.argv[l]
86    if name.startswith('--enable'):
87      sys.argv[l] = name.replace('--enable','--with')
88      if name.find('=') == -1: sys.argv[l] += '=1'
89    if name.startswith('--disable'):
90      sys.argv[l] = name.replace('--disable','--with')
91      if name.find('=') == -1: sys.argv[l] += '=0'
92      elif name.endswith('=1'): sys.argv[l].replace('=1','=0')
93    if name.startswith('--without'):
94      sys.argv[l] = name.replace('--without','--with')
95      if name.find('=') == -1: sys.argv[l] += '=0'
96      elif name.endswith('=1'): sys.argv[l].replace('=1','=0')
97
98  # if language is C then should not be checking C++
99  usingcxx = 0
100  for j in sys.argv:
101    if j.replace('++','xx') == '--with-clanguage=cxx' or j == '--with-scalar-type=complex':
102      usingcxx = 1
103      break
104    # horrible, horrible hack; downloading Prometheus needs C++
105    if j.find('--download-prometheus') >= 0:
106      usingcxx = 1
107      break
108
109  if not usingcxx:
110    foundcxx = 0
111    for l in range(0,len(sys.argv)-1):
112      name = sys.argv[l]
113      if name.startswith('--with-cxx'):
114        sys.argv[l] = '--with-cxx=0'
115        foundcxx = 1
116        break
117    if not foundcxx:
118      sys.argv.append('--with-cxx=0')
119
120  # Disable threads on RHL9
121  if rhl9():
122    sys.argv.append('--useThreads=0')
123    print '================================================================================='
124    print ' *** RHL9 detected. Threads do not work correctly with this distribution ***'
125    print ' ******** Disabling thread usage for this run of config/configure.py *****'
126    print '================================================================================='
127
128  # Check for broken cygwin
129  if chkcygwin():
130    print '================================================================================='
131    print ' *** cygwin-1.5.11-1 detected. config/configure.py fails with this version   ***'
132    print ' *** Please upgrade to cygwin-1.5.12-1 or newer version. This can  ***'
133    print ' *** be done by running cygwin-setup, selecting "next" all the way.***'
134    print '================================================================================='
135    sys.exit(3)
136
137  # Should be run from the toplevel
138  pythonDir = os.path.abspath(os.path.join('python'))
139  bsDir     = os.path.join(pythonDir, 'BuildSystem')
140  if not os.path.isdir(pythonDir):
141    raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.'))
142  if not os.path.isdir(bsDir):
143    print '================================================================================='
144    print '''++ Could not locate BuildSystem in %s/python.''' % os.getcwd()
145    print '''++ Downloading it using "bk clone http://sidl.bkbits.net/BuildSystem %s/python/BuildSystem"''' % os.getcwd()
146    print '================================================================================='
147    (status,output) = commands.getstatusoutput('bk clone http://sidl.bkbits.net/BuildSystem python/BuildSystem')
148    if status:
149      if output.find('ommand not found') >= 0:
150        print '================================================================================='
151        print '''** Unable to locate bk (Bitkeeper) to download BuildSystem; make sure bk is in your path'''
152        print '''** or manually copy BuildSystem to $PETSC_DIR/python/BuildSystem from a machine where'''
153        print '''** you do have bk installed and can clone BuildSystem. '''
154        print '================================================================================='
155      elif output.find('Cannot resolve host') >= 0:
156        print '================================================================================='
157        print '''** Unable to download BuildSystem. You must be off the network.'''
158        print '''** Connect to the internet and run config/configure.py again.'''
159        print '================================================================================='
160      else:
161        print '================================================================================='
162        print '''** Unable to download BuildSystem. Please send this message to petsc-maint@mcs.anl.gov'''
163        print '================================================================================='
164      print output
165      sys.exit(3)
166
167  sys.path.insert(0, bsDir)
168  sys.path.insert(0, pythonDir)
169  import config.framework
170  import cPickle
171
172  framework = config.framework.Framework(sys.argv[1:]+['-configModules=PETSc.Configure'], loadArgDB = 0)
173  try:
174    framework.configure(out = sys.stdout)
175    framework.storeSubstitutions(framework.argDB)
176    framework.argDB['configureCache'] = cPickle.dumps(framework)
177    import PETSc.packages
178    for i in framework.packages:
179      if hasattr(i,'postProcess'):
180        i.postProcess()
181    framework.logClear()
182    return 0
183  except RuntimeError, e:
184    emsg = str(e)
185    if not emsg.endswith('\n'): emsg += '\n'
186    msg ='*********************************************************************************\n'\
187    +'         UNABLE to CONFIGURE with GIVEN OPTIONS    (see configure.log for details):\n' \
188    +'---------------------------------------------------------------------------------------\n'  \
189    +emsg+'*********************************************************************************\n'
190    se = ''
191  except TypeError, e:
192    emsg = str(e)
193    if not emsg.endswith('\n'): emsg += '\n'
194    msg ='*********************************************************************************\n'\
195    +'                ERROR in COMMAND LINE ARGUMENT to config/configure.py \n' \
196    +'---------------------------------------------------------------------------------------\n'  \
197    +emsg+'*********************************************************************************\n'
198    se = ''
199  except ImportError, e :
200    emsg = str(e)
201    if not emsg.endswith('\n'): emsg += '\n'
202    msg ='*********************************************************************************\n'\
203    +'                     UNABLE to FIND MODULE for config/configure.py \n' \
204    +'---------------------------------------------------------------------------------------\n'  \
205    +emsg+'*********************************************************************************\n'
206    se = ''
207  except SystemExit, e:
208    if e.code is None or e.code == 0:
209      return
210    msg ='*********************************************************************************\n'\
211    +'           CONFIGURATION CRASH  (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \
212    +'*********************************************************************************\n'
213    se  = str(e)
214  except Exception, e:
215    msg ='*********************************************************************************\n'\
216    +'          CONFIGURATION CRASH  (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \
217    +'*********************************************************************************\n'
218    se  = str(e)
219
220  framework.logClear()
221  print msg
222  if hasattr(framework, 'log'):
223    import traceback
224    framework.log.write(msg+se)
225    traceback.print_tb(sys.exc_info()[2], file = framework.log)
226    if os.path.isfile(framework.logName+'.bkp'):
227      framework.logPrintDivider()
228      framework.logPrintBox('Previous configure logs below', debugSection = None)
229      f = file(framework.logName+'.bkp')
230      framework.log.write(f.read())
231      f.close()
232    sys.exit(1)
233
234if __name__ == '__main__':
235  petsc_configure([])
236
237