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