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