xref: /petsc/config/configure.py (revision 8fd717415ee0df49bfa3a488492da189679079f5)
15d5a5a7bSMatthew Knepley#!/usr/bin/env python
22787667cSMatthew G Knepleyimport os, sys
34f8a5b45SBarry Smithimport commands
4a1eda5bfSSatish Balay# to load ~/.pythonrc.py before inserting correct BuildSystem to path
5a1eda5bfSSatish Balayimport user
67c9abfe7SSatish BalayextraLogs = []
7b0b472b0SSatish Balaypetsc_arch = ''
84b8aa89bSBarry Smith
944b0d7f9SSatish Balay# Use en_US as language so that BuildSystem parses compiler messages in english
109b436e4bSSatish Balayif 'LC_LOCAL' in os.environ and os.environ['LC_LOCAL'] != '' and os.environ['LC_LOCAL'] != 'en_US' and os.environ['LC_LOCAL']!= 'en_US.UTF-8': os.environ['LC_LOCAL'] = 'en_US.UTF-8'
119b436e4bSSatish Balayif 'LANG' in os.environ and os.environ['LANG'] != '' and os.environ['LANG'] != 'en_US' and os.environ['LANG'] != 'en_US.UTF-8': os.environ['LANG'] = 'en_US.UTF-8'
1244b0d7f9SSatish Balay
13200fbeb4SSatish Balayif not hasattr(sys, 'version_info') or not sys.version_info[0] == 2 or not sys.version_info[1] >= 4:
14200fbeb4SSatish Balay  print '*** You must have Python2 version 2.4 or higher to run ./configure        *****'
15495ffa62SBarry Smith  print '*          Python is easy to install for end users or sys-admin.              *'
1632077d6dSBarry Smith  print '*                  http://www.python.org/download/                            *'
1732077d6dSBarry Smith  print '*                                                                             *'
18495ffa62SBarry Smith  print '*           You CANNOT configure PETSc without Python                         *'
19f08646a8SSatish Balay  print '*   http://www.mcs.anl.gov/petsc/documentation/installation.html     *'
20a0022257SSatish Balay  print '*******************************************************************************'
21b26a8723SBarry Smith  sys.exit(4)
222fb34ac0SMatthew Knepley
23ccb279e1SMatthew Knepleydef check_for_option_mistakes(opts):
2445faeebdSBarry Smith  for opt in opts[1:]:
25cda0060aSMatthew Knepley    name = opt.split('=')[0]
26ccb279e1SMatthew Knepley    if name.find('_') >= 0:
27ccb279e1SMatthew Knepley      exception = False
28d305a81bSVasiliy Kozyrev      for exc in ['mkl_cpardiso', 'mkl_pardiso', 'superlu_dist', 'superlu_mt', 'PETSC_ARCH', 'PETSC_DIR', 'CXX_CXXFLAGS', 'LD_SHARED', 'CC_LINKER_FLAGS', 'CXX_LINKER_FLAGS', 'FC_LINKER_FLAGS', 'AR_FLAGS', 'C_VERSION', 'CXX_VERSION', 'FC_VERSION', 'size_t', 'MPI_Comm','MPI_Fint','int64_t']:
29ccb279e1SMatthew Knepley        if name.find(exc) >= 0:
30ccb279e1SMatthew Knepley          exception = True
31ccb279e1SMatthew Knepley      if not exception:
32ccb279e1SMatthew Knepley        raise ValueError('The option '+name+' should probably be '+name.replace('_', '-'));
33ab610953SSatish Balay    if opt.find('=') >=0:
34ab610953SSatish Balay      optval = opt.split('=')[1]
35ab610953SSatish Balay      if optval == 'ifneeded':
36ab610953SSatish Balay        raise ValueError('The option '+opt+' should probably be '+opt.replace('ifneeded', '1'));
37ccb279e1SMatthew Knepley  return
38ccb279e1SMatthew Knepley
392af240f0SSatish Balaydef check_for_option_changed(opts):
402af240f0SSatish Balay# Document changes in command line options here.
41c22361cbSBarry Smith  optMap = [('c-blas-lapack','f2cblaslapack'),('cholmod','suitesparse'),('umfpack','suitesparse'),('f-blas-lapack','fblaslapack')]
422af240f0SSatish Balay  for opt in opts[1:]:
432af240f0SSatish Balay    optname = opt.split('=')[0].strip('-')
442af240f0SSatish Balay    for oldname,newname in optMap:
452af240f0SSatish Balay      if optname.find(oldname) >=0:
462af240f0SSatish Balay        raise ValueError('The option '+opt+' should probably be '+opt.replace(oldname,newname))
472af240f0SSatish Balay  return
482af240f0SSatish Balay
4959e9bfd6SSatish Balaydef check_petsc_arch(opts):
50c43ea0feSSatish Balay  # If PETSC_ARCH not specified - use script name (if not configure.py)
51b0b472b0SSatish Balay  global petsc_arch
52c43ea0feSSatish Balay  found = 0
5359e9bfd6SSatish Balay  for name in opts:
54c43ea0feSSatish Balay    if name.find('PETSC_ARCH=') >= 0:
55b0b472b0SSatish Balay      petsc_arch=name.split('=')[1]
56c43ea0feSSatish Balay      found = 1
5759e9bfd6SSatish Balay      break
5859e9bfd6SSatish Balay  # If not yet specified - use the filename of script
59c43ea0feSSatish Balay  if not found:
6059e9bfd6SSatish Balay      filename = os.path.basename(sys.argv[0])
61e68ebbecSBarry Smith      if not filename.startswith('configure') and not filename.startswith('reconfigure') and not filename.startswith('setup'):
62b0b472b0SSatish Balay        petsc_arch=os.path.splitext(os.path.basename(sys.argv[0]))[0]
63b0b472b0SSatish Balay        useName = 'PETSC_ARCH='+petsc_arch
6459e9bfd6SSatish Balay        opts.append(useName)
651937db7aSSatish Balay  return 0
664b8aa89bSBarry Smith
67f08ee00aSJason Sarichdef chkenable():
68f08ee00aSJason Sarich  #Replace all 'enable-'/'disable-' with 'with-'=0/1/tail
69f08ee00aSJason Sarich  #enable-fortran is a special case, the resulting --with-fortran is ambiguous.
70f08ee00aSJason Sarich  #Would it mean --with-fc= or --with-fortran-interfaces=?
71f08ee00aSJason Sarich  for l in range(0,len(sys.argv)):
72f08ee00aSJason Sarich    name = sys.argv[l]
73f08ee00aSJason Sarich    if name.find('enable-fortran') >= 0:
74f08ee00aSJason Sarich      if name.find('=') == -1:
75f08ee00aSJason Sarich        sys.argv[l] = name.replace('enable-fortran','with-fortran-interfaces')+'=1'
76f08ee00aSJason Sarich      else:
77f08ee00aSJason Sarich        head, tail = name.split('=', 1)
78f08ee00aSJason Sarich        sys.argv[l] = head.replace('enable-fortran','with-fortran-interfaces')+'='+tail
79f08ee00aSJason Sarich      continue
80f08ee00aSJason Sarich    if name.find('disable-fortran') >= 0:
81f08ee00aSJason Sarich      if name.find('=') == -1:
82f08ee00aSJason Sarich        sys.argv[l] = name.replace('disable-fortran','with-fortran-interfaces')+'=0'
83f08ee00aSJason Sarich      else:
84f08ee00aSJason Sarich        head, tail = name.split('=', 1)
85f08ee00aSJason Sarich        if tail == '1': tail = '0'
86f08ee00aSJason Sarich        sys.argv[l] = head.replace('disable-fortran','with-fortran-interfaces')+'='+tail
87f08ee00aSJason Sarich      continue
88f08ee00aSJason Sarich
89f08ee00aSJason Sarich
90f08ee00aSJason Sarich    if name.find('enable-') >= 0:
91f08ee00aSJason Sarich      if name.find('=') == -1:
92f08ee00aSJason Sarich        sys.argv[l] = name.replace('enable-','with-')+'=1'
93f08ee00aSJason Sarich      else:
94f08ee00aSJason Sarich        head, tail = name.split('=', 1)
95f08ee00aSJason Sarich        sys.argv[l] = head.replace('enable-','with-')+'='+tail
96f08ee00aSJason Sarich    if name.find('disable-') >= 0:
97f08ee00aSJason Sarich      if name.find('=') == -1:
98f08ee00aSJason Sarich        sys.argv[l] = name.replace('disable-','with-')+'=0'
99f08ee00aSJason Sarich      else:
100f08ee00aSJason Sarich        head, tail = name.split('=', 1)
101f08ee00aSJason Sarich        if tail == '1': tail = '0'
102f08ee00aSJason Sarich        sys.argv[l] = head.replace('disable-','with-')+'='+tail
103f08ee00aSJason Sarich    if name.find('without-') >= 0:
104f08ee00aSJason Sarich      if name.find('=') == -1:
105f08ee00aSJason Sarich        sys.argv[l] = name.replace('without-','with-')+'=0'
106f08ee00aSJason Sarich      else:
107f08ee00aSJason Sarich        head, tail = name.split('=', 1)
108f08ee00aSJason Sarich        if tail == '1': tail = '0'
109f08ee00aSJason Sarich        sys.argv[l] = head.replace('without-','with-')+'='+tail
110f08ee00aSJason Sarich
111*8fd71741SJason Sarich
112f08ee00aSJason Sarichdef chksynonyms():
113f08ee00aSJason Sarich  #replace common configure options with ones that PETSc BuildSystem recognizes
114f08ee00aSJason Sarich  for l in range(0,len(sys.argv)):
115f08ee00aSJason Sarich    name = sys.argv[l]
116f08ee00aSJason Sarich
117f08ee00aSJason Sarich
118ce54fb35SBarry Smith    if name.find('with-debug=') >= 0 or name.endswith('with-debug'):
119f08ee00aSJason Sarich      if name.find('=') == -1:
120f08ee00aSJason Sarich        sys.argv[l] = name.replace('with-debug','with-debugging')+'=1'
121f08ee00aSJason Sarich      else:
122f08ee00aSJason Sarich        head, tail = name.split('=', 1)
123f08ee00aSJason Sarich        sys.argv[l] = head.replace('with-debug','with-debugging')+'='+tail
124f08ee00aSJason Sarich
125ce54fb35SBarry Smith    if name.find('with-shared=') >= 0 or name.endswith('with-shared'):
126f08ee00aSJason Sarich      if name.find('=') == -1:
127ce54fb35SBarry Smith        sys.argv[l] = name.replace('with-shared','with-shared-libraries')+'=1'
128f08ee00aSJason Sarich      else:
129f08ee00aSJason Sarich        head, tail = name.split('=', 1)
130ce54fb35SBarry Smith        sys.argv[l] = head.replace('with-shared','with-shared-libraries')+'='+tail
131f08ee00aSJason Sarich
132*8fd71741SJason Sarich    if name.find('with-index-size=') >=0:
133*8fd71741SJason Sarich      head,tail = name.split('=',1)
134*8fd71741SJason Sarich      if int(tail)==32:
135*8fd71741SJason Sarich        sys.argv[l] = '--with-64-bit-indices=0'
136*8fd71741SJason Sarich      elif int(tail)==64:
137*8fd71741SJason Sarich        sys.argv[l] = '--with-64-bit-indices=1'
138*8fd71741SJason Sarich      else:
139*8fd71741SJason Sarich        raise RuntimeError('--with-index-size= must be 32 or 64')
140f08ee00aSJason Sarich
141*8fd71741SJason Sarich    if name.find('with-precision=') >=0:
142*8fd71741SJason Sarich      head,tail = name.split('=',1)
143*8fd71741SJason Sarich      if tail.find('quad')>=0:
144*8fd71741SJason Sarich        sys.argv[l]='--with-precision=__float128'
145f08ee00aSJason Sarich
146f08ee00aSJason Sarich
1471921852fSSatish Balaydef chkwinf90():
1486a8f6897SSatish Balay  for arg in sys.argv:
1491921852fSSatish Balay    if (arg.find('win32fe') >= 0 and (arg.find('f90') >=0 or arg.find('ifort') >=0)):
1506a8f6897SSatish Balay      return 1
1516a8f6897SSatish Balay  return 0
1526a8f6897SSatish Balay
1538a4600f2SSatish Balaydef chkdosfiles():
154360dfd13SSatish Balay  # cygwin - but not a hg clone - so check one of files in bin dir
155db1f124cSVasiliy Kozyrev  if "\r\n" in open(os.path.join('bin','petscmpiexec'),"rb").read():
156db1f124cSVasiliy Kozyrev    print '==============================================================================='
157db1f124cSVasiliy Kozyrev    print ' *** Scripts are in DOS mode. Was winzip used to extract petsc sources?    ****'
158db1f124cSVasiliy Kozyrev    print ' *** Please restart with a fresh tarball and use "tar -xzf petsc.tar.gz"   ****'
159db1f124cSVasiliy Kozyrev    print '==============================================================================='
160db1f124cSVasiliy Kozyrev    sys.exit(3)
1618a4600f2SSatish Balay  return
1628a4600f2SSatish Balay
1636a8f6897SSatish Balaydef chkcygwinlink():
1641921852fSSatish Balay  if os.path.exists('/usr/bin/cygcheck.exe') and os.path.exists('/usr/bin/link.exe') and chkwinf90():
1656a8f6897SSatish Balay      if '--ignore-cygwin-link' in sys.argv: return 0
1666a8f6897SSatish Balay      print '==============================================================================='
1671921852fSSatish Balay      print ' *** Cygwin /usr/bin/link detected! Compiles with CVF/Intel f90 can break!  **'
1686a8f6897SSatish Balay      print ' *** To workarround do: "mv /usr/bin/link.exe /usr/bin/link-cygwin.exe"     **'
1696a8f6897SSatish Balay      print ' *** Or to ignore this check, use configure option: --ignore-cygwin-link    **'
1706a8f6897SSatish Balay      print '==============================================================================='
1716a8f6897SSatish Balay      sys.exit(3)
1726a8f6897SSatish Balay  return 0
1736a8f6897SSatish Balay
17485ef4d1eSSatish Balaydef chkbrokencygwin():
1759dabcff0SSatish Balay  if os.path.exists('/usr/bin/cygcheck.exe'):
1769dabcff0SSatish Balay    buf = os.popen('/usr/bin/cygcheck.exe -c cygwin').read()
1779dabcff0SSatish Balay    if buf.find('1.5.11-1') > -1:
178a0022257SSatish Balay      print '==============================================================================='
179e2e64c6bSBarry Smith      print ' *** cygwin-1.5.11-1 detected. ./configure fails with this version ***'
1801937db7aSSatish Balay      print ' *** Please upgrade to cygwin-1.5.12-1 or newer version. This can  ***'
1811937db7aSSatish Balay      print ' *** be done by running cygwin-setup, selecting "next" all the way.***'
182a0022257SSatish Balay      print '==============================================================================='
1831937db7aSSatish Balay      sys.exit(3)
1849dabcff0SSatish Balay  return 0
1859dabcff0SSatish Balay
186ee76e990SSatish Balaydef chkusingwindowspython():
187ee76e990SSatish Balay  if sys.platform == 'win32':
188ee76e990SSatish Balay    print '==============================================================================='
189ee76e990SSatish Balay    print ' *** Windows python detected. Please rerun ./configure with cygwin-python. ***'
190ee76e990SSatish Balay    print '==============================================================================='
191ee76e990SSatish Balay    sys.exit(3)
192ee76e990SSatish Balay  return 0
193ee76e990SSatish Balay
19414f5c25cSSatish Balaydef chkcygwinpython():
19514f5c25cSSatish Balay  if os.path.exists('/usr/bin/cygcheck.exe') and sys.platform == 'cygwin' :
1961937db7aSSatish Balay    sys.argv.append('--useThreads=0')
1971937db7aSSatish Balay    extraLogs.append('''\
198a0022257SSatish Balay===============================================================================
19914f5c25cSSatish Balay** Cygwin-python detected. Threads do not work correctly. ***
20014f5c25cSSatish Balay** Disabling thread usage for this run of ./configure *******
201a0022257SSatish Balay===============================================================================''')
20271384062SSatish Balay  return 0
20371384062SSatish Balay
2041937db7aSSatish Balaydef chkrhl9():
2051937db7aSSatish Balay  if os.path.exists('/etc/redhat-release'):
206836c2c52SSatish Balay    try:
207594eb360SSatish Balay      file = open('/etc/redhat-release','r')
208836c2c52SSatish Balay      buf = file.read()
209836c2c52SSatish Balay      file.close()
210836c2c52SSatish Balay    except:
211836c2c52SSatish Balay      # can't read file - assume dangerous RHL9
2121937db7aSSatish Balay      buf = 'Shrike'
213836c2c52SSatish Balay    if buf.find('Shrike') > -1:
2141937db7aSSatish Balay      sys.argv.append('--useThreads=0')
2151937db7aSSatish Balay      extraLogs.append('''\
216a0022257SSatish Balay==============================================================================
2171937db7aSSatish Balay   *** RHL9 detected. Threads do not work correctly with this distribution ***
218e2e64c6bSBarry Smith   ****** Disabling thread usage for this run of ./configure *********
219a0022257SSatish Balay===============================================================================''')
220836c2c52SSatish Balay  return 0
221836c2c52SSatish Balay
222da58527dSSatish Balaydef check_broken_configure_log_links():
223da58527dSSatish Balay  '''Sometime symlinks can get broken if the original files are deleted. Delete such broken links'''
224da58527dSSatish Balay  import os
225da58527dSSatish Balay  for logfile in ['configure.log','configure.log.bkp']:
226da58527dSSatish Balay    if os.path.islink(logfile) and not os.path.isfile(logfile): os.remove(logfile)
227da58527dSSatish Balay  return
228da58527dSSatish Balay
229da1d79b4SSatish Balaydef move_configure_log(framework):
230fe998a80SBarry Smith  '''Move configure.log to PETSC_ARCH/lib/petsc-conf - and update configure.log.bkp in both locations appropriately'''
231b0b472b0SSatish Balay  global petsc_arch
232b0b472b0SSatish Balay
233b0b472b0SSatish Balay  if hasattr(framework,'arch'): petsc_arch = framework.arch
234b0b472b0SSatish Balay  if hasattr(framework,'logName'): curr_file = framework.logName
235b0b472b0SSatish Balay  else: curr_file = 'configure.log'
236b0b472b0SSatish Balay
237b0b472b0SSatish Balay  if petsc_arch:
238da1d79b4SSatish Balay    import shutil
239da1d79b4SSatish Balay    import os
240b0b472b0SSatish Balay
241b0b472b0SSatish Balay    # Just in case - confdir is not created
242fe998a80SBarry Smith    lib_dir = os.path.join(petsc_arch,'lib')
243fe998a80SBarry Smith    conf_dir = os.path.join(petsc_arch,'lib','petsc-conf')
244b0b472b0SSatish Balay    if not os.path.isdir(petsc_arch): os.mkdir(petsc_arch)
245fe998a80SBarry Smith    if not os.path.isdir(lib_dir): os.mkdir(lib_dir)
246b0b472b0SSatish Balay    if not os.path.isdir(conf_dir): os.mkdir(conf_dir)
247b0b472b0SSatish Balay
248da1d79b4SSatish Balay    curr_bkp  = curr_file + '.bkp'
249b0b472b0SSatish Balay    new_file  = os.path.join(conf_dir,curr_file)
250da1d79b4SSatish Balay    new_bkp   = new_file + '.bkp'
251da1d79b4SSatish Balay
252fe998a80SBarry Smith    # Keep backup in $PETSC_ARCH/lib/petsc-conf location
253da1d79b4SSatish Balay    if os.path.isfile(new_bkp): os.remove(new_bkp)
254da1d79b4SSatish Balay    if os.path.isfile(new_file): os.rename(new_file,new_bkp)
2559e50940cSSatish Balay    if os.path.isfile(curr_file):
2569e50940cSSatish Balay      shutil.copyfile(curr_file,new_file)
2579e50940cSSatish Balay      os.remove(curr_file)
258da58527dSSatish Balay    if os.path.isfile(new_file): os.symlink(new_file,curr_file)
259fe998a80SBarry Smith    # If the old bkp is using the same PETSC_ARCH/lib/petsc-conf - then update bkp link
260da1d79b4SSatish Balay    if os.path.realpath(curr_bkp) == os.path.realpath(new_file):
261da58527dSSatish Balay      if os.path.isfile(curr_bkp): os.remove(curr_bkp)
262da58527dSSatish Balay      if os.path.isfile(new_bkp): os.symlink(new_bkp,curr_bkp)
263da1d79b4SSatish Balay  return
264da1d79b4SSatish Balay
265d93c4beeSSatish Balaydef print_final_timestamp(framework):
266d93c4beeSSatish Balay  import time
267d93c4beeSSatish Balay  framework.log.write(('='*80)+'\n')
268d93c4beeSSatish Balay  framework.log.write('Finishing Configure Run at '+time.ctime(time.time())+'\n')
269d93c4beeSSatish Balay  framework.log.write(('='*80)+'\n')
270d93c4beeSSatish Balay  return
271d93c4beeSSatish Balay
2725d5a5a7bSMatthew Knepleydef petsc_configure(configure_options):
2734a532159SBarry Smith  try:
2744a532159SBarry Smith    petscdir = os.environ['PETSC_DIR']
275bf39c399SBarry Smith    sys.path.append(os.path.join(petscdir,'bin','petsc-pythonscripts'))
2764a532159SBarry Smith    import petscnagupgrade
2774a532159SBarry Smith    file     = os.path.join(petscdir,'.nagged')
2784a532159SBarry Smith    if not petscnagupgrade.naggedtoday(file):
2794a532159SBarry Smith      petscnagupgrade.currentversion(petscdir)
2804a532159SBarry Smith  except:
2814a532159SBarry Smith    pass
282a0022257SSatish Balay  print '==============================================================================='
28359e9bfd6SSatish Balay  print '             Configuring PETSc to compile on your system                       '
284a0022257SSatish Balay  print '==============================================================================='
28559e9bfd6SSatish Balay
286a258c2c4SMatthew G Knepley  try:
287c43ea0feSSatish Balay    # Command line arguments take precedence (but don't destroy argv[0])
288c43ea0feSSatish Balay    sys.argv = sys.argv[:1] + configure_options + sys.argv[1:]
289ccb279e1SMatthew Knepley    check_for_option_mistakes(sys.argv)
2902af240f0SSatish Balay    check_for_option_changed(sys.argv)
291a258c2c4SMatthew G Knepley  except (TypeError, ValueError), e:
292a258c2c4SMatthew G Knepley    emsg = str(e)
293a258c2c4SMatthew G Knepley    if not emsg.endswith('\n'): emsg = emsg+'\n'
294a258c2c4SMatthew G Knepley    msg ='*******************************************************************************\n'\
295a258c2c4SMatthew G Knepley    +'                ERROR in COMMAND LINE ARGUMENT to ./configure \n' \
296a258c2c4SMatthew G Knepley    +'-------------------------------------------------------------------------------\n'  \
297a258c2c4SMatthew G Knepley    +emsg+'*******************************************************************************\n'
298a258c2c4SMatthew G Knepley    sys.exit(msg)
29959e9bfd6SSatish Balay  # check PETSC_ARCH
30059e9bfd6SSatish Balay  check_petsc_arch(sys.argv)
301da58527dSSatish Balay  check_broken_configure_log_links()
3025fb2c094SBarry Smith
303f08ee00aSJason Sarich  #rename '--enable-' to '--with-'
304f08ee00aSJason Sarich  chkenable()
305c22cdea9SBarry Smith  # support a few standard configure option types
306f08ee00aSJason Sarich  chksynonyms()
3079dabcff0SSatish Balay  # Check for broken cygwin
3081937db7aSSatish Balay  chkbrokencygwin()
309d65f3bddSMatthew Knepley  # Disable threads on RHL9
3101937db7aSSatish Balay  chkrhl9()
311ee76e990SSatish Balay  # Make sure cygwin-python is used on windows
312ee76e990SSatish Balay  chkusingwindowspython()
31314f5c25cSSatish Balay  # Threads don't work for cygwin & python...
31414f5c25cSSatish Balay  chkcygwinpython()
3156a8f6897SSatish Balay  chkcygwinlink()
3168a4600f2SSatish Balay  chkdosfiles()
3179dabcff0SSatish Balay
31887282423SMatthew Knepley  # Should be run from the toplevel
319dbca6d9dSSatish Balay  configDir = os.path.abspath('config')
320f8833479SBarry Smith  bsDir     = os.path.join(configDir, 'BuildSystem')
321f8833479SBarry Smith  if not os.path.isdir(configDir):
3225d5a5a7bSMatthew Knepley    raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.'))
32387282423SMatthew Knepley  sys.path.insert(0, bsDir)
324f8833479SBarry Smith  sys.path.insert(0, configDir)
325e69ef9dfSMatthew Knepley  import config.base
3265d5a5a7bSMatthew Knepley  import config.framework
327f56be888SMatthew Knepley  import cPickle
3284f8a5b45SBarry Smith
3299dd2fdb1SMatthew Knepley  framework = None
3309dd2fdb1SMatthew Knepley  try:
33123a19ef1SSatish Balay    framework = config.framework.Framework(['--configModules=PETSc.Configure','--optionsModule=config.compilerOptions']+sys.argv[1:], loadArgDB = 0)
332d65f3bddSMatthew Knepley    framework.setup()
333d65f3bddSMatthew Knepley    framework.logPrint('\n'.join(extraLogs))
334f24f64feSBarry Smith    framework.configure(out = sys.stdout)
335358ebc22SMatthew Knepley    framework.storeSubstitutions(framework.argDB)
336f56be888SMatthew Knepley    framework.argDB['configureCache'] = cPickle.dumps(framework)
3377c939e48SSatish Balay    framework.printSummary()
33812c1d45bSMatthew G Knepley    framework.argDB.save(force = True)
3397cfd0b05SBarry Smith    framework.logClear()
340d93c4beeSSatish Balay    print_final_timestamp(framework)
341eefa2c0fSBarry Smith    framework.closeLog()
3429e50940cSSatish Balay    try:
343da1d79b4SSatish Balay      move_configure_log(framework)
3449e50940cSSatish Balay    except:
3459e50940cSSatish Balay      # perhaps print an error about unable to shuffle logs?
3469e50940cSSatish Balay      pass
347dd50d019SBarry Smith    return 0
348e69ef9dfSMatthew Knepley  except (RuntimeError, config.base.ConfigureSetupError), e:
3497d670a3cSBarry Smith    emsg = str(e)
35042351d26SSatish Balay    if not emsg.endswith('\n'): emsg = emsg+'\n'
351a0022257SSatish Balay    msg ='*******************************************************************************\n'\
352fe09c992SBarry Smith    +'         UNABLE to CONFIGURE with GIVEN OPTIONS    (see configure.log for details):\n' \
353a0022257SSatish Balay    +'-------------------------------------------------------------------------------\n'  \
354a0022257SSatish Balay    +emsg+'*******************************************************************************\n'
355e9f3bb17SBarry Smith    se = ''
3569dd2fdb1SMatthew Knepley  except (TypeError, ValueError), e:
3577d670a3cSBarry Smith    emsg = str(e)
35842351d26SSatish Balay    if not emsg.endswith('\n'): emsg = emsg+'\n'
359a0022257SSatish Balay    msg ='*******************************************************************************\n'\
360e2e64c6bSBarry Smith    +'                ERROR in COMMAND LINE ARGUMENT to ./configure \n' \
361a0022257SSatish Balay    +'-------------------------------------------------------------------------------\n'  \
362a0022257SSatish Balay    +emsg+'*******************************************************************************\n'
3631a02243aSBarry Smith    se = ''
36496dc2fe8SMatthew Knepley  except ImportError, e :
3657d670a3cSBarry Smith    emsg = str(e)
36642351d26SSatish Balay    if not emsg.endswith('\n'): emsg = emsg+'\n'
367a0022257SSatish Balay    msg ='*******************************************************************************\n'\
368e2e64c6bSBarry Smith    +'                     UNABLE to FIND MODULE for ./configure \n' \
369a0022257SSatish Balay    +'-------------------------------------------------------------------------------\n'  \
370a0022257SSatish Balay    +emsg+'*******************************************************************************\n'
37196dc2fe8SMatthew Knepley    se = ''
37201def6f0SMatthew Knepley  except OSError, e :
37301def6f0SMatthew Knepley    emsg = str(e)
37401def6f0SMatthew Knepley    if not emsg.endswith('\n'): emsg = emsg+'\n'
375a0022257SSatish Balay    msg ='*******************************************************************************\n'\
376e2e64c6bSBarry Smith    +'                    UNABLE to EXECUTE BINARIES for ./configure \n' \
377a0022257SSatish Balay    +'-------------------------------------------------------------------------------\n'  \
378a0022257SSatish Balay    +emsg+'*******************************************************************************\n'
37901def6f0SMatthew Knepley    se = ''
380d7d3c4beSMatthew Knepley  except SystemExit, e:
381d7d3c4beSMatthew Knepley    if e.code is None or e.code == 0:
382d7d3c4beSMatthew Knepley      return
383a0022257SSatish Balay    msg ='*******************************************************************************\n'\
384b1dada7fSMatthew Knepley    +'         CONFIGURATION FAILURE  (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \
385a0022257SSatish Balay    +'*******************************************************************************\n'
386d7d3c4beSMatthew Knepley    se  = str(e)
387e9f3bb17SBarry Smith  except Exception, e:
388a0022257SSatish Balay    msg ='*******************************************************************************\n'\
389fe09c992SBarry Smith    +'        CONFIGURATION CRASH  (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \
390a0022257SSatish Balay    +'*******************************************************************************\n'
391e9f3bb17SBarry Smith    se  = str(e)
392e9f3bb17SBarry Smith
393e9f3bb17SBarry Smith  print msg
3949dd2fdb1SMatthew Knepley  if not framework is None:
3959dd2fdb1SMatthew Knepley    framework.logClear()
396e9f3bb17SBarry Smith    if hasattr(framework, 'log'):
39722c95ba3SMatthew G Knepley      try:
398d71f8ab3SSatish Balay        if hasattr(framework,'compilerDefines'):
399bd5137a2SBarry Smith          framework.log.write('**** Configure header '+framework.compilerDefines+' ****\n')
400febd46b0SSatish Balay          framework.outputHeader(framework.log)
401d71f8ab3SSatish Balay        if hasattr(framework,'compilerFixes'):
402bd5137a2SBarry Smith          framework.log.write('**** C specific Configure header '+framework.compilerFixes+' ****\n')
403febd46b0SSatish Balay          framework.outputCHeader(framework.log)
40422c95ba3SMatthew G Knepley      except Exception, e:
40522c95ba3SMatthew G Knepley        framework.log.write('Problem writing headers to log: '+str(e))
406f6614063SBarry Smith      import traceback
407b1dada7fSMatthew Knepley      try:
408f24f64feSBarry Smith        framework.log.write(msg+se)
409f24f64feSBarry Smith        traceback.print_tb(sys.exc_info()[2], file = framework.log)
410d93c4beeSSatish Balay        print_final_timestamp(framework)
411f73e6a6cSSatish Balay        if hasattr(framework,'log'): framework.log.close()
412da1d79b4SSatish Balay        move_configure_log(framework)
413b1dada7fSMatthew Knepley      except:
414b1dada7fSMatthew Knepley        pass
415e9f3bb17SBarry Smith      sys.exit(1)
4165a74f024SMatthew Knepley  else:
4175a74f024SMatthew Knepley    print se
4185a74f024SMatthew Knepley    import traceback
4195a74f024SMatthew Knepley    traceback.print_tb(sys.exc_info()[2])
420f73e6a6cSSatish Balay  if hasattr(framework,'log'): framework.log.close()
4215d5a5a7bSMatthew Knepley
4225d5a5a7bSMatthew Knepleyif __name__ == '__main__':
423a030c540SBarry Smith  petsc_configure([])
424759acf64SBarry Smith
425