1df3bd252SSatish Balay#!/usr/bin/env python3 25b6bfdb9SJed Brownfrom __future__ import print_function 37eca831cSJacob Faibussowitschimport os 47eca831cSJacob Faibussowitschimport sys 57eca831cSJacob Faibussowitschimport pickle 67eca831cSJacob Faibussowitschimport traceback 7db5c7c58SSatish Balay 86a1f9e42SJacob Faibussowitschbanner_length = 93 97c9abfe7SSatish BalayextraLogs = [] 10b0b472b0SSatish Balaypetsc_arch = '' 114b8aa89bSBarry Smith 1244b0d7f9SSatish Balay# Use en_US as language so that BuildSystem parses compiler messages in english 13b9a05632SSatish Balaydef fixLang(lang): 14b9a05632SSatish Balay if lang in os.environ and os.environ[lang] != '': 15b9a05632SSatish Balay lv = os.environ[lang] 16b9a05632SSatish Balay enc = '' 17b9a05632SSatish Balay try: lv,enc = lv.split('.') 18b9a05632SSatish Balay except: pass 19b9a05632SSatish Balay if lv not in ['en_US','C']: lv = 'en_US' 20b9a05632SSatish Balay if enc: lv = lv+'.'+enc 21b9a05632SSatish Balay os.environ[lang] = lv 22b9a05632SSatish Balay 23b9a05632SSatish BalayfixLang('LC_LOCAL') 24b9a05632SSatish BalayfixLang('LANG') 25b9a05632SSatish Balay 26ccb279e1SMatthew Knepleydef check_for_option_mistakes(opts): 2745faeebdSBarry Smith for opt in opts[1:]: 28cda0060aSMatthew Knepley name = opt.split('=')[0] 295715f7bdSSatish Balay if name.find(' ') >= 0: 305715f7bdSSatish Balay raise ValueError('The option "'+name+'" has a space character in the name - this is likely incorrect usage.'); 31ccb279e1SMatthew Knepley if name.find('_') >= 0: 32ccb279e1SMatthew Knepley exception = False 331de7a49fSSatish 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']: 34ccb279e1SMatthew Knepley if name.find(exc) >= 0: 35ccb279e1SMatthew Knepley exception = True 36ccb279e1SMatthew Knepley if not exception: 37ccb279e1SMatthew Knepley raise ValueError('The option '+name+' should probably be '+name.replace('_', '-')); 38ab610953SSatish Balay if opt.find('=') >=0: 39ab610953SSatish Balay optval = opt.split('=')[1] 40ab610953SSatish Balay if optval == 'ifneeded': 41ab610953SSatish Balay raise ValueError('The option '+opt+' should probably be '+opt.replace('ifneeded', '1')); 42d1fb55d9SBarry Smith for exc in ['mkl_sparse', 'mkl_sparse_optimize', 'mkl_cpardiso', 'mkl_pardiso', 'superlu_dist']: 43d1fb55d9SBarry Smith if name.find(exc.replace('_','-')) > -1: 44d1fb55d9SBarry Smith raise ValueError('The option '+opt+' should be '+opt.replace(exc.replace('_','-'),exc)); 45ccb279e1SMatthew Knepley return 46ccb279e1SMatthew Knepley 472f393ef5SBarry Smithdef check_for_unsupported_combinations(opts): 482f393ef5SBarry Smith if '--with-precision=single' in opts and '--with-clanguage=cxx' in opts and '--with-scalar-type=complex' in opts: 492f393ef5SBarry Smith sys.exit(ValueError('PETSc does not support single precision complex with C++ clanguage, run with --with-clanguage=c')) 502f393ef5SBarry Smith 512af240f0SSatish Balaydef check_for_option_changed(opts): 52750b007cSBarry Smith# Document changes in command line options here. (matlab-engine is deprecated, no longer needed but still allowed) 534544382eSSatish Balay optMap = [('with-64bit-indices','with-64-bit-indices'), 54008db1b6SSatish Balay ('with-mpi-exec','with-mpiexec'), 554544382eSSatish Balay ('c-blas-lapack','f2cblaslapack'), 564544382eSSatish Balay ('cholmod','suitesparse'), 574544382eSSatish Balay ('umfpack','suitesparse'), 5869cdbcb9SBarry Smith ('matlabengine','matlab-engine'), 59b129f54cSBarry Smith ('sundials','sundials2'), 604544382eSSatish Balay ('f-blas-lapack','fblaslapack'), 614544382eSSatish Balay ('with-packages-dir','with-packages-download-dir'), 624544382eSSatish Balay ('with-external-packages-dir','with-packages-build-dir'), 634544382eSSatish Balay ('package-dirs','with-packages-search-path'), 644544382eSSatish Balay ('download-petsc4py-python','with-python-exec'), 654544382eSSatish Balay ('search-dirs','with-executables-search-path')] 662af240f0SSatish Balay for opt in opts[1:]: 672af240f0SSatish Balay optname = opt.split('=')[0].strip('-') 682af240f0SSatish Balay for oldname,newname in optMap: 69f1bd03f4SSatish Balay if optname.find(oldname) >=0 and not optname.find(newname) >=0: 702af240f0SSatish Balay raise ValueError('The option '+opt+' should probably be '+opt.replace(oldname,newname)) 712af240f0SSatish Balay return 722af240f0SSatish Balay 7359e9bfd6SSatish Balaydef check_petsc_arch(opts): 74c43ea0feSSatish Balay # If PETSC_ARCH not specified - use script name (if not configure.py) 75b0b472b0SSatish Balay global petsc_arch 76c43ea0feSSatish Balay found = 0 7759e9bfd6SSatish Balay for name in opts: 78c43ea0feSSatish Balay if name.find('PETSC_ARCH=') >= 0: 79b0b472b0SSatish Balay petsc_arch=name.split('=')[1] 80c43ea0feSSatish Balay found = 1 8159e9bfd6SSatish Balay break 8259e9bfd6SSatish Balay # If not yet specified - use the filename of script 83c43ea0feSSatish Balay if not found: 8459e9bfd6SSatish Balay filename = os.path.basename(sys.argv[0]) 85e68ebbecSBarry Smith if not filename.startswith('configure') and not filename.startswith('reconfigure') and not filename.startswith('setup'): 86b0b472b0SSatish Balay petsc_arch=os.path.splitext(os.path.basename(sys.argv[0]))[0] 87b0b472b0SSatish Balay useName = 'PETSC_ARCH='+petsc_arch 8859e9bfd6SSatish Balay opts.append(useName) 891937db7aSSatish Balay return 0 904b8aa89bSBarry Smith 91f08ee00aSJason Sarichdef chkenable(): 92f08ee00aSJason Sarich #Replace all 'enable-'/'disable-' with 'with-'=0/1/tail 93f08ee00aSJason Sarich #enable-fortran is a special case, the resulting --with-fortran is ambiguous. 941b266c99SBarry Smith #Would it mean --with-fc= 955bb5b98aSSatish Balay en_dash = u'\N{EN DASH}' 96c05720f7SSatish Balay no_break_space = u'\N{NO-BREAK SPACE}' 97f08ee00aSJason Sarich for l in range(0,len(sys.argv)): 98f08ee00aSJason Sarich name = sys.argv[l] 99c05720f7SSatish Balay if name.find(no_break_space) >= 0: 100c05720f7SSatish Balay sys.exit(ValueError('Unicode NO-BREAK SPACE char found in arguments! Please rerun configure using regular space chars: %s' % [name])) 101edf9f831SSatish Balay name = name.replace(en_dash,'-') 102c2ec76c5SSatish Balay if hasattr(name,'isprintable') and not name.isprintable(): 103d689f251SBarry Smith sys.exit(ValueError('Non-printable characters or control characters found in arguments! Please rerun configure using only printable character arguments: %s' % [name])) 1046293a234SJunchao Zhang if name.lstrip('-').startswith('enable-cxx'): 1052b700d61SJason Sarich if name.find('=') == -1: 106edf9f831SSatish Balay name = name.replace('enable-cxx','with-clanguage=C++',1) 1072b700d61SJason Sarich else: 1082b700d61SJason Sarich head, tail = name.split('=', 1) 1092b700d61SJason Sarich if tail=='0': 110edf9f831SSatish Balay name = head.replace('enable-cxx','with-clanguage=C',1) 1112b700d61SJason Sarich else: 112edf9f831SSatish Balay name = head.replace('enable-cxx','with-clanguage=C++',1) 113edf9f831SSatish Balay sys.argv[l] = name 1142b700d61SJason Sarich continue 1156293a234SJunchao Zhang if name.lstrip('-').startswith('disable-cxx'): 1162b700d61SJason Sarich if name.find('=') == -1: 117edf9f831SSatish Balay name = name.replace('disable-cxx','with-clanguage=C',1) 1182b700d61SJason Sarich else: 1192b700d61SJason Sarich head, tail = name.split('=', 1) 1202b700d61SJason Sarich if tail == '0': 121edf9f831SSatish Balay name = head.replace('disable-cxx','with-clanguage=C++',1) 1222b700d61SJason Sarich else: 123edf9f831SSatish Balay name = head.replace('disable-cxx','with-clanguage=C',1) 124edf9f831SSatish Balay sys.argv[l] = name 1252b700d61SJason Sarich continue 1262b700d61SJason Sarich 1276293a234SJunchao Zhang if name.lstrip('-').startswith('enable-'): 128f08ee00aSJason Sarich if name.find('=') == -1: 129edf9f831SSatish Balay name = name.replace('enable-','with-',1)+'=1' 130f08ee00aSJason Sarich else: 131f08ee00aSJason Sarich head, tail = name.split('=', 1) 132edf9f831SSatish Balay name = head.replace('enable-','with-',1)+'='+tail 1336293a234SJunchao Zhang if name.lstrip('-').startswith('disable-'): 134f08ee00aSJason Sarich if name.find('=') == -1: 135edf9f831SSatish Balay name = name.replace('disable-','with-',1)+'=0' 136f08ee00aSJason Sarich else: 137f08ee00aSJason Sarich head, tail = name.split('=', 1) 138f08ee00aSJason Sarich if tail == '1': tail = '0' 139edf9f831SSatish Balay name = head.replace('disable-','with-',1)+'='+tail 1406293a234SJunchao Zhang if name.lstrip('-').startswith('without-'): 141f08ee00aSJason Sarich if name.find('=') == -1: 142edf9f831SSatish Balay name = name.replace('without-','with-',1)+'=0' 143f08ee00aSJason Sarich else: 144f08ee00aSJason Sarich head, tail = name.split('=', 1) 145f08ee00aSJason Sarich if tail == '1': tail = '0' 146edf9f831SSatish Balay name = head.replace('without-','with-',1)+'='+tail 147edf9f831SSatish Balay sys.argv[l] = name 148f08ee00aSJason Sarich 149f08ee00aSJason Sarichdef chksynonyms(): 150f08ee00aSJason Sarich #replace common configure options with ones that PETSc BuildSystem recognizes 15198d87fb0SBarry Smith simplereplacements = {'F77' : 'FC', 'F90' : 'FC'} 152f08ee00aSJason Sarich for l in range(0,len(sys.argv)): 153f08ee00aSJason Sarich name = sys.argv[l] 154f08ee00aSJason Sarich 15586d91f96SSatish Balay name = name.replace('download-petsc4py','with-petsc4py') 156c58b03afSBarry Smith name = name.replace('with-openmpi','with-mpi') 157c58b03afSBarry Smith name = name.replace('with-mpich','with-mpi') 158c58b03afSBarry Smith name = name.replace('with-blas-lapack','with-blaslapack') 1593bdc3ccdSStefano Zampini name = name.replace('with-cuda-gencodearch','with-cuda-arch') 160c69ce369SMartin Diehl name = name.replace('download-hdf5-fortran-bindings','with-hdf5-fortran-bindings') 161c87df54fSBarry Smith 162ce54fb35SBarry Smith if name.find('with-debug=') >= 0 or name.endswith('with-debug'): 163f08ee00aSJason Sarich if name.find('=') == -1: 164c58b03afSBarry Smith name = name.replace('with-debug','with-debugging')+'=1' 165f08ee00aSJason Sarich else: 166f08ee00aSJason Sarich head, tail = name.split('=', 1) 167c58b03afSBarry Smith name = head.replace('with-debug','with-debugging')+'='+tail 168f08ee00aSJason Sarich 169ce54fb35SBarry Smith if name.find('with-shared=') >= 0 or name.endswith('with-shared'): 170f08ee00aSJason Sarich if name.find('=') == -1: 171c58b03afSBarry Smith name = name.replace('with-shared','with-shared-libraries')+'=1' 172f08ee00aSJason Sarich else: 173f08ee00aSJason Sarich head, tail = name.split('=', 1) 174c58b03afSBarry Smith name = head.replace('with-shared','with-shared-libraries')+'='+tail 175f08ee00aSJason Sarich 1768fd71741SJason Sarich if name.find('with-index-size=') >=0: 1778fd71741SJason Sarich head,tail = name.split('=',1) 1788fd71741SJason Sarich if int(tail)==32: 179c58b03afSBarry Smith name = '--with-64-bit-indices=0' 1808fd71741SJason Sarich elif int(tail)==64: 181c58b03afSBarry Smith name = '--with-64-bit-indices=1' 1828fd71741SJason Sarich else: 1838fd71741SJason Sarich raise RuntimeError('--with-index-size= must be 32 or 64') 184f08ee00aSJason Sarich 1858fd71741SJason Sarich if name.find('with-precision=') >=0: 1868fd71741SJason Sarich head,tail = name.split('=',1) 1878fd71741SJason Sarich if tail.find('quad')>=0: 188c58b03afSBarry Smith name='--with-precision=__float128' 189f08ee00aSJason Sarich 19098d87fb0SBarry Smith for i,j in simplereplacements.items(): 19198d87fb0SBarry Smith if name.find(i+'=') >= 0: 192c58b03afSBarry Smith name = name.replace(i+'=',j+'=') 19398d87fb0SBarry Smith elif name.find('with-'+i.lower()+'=') >= 0: 194c58b03afSBarry Smith name = name.replace(i.lower()+'=',j.lower()+'=') 195c58b03afSBarry Smith 196c58b03afSBarry Smith # restore 'sys.argv[l]' from the intermediate var 'name' 197c58b03afSBarry Smith sys.argv[l] = name 198f08ee00aSJason Sarich 199b917b182SSatish Balaydef chkwincompilerusinglink(): 2006a8f6897SSatish Balay for arg in sys.argv: 2019aae4796SBarry Smith if (arg.find('win32fe') >= 0 and (arg.find('ifort') >=0 or arg.find('icl') >=0)): 2026a8f6897SSatish Balay return 1 2036a8f6897SSatish Balay return 0 2046a8f6897SSatish Balay 2058a4600f2SSatish Balaydef chkdosfiles(): 206360dfd13SSatish Balay # cygwin - but not a hg clone - so check one of files in bin dir 2078fb0cc24SJed Brown if b"\r\n" in open(os.path.join('lib','petsc','bin','petscmpiexec'),"rb").read(): 2085b6bfdb9SJed Brown print('===============================================================================') 2095b6bfdb9SJed Brown print(' *** Scripts are in DOS mode. Was winzip used to extract petsc sources? ****') 2105b6bfdb9SJed Brown print(' *** Please restart with a fresh tarball and use "tar -xzf petsc.tar.gz" ****') 2115b6bfdb9SJed Brown print('===============================================================================') 212db1f124cSVasiliy Kozyrev sys.exit(3) 2138a4600f2SSatish Balay return 2148a4600f2SSatish Balay 2156a8f6897SSatish Balaydef chkcygwinlink(): 216b917b182SSatish Balay if os.path.exists('/usr/bin/cygcheck.exe') and os.path.exists('/usr/bin/link.exe') and chkwincompilerusinglink(): 2176a8f6897SSatish Balay if '--ignore-cygwin-link' in sys.argv: return 0 2185b6bfdb9SJed Brown print('===============================================================================') 219b917b182SSatish Balay print(' *** Cygwin /usr/bin/link detected! Compiles with Intel icl/ifort can break! **') 220a5b23f4aSJose E. Roman print(' *** To workaround do: "mv /usr/bin/link.exe /usr/bin/link-cygwin.exe" **') 221b917b182SSatish Balay print(' *** Or to ignore this check, use configure option: --ignore-cygwin-link. But compiles can fail. **') 2225b6bfdb9SJed Brown print('===============================================================================') 2236a8f6897SSatish Balay sys.exit(3) 2246a8f6897SSatish Balay return 0 2256a8f6897SSatish Balay 22685ef4d1eSSatish Balaydef chkbrokencygwin(): 2279dabcff0SSatish Balay if os.path.exists('/usr/bin/cygcheck.exe'): 2289dabcff0SSatish Balay buf = os.popen('/usr/bin/cygcheck.exe -c cygwin').read() 2299dabcff0SSatish Balay if buf.find('1.5.11-1') > -1: 2305b6bfdb9SJed Brown print('===============================================================================') 2315b6bfdb9SJed Brown print(' *** cygwin-1.5.11-1 detected. ./configure fails with this version ***') 2325b6bfdb9SJed Brown print(' *** Please upgrade to cygwin-1.5.12-1 or newer version. This can ***') 2335b6bfdb9SJed Brown print(' *** be done by running cygwin-setup, selecting "next" all the way.***') 2345b6bfdb9SJed Brown print('===============================================================================') 2351937db7aSSatish Balay sys.exit(3) 2369dabcff0SSatish Balay return 0 2379dabcff0SSatish Balay 238ee76e990SSatish Balaydef chkusingwindowspython(): 239ee76e990SSatish Balay if sys.platform == 'win32': 2405b6bfdb9SJed Brown print('===============================================================================') 2415b6bfdb9SJed Brown print(' *** Windows python detected. Please rerun ./configure with cygwin-python. ***') 2425b6bfdb9SJed Brown print('===============================================================================') 243ee76e990SSatish Balay sys.exit(3) 244ee76e990SSatish Balay return 0 245ee76e990SSatish Balay 24614f5c25cSSatish Balaydef chkcygwinpython(): 2471150532aSSatish Balay if sys.platform == 'cygwin' : 2481150532aSSatish Balay import platform 2491150532aSSatish Balay import re 2501150532aSSatish Balay r=re.compile("([0-9]+).([0-9]+).([0-9]+)") 2511150532aSSatish Balay m=r.match(platform.release()) 2521150532aSSatish Balay major=int(m.group(1)) 2531150532aSSatish Balay minor=int(m.group(2)) 2541150532aSSatish Balay subminor=int(m.group(3)) 2551150532aSSatish Balay if ((major < 1) or (major == 1 and minor < 7) or (major == 1 and minor == 7 and subminor < 34)): 2561937db7aSSatish Balay sys.argv.append('--useThreads=0') 2571937db7aSSatish Balay extraLogs.append('''\ 258a0022257SSatish Balay=============================================================================== 2591150532aSSatish Balay** Cygwin version is older than 1.7.34. Python threads do not work correctly. *** 26014f5c25cSSatish Balay** Disabling thread usage for this run of ./configure ******* 261a0022257SSatish Balay===============================================================================''') 26271384062SSatish Balay return 0 26371384062SSatish Balay 264cfb8f47aSBarry Smithdef chkcygwinwindowscompilers(): 26533a1b2deSBarry Smith ''' Converts Microsoft and Intel Windows compilers to PETSc script using win32fe''' 266cfb8f47aSBarry Smith if os.path.exists('/usr/bin/cygcheck.exe'): 26733a1b2deSBarry Smith path = os.path.join(os.getcwd(),'lib','petsc','bin','win32fe') 268cfb8f47aSBarry Smith for l in range(1,len(sys.argv)): 269cfb8f47aSBarry Smith option = sys.argv[l] 27033a1b2deSBarry Smith for i in ['cl','icl','ifort','lib','nvcc']: 27133a1b2deSBarry Smith if option.endswith('="win32fe '+i+'"'): 272*7d7394c2SSatish Balay sys.argv[l] = option[:option.find('=')+1]+os.path.join(path,'win32fe_'+i) 27333a1b2deSBarry Smith print('===============================================================================') 27433a1b2deSBarry Smith print(' *** Arguments of the form XXX="win32fe '+i+'" are deprecated ****') 27533a1b2deSBarry Smith print(' *** Use XXX='+i+' ****') 27633a1b2deSBarry Smith print('===============================================================================') 27733a1b2deSBarry Smith 27833a1b2deSBarry Smith break 27933a1b2deSBarry Smith if option.endswith('='+i): 280*7d7394c2SSatish Balay sys.argv[l] = option[:option.find('=')+1]+os.path.join(path,'win32fe_'+i) 281cfb8f47aSBarry Smith break 282cfb8f47aSBarry Smith return 0 283cfb8f47aSBarry Smith 2841937db7aSSatish Balaydef chkrhl9(): 2851937db7aSSatish Balay if os.path.exists('/etc/redhat-release'): 286836c2c52SSatish Balay try: 287594eb360SSatish Balay file = open('/etc/redhat-release','r') 288836c2c52SSatish Balay buf = file.read() 289836c2c52SSatish Balay file.close() 290836c2c52SSatish Balay except: 291836c2c52SSatish Balay # can't read file - assume dangerous RHL9 2921937db7aSSatish Balay buf = 'Shrike' 293836c2c52SSatish Balay if buf.find('Shrike') > -1: 2941937db7aSSatish Balay sys.argv.append('--useThreads=0') 2951937db7aSSatish Balay extraLogs.append('''\ 296a0022257SSatish Balay============================================================================== 2971937db7aSSatish Balay *** RHL9 detected. Threads do not work correctly with this distribution *** 298e2e64c6bSBarry Smith ****** Disabling thread usage for this run of ./configure ********* 299a0022257SSatish Balay===============================================================================''') 300836c2c52SSatish Balay return 0 301836c2c52SSatish Balay 302fd1ac241SSatish Balaydef chktmpnoexec(): 303e08ecd42SSatish Balay if not hasattr(os,'ST_NOEXEC'): return # novermin 304fd1ac241SSatish Balay if 'TMPDIR' in os.environ: tmpDir = os.environ['TMPDIR'] 305fd1ac241SSatish Balay else: tmpDir = '/tmp' 306e08ecd42SSatish Balay if os.statvfs(tmpDir).f_flag & os.ST_NOEXEC: # novermin 307e08ecd42SSatish Balay if os.statvfs(os.path.abspath('.')).f_flag & os.ST_NOEXEC: # novermin 308fd1ac241SSatish Balay print('************************************************************************') 309fd1ac241SSatish Balay print('* TMPDIR '+tmpDir+' has noexec attribute. Same with '+os.path.abspath('.')+' where petsc is built.') 310fd1ac241SSatish Balay print('* Suggest building PETSc in a location without this restriction!') 311fd1ac241SSatish Balay print('* Alternatively, set env variable TMPDIR to a location that is not restricted to run binaries.') 312fd1ac241SSatish Balay print('************************************************************************') 313fd1ac241SSatish Balay sys.exit(4) 314fd1ac241SSatish Balay else: 315fd1ac241SSatish Balay newTmp = os.path.abspath('tmp-petsc') 316fd1ac241SSatish Balay print('************************************************************************') 317fd1ac241SSatish Balay print('* TMPDIR '+tmpDir+' has noexec attribute. Using '+newTmp+' instead.') 318fd1ac241SSatish Balay print('************************************************************************') 319fd1ac241SSatish Balay if not os.path.isdir(newTmp): os.mkdir(os.path.abspath(newTmp)) 320fd1ac241SSatish Balay os.environ['TMPDIR'] = newTmp 321fd1ac241SSatish Balay return 322fd1ac241SSatish Balay 32305f86fb1SBarry Smithdef check_cray_modules(): 32405f86fb1SBarry Smith import script 32505f86fb1SBarry Smith '''For Cray systems check if the cc, CC, ftn compiler suite modules have been set''' 32605f86fb1SBarry Smith cray = os.getenv('CRAY_SITE_LIST_DIR') 32705f86fb1SBarry Smith if not cray: return 32805f86fb1SBarry Smith cray = os.getenv('CRAYPE_DIR') 32905f86fb1SBarry Smith if not cray: 33005f86fb1SBarry Smith print('************************************************************************') 33105f86fb1SBarry Smith print('* You are on a Cray system but no programming environments have been loaded') 33205f86fb1SBarry Smith print('* Perhaps you need:') 33305f86fb1SBarry Smith print('* module load intel ; module load PrgEnv-intel') 33405f86fb1SBarry Smith print('* or module load PrgEnv-cray') 33505f86fb1SBarry Smith print('* or module load PrgEnv-gnu') 336a17b96a8SKyle Gerard Felker print('* See https://petsc.org/release/install/install/#installing-on-large-scale-doe-systems') 33705f86fb1SBarry Smith print('************************************************************************') 33805f86fb1SBarry Smith sys.exit(4) 33905f86fb1SBarry Smith 340da58527dSSatish Balaydef check_broken_configure_log_links(): 341da58527dSSatish Balay '''Sometime symlinks can get broken if the original files are deleted. Delete such broken links''' 342da58527dSSatish Balay import os 343da58527dSSatish Balay for logfile in ['configure.log','configure.log.bkp']: 344da58527dSSatish Balay if os.path.islink(logfile) and not os.path.isfile(logfile): os.remove(logfile) 345da58527dSSatish Balay return 346da58527dSSatish Balay 347da1d79b4SSatish Balaydef move_configure_log(framework): 348af0996ceSBarry Smith '''Move configure.log to PETSC_ARCH/lib/petsc/conf - and update configure.log.bkp in both locations appropriately''' 349b0b472b0SSatish Balay global petsc_arch 350b0b472b0SSatish Balay 351b0b472b0SSatish Balay if hasattr(framework,'arch'): petsc_arch = framework.arch 352b0b472b0SSatish Balay if hasattr(framework,'logName'): curr_file = framework.logName 353b0b472b0SSatish Balay else: curr_file = 'configure.log' 354b0b472b0SSatish Balay 355b0b472b0SSatish Balay if petsc_arch: 356da1d79b4SSatish Balay import shutil 357da1d79b4SSatish Balay import os 358b0b472b0SSatish Balay 359b0b472b0SSatish Balay # Just in case - confdir is not created 360fe998a80SBarry Smith lib_dir = os.path.join(petsc_arch,'lib') 361be5c6b33SBarry Smith petsc_dir = os.path.join(petsc_arch,'lib','petsc') 362af0996ceSBarry Smith conf_dir = os.path.join(petsc_arch,'lib','petsc','conf') 363b0b472b0SSatish Balay if not os.path.isdir(petsc_arch): os.mkdir(petsc_arch) 364fe998a80SBarry Smith if not os.path.isdir(lib_dir): os.mkdir(lib_dir) 365be5c6b33SBarry Smith if not os.path.isdir(petsc_dir): os.mkdir(petsc_dir) 366b0b472b0SSatish Balay if not os.path.isdir(conf_dir): os.mkdir(conf_dir) 367b0b472b0SSatish Balay 368da1d79b4SSatish Balay curr_bkp = curr_file + '.bkp' 369b0b472b0SSatish Balay new_file = os.path.join(conf_dir,curr_file) 370da1d79b4SSatish Balay new_bkp = new_file + '.bkp' 371da1d79b4SSatish Balay 372af0996ceSBarry Smith # Keep backup in $PETSC_ARCH/lib/petsc/conf location 373da1d79b4SSatish Balay if os.path.isfile(new_bkp): os.remove(new_bkp) 374da1d79b4SSatish Balay if os.path.isfile(new_file): os.rename(new_file,new_bkp) 3759e50940cSSatish Balay if os.path.isfile(curr_file): 3769e50940cSSatish Balay shutil.copyfile(curr_file,new_file) 3779e50940cSSatish Balay os.remove(curr_file) 378da58527dSSatish Balay if os.path.isfile(new_file): os.symlink(new_file,curr_file) 379af0996ceSBarry Smith # If the old bkp is using the same PETSC_ARCH/lib/petsc/conf - then update bkp link 380da1d79b4SSatish Balay if os.path.realpath(curr_bkp) == os.path.realpath(new_file): 381da58527dSSatish Balay if os.path.isfile(curr_bkp): os.remove(curr_bkp) 382da58527dSSatish Balay if os.path.isfile(new_bkp): os.symlink(new_bkp,curr_bkp) 383da1d79b4SSatish Balay return 384da1d79b4SSatish Balay 385d93c4beeSSatish Balaydef print_final_timestamp(framework): 386d93c4beeSSatish Balay import time 387d93c4beeSSatish Balay framework.log.write(('='*80)+'\n') 3887a01bd3eSSatish Balay framework.log.write('Finishing configure run at '+time.strftime('%a, %d %b %Y %H:%M:%S %z')+'\n') 389d93c4beeSSatish Balay framework.log.write(('='*80)+'\n') 390d93c4beeSSatish Balay return 391d93c4beeSSatish Balay 3925d5a5a7bSMatthew Knepleydef petsc_configure(configure_options): 393856b83eaSSatish Balay petscdir = os.getcwd() 3946e464aa7SMatthew G. Knepley try: 395c3a89c15SBarry Smith sys.path.append(os.path.join(petscdir,'lib','petsc','bin')) 3964a532159SBarry Smith import petscnagupgrade 3974a532159SBarry Smith file = os.path.join(petscdir,'.nagged') 3984a532159SBarry Smith if not petscnagupgrade.naggedtoday(file): 3994a532159SBarry Smith petscnagupgrade.currentversion(petscdir) 4004a532159SBarry Smith except: 4014a532159SBarry Smith pass 40259e9bfd6SSatish Balay 4037eca831cSJacob Faibussowitsch # Should be run from the toplevel 4047eca831cSJacob Faibussowitsch configDir = os.path.abspath('config') 4057eca831cSJacob Faibussowitsch bsDir = os.path.join(configDir, 'BuildSystem') 4067eca831cSJacob Faibussowitsch if not os.path.isdir(configDir): 4077eca831cSJacob Faibussowitsch raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.')) 4087eca831cSJacob Faibussowitsch sys.path.insert(0, bsDir) 4097eca831cSJacob Faibussowitsch sys.path.insert(0, configDir) 4107eca831cSJacob Faibussowitsch import logger 4117eca831cSJacob Faibussowitsch import config.base 4127eca831cSJacob Faibussowitsch import config.framework 4137eca831cSJacob Faibussowitsch 414a258c2c4SMatthew G Knepley try: 415c43ea0feSSatish Balay # Command line arguments take precedence (but don't destroy argv[0]) 416c43ea0feSSatish Balay sys.argv = sys.argv[:1] + configure_options + sys.argv[1:] 417ccb279e1SMatthew Knepley check_for_option_mistakes(sys.argv) 4182af240f0SSatish Balay check_for_option_changed(sys.argv) 4195b6bfdb9SJed Brown except (TypeError, ValueError) as e: 4207eca831cSJacob Faibussowitsch msg = logger.build_multiline_error_message('ERROR in COMMAND LINE ARGUMENT to ./configure', str(e)) 421a258c2c4SMatthew G Knepley sys.exit(msg) 42259e9bfd6SSatish Balay # check PETSC_ARCH 4232f393ef5SBarry Smith check_for_unsupported_combinations(sys.argv) 42459e9bfd6SSatish Balay check_petsc_arch(sys.argv) 425da58527dSSatish Balay check_broken_configure_log_links() 4265fb2c094SBarry Smith 427f08ee00aSJason Sarich #rename '--enable-' to '--with-' 428f08ee00aSJason Sarich chkenable() 429c22cdea9SBarry Smith # support a few standard configure option types 430f08ee00aSJason Sarich chksynonyms() 4319dabcff0SSatish Balay # Check for broken cygwin 4321937db7aSSatish Balay chkbrokencygwin() 433d65f3bddSMatthew Knepley # Disable threads on RHL9 4341937db7aSSatish Balay chkrhl9() 435ee76e990SSatish Balay # Make sure cygwin-python is used on windows 436ee76e990SSatish Balay chkusingwindowspython() 43714f5c25cSSatish Balay # Threads don't work for cygwin & python... 43814f5c25cSSatish Balay chkcygwinpython() 4396a8f6897SSatish Balay chkcygwinlink() 4408a4600f2SSatish Balay chkdosfiles() 441cfb8f47aSBarry Smith chkcygwinwindowscompilers() 442fd1ac241SSatish Balay chktmpnoexec() 4439dabcff0SSatish Balay 444a9acdec7SBarry Smith for l in range(1,len(sys.argv)): 445a9acdec7SBarry Smith if sys.argv[l].startswith('--with-fc=') and sys.argv[l].endswith('nagfor'): 446a9acdec7SBarry Smith # need a way to save this value and later CC so that petscnagfor may use them 447a9acdec7SBarry Smith name = sys.argv[l].split('=')[1] 448a9acdec7SBarry Smith sys.argv[l] = '--with-fc='+os.path.join(os.path.abspath('.'),'lib','petsc','bin','petscnagfor') 449a9acdec7SBarry Smith break 450a9acdec7SBarry Smith 451a9acdec7SBarry Smith 45205f86fb1SBarry Smith # Check Cray without modules 45305f86fb1SBarry Smith check_cray_modules() 45405f86fb1SBarry Smith 45538c5b55eSBarry Smith tbo = None 4569dd2fdb1SMatthew Knepley framework = None 4579dd2fdb1SMatthew Knepley try: 45823a19ef1SSatish Balay framework = config.framework.Framework(['--configModules=PETSc.Configure','--optionsModule=config.compilerOptions']+sys.argv[1:], loadArgDB = 0) 459d65f3bddSMatthew Knepley framework.setup() 460ce040abeSJacob Faibussowitsch framework.logPrintBox('Configuring PETSc to compile on your system') 461d65f3bddSMatthew Knepley framework.logPrint('\n'.join(extraLogs)) 462f24f64feSBarry Smith framework.configure(out = sys.stdout) 463358ebc22SMatthew Knepley framework.storeSubstitutions(framework.argDB) 464492432c8SJed Brown framework.argDB['configureCache'] = pickle.dumps(framework) 4657c939e48SSatish Balay framework.printSummary() 46612c1d45bSMatthew G Knepley framework.argDB.save(force = True) 4677cfd0b05SBarry Smith framework.logClear() 468d93c4beeSSatish Balay print_final_timestamp(framework) 469eefa2c0fSBarry Smith framework.closeLog() 4709e50940cSSatish Balay try: 471da1d79b4SSatish Balay move_configure_log(framework) 4729e50940cSSatish Balay except: 4739e50940cSSatish Balay # perhaps print an error about unable to shuffle logs? 4749e50940cSSatish Balay pass 475dd50d019SBarry Smith return 0 4765b6bfdb9SJed Brown except (RuntimeError, config.base.ConfigureSetupError) as e: 4771a7b8b2eSBarry Smith tbo = sys.exc_info()[2] 4787eca831cSJacob Faibussowitsch msg = logger.build_multiline_error_message('UNABLE to CONFIGURE with GIVEN OPTIONS (see configure.log for details):', str(e)) 479e9f3bb17SBarry Smith se = '' 4805b6bfdb9SJed Brown except (TypeError, ValueError) as e: 48138c5b55eSBarry Smith # this exception is automatically deleted by Python so we need to save it to print below 48238c5b55eSBarry Smith tbo = sys.exc_info()[2] 4837eca831cSJacob Faibussowitsch msg = logger.build_multiline_error_message('TypeError or ValueError possibly related to ERROR in COMMAND LINE ARGUMENT while running ./configure', str(e)) 4841a02243aSBarry Smith se = '' 4855b6bfdb9SJed Brown except ImportError as e : 486edd0a2d9SBarry Smith # this exception is automatically deleted by Python so we need to save it to print below 487edd0a2d9SBarry Smith tbo = sys.exc_info()[2] 488a207d08eSSatish Balay msg = logger.build_multiline_error_message('ImportError while running ./configure', str(e)) 48996dc2fe8SMatthew Knepley se = '' 4905b6bfdb9SJed Brown except OSError as e : 4911a7b8b2eSBarry Smith tbo = sys.exc_info()[2] 492a207d08eSSatish Balay msg = logger.build_multiline_error_message('OSError while running ./configure', str(e)) 49301def6f0SMatthew Knepley se = '' 4945b6bfdb9SJed Brown except SystemExit as e: 4951a7b8b2eSBarry Smith tbo = sys.exc_info()[2] 496d7d3c4beSMatthew Knepley if e.code is None or e.code == 0: 497d7d3c4beSMatthew Knepley return 49841f847afSJed Brown if e.code == 10: 499c524ecbbSBarry Smith sys.exit(10) 5007eca831cSJacob Faibussowitsch msg = logger.build_multiline_error_message('CONFIGURATION FAILURE (Please send configure.log to petsc-maint@mcs.anl.gov)', str(e)) 501d7d3c4beSMatthew Knepley se = str(e) 5025b6bfdb9SJed Brown except Exception as e: 5031a7b8b2eSBarry Smith tbo = sys.exc_info()[2] 5047eca831cSJacob Faibussowitsch msg = logger.build_multiline_error_message('CONFIGURATION CRASH (Please send configure.log to petsc-maint@mcs.anl.gov)', str(e)) 505e9f3bb17SBarry Smith se = str(e) 506e9f3bb17SBarry Smith 50712bc4562SPierre Jolivet print('\n'+msg) 5089dd2fdb1SMatthew Knepley if not framework is None: 5099dd2fdb1SMatthew Knepley framework.logClear() 510e9f3bb17SBarry Smith if hasattr(framework, 'log'): 51122c95ba3SMatthew G Knepley try: 512d71f8ab3SSatish Balay if hasattr(framework,'compilerDefines'): 513bd5137a2SBarry Smith framework.log.write('**** Configure header '+framework.compilerDefines+' ****\n') 514febd46b0SSatish Balay framework.outputHeader(framework.log) 515d71f8ab3SSatish Balay if hasattr(framework,'compilerFixes'): 516bd5137a2SBarry Smith framework.log.write('**** C specific Configure header '+framework.compilerFixes+' ****\n') 517febd46b0SSatish Balay framework.outputCHeader(framework.log) 5185b6bfdb9SJed Brown except Exception as e: 51922c95ba3SMatthew G Knepley framework.log.write('Problem writing headers to log: '+str(e)) 520b1dada7fSMatthew Knepley try: 5217e4ff156SBarry Smith if hasattr(framework,'additional_error_message'): se += logger.build_multiline_message('',framework.additional_error_message)+'\n\n' 522f24f64feSBarry Smith framework.log.write(msg+se) 52338c5b55eSBarry Smith traceback.print_tb(tbo, file = framework.log) 524d93c4beeSSatish Balay print_final_timestamp(framework) 525f73e6a6cSSatish Balay if hasattr(framework,'log'): framework.log.close() 526da1d79b4SSatish Balay move_configure_log(framework) 527957f4b51SBarry Smith except Exception as e: 528957f4b51SBarry Smith print('Error printing error message from exception or printing the traceback:'+str(e)) 5291a7b8b2eSBarry Smith traceback.print_tb(sys.exc_info()[2]) 530e9f3bb17SBarry Smith sys.exit(1) 5315a74f024SMatthew Knepley else: 5325b6bfdb9SJed Brown print(se) 5331a7b8b2eSBarry Smith traceback.print_tb(tbo) 534957f4b51SBarry Smith else: 535957f4b51SBarry Smith print(se) 5361a7b8b2eSBarry Smith traceback.print_tb(tbo) 537f73e6a6cSSatish Balay if hasattr(framework,'log'): framework.log.close() 5385d5a5a7bSMatthew Knepley 5395d5a5a7bSMatthew Knepleyif __name__ == '__main__': 540a030c540SBarry Smith petsc_configure([]) 541