xref: /petsc/config/configure.py (revision cfb8f47a255e92df98c85d6ae15e0061c7307176)
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.
414544382eSSatish Balay  optMap = [('with-64bit-indices','with-64-bit-indices'),
42008db1b6SSatish Balay            ('with-mpi-exec','with-mpiexec'),
434544382eSSatish Balay            ('c-blas-lapack','f2cblaslapack'),
444544382eSSatish Balay            ('cholmod','suitesparse'),
454544382eSSatish Balay            ('umfpack','suitesparse'),
464544382eSSatish Balay            ('f-blas-lapack','fblaslapack'),
474544382eSSatish Balay            ('with-cuda-arch',
484544382eSSatish Balay             'CUDAFLAGS=-arch'),
494544382eSSatish Balay            ('with-packages-dir','with-packages-download-dir'),
504544382eSSatish Balay            ('with-external-packages-dir','with-packages-build-dir'),
514544382eSSatish Balay            ('package-dirs','with-packages-search-path'),
524544382eSSatish Balay            ('download-petsc4py-python','with-python-exec'),
534544382eSSatish Balay            ('search-dirs','with-executables-search-path')]
542af240f0SSatish Balay  for opt in opts[1:]:
552af240f0SSatish Balay    optname = opt.split('=')[0].strip('-')
562af240f0SSatish Balay    for oldname,newname in optMap:
572af240f0SSatish Balay      if optname.find(oldname) >=0:
582af240f0SSatish Balay        raise ValueError('The option '+opt+' should probably be '+opt.replace(oldname,newname))
592af240f0SSatish Balay  return
602af240f0SSatish Balay
6159e9bfd6SSatish Balaydef check_petsc_arch(opts):
62c43ea0feSSatish Balay  # If PETSC_ARCH not specified - use script name (if not configure.py)
63b0b472b0SSatish Balay  global petsc_arch
64c43ea0feSSatish Balay  found = 0
6559e9bfd6SSatish Balay  for name in opts:
66c43ea0feSSatish Balay    if name.find('PETSC_ARCH=') >= 0:
67b0b472b0SSatish Balay      petsc_arch=name.split('=')[1]
68c43ea0feSSatish Balay      found = 1
6959e9bfd6SSatish Balay      break
7059e9bfd6SSatish Balay  # If not yet specified - use the filename of script
71c43ea0feSSatish Balay  if not found:
7259e9bfd6SSatish Balay      filename = os.path.basename(sys.argv[0])
73e68ebbecSBarry Smith      if not filename.startswith('configure') and not filename.startswith('reconfigure') and not filename.startswith('setup'):
74b0b472b0SSatish Balay        petsc_arch=os.path.splitext(os.path.basename(sys.argv[0]))[0]
75b0b472b0SSatish Balay        useName = 'PETSC_ARCH='+petsc_arch
7659e9bfd6SSatish Balay        opts.append(useName)
771937db7aSSatish Balay  return 0
784b8aa89bSBarry Smith
79f08ee00aSJason Sarichdef chkenable():
80f08ee00aSJason Sarich  #Replace all 'enable-'/'disable-' with 'with-'=0/1/tail
81f08ee00aSJason Sarich  #enable-fortran is a special case, the resulting --with-fortran is ambiguous.
821b266c99SBarry Smith  #Would it mean --with-fc=
835bb5b98aSSatish Balay  en_dash = u'\N{EN DASH}'
845bb5b98aSSatish Balay  if sys.version_info < (3, 0):
855bb5b98aSSatish Balay    en_dash = en_dash.encode('utf-8')
86f08ee00aSJason Sarich  for l in range(0,len(sys.argv)):
87f08ee00aSJason Sarich    name = sys.argv[l]
88f08ee00aSJason Sarich
895bb5b98aSSatish Balay    if name.find(en_dash)  >= 0:
905bb5b98aSSatish Balay      sys.argv[l] = name.replace(en_dash,'-')
912b700d61SJason Sarich    if name.find('enable-cxx') >= 0:
922b700d61SJason Sarich      if name.find('=') == -1:
932b700d61SJason Sarich        sys.argv[l] = name.replace('enable-cxx','with-clanguage=C++')
942b700d61SJason Sarich      else:
952b700d61SJason Sarich        head, tail = name.split('=', 1)
962b700d61SJason Sarich        if tail=='0':
972b700d61SJason Sarich          sys.argv[l] = head.replace('enable-cxx','with-clanguage=C')
982b700d61SJason Sarich        else:
992b700d61SJason Sarich          sys.argv[l] = head.replace('enable-cxx','with-clanguage=C++')
1002b700d61SJason Sarich      continue
1012b700d61SJason Sarich    if name.find('disable-cxx') >= 0:
1022b700d61SJason Sarich      if name.find('=') == -1:
1032b700d61SJason Sarich        sys.argv[l] = name.replace('disable-cxx','with-clanguage=C')
1042b700d61SJason Sarich      else:
1052b700d61SJason Sarich        head, tail = name.split('=', 1)
1062b700d61SJason Sarich        if tail == '0':
1072b700d61SJason Sarich          sys.argv[l] = head.replace('disable-cxx','with-clanguage=C++')
1082b700d61SJason Sarich        else:
1092b700d61SJason Sarich          sys.argv[l] = head.replace('disable-cxx','with-clanguage=C')
1102b700d61SJason Sarich      continue
1112b700d61SJason Sarich
112f08ee00aSJason Sarich
113f08ee00aSJason Sarich    if name.find('enable-') >= 0:
114f08ee00aSJason Sarich      if name.find('=') == -1:
115f08ee00aSJason Sarich        sys.argv[l] = name.replace('enable-','with-')+'=1'
116f08ee00aSJason Sarich      else:
117f08ee00aSJason Sarich        head, tail = name.split('=', 1)
118f08ee00aSJason Sarich        sys.argv[l] = head.replace('enable-','with-')+'='+tail
119f08ee00aSJason Sarich    if name.find('disable-') >= 0:
120f08ee00aSJason Sarich      if name.find('=') == -1:
121f08ee00aSJason Sarich        sys.argv[l] = name.replace('disable-','with-')+'=0'
122f08ee00aSJason Sarich      else:
123f08ee00aSJason Sarich        head, tail = name.split('=', 1)
124f08ee00aSJason Sarich        if tail == '1': tail = '0'
125f08ee00aSJason Sarich        sys.argv[l] = head.replace('disable-','with-')+'='+tail
126f08ee00aSJason Sarich    if name.find('without-') >= 0:
127f08ee00aSJason Sarich      if name.find('=') == -1:
128f08ee00aSJason Sarich        sys.argv[l] = name.replace('without-','with-')+'=0'
129f08ee00aSJason Sarich      else:
130f08ee00aSJason Sarich        head, tail = name.split('=', 1)
131f08ee00aSJason Sarich        if tail == '1': tail = '0'
132f08ee00aSJason Sarich        sys.argv[l] = head.replace('without-','with-')+'='+tail
133f08ee00aSJason Sarich
134f08ee00aSJason Sarichdef chksynonyms():
135f08ee00aSJason Sarich  #replace common configure options with ones that PETSc BuildSystem recognizes
13698d87fb0SBarry Smith  simplereplacements = {'F77' : 'FC', 'F90' : 'FC'}
137f08ee00aSJason Sarich  for l in range(0,len(sys.argv)):
138f08ee00aSJason Sarich    name = sys.argv[l]
139f08ee00aSJason Sarich
1406cdd910dSSatish Balay    if name.find('with-blas-lapack') >= 0:
1416cdd910dSSatish Balay      sys.argv[l] = name.replace('with-blas-lapack','with-blaslapack')
142c87df54fSBarry Smith
143ce54fb35SBarry Smith    if name.find('with-debug=') >= 0 or name.endswith('with-debug'):
144f08ee00aSJason Sarich      if name.find('=') == -1:
145f08ee00aSJason Sarich        sys.argv[l] = name.replace('with-debug','with-debugging')+'=1'
146f08ee00aSJason Sarich      else:
147f08ee00aSJason Sarich        head, tail = name.split('=', 1)
148f08ee00aSJason Sarich        sys.argv[l] = head.replace('with-debug','with-debugging')+'='+tail
149f08ee00aSJason Sarich
150ce54fb35SBarry Smith    if name.find('with-shared=') >= 0 or name.endswith('with-shared'):
151f08ee00aSJason Sarich      if name.find('=') == -1:
152ce54fb35SBarry Smith        sys.argv[l] = name.replace('with-shared','with-shared-libraries')+'=1'
153f08ee00aSJason Sarich      else:
154f08ee00aSJason Sarich        head, tail = name.split('=', 1)
155ce54fb35SBarry Smith        sys.argv[l] = head.replace('with-shared','with-shared-libraries')+'='+tail
156f08ee00aSJason Sarich
1578fd71741SJason Sarich    if name.find('with-index-size=') >=0:
1588fd71741SJason Sarich      head,tail = name.split('=',1)
1598fd71741SJason Sarich      if int(tail)==32:
1608fd71741SJason Sarich        sys.argv[l] = '--with-64-bit-indices=0'
1618fd71741SJason Sarich      elif int(tail)==64:
1628fd71741SJason Sarich        sys.argv[l] = '--with-64-bit-indices=1'
1638fd71741SJason Sarich      else:
1648fd71741SJason Sarich        raise RuntimeError('--with-index-size= must be 32 or 64')
165f08ee00aSJason Sarich
1668fd71741SJason Sarich    if name.find('with-precision=') >=0:
1678fd71741SJason Sarich      head,tail = name.split('=',1)
1688fd71741SJason Sarich      if tail.find('quad')>=0:
1698fd71741SJason Sarich        sys.argv[l]='--with-precision=__float128'
170f08ee00aSJason Sarich
17198d87fb0SBarry Smith    for i,j in simplereplacements.items():
17298d87fb0SBarry Smith      if name.find(i+'=') >= 0:
17398d87fb0SBarry Smith        sys.argv[l] = name.replace(i+'=',j+'=')
17498d87fb0SBarry Smith      elif name.find('with-'+i.lower()+'=') >= 0:
17598d87fb0SBarry Smith        sys.argv[l] = name.replace(i.lower()+'=',j.lower()+'=')
176f08ee00aSJason Sarich
1771921852fSSatish Balaydef chkwinf90():
1786a8f6897SSatish Balay  for arg in sys.argv:
1791921852fSSatish Balay    if (arg.find('win32fe') >= 0 and (arg.find('f90') >=0 or arg.find('ifort') >=0)):
1806a8f6897SSatish Balay      return 1
1816a8f6897SSatish Balay  return 0
1826a8f6897SSatish Balay
1838a4600f2SSatish Balaydef chkdosfiles():
184360dfd13SSatish Balay  # cygwin - but not a hg clone - so check one of files in bin dir
1858fb0cc24SJed Brown  if b"\r\n" in open(os.path.join('lib','petsc','bin','petscmpiexec'),"rb").read():
1865b6bfdb9SJed Brown    print('===============================================================================')
1875b6bfdb9SJed Brown    print(' *** Scripts are in DOS mode. Was winzip used to extract petsc sources?    ****')
1885b6bfdb9SJed Brown    print(' *** Please restart with a fresh tarball and use "tar -xzf petsc.tar.gz"   ****')
1895b6bfdb9SJed Brown    print('===============================================================================')
190db1f124cSVasiliy Kozyrev    sys.exit(3)
1918a4600f2SSatish Balay  return
1928a4600f2SSatish Balay
1936a8f6897SSatish Balaydef chkcygwinlink():
1941921852fSSatish Balay  if os.path.exists('/usr/bin/cygcheck.exe') and os.path.exists('/usr/bin/link.exe') and chkwinf90():
1956a8f6897SSatish Balay      if '--ignore-cygwin-link' in sys.argv: return 0
1965b6bfdb9SJed Brown      print('===============================================================================')
1975b6bfdb9SJed Brown      print(' *** Cygwin /usr/bin/link detected! Compiles with CVF/Intel f90 can break!  **')
1985b6bfdb9SJed Brown      print(' *** To workarround do: "mv /usr/bin/link.exe /usr/bin/link-cygwin.exe"     **')
1995b6bfdb9SJed Brown      print(' *** Or to ignore this check, use configure option: --ignore-cygwin-link    **')
2005b6bfdb9SJed Brown      print('===============================================================================')
2016a8f6897SSatish Balay      sys.exit(3)
2026a8f6897SSatish Balay  return 0
2036a8f6897SSatish Balay
20485ef4d1eSSatish Balaydef chkbrokencygwin():
2059dabcff0SSatish Balay  if os.path.exists('/usr/bin/cygcheck.exe'):
2069dabcff0SSatish Balay    buf = os.popen('/usr/bin/cygcheck.exe -c cygwin').read()
2079dabcff0SSatish Balay    if buf.find('1.5.11-1') > -1:
2085b6bfdb9SJed Brown      print('===============================================================================')
2095b6bfdb9SJed Brown      print(' *** cygwin-1.5.11-1 detected. ./configure fails with this version ***')
2105b6bfdb9SJed Brown      print(' *** Please upgrade to cygwin-1.5.12-1 or newer version. This can  ***')
2115b6bfdb9SJed Brown      print(' *** be done by running cygwin-setup, selecting "next" all the way.***')
2125b6bfdb9SJed Brown      print('===============================================================================')
2131937db7aSSatish Balay      sys.exit(3)
2149dabcff0SSatish Balay  return 0
2159dabcff0SSatish Balay
216ee76e990SSatish Balaydef chkusingwindowspython():
217ee76e990SSatish Balay  if sys.platform == 'win32':
2185b6bfdb9SJed Brown    print('===============================================================================')
2195b6bfdb9SJed Brown    print(' *** Windows python detected. Please rerun ./configure with cygwin-python. ***')
2205b6bfdb9SJed Brown    print('===============================================================================')
221ee76e990SSatish Balay    sys.exit(3)
222ee76e990SSatish Balay  return 0
223ee76e990SSatish Balay
22414f5c25cSSatish Balaydef chkcygwinpython():
2251150532aSSatish Balay  if sys.platform == 'cygwin' :
2261150532aSSatish Balay    import platform
2271150532aSSatish Balay    import re
2281150532aSSatish Balay    r=re.compile("([0-9]+).([0-9]+).([0-9]+)")
2291150532aSSatish Balay    m=r.match(platform.release())
2301150532aSSatish Balay    major=int(m.group(1))
2311150532aSSatish Balay    minor=int(m.group(2))
2321150532aSSatish Balay    subminor=int(m.group(3))
2331150532aSSatish Balay    if ((major < 1) or (major == 1 and minor < 7) or (major == 1 and minor == 7 and subminor < 34)):
2341937db7aSSatish Balay      sys.argv.append('--useThreads=0')
2351937db7aSSatish Balay      extraLogs.append('''\
236a0022257SSatish Balay===============================================================================
2371150532aSSatish Balay** Cygwin version is older than 1.7.34. Python threads do not work correctly. ***
23814f5c25cSSatish Balay** Disabling thread usage for this run of ./configure *******
239a0022257SSatish Balay===============================================================================''')
24071384062SSatish Balay  return 0
24171384062SSatish Balay
242*cfb8f47aSBarry Smithdef chkcygwinwindowscompilers():
243*cfb8f47aSBarry Smith  '''Adds win32fe for Microsoft/Intel compilers'''
244*cfb8f47aSBarry Smith  if os.path.exists('/usr/bin/cygcheck.exe'):
245*cfb8f47aSBarry Smith    for l in range(1,len(sys.argv)):
246*cfb8f47aSBarry Smith      option = sys.argv[l]
247*cfb8f47aSBarry Smith      for i in ['cl','icl','ifort']:
248*cfb8f47aSBarry Smith        if option.startswith(i):
249*cfb8f47aSBarry Smith          sys.argv[l] = 'win32fe '+option
250*cfb8f47aSBarry Smith          break
251*cfb8f47aSBarry Smith  return 0
252*cfb8f47aSBarry Smith
2531937db7aSSatish Balaydef chkrhl9():
2541937db7aSSatish Balay  if os.path.exists('/etc/redhat-release'):
255836c2c52SSatish Balay    try:
256594eb360SSatish Balay      file = open('/etc/redhat-release','r')
257836c2c52SSatish Balay      buf = file.read()
258836c2c52SSatish Balay      file.close()
259836c2c52SSatish Balay    except:
260836c2c52SSatish Balay      # can't read file - assume dangerous RHL9
2611937db7aSSatish Balay      buf = 'Shrike'
262836c2c52SSatish Balay    if buf.find('Shrike') > -1:
2631937db7aSSatish Balay      sys.argv.append('--useThreads=0')
2641937db7aSSatish Balay      extraLogs.append('''\
265a0022257SSatish Balay==============================================================================
2661937db7aSSatish Balay   *** RHL9 detected. Threads do not work correctly with this distribution ***
267e2e64c6bSBarry Smith   ****** Disabling thread usage for this run of ./configure *********
268a0022257SSatish Balay===============================================================================''')
269836c2c52SSatish Balay  return 0
270836c2c52SSatish Balay
271da58527dSSatish Balaydef check_broken_configure_log_links():
272da58527dSSatish Balay  '''Sometime symlinks can get broken if the original files are deleted. Delete such broken links'''
273da58527dSSatish Balay  import os
274da58527dSSatish Balay  for logfile in ['configure.log','configure.log.bkp']:
275da58527dSSatish Balay    if os.path.islink(logfile) and not os.path.isfile(logfile): os.remove(logfile)
276da58527dSSatish Balay  return
277da58527dSSatish Balay
278da1d79b4SSatish Balaydef move_configure_log(framework):
279af0996ceSBarry Smith  '''Move configure.log to PETSC_ARCH/lib/petsc/conf - and update configure.log.bkp in both locations appropriately'''
280b0b472b0SSatish Balay  global petsc_arch
281b0b472b0SSatish Balay
282b0b472b0SSatish Balay  if hasattr(framework,'arch'): petsc_arch = framework.arch
283b0b472b0SSatish Balay  if hasattr(framework,'logName'): curr_file = framework.logName
284b0b472b0SSatish Balay  else: curr_file = 'configure.log'
285b0b472b0SSatish Balay
286b0b472b0SSatish Balay  if petsc_arch:
287da1d79b4SSatish Balay    import shutil
288da1d79b4SSatish Balay    import os
289b0b472b0SSatish Balay
290b0b472b0SSatish Balay    # Just in case - confdir is not created
291fe998a80SBarry Smith    lib_dir = os.path.join(petsc_arch,'lib')
292af0996ceSBarry Smith    conf_dir = os.path.join(petsc_arch,'lib','petsc','conf')
293b0b472b0SSatish Balay    if not os.path.isdir(petsc_arch): os.mkdir(petsc_arch)
294fe998a80SBarry Smith    if not os.path.isdir(lib_dir): os.mkdir(lib_dir)
295b0b472b0SSatish Balay    if not os.path.isdir(conf_dir): os.mkdir(conf_dir)
296b0b472b0SSatish Balay
297da1d79b4SSatish Balay    curr_bkp  = curr_file + '.bkp'
298b0b472b0SSatish Balay    new_file  = os.path.join(conf_dir,curr_file)
299da1d79b4SSatish Balay    new_bkp   = new_file + '.bkp'
300da1d79b4SSatish Balay
301af0996ceSBarry Smith    # Keep backup in $PETSC_ARCH/lib/petsc/conf location
302da1d79b4SSatish Balay    if os.path.isfile(new_bkp): os.remove(new_bkp)
303da1d79b4SSatish Balay    if os.path.isfile(new_file): os.rename(new_file,new_bkp)
3049e50940cSSatish Balay    if os.path.isfile(curr_file):
3059e50940cSSatish Balay      shutil.copyfile(curr_file,new_file)
3069e50940cSSatish Balay      os.remove(curr_file)
307da58527dSSatish Balay    if os.path.isfile(new_file): os.symlink(new_file,curr_file)
308af0996ceSBarry Smith    # If the old bkp is using the same PETSC_ARCH/lib/petsc/conf - then update bkp link
309da1d79b4SSatish Balay    if os.path.realpath(curr_bkp) == os.path.realpath(new_file):
310da58527dSSatish Balay      if os.path.isfile(curr_bkp): os.remove(curr_bkp)
311da58527dSSatish Balay      if os.path.isfile(new_bkp): os.symlink(new_bkp,curr_bkp)
312da1d79b4SSatish Balay  return
313da1d79b4SSatish Balay
314d93c4beeSSatish Balaydef print_final_timestamp(framework):
315d93c4beeSSatish Balay  import time
316d93c4beeSSatish Balay  framework.log.write(('='*80)+'\n')
3177a01bd3eSSatish Balay  framework.log.write('Finishing configure run at '+time.strftime('%a, %d %b %Y %H:%M:%S %z')+'\n')
318d93c4beeSSatish Balay  framework.log.write(('='*80)+'\n')
319d93c4beeSSatish Balay  return
320d93c4beeSSatish Balay
3215d5a5a7bSMatthew Knepleydef petsc_configure(configure_options):
3226e464aa7SMatthew G. Knepley  if 'PETSC_DIR' in os.environ:
3234a532159SBarry Smith    petscdir = os.environ['PETSC_DIR']
3246e464aa7SMatthew G. Knepley    if petscdir.find(' ') > -1:
3256e464aa7SMatthew 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')
3266e464aa7SMatthew G. Knepley    try:
327c3a89c15SBarry Smith      sys.path.append(os.path.join(petscdir,'lib','petsc','bin'))
3284a532159SBarry Smith      import petscnagupgrade
3294a532159SBarry Smith      file     = os.path.join(petscdir,'.nagged')
3304a532159SBarry Smith      if not petscnagupgrade.naggedtoday(file):
3314a532159SBarry Smith        petscnagupgrade.currentversion(petscdir)
3324a532159SBarry Smith    except:
3334a532159SBarry Smith      pass
3345b6bfdb9SJed Brown  print('===============================================================================')
3355b6bfdb9SJed Brown  print('             Configuring PETSc to compile on your system                       ')
3365b6bfdb9SJed Brown  print('===============================================================================')
33759e9bfd6SSatish Balay
338a258c2c4SMatthew G Knepley  try:
339c43ea0feSSatish Balay    # Command line arguments take precedence (but don't destroy argv[0])
340c43ea0feSSatish Balay    sys.argv = sys.argv[:1] + configure_options + sys.argv[1:]
341ccb279e1SMatthew Knepley    check_for_option_mistakes(sys.argv)
3422af240f0SSatish Balay    check_for_option_changed(sys.argv)
3435b6bfdb9SJed Brown  except (TypeError, ValueError) as e:
344a258c2c4SMatthew G Knepley    emsg = str(e)
345a258c2c4SMatthew G Knepley    if not emsg.endswith('\n'): emsg = emsg+'\n'
346a258c2c4SMatthew G Knepley    msg ='*******************************************************************************\n'\
347a258c2c4SMatthew G Knepley    +'                ERROR in COMMAND LINE ARGUMENT to ./configure \n' \
348a258c2c4SMatthew G Knepley    +'-------------------------------------------------------------------------------\n'  \
349a258c2c4SMatthew G Knepley    +emsg+'*******************************************************************************\n'
350a258c2c4SMatthew G Knepley    sys.exit(msg)
35159e9bfd6SSatish Balay  # check PETSC_ARCH
3522f393ef5SBarry Smith  check_for_unsupported_combinations(sys.argv)
35359e9bfd6SSatish Balay  check_petsc_arch(sys.argv)
354da58527dSSatish Balay  check_broken_configure_log_links()
3555fb2c094SBarry Smith
356f08ee00aSJason Sarich  #rename '--enable-' to '--with-'
357f08ee00aSJason Sarich  chkenable()
358c22cdea9SBarry Smith  # support a few standard configure option types
359f08ee00aSJason Sarich  chksynonyms()
3609dabcff0SSatish Balay  # Check for broken cygwin
3611937db7aSSatish Balay  chkbrokencygwin()
362d65f3bddSMatthew Knepley  # Disable threads on RHL9
3631937db7aSSatish Balay  chkrhl9()
364ee76e990SSatish Balay  # Make sure cygwin-python is used on windows
365ee76e990SSatish Balay  chkusingwindowspython()
36614f5c25cSSatish Balay  # Threads don't work for cygwin & python...
36714f5c25cSSatish Balay  chkcygwinpython()
3686a8f6897SSatish Balay  chkcygwinlink()
3698a4600f2SSatish Balay  chkdosfiles()
370*cfb8f47aSBarry Smith  chkcygwinwindowscompilers()
3719dabcff0SSatish Balay
37287282423SMatthew Knepley  # Should be run from the toplevel
373dbca6d9dSSatish Balay  configDir = os.path.abspath('config')
374f8833479SBarry Smith  bsDir     = os.path.join(configDir, 'BuildSystem')
375f8833479SBarry Smith  if not os.path.isdir(configDir):
3765d5a5a7bSMatthew Knepley    raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.'))
37787282423SMatthew Knepley  sys.path.insert(0, bsDir)
378f8833479SBarry Smith  sys.path.insert(0, configDir)
379e69ef9dfSMatthew Knepley  import config.base
3805d5a5a7bSMatthew Knepley  import config.framework
381492432c8SJed Brown  import pickle
3824e5e6a77SJed Brown  import traceback
3834f8a5b45SBarry Smith
3849dd2fdb1SMatthew Knepley  framework = None
3859dd2fdb1SMatthew Knepley  try:
38623a19ef1SSatish Balay    framework = config.framework.Framework(['--configModules=PETSc.Configure','--optionsModule=config.compilerOptions']+sys.argv[1:], loadArgDB = 0)
387d65f3bddSMatthew Knepley    framework.setup()
388d65f3bddSMatthew Knepley    framework.logPrint('\n'.join(extraLogs))
389f24f64feSBarry Smith    framework.configure(out = sys.stdout)
390358ebc22SMatthew Knepley    framework.storeSubstitutions(framework.argDB)
391492432c8SJed Brown    framework.argDB['configureCache'] = pickle.dumps(framework)
3927c939e48SSatish Balay    framework.printSummary()
39312c1d45bSMatthew G Knepley    framework.argDB.save(force = True)
3947cfd0b05SBarry Smith    framework.logClear()
395d93c4beeSSatish Balay    print_final_timestamp(framework)
396eefa2c0fSBarry Smith    framework.closeLog()
3979e50940cSSatish Balay    try:
398da1d79b4SSatish Balay      move_configure_log(framework)
3999e50940cSSatish Balay    except:
4009e50940cSSatish Balay      # perhaps print an error about unable to shuffle logs?
4019e50940cSSatish Balay      pass
402dd50d019SBarry Smith    return 0
4035b6bfdb9SJed Brown  except (RuntimeError, config.base.ConfigureSetupError) as e:
4047d670a3cSBarry Smith    emsg = str(e)
40542351d26SSatish Balay    if not emsg.endswith('\n'): emsg = emsg+'\n'
406a0022257SSatish Balay    msg ='*******************************************************************************\n'\
407fe09c992SBarry Smith    +'         UNABLE to CONFIGURE with GIVEN OPTIONS    (see configure.log for details):\n' \
408a0022257SSatish Balay    +'-------------------------------------------------------------------------------\n'  \
409a0022257SSatish Balay    +emsg+'*******************************************************************************\n'
410e9f3bb17SBarry Smith    se = ''
4115b6bfdb9SJed Brown  except (TypeError, ValueError) as e:
4127d670a3cSBarry Smith    emsg = str(e)
41342351d26SSatish Balay    if not emsg.endswith('\n'): emsg = emsg+'\n'
414a0022257SSatish Balay    msg ='*******************************************************************************\n'\
415957f4b51SBarry Smith    +'    TypeError or ValueError possibly related to ERROR in COMMAND LINE ARGUMENT to ./configure \n' \
416a0022257SSatish Balay    +'-------------------------------------------------------------------------------\n'  \
417a0022257SSatish Balay    +emsg+'*******************************************************************************\n'
4181a02243aSBarry Smith    se = ''
4195b6bfdb9SJed Brown  except ImportError as e :
4207d670a3cSBarry Smith    emsg = str(e)
42142351d26SSatish Balay    if not emsg.endswith('\n'): emsg = emsg+'\n'
422a0022257SSatish Balay    msg ='*******************************************************************************\n'\
423e2e64c6bSBarry Smith    +'                     UNABLE to FIND MODULE for ./configure \n' \
424a0022257SSatish Balay    +'-------------------------------------------------------------------------------\n'  \
425a0022257SSatish Balay    +emsg+'*******************************************************************************\n'
42696dc2fe8SMatthew Knepley    se = ''
4275b6bfdb9SJed Brown  except OSError as e :
42801def6f0SMatthew Knepley    emsg = str(e)
42901def6f0SMatthew Knepley    if not emsg.endswith('\n'): emsg = emsg+'\n'
430a0022257SSatish Balay    msg ='*******************************************************************************\n'\
431e2e64c6bSBarry Smith    +'                    UNABLE to EXECUTE BINARIES for ./configure \n' \
432a0022257SSatish Balay    +'-------------------------------------------------------------------------------\n'  \
433a0022257SSatish Balay    +emsg+'*******************************************************************************\n'
43401def6f0SMatthew Knepley    se = ''
4355b6bfdb9SJed Brown  except SystemExit as e:
436d7d3c4beSMatthew Knepley    if e.code is None or e.code == 0:
437d7d3c4beSMatthew Knepley      return
438c524ecbbSBarry Smith    if e.code is 10:
439c524ecbbSBarry Smith      sys.exit(10)
440a0022257SSatish Balay    msg ='*******************************************************************************\n'\
441b1dada7fSMatthew Knepley    +'         CONFIGURATION FAILURE  (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \
442a0022257SSatish Balay    +'*******************************************************************************\n'
443d7d3c4beSMatthew Knepley    se  = str(e)
4445b6bfdb9SJed Brown  except Exception as e:
445a0022257SSatish Balay    msg ='*******************************************************************************\n'\
446fe09c992SBarry Smith    +'        CONFIGURATION CRASH  (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \
447a0022257SSatish Balay    +'*******************************************************************************\n'
448e9f3bb17SBarry Smith    se  = str(e)
449e9f3bb17SBarry Smith
4505b6bfdb9SJed Brown  print(msg)
4519dd2fdb1SMatthew Knepley  if not framework is None:
4529dd2fdb1SMatthew Knepley    framework.logClear()
453e9f3bb17SBarry Smith    if hasattr(framework, 'log'):
45422c95ba3SMatthew G Knepley      try:
455d71f8ab3SSatish Balay        if hasattr(framework,'compilerDefines'):
456bd5137a2SBarry Smith          framework.log.write('**** Configure header '+framework.compilerDefines+' ****\n')
457febd46b0SSatish Balay          framework.outputHeader(framework.log)
458d71f8ab3SSatish Balay        if hasattr(framework,'compilerFixes'):
459bd5137a2SBarry Smith          framework.log.write('**** C specific Configure header '+framework.compilerFixes+' ****\n')
460febd46b0SSatish Balay          framework.outputCHeader(framework.log)
4615b6bfdb9SJed Brown      except Exception as e:
46222c95ba3SMatthew G Knepley        framework.log.write('Problem writing headers to log: '+str(e))
463b1dada7fSMatthew Knepley      try:
464f24f64feSBarry Smith        framework.log.write(msg+se)
465f24f64feSBarry Smith        traceback.print_tb(sys.exc_info()[2], file = framework.log)
466d93c4beeSSatish Balay        print_final_timestamp(framework)
467f73e6a6cSSatish Balay        if hasattr(framework,'log'): framework.log.close()
468da1d79b4SSatish Balay        move_configure_log(framework)
469957f4b51SBarry Smith      except Exception as e:
470957f4b51SBarry Smith        print('Error printing error message from exception or printing the traceback:'+str(e))
471957f4b51SBarry Smith        traceback.print_tb(sys.exc_info()[2])
472e9f3bb17SBarry Smith      sys.exit(1)
4735a74f024SMatthew Knepley    else:
4745b6bfdb9SJed Brown      print(se)
475957f4b51SBarry Smith      traceback.print_tb(sys.exc_info()[2])
476957f4b51SBarry Smith  else:
477957f4b51SBarry Smith    print(se)
4785a74f024SMatthew Knepley    traceback.print_tb(sys.exc_info()[2])
479f73e6a6cSSatish Balay  if hasattr(framework,'log'): framework.log.close()
4805d5a5a7bSMatthew Knepley
4815d5a5a7bSMatthew Knepleyif __name__ == '__main__':
482a030c540SBarry Smith  petsc_configure([])
483759acf64SBarry Smith
484