xref: /petsc/config/configure.py (revision 09f3b4e5628a00a1eaf17d80982cfbcc515cc9c1)
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 or not sys.version_info[0] >= 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') and not filename.startswith('reconfigure'):
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  extraLogs = []
78
79  # support a few standard configure option types
80  for l in range(0,len(sys.argv)):
81    name = sys.argv[l]
82    if name.find('-download-') >= 0:
83      sys.argv[l] = name.lower()
84    if name.find('-enable-') >= 0:
85      sys.argv[l] = name.replace('-enable-','-with-')
86      if name.find('=') == -1: sys.argv[l] += '=1'
87    if name.find('-disable-') >= 0:
88      sys.argv[l] = name.replace('-disable-','-with-')
89      if name.find('=') == -1: sys.argv[l] += '=0'
90      elif name.endswith('=1'): sys.argv[l].replace('=1','=0')
91    if name.find('-without-') >= 0:
92      sys.argv[l] = name.replace('-without-','-with-')
93      if name.find('=') == -1: sys.argv[l] += '=0'
94      elif name.endswith('=1'): sys.argv[l].replace('=1','=0')
95
96  # Check for broken cygwin
97  if chkcygwin():
98    print '================================================================================='
99    print ' *** cygwin-1.5.11-1 detected. config/configure.py fails with this version   ***'
100    print ' *** Please upgrade to cygwin-1.5.12-1 or newer version. This can  ***'
101    print ' *** be done by running cygwin-setup, selecting "next" all the way.***'
102    print '================================================================================='
103    sys.exit(3)
104
105  # Disable threads on RHL9
106  if rhl9():
107    sys.argv.append('--useThreads=0')
108    extraLogs.append('''\
109================================================================================
110   *** RHL9 detected. Threads do not work correctly with this distribution ***
111    ****** Disabling thread usage for this run of config/configure.py *******
112================================================================================''')
113
114  # Threads don't work for cygwin & python-2.4
115  if chkcygwinpython():
116    sys.argv.append('--useThreads=0')
117    extraLogs.append('''\
118================================================================================
119** Cygwin-python-2.4 detected. Threads do not work correctly with this version *
120 ********* Disabling thread usage for this run of config/configure.py **********
121================================================================================''')
122
123  # Should be run from the toplevel
124  pythonDir = os.path.abspath(os.path.join('python'))
125  bsDir     = os.path.join(pythonDir, 'BuildSystem')
126  if not os.path.isdir(pythonDir):
127    raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.'))
128  if not os.path.isdir(bsDir):
129    print '================================================================================='
130    print '''++ Could not locate BuildSystem in %s/python.''' % os.getcwd()
131    print '''++ Downloading it using "bk clone http://sidl.bkbits.net/BuildSystem %s/python/BuildSystem"''' % os.getcwd()
132    print '================================================================================='
133    (status,output) = commands.getstatusoutput('bk clone http://sidl.bkbits.net/BuildSystem python/BuildSystem')
134    if status:
135      if output.find('ommand not found') >= 0:
136        print '================================================================================='
137        print '''** Unable to locate bk (Bitkeeper) to download BuildSystem; make sure bk is in your path'''
138        print '''** or manually copy BuildSystem to $PETSC_DIR/python/BuildSystem from a machine where'''
139        print '''** you do have bk installed and can clone BuildSystem. '''
140        print '================================================================================='
141      elif output.find('Cannot resolve host') >= 0:
142        print '================================================================================='
143        print '''** Unable to download BuildSystem. You must be off the network.'''
144        print '''** Connect to the internet and run config/configure.py again.'''
145        print '================================================================================='
146      else:
147        print '================================================================================='
148        print '''** Unable to download BuildSystem. Please send this message to petsc-maint@mcs.anl.gov'''
149        print '================================================================================='
150      print output
151      sys.exit(3)
152
153  sys.path.insert(0, bsDir)
154  sys.path.insert(0, pythonDir)
155  import config.framework
156  import cPickle
157
158  # Disable shared libraries by default
159  import nargs
160  if nargs.Arg.findArgument('with-shared', sys.argv[1:]) is None:
161    sys.argv.append('--with-shared=0')
162
163  framework = config.framework.Framework(sys.argv[1:]+['-configModules=PETSc.Configure','-optionsModule=PETSc.compilerOptions'], loadArgDB = 0)
164  framework.setup()
165  framework.logPrint('\n'.join(extraLogs))
166  try:
167    framework.configure(out = sys.stdout)
168    framework.storeSubstitutions(framework.argDB)
169    framework.argDB['configureCache'] = cPickle.dumps(framework)
170    import PETSc.packages
171    for i in framework.packages:
172      if hasattr(i,'postProcess'):
173        i.postProcess()
174    framework.logClear()
175    return 0
176  except RuntimeError, e:
177    emsg = str(e)
178    if not emsg.endswith('\n'): emsg += '\n'
179    msg ='*********************************************************************************\n'\
180    +'         UNABLE to CONFIGURE with GIVEN OPTIONS    (see configure.log for details):\n' \
181    +'---------------------------------------------------------------------------------------\n'  \
182    +emsg+'*********************************************************************************\n'
183    se = ''
184  except TypeError, e:
185    emsg = str(e)
186    if not emsg.endswith('\n'): emsg += '\n'
187    msg ='*********************************************************************************\n'\
188    +'                ERROR in COMMAND LINE ARGUMENT to config/configure.py \n' \
189    +'---------------------------------------------------------------------------------------\n'  \
190    +emsg+'*********************************************************************************\n'
191    se = ''
192  except ImportError, e :
193    emsg = str(e)
194    if not emsg.endswith('\n'): emsg += '\n'
195    msg ='*********************************************************************************\n'\
196    +'                     UNABLE to FIND MODULE for config/configure.py \n' \
197    +'---------------------------------------------------------------------------------------\n'  \
198    +emsg+'*********************************************************************************\n'
199    se = ''
200  except SystemExit, e:
201    if e.code is None or e.code == 0:
202      return
203    msg ='*********************************************************************************\n'\
204    +'           CONFIGURATION CRASH  (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \
205    +'*********************************************************************************\n'
206    se  = str(e)
207  except Exception, e:
208    msg ='*********************************************************************************\n'\
209    +'          CONFIGURATION CRASH  (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \
210    +'*********************************************************************************\n'
211    se  = str(e)
212
213  framework.logClear()
214  print msg
215  if hasattr(framework, 'log'):
216    import traceback
217    framework.log.write(msg+se)
218    traceback.print_tb(sys.exc_info()[2], file = framework.log)
219    if os.path.isfile(framework.logName+'.bkp'):
220      framework.logPrintDivider()
221      framework.logPrintBox('Previous configure logs below', debugSection = None)
222      f = file(framework.logName+'.bkp')
223      framework.log.write(f.read())
224      f.close()
225    sys.exit(1)
226
227if __name__ == '__main__':
228  petsc_configure([])
229
230