xref: /petsc/config/configure.py (revision 4544382e204b36ba5972f540e6c92023a163aed1)
15d5a5a7bSMatthew Knepley#!/usr/bin/env python
25b6bfdb9SJed Brownfrom __future__ import print_function
32787667cSMatthew G Knepleyimport os, sys
4db5c7c58SSatish Balay
57c9abfe7SSatish BalayextraLogs = []
6b0b472b0SSatish Balaypetsc_arch = ''
74b8aa89bSBarry Smith
844b0d7f9SSatish Balay# Use en_US as language so that BuildSystem parses compiler messages in english
99b436e4bSSatish 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'
109b436e4bSSatish 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'
1144b0d7f9SSatish Balay
12813ae6e9SJed Brownif sys.version_info < (2,6):
1327821aeaSJed Brown  print('************************************************************************')
1427821aeaSJed Brown  print('*      Python version 2.6+ or 3.4+ is required to run ./configure      *')
1527821aeaSJed Brown  print('*         Try: "python2.7 ./configure" or "python3 ./configure"        *')
1627821aeaSJed Brown  print('************************************************************************')
17b26a8723SBarry Smith  sys.exit(4)
182fb34ac0SMatthew Knepley
19ccb279e1SMatthew Knepleydef check_for_option_mistakes(opts):
2045faeebdSBarry Smith  for opt in opts[1:]:
21cda0060aSMatthew Knepley    name = opt.split('=')[0]
22ccb279e1SMatthew Knepley    if name.find('_') >= 0:
23ccb279e1SMatthew Knepley      exception = False
241de7a49fSSatish Balay      for exc in ['mkl_sparse', 'mkl_sparse_optimize', 'mkl_cpardiso', 'mkl_pardiso', 'superlu_dist', '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']:
25ccb279e1SMatthew Knepley        if name.find(exc) >= 0:
26ccb279e1SMatthew Knepley          exception = True
27ccb279e1SMatthew Knepley      if not exception:
28ccb279e1SMatthew Knepley        raise ValueError('The option '+name+' should probably be '+name.replace('_', '-'));
29ab610953SSatish Balay    if opt.find('=') >=0:
30ab610953SSatish Balay      optval = opt.split('=')[1]
31ab610953SSatish Balay      if optval == 'ifneeded':
32ab610953SSatish Balay        raise ValueError('The option '+opt+' should probably be '+opt.replace('ifneeded', '1'));
33ccb279e1SMatthew Knepley  return
34ccb279e1SMatthew Knepley
352f393ef5SBarry Smithdef check_for_unsupported_combinations(opts):
362f393ef5SBarry Smith  if '--with-precision=single' in opts and '--with-clanguage=cxx' in opts and '--with-scalar-type=complex' in opts:
372f393ef5SBarry Smith    sys.exit(ValueError('PETSc does not support single precision complex with C++ clanguage, run with --with-clanguage=c'))
382f393ef5SBarry Smith
392af240f0SSatish Balaydef check_for_option_changed(opts):
402af240f0SSatish Balay# Document changes in command line options here.
41*4544382eSSatish Balay  optMap = [('with-64bit-indices','with-64-bit-indices'),
42*4544382eSSatish Balay            ('c-blas-lapack','f2cblaslapack'),
43*4544382eSSatish Balay            ('cholmod','suitesparse'),
44*4544382eSSatish Balay            ('umfpack','suitesparse'),
45*4544382eSSatish Balay            ('f-blas-lapack','fblaslapack'),
46*4544382eSSatish Balay            ('with-cuda-arch',
47*4544382eSSatish Balay             'CUDAFLAGS=-arch'),
48*4544382eSSatish Balay            ('with-packages-dir','with-packages-download-dir'),
49*4544382eSSatish Balay            ('with-external-packages-dir','with-packages-build-dir'),
50*4544382eSSatish Balay            ('package-dirs','with-packages-search-path'),
51*4544382eSSatish Balay            ('download-petsc4py-python','with-python-exec'),
52*4544382eSSatish Balay            ('search-dirs','with-executables-search-path')]
532af240f0SSatish Balay  for opt in opts[1:]:
542af240f0SSatish Balay    optname = opt.split('=')[0].strip('-')
552af240f0SSatish Balay    for oldname,newname in optMap:
562af240f0SSatish Balay      if optname.find(oldname) >=0:
572af240f0SSatish Balay        raise ValueError('The option '+opt+' should probably be '+opt.replace(oldname,newname))
582af240f0SSatish Balay  return
592af240f0SSatish Balay
6059e9bfd6SSatish Balaydef check_petsc_arch(opts):
61c43ea0feSSatish Balay  # If PETSC_ARCH not specified - use script name (if not configure.py)
62b0b472b0SSatish Balay  global petsc_arch
63c43ea0feSSatish Balay  found = 0
6459e9bfd6SSatish Balay  for name in opts:
65c43ea0feSSatish Balay    if name.find('PETSC_ARCH=') >= 0:
66b0b472b0SSatish Balay      petsc_arch=name.split('=')[1]
67c43ea0feSSatish Balay      found = 1
6859e9bfd6SSatish Balay      break
6959e9bfd6SSatish Balay  # If not yet specified - use the filename of script
70c43ea0feSSatish Balay  if not found:
7159e9bfd6SSatish Balay      filename = os.path.basename(sys.argv[0])
72e68ebbecSBarry Smith      if not filename.startswith('configure') and not filename.startswith('reconfigure') and not filename.startswith('setup'):
73b0b472b0SSatish Balay        petsc_arch=os.path.splitext(os.path.basename(sys.argv[0]))[0]
74b0b472b0SSatish Balay        useName = 'PETSC_ARCH='+petsc_arch
7559e9bfd6SSatish Balay        opts.append(useName)
761937db7aSSatish Balay  return 0
774b8aa89bSBarry Smith
78f08ee00aSJason Sarichdef chkenable():
79f08ee00aSJason Sarich  #Replace all 'enable-'/'disable-' with 'with-'=0/1/tail
80f08ee00aSJason Sarich  #enable-fortran is a special case, the resulting --with-fortran is ambiguous.
811b266c99SBarry Smith  #Would it mean --with-fc=
825bb5b98aSSatish Balay  en_dash = u'\N{EN DASH}'
835bb5b98aSSatish Balay  if sys.version_info < (3, 0):
845bb5b98aSSatish Balay    en_dash = en_dash.encode('utf-8')
85f08ee00aSJason Sarich  for l in range(0,len(sys.argv)):
86f08ee00aSJason Sarich    name = sys.argv[l]
87f08ee00aSJason Sarich
885bb5b98aSSatish Balay    if name.find(en_dash)  >= 0:
895bb5b98aSSatish Balay      sys.argv[l] = name.replace(en_dash,'-')
902b700d61SJason Sarich    if name.find('enable-cxx') >= 0:
912b700d61SJason Sarich      if name.find('=') == -1:
922b700d61SJason Sarich        sys.argv[l] = name.replace('enable-cxx','with-clanguage=C++')
932b700d61SJason Sarich      else:
942b700d61SJason Sarich        head, tail = name.split('=', 1)
952b700d61SJason Sarich        if tail=='0':
962b700d61SJason Sarich          sys.argv[l] = head.replace('enable-cxx','with-clanguage=C')
972b700d61SJason Sarich        else:
982b700d61SJason Sarich          sys.argv[l] = head.replace('enable-cxx','with-clanguage=C++')
992b700d61SJason Sarich      continue
1002b700d61SJason Sarich    if name.find('disable-cxx') >= 0:
1012b700d61SJason Sarich      if name.find('=') == -1:
1022b700d61SJason Sarich        sys.argv[l] = name.replace('disable-cxx','with-clanguage=C')
1032b700d61SJason Sarich      else:
1042b700d61SJason Sarich        head, tail = name.split('=', 1)
1052b700d61SJason Sarich        if tail == '0':
1062b700d61SJason Sarich          sys.argv[l] = head.replace('disable-cxx','with-clanguage=C++')
1072b700d61SJason Sarich        else:
1082b700d61SJason Sarich          sys.argv[l] = head.replace('disable-cxx','with-clanguage=C')
1092b700d61SJason Sarich      continue
1102b700d61SJason Sarich
111f08ee00aSJason Sarich
112f08ee00aSJason Sarich    if name.find('enable-') >= 0:
113f08ee00aSJason Sarich      if name.find('=') == -1:
114f08ee00aSJason Sarich        sys.argv[l] = name.replace('enable-','with-')+'=1'
115f08ee00aSJason Sarich      else:
116f08ee00aSJason Sarich        head, tail = name.split('=', 1)
117f08ee00aSJason Sarich        sys.argv[l] = head.replace('enable-','with-')+'='+tail
118f08ee00aSJason Sarich    if name.find('disable-') >= 0:
119f08ee00aSJason Sarich      if name.find('=') == -1:
120f08ee00aSJason Sarich        sys.argv[l] = name.replace('disable-','with-')+'=0'
121f08ee00aSJason Sarich      else:
122f08ee00aSJason Sarich        head, tail = name.split('=', 1)
123f08ee00aSJason Sarich        if tail == '1': tail = '0'
124f08ee00aSJason Sarich        sys.argv[l] = head.replace('disable-','with-')+'='+tail
125f08ee00aSJason Sarich    if name.find('without-') >= 0:
126f08ee00aSJason Sarich      if name.find('=') == -1:
127f08ee00aSJason Sarich        sys.argv[l] = name.replace('without-','with-')+'=0'
128f08ee00aSJason Sarich      else:
129f08ee00aSJason Sarich        head, tail = name.split('=', 1)
130f08ee00aSJason Sarich        if tail == '1': tail = '0'
131f08ee00aSJason Sarich        sys.argv[l] = head.replace('without-','with-')+'='+tail
132f08ee00aSJason Sarich
13377e64500SBarry Smithdef argsAddDownload(value,deps = [],options = []):
13477e64500SBarry Smith  # Adds --download-value to args if the command line DOES NOT already has --with-value or --download-value in it
13577e64500SBarry Smith  # this is to prevent introducing conflicting arguments to ones that already exist
136d2fc035dSSatish Balay  for opt in sys.argv[1:]:
137d2fc035dSSatish Balay    optname = opt.split('=')[0].strip('-')
1380b40560fSSatish Balay    if optname in ['download-'+value,'with-'+value,'with-'+value+'-dir','with-'+value+'-include','with-'+value+'-lib']: return
13977e64500SBarry Smith  sys.argv.append('--download-'+value)
14077e64500SBarry Smith  for i in deps:
14177e64500SBarry Smith    argsAddDownload(i)
14277e64500SBarry Smith  for i in options:
14377e64500SBarry Smith    sys.argv.append(i)
1448fd71741SJason Sarich
145f08ee00aSJason Sarichdef chksynonyms():
146f08ee00aSJason Sarich  #replace common configure options with ones that PETSc BuildSystem recognizes
147a41fa05bSBarry Smith  downloadxsdk = 0
148a41fa05bSBarry Smith  downloadideas = 0
149f08ee00aSJason Sarich  for l in range(0,len(sys.argv)):
150f08ee00aSJason Sarich    name = sys.argv[l]
151f08ee00aSJason Sarich
152db60c0f3SSatish Balay    if name.find('download-xsdk=') >= 0 or name.endswith('download-xsdk'):
153a41fa05bSBarry Smith      downloadxsdk = 1
154a41fa05bSBarry Smith
155db60c0f3SSatish Balay    if name.find('download-ideas=') >= 0 or name.endswith('download-ideas'):
156a41fa05bSBarry Smith      downloadideas = 1
157f08ee00aSJason Sarich
1586cdd910dSSatish Balay    if name.find('with-blas-lapack') >= 0:
1596cdd910dSSatish Balay      sys.argv[l] = name.replace('with-blas-lapack','with-blaslapack')
160c87df54fSBarry Smith
161ce54fb35SBarry Smith    if name.find('with-debug=') >= 0 or name.endswith('with-debug'):
162f08ee00aSJason Sarich      if name.find('=') == -1:
163f08ee00aSJason Sarich        sys.argv[l] = name.replace('with-debug','with-debugging')+'=1'
164f08ee00aSJason Sarich      else:
165f08ee00aSJason Sarich        head, tail = name.split('=', 1)
166f08ee00aSJason Sarich        sys.argv[l] = head.replace('with-debug','with-debugging')+'='+tail
167f08ee00aSJason Sarich
168ce54fb35SBarry Smith    if name.find('with-shared=') >= 0 or name.endswith('with-shared'):
169f08ee00aSJason Sarich      if name.find('=') == -1:
170ce54fb35SBarry Smith        sys.argv[l] = name.replace('with-shared','with-shared-libraries')+'=1'
171f08ee00aSJason Sarich      else:
172f08ee00aSJason Sarich        head, tail = name.split('=', 1)
173ce54fb35SBarry Smith        sys.argv[l] = head.replace('with-shared','with-shared-libraries')+'='+tail
174f08ee00aSJason Sarich
1758fd71741SJason Sarich    if name.find('with-index-size=') >=0:
1768fd71741SJason Sarich      head,tail = name.split('=',1)
1778fd71741SJason Sarich      if int(tail)==32:
1788fd71741SJason Sarich        sys.argv[l] = '--with-64-bit-indices=0'
1798fd71741SJason Sarich      elif int(tail)==64:
1808fd71741SJason Sarich        sys.argv[l] = '--with-64-bit-indices=1'
1818fd71741SJason Sarich      else:
1828fd71741SJason Sarich        raise RuntimeError('--with-index-size= must be 32 or 64')
183f08ee00aSJason Sarich
1848fd71741SJason Sarich    if name.find('with-precision=') >=0:
1858fd71741SJason Sarich      head,tail = name.split('=',1)
1868fd71741SJason Sarich      if tail.find('quad')>=0:
1878fd71741SJason Sarich        sys.argv[l]='--with-precision=__float128'
188f08ee00aSJason Sarich
189a41fa05bSBarry Smith  if downloadideas:
19077e64500SBarry Smith    downloadxsdk = 1
19177e64500SBarry Smith    argsAddDownload('alquimia')
19277e64500SBarry Smith    # mstk currently cannot build a shared library
19377e64500SBarry Smith    argsAddDownload('mstk',[],['--download-mstk-shared=0'])
1947a3d669cSBarry Smith    argsAddDownload('ascem-io')
195b21bda25SBarry Smith    argsAddDownload('unittestcpp')
196a41fa05bSBarry Smith
197a41fa05bSBarry Smith  if downloadxsdk:
198a41fa05bSBarry Smith    # Common external libraries
19927ee2e53SSatish Balay    argsAddDownload('pflotran')
200e9b64aeeSSatish Balay    argsAddDownload('hdf5',['zlib'])
20177e64500SBarry Smith    argsAddDownload('netcdf')
20277e64500SBarry Smith    argsAddDownload('metis')
203a41fa05bSBarry Smith
20477e64500SBarry Smith    argsAddDownload('superlu_dist',['parmetis'])
205a41fa05bSBarry Smith
20677e64500SBarry Smith    argsAddDownload('hypre')
20777e64500SBarry Smith
2086236a943SBarry Smith    argsAddDownload('trilinos',['boost','xsdktrilinos'],['--with-cxx-dialect=C++11'])
209a41fa05bSBarry Smith
210f08ee00aSJason Sarich
2111921852fSSatish Balaydef chkwinf90():
2126a8f6897SSatish Balay  for arg in sys.argv:
2131921852fSSatish Balay    if (arg.find('win32fe') >= 0 and (arg.find('f90') >=0 or arg.find('ifort') >=0)):
2146a8f6897SSatish Balay      return 1
2156a8f6897SSatish Balay  return 0
2166a8f6897SSatish Balay
2178a4600f2SSatish Balaydef chkdosfiles():
218360dfd13SSatish Balay  # cygwin - but not a hg clone - so check one of files in bin dir
2198fb0cc24SJed Brown  if b"\r\n" in open(os.path.join('lib','petsc','bin','petscmpiexec'),"rb").read():
2205b6bfdb9SJed Brown    print('===============================================================================')
2215b6bfdb9SJed Brown    print(' *** Scripts are in DOS mode. Was winzip used to extract petsc sources?    ****')
2225b6bfdb9SJed Brown    print(' *** Please restart with a fresh tarball and use "tar -xzf petsc.tar.gz"   ****')
2235b6bfdb9SJed Brown    print('===============================================================================')
224db1f124cSVasiliy Kozyrev    sys.exit(3)
2258a4600f2SSatish Balay  return
2268a4600f2SSatish Balay
2276a8f6897SSatish Balaydef chkcygwinlink():
2281921852fSSatish Balay  if os.path.exists('/usr/bin/cygcheck.exe') and os.path.exists('/usr/bin/link.exe') and chkwinf90():
2296a8f6897SSatish Balay      if '--ignore-cygwin-link' in sys.argv: return 0
2305b6bfdb9SJed Brown      print('===============================================================================')
2315b6bfdb9SJed Brown      print(' *** Cygwin /usr/bin/link detected! Compiles with CVF/Intel f90 can break!  **')
2325b6bfdb9SJed Brown      print(' *** To workarround do: "mv /usr/bin/link.exe /usr/bin/link-cygwin.exe"     **')
2335b6bfdb9SJed Brown      print(' *** Or to ignore this check, use configure option: --ignore-cygwin-link    **')
2345b6bfdb9SJed Brown      print('===============================================================================')
2356a8f6897SSatish Balay      sys.exit(3)
2366a8f6897SSatish Balay  return 0
2376a8f6897SSatish Balay
23885ef4d1eSSatish Balaydef chkbrokencygwin():
2399dabcff0SSatish Balay  if os.path.exists('/usr/bin/cygcheck.exe'):
2409dabcff0SSatish Balay    buf = os.popen('/usr/bin/cygcheck.exe -c cygwin').read()
2419dabcff0SSatish Balay    if buf.find('1.5.11-1') > -1:
2425b6bfdb9SJed Brown      print('===============================================================================')
2435b6bfdb9SJed Brown      print(' *** cygwin-1.5.11-1 detected. ./configure fails with this version ***')
2445b6bfdb9SJed Brown      print(' *** Please upgrade to cygwin-1.5.12-1 or newer version. This can  ***')
2455b6bfdb9SJed Brown      print(' *** be done by running cygwin-setup, selecting "next" all the way.***')
2465b6bfdb9SJed Brown      print('===============================================================================')
2471937db7aSSatish Balay      sys.exit(3)
2489dabcff0SSatish Balay  return 0
2499dabcff0SSatish Balay
250ee76e990SSatish Balaydef chkusingwindowspython():
251ee76e990SSatish Balay  if sys.platform == 'win32':
2525b6bfdb9SJed Brown    print('===============================================================================')
2535b6bfdb9SJed Brown    print(' *** Windows python detected. Please rerun ./configure with cygwin-python. ***')
2545b6bfdb9SJed Brown    print('===============================================================================')
255ee76e990SSatish Balay    sys.exit(3)
256ee76e990SSatish Balay  return 0
257ee76e990SSatish Balay
25814f5c25cSSatish Balaydef chkcygwinpython():
2591150532aSSatish Balay  if sys.platform == 'cygwin' :
2601150532aSSatish Balay    import platform
2611150532aSSatish Balay    import re
2621150532aSSatish Balay    r=re.compile("([0-9]+).([0-9]+).([0-9]+)")
2631150532aSSatish Balay    m=r.match(platform.release())
2641150532aSSatish Balay    major=int(m.group(1))
2651150532aSSatish Balay    minor=int(m.group(2))
2661150532aSSatish Balay    subminor=int(m.group(3))
2671150532aSSatish Balay    if ((major < 1) or (major == 1 and minor < 7) or (major == 1 and minor == 7 and subminor < 34)):
2681937db7aSSatish Balay      sys.argv.append('--useThreads=0')
2691937db7aSSatish Balay      extraLogs.append('''\
270a0022257SSatish Balay===============================================================================
2711150532aSSatish Balay** Cygwin version is older than 1.7.34. Python threads do not work correctly. ***
27214f5c25cSSatish Balay** Disabling thread usage for this run of ./configure *******
273a0022257SSatish Balay===============================================================================''')
27471384062SSatish Balay  return 0
27571384062SSatish Balay
2761937db7aSSatish Balaydef chkrhl9():
2771937db7aSSatish Balay  if os.path.exists('/etc/redhat-release'):
278836c2c52SSatish Balay    try:
279594eb360SSatish Balay      file = open('/etc/redhat-release','r')
280836c2c52SSatish Balay      buf = file.read()
281836c2c52SSatish Balay      file.close()
282836c2c52SSatish Balay    except:
283836c2c52SSatish Balay      # can't read file - assume dangerous RHL9
2841937db7aSSatish Balay      buf = 'Shrike'
285836c2c52SSatish Balay    if buf.find('Shrike') > -1:
2861937db7aSSatish Balay      sys.argv.append('--useThreads=0')
2871937db7aSSatish Balay      extraLogs.append('''\
288a0022257SSatish Balay==============================================================================
2891937db7aSSatish Balay   *** RHL9 detected. Threads do not work correctly with this distribution ***
290e2e64c6bSBarry Smith   ****** Disabling thread usage for this run of ./configure *********
291a0022257SSatish Balay===============================================================================''')
292836c2c52SSatish Balay  return 0
293836c2c52SSatish Balay
294da58527dSSatish Balaydef check_broken_configure_log_links():
295da58527dSSatish Balay  '''Sometime symlinks can get broken if the original files are deleted. Delete such broken links'''
296da58527dSSatish Balay  import os
297da58527dSSatish Balay  for logfile in ['configure.log','configure.log.bkp']:
298da58527dSSatish Balay    if os.path.islink(logfile) and not os.path.isfile(logfile): os.remove(logfile)
299da58527dSSatish Balay  return
300da58527dSSatish Balay
301da1d79b4SSatish Balaydef move_configure_log(framework):
302af0996ceSBarry Smith  '''Move configure.log to PETSC_ARCH/lib/petsc/conf - and update configure.log.bkp in both locations appropriately'''
303b0b472b0SSatish Balay  global petsc_arch
304b0b472b0SSatish Balay
305b0b472b0SSatish Balay  if hasattr(framework,'arch'): petsc_arch = framework.arch
306b0b472b0SSatish Balay  if hasattr(framework,'logName'): curr_file = framework.logName
307b0b472b0SSatish Balay  else: curr_file = 'configure.log'
308b0b472b0SSatish Balay
309b0b472b0SSatish Balay  if petsc_arch:
310da1d79b4SSatish Balay    import shutil
311da1d79b4SSatish Balay    import os
312b0b472b0SSatish Balay
313b0b472b0SSatish Balay    # Just in case - confdir is not created
314fe998a80SBarry Smith    lib_dir = os.path.join(petsc_arch,'lib')
315af0996ceSBarry Smith    conf_dir = os.path.join(petsc_arch,'lib','petsc','conf')
316b0b472b0SSatish Balay    if not os.path.isdir(petsc_arch): os.mkdir(petsc_arch)
317fe998a80SBarry Smith    if not os.path.isdir(lib_dir): os.mkdir(lib_dir)
318b0b472b0SSatish Balay    if not os.path.isdir(conf_dir): os.mkdir(conf_dir)
319b0b472b0SSatish Balay
320da1d79b4SSatish Balay    curr_bkp  = curr_file + '.bkp'
321b0b472b0SSatish Balay    new_file  = os.path.join(conf_dir,curr_file)
322da1d79b4SSatish Balay    new_bkp   = new_file + '.bkp'
323da1d79b4SSatish Balay
324af0996ceSBarry Smith    # Keep backup in $PETSC_ARCH/lib/petsc/conf location
325da1d79b4SSatish Balay    if os.path.isfile(new_bkp): os.remove(new_bkp)
326da1d79b4SSatish Balay    if os.path.isfile(new_file): os.rename(new_file,new_bkp)
3279e50940cSSatish Balay    if os.path.isfile(curr_file):
3289e50940cSSatish Balay      shutil.copyfile(curr_file,new_file)
3299e50940cSSatish Balay      os.remove(curr_file)
330da58527dSSatish Balay    if os.path.isfile(new_file): os.symlink(new_file,curr_file)
331af0996ceSBarry Smith    # If the old bkp is using the same PETSC_ARCH/lib/petsc/conf - then update bkp link
332da1d79b4SSatish Balay    if os.path.realpath(curr_bkp) == os.path.realpath(new_file):
333da58527dSSatish Balay      if os.path.isfile(curr_bkp): os.remove(curr_bkp)
334da58527dSSatish Balay      if os.path.isfile(new_bkp): os.symlink(new_bkp,curr_bkp)
335da1d79b4SSatish Balay  return
336da1d79b4SSatish Balay
337d93c4beeSSatish Balaydef print_final_timestamp(framework):
338d93c4beeSSatish Balay  import time
339d93c4beeSSatish Balay  framework.log.write(('='*80)+'\n')
3407a01bd3eSSatish Balay  framework.log.write('Finishing configure run at '+time.strftime('%a, %d %b %Y %H:%M:%S %z')+'\n')
341d93c4beeSSatish Balay  framework.log.write(('='*80)+'\n')
342d93c4beeSSatish Balay  return
343d93c4beeSSatish Balay
3445d5a5a7bSMatthew Knepleydef petsc_configure(configure_options):
3456e464aa7SMatthew G. Knepley  if 'PETSC_DIR' in os.environ:
3464a532159SBarry Smith    petscdir = os.environ['PETSC_DIR']
3476e464aa7SMatthew G. Knepley    if petscdir.find(' ') > -1:
3486e464aa7SMatthew G. Knepley      raise RuntimeError('Your PETSC_DIR '+petscdir+' has spaces in it; this is not allowed.\n Change the directory with PETSc to not have spaces in it')
3496e464aa7SMatthew G. Knepley    try:
350c3a89c15SBarry Smith      sys.path.append(os.path.join(petscdir,'lib','petsc','bin'))
3514a532159SBarry Smith      import petscnagupgrade
3524a532159SBarry Smith      file     = os.path.join(petscdir,'.nagged')
3534a532159SBarry Smith      if not petscnagupgrade.naggedtoday(file):
3544a532159SBarry Smith        petscnagupgrade.currentversion(petscdir)
3554a532159SBarry Smith    except:
3564a532159SBarry Smith      pass
3575b6bfdb9SJed Brown  print('===============================================================================')
3585b6bfdb9SJed Brown  print('             Configuring PETSc to compile on your system                       ')
3595b6bfdb9SJed Brown  print('===============================================================================')
36059e9bfd6SSatish Balay
361a258c2c4SMatthew G Knepley  try:
362c43ea0feSSatish Balay    # Command line arguments take precedence (but don't destroy argv[0])
363c43ea0feSSatish Balay    sys.argv = sys.argv[:1] + configure_options + sys.argv[1:]
364ccb279e1SMatthew Knepley    check_for_option_mistakes(sys.argv)
3652af240f0SSatish Balay    check_for_option_changed(sys.argv)
3665b6bfdb9SJed Brown  except (TypeError, ValueError) as e:
367a258c2c4SMatthew G Knepley    emsg = str(e)
368a258c2c4SMatthew G Knepley    if not emsg.endswith('\n'): emsg = emsg+'\n'
369a258c2c4SMatthew G Knepley    msg ='*******************************************************************************\n'\
370a258c2c4SMatthew G Knepley    +'                ERROR in COMMAND LINE ARGUMENT to ./configure \n' \
371a258c2c4SMatthew G Knepley    +'-------------------------------------------------------------------------------\n'  \
372a258c2c4SMatthew G Knepley    +emsg+'*******************************************************************************\n'
373a258c2c4SMatthew G Knepley    sys.exit(msg)
37459e9bfd6SSatish Balay  # check PETSC_ARCH
3752f393ef5SBarry Smith  check_for_unsupported_combinations(sys.argv)
37659e9bfd6SSatish Balay  check_petsc_arch(sys.argv)
377da58527dSSatish Balay  check_broken_configure_log_links()
3785fb2c094SBarry Smith
379f08ee00aSJason Sarich  #rename '--enable-' to '--with-'
380f08ee00aSJason Sarich  chkenable()
381c22cdea9SBarry Smith  # support a few standard configure option types
382f08ee00aSJason Sarich  chksynonyms()
3839dabcff0SSatish Balay  # Check for broken cygwin
3841937db7aSSatish Balay  chkbrokencygwin()
385d65f3bddSMatthew Knepley  # Disable threads on RHL9
3861937db7aSSatish Balay  chkrhl9()
387ee76e990SSatish Balay  # Make sure cygwin-python is used on windows
388ee76e990SSatish Balay  chkusingwindowspython()
38914f5c25cSSatish Balay  # Threads don't work for cygwin & python...
39014f5c25cSSatish Balay  chkcygwinpython()
3916a8f6897SSatish Balay  chkcygwinlink()
3928a4600f2SSatish Balay  chkdosfiles()
3939dabcff0SSatish Balay
39487282423SMatthew Knepley  # Should be run from the toplevel
395dbca6d9dSSatish Balay  configDir = os.path.abspath('config')
396f8833479SBarry Smith  bsDir     = os.path.join(configDir, 'BuildSystem')
397f8833479SBarry Smith  if not os.path.isdir(configDir):
3985d5a5a7bSMatthew Knepley    raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.'))
39987282423SMatthew Knepley  sys.path.insert(0, bsDir)
400f8833479SBarry Smith  sys.path.insert(0, configDir)
401e69ef9dfSMatthew Knepley  import config.base
4025d5a5a7bSMatthew Knepley  import config.framework
403492432c8SJed Brown  import pickle
4044f8a5b45SBarry Smith
4059dd2fdb1SMatthew Knepley  framework = None
4069dd2fdb1SMatthew Knepley  try:
40723a19ef1SSatish Balay    framework = config.framework.Framework(['--configModules=PETSc.Configure','--optionsModule=config.compilerOptions']+sys.argv[1:], loadArgDB = 0)
408d65f3bddSMatthew Knepley    framework.setup()
409d65f3bddSMatthew Knepley    framework.logPrint('\n'.join(extraLogs))
410f24f64feSBarry Smith    framework.configure(out = sys.stdout)
411358ebc22SMatthew Knepley    framework.storeSubstitutions(framework.argDB)
412492432c8SJed Brown    framework.argDB['configureCache'] = pickle.dumps(framework)
4137c939e48SSatish Balay    framework.printSummary()
41412c1d45bSMatthew G Knepley    framework.argDB.save(force = True)
4157cfd0b05SBarry Smith    framework.logClear()
416d93c4beeSSatish Balay    print_final_timestamp(framework)
417eefa2c0fSBarry Smith    framework.closeLog()
4189e50940cSSatish Balay    try:
419da1d79b4SSatish Balay      move_configure_log(framework)
4209e50940cSSatish Balay    except:
4219e50940cSSatish Balay      # perhaps print an error about unable to shuffle logs?
4229e50940cSSatish Balay      pass
423dd50d019SBarry Smith    return 0
4245b6bfdb9SJed Brown  except (RuntimeError, config.base.ConfigureSetupError) as e:
4257d670a3cSBarry Smith    emsg = str(e)
42642351d26SSatish Balay    if not emsg.endswith('\n'): emsg = emsg+'\n'
427a0022257SSatish Balay    msg ='*******************************************************************************\n'\
428fe09c992SBarry Smith    +'         UNABLE to CONFIGURE with GIVEN OPTIONS    (see configure.log for details):\n' \
429a0022257SSatish Balay    +'-------------------------------------------------------------------------------\n'  \
430a0022257SSatish Balay    +emsg+'*******************************************************************************\n'
431e9f3bb17SBarry Smith    se = ''
4325b6bfdb9SJed Brown  except (TypeError, ValueError) as e:
4337d670a3cSBarry Smith    emsg = str(e)
43442351d26SSatish Balay    if not emsg.endswith('\n'): emsg = emsg+'\n'
435a0022257SSatish Balay    msg ='*******************************************************************************\n'\
436e2e64c6bSBarry Smith    +'                ERROR in COMMAND LINE ARGUMENT to ./configure \n' \
437a0022257SSatish Balay    +'-------------------------------------------------------------------------------\n'  \
438a0022257SSatish Balay    +emsg+'*******************************************************************************\n'
4391a02243aSBarry Smith    se = ''
4405b6bfdb9SJed Brown  except ImportError as e :
4417d670a3cSBarry Smith    emsg = str(e)
44242351d26SSatish Balay    if not emsg.endswith('\n'): emsg = emsg+'\n'
443a0022257SSatish Balay    msg ='*******************************************************************************\n'\
444e2e64c6bSBarry Smith    +'                     UNABLE to FIND MODULE for ./configure \n' \
445a0022257SSatish Balay    +'-------------------------------------------------------------------------------\n'  \
446a0022257SSatish Balay    +emsg+'*******************************************************************************\n'
44796dc2fe8SMatthew Knepley    se = ''
4485b6bfdb9SJed Brown  except OSError as e :
44901def6f0SMatthew Knepley    emsg = str(e)
45001def6f0SMatthew Knepley    if not emsg.endswith('\n'): emsg = emsg+'\n'
451a0022257SSatish Balay    msg ='*******************************************************************************\n'\
452e2e64c6bSBarry Smith    +'                    UNABLE to EXECUTE BINARIES for ./configure \n' \
453a0022257SSatish Balay    +'-------------------------------------------------------------------------------\n'  \
454a0022257SSatish Balay    +emsg+'*******************************************************************************\n'
45501def6f0SMatthew Knepley    se = ''
4565b6bfdb9SJed Brown  except SystemExit as e:
457d7d3c4beSMatthew Knepley    if e.code is None or e.code == 0:
458d7d3c4beSMatthew Knepley      return
459c524ecbbSBarry Smith    if e.code is 10:
460c524ecbbSBarry Smith      sys.exit(10)
461a0022257SSatish Balay    msg ='*******************************************************************************\n'\
462b1dada7fSMatthew Knepley    +'         CONFIGURATION FAILURE  (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \
463a0022257SSatish Balay    +'*******************************************************************************\n'
464d7d3c4beSMatthew Knepley    se  = str(e)
4655b6bfdb9SJed Brown  except Exception as e:
466a0022257SSatish Balay    msg ='*******************************************************************************\n'\
467fe09c992SBarry Smith    +'        CONFIGURATION CRASH  (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \
468a0022257SSatish Balay    +'*******************************************************************************\n'
469e9f3bb17SBarry Smith    se  = str(e)
470e9f3bb17SBarry Smith
4715b6bfdb9SJed Brown  print(msg)
4729dd2fdb1SMatthew Knepley  if not framework is None:
4739dd2fdb1SMatthew Knepley    framework.logClear()
474e9f3bb17SBarry Smith    if hasattr(framework, 'log'):
47522c95ba3SMatthew G Knepley      try:
476d71f8ab3SSatish Balay        if hasattr(framework,'compilerDefines'):
477bd5137a2SBarry Smith          framework.log.write('**** Configure header '+framework.compilerDefines+' ****\n')
478febd46b0SSatish Balay          framework.outputHeader(framework.log)
479d71f8ab3SSatish Balay        if hasattr(framework,'compilerFixes'):
480bd5137a2SBarry Smith          framework.log.write('**** C specific Configure header '+framework.compilerFixes+' ****\n')
481febd46b0SSatish Balay          framework.outputCHeader(framework.log)
4825b6bfdb9SJed Brown      except Exception as e:
48322c95ba3SMatthew G Knepley        framework.log.write('Problem writing headers to log: '+str(e))
484f6614063SBarry Smith      import traceback
485b1dada7fSMatthew Knepley      try:
486f24f64feSBarry Smith        framework.log.write(msg+se)
487f24f64feSBarry Smith        traceback.print_tb(sys.exc_info()[2], file = framework.log)
488d93c4beeSSatish Balay        print_final_timestamp(framework)
489f73e6a6cSSatish Balay        if hasattr(framework,'log'): framework.log.close()
490da1d79b4SSatish Balay        move_configure_log(framework)
491b1dada7fSMatthew Knepley      except:
492b1dada7fSMatthew Knepley        pass
493e9f3bb17SBarry Smith      sys.exit(1)
4945a74f024SMatthew Knepley  else:
4955b6bfdb9SJed Brown    print(se)
4965a74f024SMatthew Knepley    import traceback
4975a74f024SMatthew Knepley    traceback.print_tb(sys.exc_info()[2])
498f73e6a6cSSatish Balay  if hasattr(framework,'log'): framework.log.close()
4995d5a5a7bSMatthew Knepley
5005d5a5a7bSMatthew Knepleyif __name__ == '__main__':
501a030c540SBarry Smith  petsc_configure([])
502759acf64SBarry Smith
503