xref: /petsc/config/configure.py (revision 91dcc5a8334bde471e887179eedaaa630561d9b5)
15d5a5a7bSMatthew Knepley#!/usr/bin/env python
22787667cSMatthew G Knepleyimport os, sys
3db5c7c58SSatish Balay
47c9abfe7SSatish BalayextraLogs = []
5b0b472b0SSatish Balaypetsc_arch = ''
64b8aa89bSBarry Smith
744b0d7f9SSatish Balay# Use en_US as language so that BuildSystem parses compiler messages in english
89b436e4bSSatish 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'
99b436e4bSSatish 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'
1044b0d7f9SSatish Balay
11db5c7c58SSatish Balayif not hasattr(sys, 'version_info') or not sys.version_info[0] == 2 or not sys.version_info[1] >= 6:
12db5c7c58SSatish Balay  print '*******************************************************************************'
13db5c7c58SSatish Balay  print '*       Python2 version 2.6 or higher is required to run ./configure          *'
14db5c7c58SSatish Balay  print '*          Try: "python2.7 ./configure" or "python2.6 ./configure"            *'
15a0022257SSatish Balay  print '*******************************************************************************'
16b26a8723SBarry Smith  sys.exit(4)
172fb34ac0SMatthew Knepley
18ccb279e1SMatthew Knepleydef check_for_option_mistakes(opts):
1945faeebdSBarry Smith  for opt in opts[1:]:
20cda0060aSMatthew Knepley    name = opt.split('=')[0]
21ccb279e1SMatthew Knepley    if name.find('_') >= 0:
22ccb279e1SMatthew Knepley      exception = False
23d305a81bSVasiliy 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']:
24ccb279e1SMatthew Knepley        if name.find(exc) >= 0:
25ccb279e1SMatthew Knepley          exception = True
26ccb279e1SMatthew Knepley      if not exception:
27ccb279e1SMatthew Knepley        raise ValueError('The option '+name+' should probably be '+name.replace('_', '-'));
28ab610953SSatish Balay    if opt.find('=') >=0:
29ab610953SSatish Balay      optval = opt.split('=')[1]
30ab610953SSatish Balay      if optval == 'ifneeded':
31ab610953SSatish Balay        raise ValueError('The option '+opt+' should probably be '+opt.replace('ifneeded', '1'));
32ccb279e1SMatthew Knepley  return
33ccb279e1SMatthew Knepley
342f393ef5SBarry Smithdef check_for_unsupported_combinations(opts):
352f393ef5SBarry Smith  if '--with-precision=single' in opts and '--with-clanguage=cxx' in opts and '--with-scalar-type=complex' in opts:
362f393ef5SBarry Smith    sys.exit(ValueError('PETSc does not support single precision complex with C++ clanguage, run with --with-clanguage=c'))
372f393ef5SBarry Smith
382af240f0SSatish Balaydef check_for_option_changed(opts):
392af240f0SSatish Balay# Document changes in command line options here.
4069c3d79aSBarry Smith  optMap = [('with-64bit-indices','with-64-bit-indices'),('c-blas-lapack','f2cblaslapack'),('cholmod','suitesparse'),('umfpack','suitesparse'),('f-blas-lapack','fblaslapack')]
412af240f0SSatish Balay  for opt in opts[1:]:
422af240f0SSatish Balay    optname = opt.split('=')[0].strip('-')
432af240f0SSatish Balay    for oldname,newname in optMap:
442af240f0SSatish Balay      if optname.find(oldname) >=0:
452af240f0SSatish Balay        raise ValueError('The option '+opt+' should probably be '+opt.replace(oldname,newname))
462af240f0SSatish Balay  return
472af240f0SSatish Balay
4859e9bfd6SSatish Balaydef check_petsc_arch(opts):
49c43ea0feSSatish Balay  # If PETSC_ARCH not specified - use script name (if not configure.py)
50b0b472b0SSatish Balay  global petsc_arch
51c43ea0feSSatish Balay  found = 0
5259e9bfd6SSatish Balay  for name in opts:
53c43ea0feSSatish Balay    if name.find('PETSC_ARCH=') >= 0:
54b0b472b0SSatish Balay      petsc_arch=name.split('=')[1]
55c43ea0feSSatish Balay      found = 1
5659e9bfd6SSatish Balay      break
5759e9bfd6SSatish Balay  # If not yet specified - use the filename of script
58c43ea0feSSatish Balay  if not found:
5959e9bfd6SSatish Balay      filename = os.path.basename(sys.argv[0])
60e68ebbecSBarry Smith      if not filename.startswith('configure') and not filename.startswith('reconfigure') and not filename.startswith('setup'):
61b0b472b0SSatish Balay        petsc_arch=os.path.splitext(os.path.basename(sys.argv[0]))[0]
62b0b472b0SSatish Balay        useName = 'PETSC_ARCH='+petsc_arch
6359e9bfd6SSatish Balay        opts.append(useName)
641937db7aSSatish Balay  return 0
654b8aa89bSBarry Smith
66f08ee00aSJason Sarichdef chkenable():
67f08ee00aSJason Sarich  #Replace all 'enable-'/'disable-' with 'with-'=0/1/tail
68f08ee00aSJason Sarich  #enable-fortran is a special case, the resulting --with-fortran is ambiguous.
69f08ee00aSJason Sarich  #Would it mean --with-fc= or --with-fortran-interfaces=?
70f08ee00aSJason Sarich  for l in range(0,len(sys.argv)):
71f08ee00aSJason Sarich    name = sys.argv[l]
72f08ee00aSJason Sarich    if name.find('enable-fortran') >= 0:
73f08ee00aSJason Sarich      if name.find('=') == -1:
74f08ee00aSJason Sarich        sys.argv[l] = name.replace('enable-fortran','with-fortran-interfaces')+'=1'
75f08ee00aSJason Sarich      else:
76f08ee00aSJason Sarich        head, tail = name.split('=', 1)
77f08ee00aSJason Sarich        sys.argv[l] = head.replace('enable-fortran','with-fortran-interfaces')+'='+tail
78f08ee00aSJason Sarich      continue
79f08ee00aSJason Sarich    if name.find('disable-fortran') >= 0:
80f08ee00aSJason Sarich      if name.find('=') == -1:
81f08ee00aSJason Sarich        sys.argv[l] = name.replace('disable-fortran','with-fortran-interfaces')+'=0'
82f08ee00aSJason Sarich      else:
83f08ee00aSJason Sarich        head, tail = name.split('=', 1)
84f08ee00aSJason Sarich        if tail == '1': tail = '0'
85f08ee00aSJason Sarich        sys.argv[l] = head.replace('disable-fortran','with-fortran-interfaces')+'='+tail
86f08ee00aSJason Sarich      continue
87f08ee00aSJason Sarich
882b700d61SJason Sarich    if name.find('enable-cxx') >= 0:
892b700d61SJason Sarich      if name.find('=') == -1:
902b700d61SJason Sarich        sys.argv[l] = name.replace('enable-cxx','with-clanguage=C++')
912b700d61SJason Sarich      else:
922b700d61SJason Sarich        head, tail = name.split('=', 1)
932b700d61SJason Sarich        if tail=='0':
942b700d61SJason Sarich          sys.argv[l] = head.replace('enable-cxx','with-clanguage=C')
952b700d61SJason Sarich        else:
962b700d61SJason Sarich          sys.argv[l] = head.replace('enable-cxx','with-clanguage=C++')
972b700d61SJason Sarich      continue
982b700d61SJason Sarich    if name.find('disable-cxx') >= 0:
992b700d61SJason Sarich      if name.find('=') == -1:
1002b700d61SJason Sarich        sys.argv[l] = name.replace('disable-cxx','with-clanguage=C')
1012b700d61SJason Sarich      else:
1022b700d61SJason Sarich        head, tail = name.split('=', 1)
1032b700d61SJason Sarich        if tail == '0':
1042b700d61SJason Sarich          sys.argv[l] = head.replace('disable-cxx','with-clanguage=C++')
1052b700d61SJason Sarich        else:
1062b700d61SJason Sarich          sys.argv[l] = head.replace('disable-cxx','with-clanguage=C')
1072b700d61SJason Sarich      continue
1082b700d61SJason Sarich
109f08ee00aSJason Sarich
110f08ee00aSJason Sarich    if name.find('enable-') >= 0:
111f08ee00aSJason Sarich      if name.find('=') == -1:
112f08ee00aSJason Sarich        sys.argv[l] = name.replace('enable-','with-')+'=1'
113f08ee00aSJason Sarich      else:
114f08ee00aSJason Sarich        head, tail = name.split('=', 1)
115f08ee00aSJason Sarich        sys.argv[l] = head.replace('enable-','with-')+'='+tail
116f08ee00aSJason Sarich    if name.find('disable-') >= 0:
117f08ee00aSJason Sarich      if name.find('=') == -1:
118f08ee00aSJason Sarich        sys.argv[l] = name.replace('disable-','with-')+'=0'
119f08ee00aSJason Sarich      else:
120f08ee00aSJason Sarich        head, tail = name.split('=', 1)
121f08ee00aSJason Sarich        if tail == '1': tail = '0'
122f08ee00aSJason Sarich        sys.argv[l] = head.replace('disable-','with-')+'='+tail
123f08ee00aSJason Sarich    if name.find('without-') >= 0:
124f08ee00aSJason Sarich      if name.find('=') == -1:
125f08ee00aSJason Sarich        sys.argv[l] = name.replace('without-','with-')+'=0'
126f08ee00aSJason Sarich      else:
127f08ee00aSJason Sarich        head, tail = name.split('=', 1)
128f08ee00aSJason Sarich        if tail == '1': tail = '0'
129f08ee00aSJason Sarich        sys.argv[l] = head.replace('without-','with-')+'='+tail
130f08ee00aSJason Sarich
13177e64500SBarry Smithdef argsAddDownload(value,deps = [],options = []):
13277e64500SBarry Smith  # Adds --download-value to args if the command line DOES NOT already has --with-value or --download-value in it
13377e64500SBarry Smith  # this is to prevent introducing conflicting arguments to ones that already exist
13461b0a1dcSBarry Smith  for i in sys.argv:
13538ac3b23SBarry Smith    if i.startswith('--with-'+value): return
13638ac3b23SBarry Smith    if i.startswith('--download-'+value) and not i.startswith('--download-'+value+'-commit'): return
13777e64500SBarry Smith  sys.argv.append('--download-'+value)
13877e64500SBarry Smith  for i in deps:
13977e64500SBarry Smith    argsAddDownload(i)
14077e64500SBarry Smith  for i in options:
14177e64500SBarry Smith    sys.argv.append(i)
1428fd71741SJason Sarich
143f08ee00aSJason Sarichdef chksynonyms():
144f08ee00aSJason Sarich  #replace common configure options with ones that PETSc BuildSystem recognizes
145a41fa05bSBarry Smith  downloadxsdk = 0
146a41fa05bSBarry Smith  downloadideas = 0
147f08ee00aSJason Sarich  for l in range(0,len(sys.argv)):
148f08ee00aSJason Sarich    name = sys.argv[l]
149f08ee00aSJason Sarich
150a41fa05bSBarry Smith    if name.startswith('--download-xsdk'):
151a41fa05bSBarry Smith      downloadxsdk = 1
152a41fa05bSBarry Smith
153a41fa05bSBarry Smith    if name.startswith('--download-ideas'):
154a41fa05bSBarry Smith      downloadideas = 1
155f08ee00aSJason Sarich
156ce54fb35SBarry Smith    if name.find('with-debug=') >= 0 or name.endswith('with-debug'):
157f08ee00aSJason Sarich      if name.find('=') == -1:
158f08ee00aSJason Sarich        sys.argv[l] = name.replace('with-debug','with-debugging')+'=1'
159f08ee00aSJason Sarich      else:
160f08ee00aSJason Sarich        head, tail = name.split('=', 1)
161f08ee00aSJason Sarich        sys.argv[l] = head.replace('with-debug','with-debugging')+'='+tail
162f08ee00aSJason Sarich
163ce54fb35SBarry Smith    if name.find('with-shared=') >= 0 or name.endswith('with-shared'):
164f08ee00aSJason Sarich      if name.find('=') == -1:
165ce54fb35SBarry Smith        sys.argv[l] = name.replace('with-shared','with-shared-libraries')+'=1'
166f08ee00aSJason Sarich      else:
167f08ee00aSJason Sarich        head, tail = name.split('=', 1)
168ce54fb35SBarry Smith        sys.argv[l] = head.replace('with-shared','with-shared-libraries')+'='+tail
169f08ee00aSJason Sarich
1708fd71741SJason Sarich    if name.find('with-index-size=') >=0:
1718fd71741SJason Sarich      head,tail = name.split('=',1)
1728fd71741SJason Sarich      if int(tail)==32:
1738fd71741SJason Sarich        sys.argv[l] = '--with-64-bit-indices=0'
1748fd71741SJason Sarich      elif int(tail)==64:
1758fd71741SJason Sarich        sys.argv[l] = '--with-64-bit-indices=1'
1768fd71741SJason Sarich      else:
1778fd71741SJason Sarich        raise RuntimeError('--with-index-size= must be 32 or 64')
178f08ee00aSJason Sarich
1798fd71741SJason Sarich    if name.find('with-precision=') >=0:
1808fd71741SJason Sarich      head,tail = name.split('=',1)
1818fd71741SJason Sarich      if tail.find('quad')>=0:
1828fd71741SJason Sarich        sys.argv[l]='--with-precision=__float128'
183f08ee00aSJason Sarich
184a41fa05bSBarry Smith  if downloadideas:
18577e64500SBarry Smith    downloadxsdk = 1
18677e64500SBarry Smith    argsAddDownload('pflotran')
18777e64500SBarry Smith    argsAddDownload('alquimia')
18877e64500SBarry Smith    # mstk currently cannot build a shared library
18977e64500SBarry Smith    argsAddDownload('mstk',[],['--download-mstk-shared=0'])
1907a3d669cSBarry Smith    argsAddDownload('ascem-io')
191b21bda25SBarry Smith    argsAddDownload('unittestcpp')
192a41fa05bSBarry Smith
193a41fa05bSBarry Smith  if downloadxsdk:
194a41fa05bSBarry Smith    # Common external libraries
19577e64500SBarry Smith    argsAddDownload('hdf5')
19677e64500SBarry Smith    argsAddDownload('netcdf')
19777e64500SBarry Smith    argsAddDownload('exodusii')
19877e64500SBarry Smith    argsAddDownload('metis')
199a41fa05bSBarry Smith
20077e64500SBarry Smith    argsAddDownload('superlu_dist',['parmetis'])
201a41fa05bSBarry Smith
20277e64500SBarry Smith    argsAddDownload('hypre')
20377e64500SBarry Smith
20477e64500SBarry Smith    argsAddDownload('trilinos',['boost'],['--with-cxx-dialect=C++11'])
205*91dcc5a8SBarry Smith    argsAddDownload('xsdktrilinos')
206a41fa05bSBarry Smith
207f08ee00aSJason Sarich
2081921852fSSatish Balaydef chkwinf90():
2096a8f6897SSatish Balay  for arg in sys.argv:
2101921852fSSatish Balay    if (arg.find('win32fe') >= 0 and (arg.find('f90') >=0 or arg.find('ifort') >=0)):
2116a8f6897SSatish Balay      return 1
2126a8f6897SSatish Balay  return 0
2136a8f6897SSatish Balay
2148a4600f2SSatish Balaydef chkdosfiles():
215360dfd13SSatish Balay  # cygwin - but not a hg clone - so check one of files in bin dir
216db1f124cSVasiliy Kozyrev  if "\r\n" in open(os.path.join('bin','petscmpiexec'),"rb").read():
217db1f124cSVasiliy Kozyrev    print '==============================================================================='
218db1f124cSVasiliy Kozyrev    print ' *** Scripts are in DOS mode. Was winzip used to extract petsc sources?    ****'
219db1f124cSVasiliy Kozyrev    print ' *** Please restart with a fresh tarball and use "tar -xzf petsc.tar.gz"   ****'
220db1f124cSVasiliy Kozyrev    print '==============================================================================='
221db1f124cSVasiliy Kozyrev    sys.exit(3)
2228a4600f2SSatish Balay  return
2238a4600f2SSatish Balay
2246a8f6897SSatish Balaydef chkcygwinlink():
2251921852fSSatish Balay  if os.path.exists('/usr/bin/cygcheck.exe') and os.path.exists('/usr/bin/link.exe') and chkwinf90():
2266a8f6897SSatish Balay      if '--ignore-cygwin-link' in sys.argv: return 0
2276a8f6897SSatish Balay      print '==============================================================================='
2281921852fSSatish Balay      print ' *** Cygwin /usr/bin/link detected! Compiles with CVF/Intel f90 can break!  **'
2296a8f6897SSatish Balay      print ' *** To workarround do: "mv /usr/bin/link.exe /usr/bin/link-cygwin.exe"     **'
2306a8f6897SSatish Balay      print ' *** Or to ignore this check, use configure option: --ignore-cygwin-link    **'
2316a8f6897SSatish Balay      print '==============================================================================='
2326a8f6897SSatish Balay      sys.exit(3)
2336a8f6897SSatish Balay  return 0
2346a8f6897SSatish Balay
23585ef4d1eSSatish Balaydef chkbrokencygwin():
2369dabcff0SSatish Balay  if os.path.exists('/usr/bin/cygcheck.exe'):
2379dabcff0SSatish Balay    buf = os.popen('/usr/bin/cygcheck.exe -c cygwin').read()
2389dabcff0SSatish Balay    if buf.find('1.5.11-1') > -1:
239a0022257SSatish Balay      print '==============================================================================='
240e2e64c6bSBarry Smith      print ' *** cygwin-1.5.11-1 detected. ./configure fails with this version ***'
2411937db7aSSatish Balay      print ' *** Please upgrade to cygwin-1.5.12-1 or newer version. This can  ***'
2421937db7aSSatish Balay      print ' *** be done by running cygwin-setup, selecting "next" all the way.***'
243a0022257SSatish Balay      print '==============================================================================='
2441937db7aSSatish Balay      sys.exit(3)
2459dabcff0SSatish Balay  return 0
2469dabcff0SSatish Balay
247ee76e990SSatish Balaydef chkusingwindowspython():
248ee76e990SSatish Balay  if sys.platform == 'win32':
249ee76e990SSatish Balay    print '==============================================================================='
250ee76e990SSatish Balay    print ' *** Windows python detected. Please rerun ./configure with cygwin-python. ***'
251ee76e990SSatish Balay    print '==============================================================================='
252ee76e990SSatish Balay    sys.exit(3)
253ee76e990SSatish Balay  return 0
254ee76e990SSatish Balay
25514f5c25cSSatish Balaydef chkcygwinpython():
2561150532aSSatish Balay  if sys.platform == 'cygwin' :
2571150532aSSatish Balay    import platform
2581150532aSSatish Balay    import re
2591150532aSSatish Balay    r=re.compile("([0-9]+).([0-9]+).([0-9]+)")
2601150532aSSatish Balay    m=r.match(platform.release())
2611150532aSSatish Balay    major=int(m.group(1))
2621150532aSSatish Balay    minor=int(m.group(2))
2631150532aSSatish Balay    subminor=int(m.group(3))
2641150532aSSatish Balay    if ((major < 1) or (major == 1 and minor < 7) or (major == 1 and minor == 7 and subminor < 34)):
2651937db7aSSatish Balay      sys.argv.append('--useThreads=0')
2661937db7aSSatish Balay      extraLogs.append('''\
267a0022257SSatish Balay===============================================================================
2681150532aSSatish Balay** Cygwin version is older than 1.7.34. Python threads do not work correctly. ***
26914f5c25cSSatish Balay** Disabling thread usage for this run of ./configure *******
270a0022257SSatish Balay===============================================================================''')
27171384062SSatish Balay  return 0
27271384062SSatish Balay
2731937db7aSSatish Balaydef chkrhl9():
2741937db7aSSatish Balay  if os.path.exists('/etc/redhat-release'):
275836c2c52SSatish Balay    try:
276594eb360SSatish Balay      file = open('/etc/redhat-release','r')
277836c2c52SSatish Balay      buf = file.read()
278836c2c52SSatish Balay      file.close()
279836c2c52SSatish Balay    except:
280836c2c52SSatish Balay      # can't read file - assume dangerous RHL9
2811937db7aSSatish Balay      buf = 'Shrike'
282836c2c52SSatish Balay    if buf.find('Shrike') > -1:
2831937db7aSSatish Balay      sys.argv.append('--useThreads=0')
2841937db7aSSatish Balay      extraLogs.append('''\
285a0022257SSatish Balay==============================================================================
2861937db7aSSatish Balay   *** RHL9 detected. Threads do not work correctly with this distribution ***
287e2e64c6bSBarry Smith   ****** Disabling thread usage for this run of ./configure *********
288a0022257SSatish Balay===============================================================================''')
289836c2c52SSatish Balay  return 0
290836c2c52SSatish Balay
291da58527dSSatish Balaydef check_broken_configure_log_links():
292da58527dSSatish Balay  '''Sometime symlinks can get broken if the original files are deleted. Delete such broken links'''
293da58527dSSatish Balay  import os
294da58527dSSatish Balay  for logfile in ['configure.log','configure.log.bkp']:
295da58527dSSatish Balay    if os.path.islink(logfile) and not os.path.isfile(logfile): os.remove(logfile)
296da58527dSSatish Balay  return
297da58527dSSatish Balay
298da1d79b4SSatish Balaydef move_configure_log(framework):
299af0996ceSBarry Smith  '''Move configure.log to PETSC_ARCH/lib/petsc/conf - and update configure.log.bkp in both locations appropriately'''
300b0b472b0SSatish Balay  global petsc_arch
301b0b472b0SSatish Balay
302b0b472b0SSatish Balay  if hasattr(framework,'arch'): petsc_arch = framework.arch
303b0b472b0SSatish Balay  if hasattr(framework,'logName'): curr_file = framework.logName
304b0b472b0SSatish Balay  else: curr_file = 'configure.log'
305b0b472b0SSatish Balay
306b0b472b0SSatish Balay  if petsc_arch:
307da1d79b4SSatish Balay    import shutil
308da1d79b4SSatish Balay    import os
309b0b472b0SSatish Balay
310b0b472b0SSatish Balay    # Just in case - confdir is not created
311fe998a80SBarry Smith    lib_dir = os.path.join(petsc_arch,'lib')
312af0996ceSBarry Smith    conf_dir = os.path.join(petsc_arch,'lib','petsc','conf')
313b0b472b0SSatish Balay    if not os.path.isdir(petsc_arch): os.mkdir(petsc_arch)
314fe998a80SBarry Smith    if not os.path.isdir(lib_dir): os.mkdir(lib_dir)
315b0b472b0SSatish Balay    if not os.path.isdir(conf_dir): os.mkdir(conf_dir)
316b0b472b0SSatish Balay
317da1d79b4SSatish Balay    curr_bkp  = curr_file + '.bkp'
318b0b472b0SSatish Balay    new_file  = os.path.join(conf_dir,curr_file)
319da1d79b4SSatish Balay    new_bkp   = new_file + '.bkp'
320da1d79b4SSatish Balay
321af0996ceSBarry Smith    # Keep backup in $PETSC_ARCH/lib/petsc/conf location
322da1d79b4SSatish Balay    if os.path.isfile(new_bkp): os.remove(new_bkp)
323da1d79b4SSatish Balay    if os.path.isfile(new_file): os.rename(new_file,new_bkp)
3249e50940cSSatish Balay    if os.path.isfile(curr_file):
3259e50940cSSatish Balay      shutil.copyfile(curr_file,new_file)
3269e50940cSSatish Balay      os.remove(curr_file)
327da58527dSSatish Balay    if os.path.isfile(new_file): os.symlink(new_file,curr_file)
328af0996ceSBarry Smith    # If the old bkp is using the same PETSC_ARCH/lib/petsc/conf - then update bkp link
329da1d79b4SSatish Balay    if os.path.realpath(curr_bkp) == os.path.realpath(new_file):
330da58527dSSatish Balay      if os.path.isfile(curr_bkp): os.remove(curr_bkp)
331da58527dSSatish Balay      if os.path.isfile(new_bkp): os.symlink(new_bkp,curr_bkp)
332da1d79b4SSatish Balay  return
333da1d79b4SSatish Balay
334d93c4beeSSatish Balaydef print_final_timestamp(framework):
335d93c4beeSSatish Balay  import time
336d93c4beeSSatish Balay  framework.log.write(('='*80)+'\n')
337d93c4beeSSatish Balay  framework.log.write('Finishing Configure Run at '+time.ctime(time.time())+'\n')
338d93c4beeSSatish Balay  framework.log.write(('='*80)+'\n')
339d93c4beeSSatish Balay  return
340d93c4beeSSatish Balay
3415d5a5a7bSMatthew Knepleydef petsc_configure(configure_options):
3424a532159SBarry Smith  try:
3434a532159SBarry Smith    petscdir = os.environ['PETSC_DIR']
344af0996ceSBarry Smith    sys.path.append(os.path.join(petscdir,'bin'))
3454a532159SBarry Smith    import petscnagupgrade
3464a532159SBarry Smith    file     = os.path.join(petscdir,'.nagged')
3474a532159SBarry Smith    if not petscnagupgrade.naggedtoday(file):
3484a532159SBarry Smith      petscnagupgrade.currentversion(petscdir)
3494a532159SBarry Smith  except:
3504a532159SBarry Smith    pass
351a0022257SSatish Balay  print '==============================================================================='
35259e9bfd6SSatish Balay  print '             Configuring PETSc to compile on your system                       '
353a0022257SSatish Balay  print '==============================================================================='
35459e9bfd6SSatish Balay
355a258c2c4SMatthew G Knepley  try:
356c43ea0feSSatish Balay    # Command line arguments take precedence (but don't destroy argv[0])
357c43ea0feSSatish Balay    sys.argv = sys.argv[:1] + configure_options + sys.argv[1:]
358ccb279e1SMatthew Knepley    check_for_option_mistakes(sys.argv)
3592af240f0SSatish Balay    check_for_option_changed(sys.argv)
360a258c2c4SMatthew G Knepley  except (TypeError, ValueError), e:
361a258c2c4SMatthew G Knepley    emsg = str(e)
362a258c2c4SMatthew G Knepley    if not emsg.endswith('\n'): emsg = emsg+'\n'
363a258c2c4SMatthew G Knepley    msg ='*******************************************************************************\n'\
364a258c2c4SMatthew G Knepley    +'                ERROR in COMMAND LINE ARGUMENT to ./configure \n' \
365a258c2c4SMatthew G Knepley    +'-------------------------------------------------------------------------------\n'  \
366a258c2c4SMatthew G Knepley    +emsg+'*******************************************************************************\n'
367a258c2c4SMatthew G Knepley    sys.exit(msg)
36859e9bfd6SSatish Balay  # check PETSC_ARCH
3692f393ef5SBarry Smith  check_for_unsupported_combinations(sys.argv)
37059e9bfd6SSatish Balay  check_petsc_arch(sys.argv)
371da58527dSSatish Balay  check_broken_configure_log_links()
3725fb2c094SBarry Smith
373f08ee00aSJason Sarich  #rename '--enable-' to '--with-'
374f08ee00aSJason Sarich  chkenable()
375c22cdea9SBarry Smith  # support a few standard configure option types
376f08ee00aSJason Sarich  chksynonyms()
3779dabcff0SSatish Balay  # Check for broken cygwin
3781937db7aSSatish Balay  chkbrokencygwin()
379d65f3bddSMatthew Knepley  # Disable threads on RHL9
3801937db7aSSatish Balay  chkrhl9()
381ee76e990SSatish Balay  # Make sure cygwin-python is used on windows
382ee76e990SSatish Balay  chkusingwindowspython()
38314f5c25cSSatish Balay  # Threads don't work for cygwin & python...
38414f5c25cSSatish Balay  chkcygwinpython()
3856a8f6897SSatish Balay  chkcygwinlink()
3868a4600f2SSatish Balay  chkdosfiles()
3879dabcff0SSatish Balay
38887282423SMatthew Knepley  # Should be run from the toplevel
389dbca6d9dSSatish Balay  configDir = os.path.abspath('config')
390f8833479SBarry Smith  bsDir     = os.path.join(configDir, 'BuildSystem')
391f8833479SBarry Smith  if not os.path.isdir(configDir):
3925d5a5a7bSMatthew Knepley    raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.'))
39387282423SMatthew Knepley  sys.path.insert(0, bsDir)
394f8833479SBarry Smith  sys.path.insert(0, configDir)
395e69ef9dfSMatthew Knepley  import config.base
3965d5a5a7bSMatthew Knepley  import config.framework
397f56be888SMatthew Knepley  import cPickle
3984f8a5b45SBarry Smith
3999dd2fdb1SMatthew Knepley  framework = None
4009dd2fdb1SMatthew Knepley  try:
40123a19ef1SSatish Balay    framework = config.framework.Framework(['--configModules=PETSc.Configure','--optionsModule=config.compilerOptions']+sys.argv[1:], loadArgDB = 0)
402d65f3bddSMatthew Knepley    framework.setup()
403d65f3bddSMatthew Knepley    framework.logPrint('\n'.join(extraLogs))
404f24f64feSBarry Smith    framework.configure(out = sys.stdout)
405358ebc22SMatthew Knepley    framework.storeSubstitutions(framework.argDB)
406f56be888SMatthew Knepley    framework.argDB['configureCache'] = cPickle.dumps(framework)
4077c939e48SSatish Balay    framework.printSummary()
40812c1d45bSMatthew G Knepley    framework.argDB.save(force = True)
4097cfd0b05SBarry Smith    framework.logClear()
410d93c4beeSSatish Balay    print_final_timestamp(framework)
411eefa2c0fSBarry Smith    framework.closeLog()
4129e50940cSSatish Balay    try:
413da1d79b4SSatish Balay      move_configure_log(framework)
4149e50940cSSatish Balay    except:
4159e50940cSSatish Balay      # perhaps print an error about unable to shuffle logs?
4169e50940cSSatish Balay      pass
417dd50d019SBarry Smith    return 0
418e69ef9dfSMatthew Knepley  except (RuntimeError, config.base.ConfigureSetupError), e:
4197d670a3cSBarry Smith    emsg = str(e)
42042351d26SSatish Balay    if not emsg.endswith('\n'): emsg = emsg+'\n'
421a0022257SSatish Balay    msg ='*******************************************************************************\n'\
422fe09c992SBarry Smith    +'         UNABLE to CONFIGURE with GIVEN OPTIONS    (see configure.log for details):\n' \
423a0022257SSatish Balay    +'-------------------------------------------------------------------------------\n'  \
424a0022257SSatish Balay    +emsg+'*******************************************************************************\n'
425e9f3bb17SBarry Smith    se = ''
4269dd2fdb1SMatthew Knepley  except (TypeError, ValueError), e:
4277d670a3cSBarry Smith    emsg = str(e)
42842351d26SSatish Balay    if not emsg.endswith('\n'): emsg = emsg+'\n'
429a0022257SSatish Balay    msg ='*******************************************************************************\n'\
430e2e64c6bSBarry Smith    +'                ERROR in COMMAND LINE ARGUMENT to ./configure \n' \
431a0022257SSatish Balay    +'-------------------------------------------------------------------------------\n'  \
432a0022257SSatish Balay    +emsg+'*******************************************************************************\n'
4331a02243aSBarry Smith    se = ''
43496dc2fe8SMatthew Knepley  except ImportError, e :
4357d670a3cSBarry Smith    emsg = str(e)
43642351d26SSatish Balay    if not emsg.endswith('\n'): emsg = emsg+'\n'
437a0022257SSatish Balay    msg ='*******************************************************************************\n'\
438e2e64c6bSBarry Smith    +'                     UNABLE to FIND MODULE for ./configure \n' \
439a0022257SSatish Balay    +'-------------------------------------------------------------------------------\n'  \
440a0022257SSatish Balay    +emsg+'*******************************************************************************\n'
44196dc2fe8SMatthew Knepley    se = ''
44201def6f0SMatthew Knepley  except OSError, e :
44301def6f0SMatthew Knepley    emsg = str(e)
44401def6f0SMatthew Knepley    if not emsg.endswith('\n'): emsg = emsg+'\n'
445a0022257SSatish Balay    msg ='*******************************************************************************\n'\
446e2e64c6bSBarry Smith    +'                    UNABLE to EXECUTE BINARIES for ./configure \n' \
447a0022257SSatish Balay    +'-------------------------------------------------------------------------------\n'  \
448a0022257SSatish Balay    +emsg+'*******************************************************************************\n'
44901def6f0SMatthew Knepley    se = ''
450d7d3c4beSMatthew Knepley  except SystemExit, e:
451d7d3c4beSMatthew Knepley    if e.code is None or e.code == 0:
452d7d3c4beSMatthew Knepley      return
453c524ecbbSBarry Smith    if e.code is 10:
454c524ecbbSBarry Smith      sys.exit(10)
455a0022257SSatish Balay    msg ='*******************************************************************************\n'\
456b1dada7fSMatthew Knepley    +'         CONFIGURATION FAILURE  (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \
457a0022257SSatish Balay    +'*******************************************************************************\n'
458d7d3c4beSMatthew Knepley    se  = str(e)
459e9f3bb17SBarry Smith  except Exception, e:
460a0022257SSatish Balay    msg ='*******************************************************************************\n'\
461fe09c992SBarry Smith    +'        CONFIGURATION CRASH  (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \
462a0022257SSatish Balay    +'*******************************************************************************\n'
463e9f3bb17SBarry Smith    se  = str(e)
464e9f3bb17SBarry Smith
465e9f3bb17SBarry Smith  print msg
4669dd2fdb1SMatthew Knepley  if not framework is None:
4679dd2fdb1SMatthew Knepley    framework.logClear()
468e9f3bb17SBarry Smith    if hasattr(framework, 'log'):
46922c95ba3SMatthew G Knepley      try:
470d71f8ab3SSatish Balay        if hasattr(framework,'compilerDefines'):
471bd5137a2SBarry Smith          framework.log.write('**** Configure header '+framework.compilerDefines+' ****\n')
472febd46b0SSatish Balay          framework.outputHeader(framework.log)
473d71f8ab3SSatish Balay        if hasattr(framework,'compilerFixes'):
474bd5137a2SBarry Smith          framework.log.write('**** C specific Configure header '+framework.compilerFixes+' ****\n')
475febd46b0SSatish Balay          framework.outputCHeader(framework.log)
47622c95ba3SMatthew G Knepley      except Exception, e:
47722c95ba3SMatthew G Knepley        framework.log.write('Problem writing headers to log: '+str(e))
478f6614063SBarry Smith      import traceback
479b1dada7fSMatthew Knepley      try:
480f24f64feSBarry Smith        framework.log.write(msg+se)
481f24f64feSBarry Smith        traceback.print_tb(sys.exc_info()[2], file = framework.log)
482d93c4beeSSatish Balay        print_final_timestamp(framework)
483f73e6a6cSSatish Balay        if hasattr(framework,'log'): framework.log.close()
484da1d79b4SSatish Balay        move_configure_log(framework)
485b1dada7fSMatthew Knepley      except:
486b1dada7fSMatthew Knepley        pass
487e9f3bb17SBarry Smith      sys.exit(1)
4885a74f024SMatthew Knepley  else:
4895a74f024SMatthew Knepley    print se
4905a74f024SMatthew Knepley    import traceback
4915a74f024SMatthew Knepley    traceback.print_tb(sys.exc_info()[2])
492f73e6a6cSSatish Balay  if hasattr(framework,'log'): framework.log.close()
4935d5a5a7bSMatthew Knepley
4945d5a5a7bSMatthew Knepleyif __name__ == '__main__':
495a030c540SBarry Smith  petsc_configure([])
496759acf64SBarry Smith
497