1df3bd252SSatish Balay#!/usr/bin/env python3 25b6bfdb9SJed Brownfrom __future__ import print_function 32787667cSMatthew G Knepleyimport os, sys 4db5c7c58SSatish Balay 5*6a1f9e42SJacob Faibussowitschbanner_length = 93 67c9abfe7SSatish BalayextraLogs = [] 7b0b472b0SSatish Balaypetsc_arch = '' 84b8aa89bSBarry Smith 944b0d7f9SSatish Balay# Use en_US as language so that BuildSystem parses compiler messages in english 10b9a05632SSatish Balaydef fixLang(lang): 11b9a05632SSatish Balay if lang in os.environ and os.environ[lang] != '': 12b9a05632SSatish Balay lv = os.environ[lang] 13b9a05632SSatish Balay enc = '' 14b9a05632SSatish Balay try: lv,enc = lv.split('.') 15b9a05632SSatish Balay except: pass 16b9a05632SSatish Balay if lv not in ['en_US','C']: lv = 'en_US' 17b9a05632SSatish Balay if enc: lv = lv+'.'+enc 18b9a05632SSatish Balay os.environ[lang] = lv 19b9a05632SSatish Balay 20b9a05632SSatish BalayfixLang('LC_LOCAL') 21b9a05632SSatish BalayfixLang('LANG') 22b9a05632SSatish Balay 2344b0d7f9SSatish Balay 24ccb279e1SMatthew Knepleydef check_for_option_mistakes(opts): 2545faeebdSBarry Smith for opt in opts[1:]: 26cda0060aSMatthew Knepley name = opt.split('=')[0] 275715f7bdSSatish Balay if name.find(' ') >= 0: 285715f7bdSSatish Balay raise ValueError('The option "'+name+'" has a space character in the name - this is likely incorrect usage.'); 29ccb279e1SMatthew Knepley if name.find('_') >= 0: 30ccb279e1SMatthew Knepley exception = False 311de7a49fSSatish 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']: 32ccb279e1SMatthew Knepley if name.find(exc) >= 0: 33ccb279e1SMatthew Knepley exception = True 34ccb279e1SMatthew Knepley if not exception: 35ccb279e1SMatthew Knepley raise ValueError('The option '+name+' should probably be '+name.replace('_', '-')); 36ab610953SSatish Balay if opt.find('=') >=0: 37ab610953SSatish Balay optval = opt.split('=')[1] 38ab610953SSatish Balay if optval == 'ifneeded': 39ab610953SSatish Balay raise ValueError('The option '+opt+' should probably be '+opt.replace('ifneeded', '1')); 40d1fb55d9SBarry Smith for exc in ['mkl_sparse', 'mkl_sparse_optimize', 'mkl_cpardiso', 'mkl_pardiso', 'superlu_dist']: 41d1fb55d9SBarry Smith if name.find(exc.replace('_','-')) > -1: 42d1fb55d9SBarry Smith raise ValueError('The option '+opt+' should be '+opt.replace(exc.replace('_','-'),exc)); 43ccb279e1SMatthew Knepley return 44ccb279e1SMatthew Knepley 452f393ef5SBarry Smithdef check_for_unsupported_combinations(opts): 462f393ef5SBarry Smith if '--with-precision=single' in opts and '--with-clanguage=cxx' in opts and '--with-scalar-type=complex' in opts: 472f393ef5SBarry Smith sys.exit(ValueError('PETSc does not support single precision complex with C++ clanguage, run with --with-clanguage=c')) 482f393ef5SBarry Smith 492af240f0SSatish Balaydef check_for_option_changed(opts): 50750b007cSBarry Smith# Document changes in command line options here. (matlab-engine is deprecated, no longer needed but still allowed) 514544382eSSatish Balay optMap = [('with-64bit-indices','with-64-bit-indices'), 52008db1b6SSatish Balay ('with-mpi-exec','with-mpiexec'), 534544382eSSatish Balay ('c-blas-lapack','f2cblaslapack'), 544544382eSSatish Balay ('cholmod','suitesparse'), 554544382eSSatish Balay ('umfpack','suitesparse'), 5669cdbcb9SBarry Smith ('matlabengine','matlab-engine'), 57b129f54cSBarry Smith ('sundials','sundials2'), 584544382eSSatish Balay ('f-blas-lapack','fblaslapack'), 594544382eSSatish Balay ('with-packages-dir','with-packages-download-dir'), 604544382eSSatish Balay ('with-external-packages-dir','with-packages-build-dir'), 614544382eSSatish Balay ('package-dirs','with-packages-search-path'), 624544382eSSatish Balay ('download-petsc4py-python','with-python-exec'), 634544382eSSatish Balay ('search-dirs','with-executables-search-path')] 642af240f0SSatish Balay for opt in opts[1:]: 652af240f0SSatish Balay optname = opt.split('=')[0].strip('-') 662af240f0SSatish Balay for oldname,newname in optMap: 67f1bd03f4SSatish Balay if optname.find(oldname) >=0 and not optname.find(newname) >=0: 682af240f0SSatish Balay raise ValueError('The option '+opt+' should probably be '+opt.replace(oldname,newname)) 692af240f0SSatish Balay return 702af240f0SSatish Balay 7159e9bfd6SSatish Balaydef check_petsc_arch(opts): 72c43ea0feSSatish Balay # If PETSC_ARCH not specified - use script name (if not configure.py) 73b0b472b0SSatish Balay global petsc_arch 74c43ea0feSSatish Balay found = 0 7559e9bfd6SSatish Balay for name in opts: 76c43ea0feSSatish Balay if name.find('PETSC_ARCH=') >= 0: 77b0b472b0SSatish Balay petsc_arch=name.split('=')[1] 78c43ea0feSSatish Balay found = 1 7959e9bfd6SSatish Balay break 8059e9bfd6SSatish Balay # If not yet specified - use the filename of script 81c43ea0feSSatish Balay if not found: 8259e9bfd6SSatish Balay filename = os.path.basename(sys.argv[0]) 83e68ebbecSBarry Smith if not filename.startswith('configure') and not filename.startswith('reconfigure') and not filename.startswith('setup'): 84b0b472b0SSatish Balay petsc_arch=os.path.splitext(os.path.basename(sys.argv[0]))[0] 85b0b472b0SSatish Balay useName = 'PETSC_ARCH='+petsc_arch 8659e9bfd6SSatish Balay opts.append(useName) 871937db7aSSatish Balay return 0 884b8aa89bSBarry Smith 89f08ee00aSJason Sarichdef chkenable(): 90f08ee00aSJason Sarich #Replace all 'enable-'/'disable-' with 'with-'=0/1/tail 91f08ee00aSJason Sarich #enable-fortran is a special case, the resulting --with-fortran is ambiguous. 921b266c99SBarry Smith #Would it mean --with-fc= 935bb5b98aSSatish Balay en_dash = u'\N{EN DASH}' 94c05720f7SSatish Balay no_break_space = u'\N{NO-BREAK SPACE}' 95f08ee00aSJason Sarich for l in range(0,len(sys.argv)): 96f08ee00aSJason Sarich name = sys.argv[l] 97c05720f7SSatish Balay if name.find(no_break_space) >= 0: 98c05720f7SSatish Balay sys.exit(ValueError('Unicode NO-BREAK SPACE char found in arguments! Please rerun configure using regular space chars: %s' % [name])) 99edf9f831SSatish Balay name = name.replace(en_dash,'-') 100c2ec76c5SSatish Balay if hasattr(name,'isprintable') and not name.isprintable(): 101d689f251SBarry Smith sys.exit(ValueError('Non-printable characters or control characters found in arguments! Please rerun configure using only printable character arguments: %s' % [name])) 1026293a234SJunchao Zhang if name.lstrip('-').startswith('enable-cxx'): 1032b700d61SJason Sarich if name.find('=') == -1: 104edf9f831SSatish Balay name = name.replace('enable-cxx','with-clanguage=C++',1) 1052b700d61SJason Sarich else: 1062b700d61SJason Sarich head, tail = name.split('=', 1) 1072b700d61SJason Sarich if tail=='0': 108edf9f831SSatish Balay name = head.replace('enable-cxx','with-clanguage=C',1) 1092b700d61SJason Sarich else: 110edf9f831SSatish Balay name = head.replace('enable-cxx','with-clanguage=C++',1) 111edf9f831SSatish Balay sys.argv[l] = name 1122b700d61SJason Sarich continue 1136293a234SJunchao Zhang if name.lstrip('-').startswith('disable-cxx'): 1142b700d61SJason Sarich if name.find('=') == -1: 115edf9f831SSatish Balay name = name.replace('disable-cxx','with-clanguage=C',1) 1162b700d61SJason Sarich else: 1172b700d61SJason Sarich head, tail = name.split('=', 1) 1182b700d61SJason Sarich if tail == '0': 119edf9f831SSatish Balay name = head.replace('disable-cxx','with-clanguage=C++',1) 1202b700d61SJason Sarich else: 121edf9f831SSatish Balay name = head.replace('disable-cxx','with-clanguage=C',1) 122edf9f831SSatish Balay sys.argv[l] = name 1232b700d61SJason Sarich continue 1242b700d61SJason Sarich 1256293a234SJunchao Zhang if name.lstrip('-').startswith('enable-'): 126f08ee00aSJason Sarich if name.find('=') == -1: 127edf9f831SSatish Balay name = name.replace('enable-','with-',1)+'=1' 128f08ee00aSJason Sarich else: 129f08ee00aSJason Sarich head, tail = name.split('=', 1) 130edf9f831SSatish Balay name = head.replace('enable-','with-',1)+'='+tail 1316293a234SJunchao Zhang if name.lstrip('-').startswith('disable-'): 132f08ee00aSJason Sarich if name.find('=') == -1: 133edf9f831SSatish Balay name = name.replace('disable-','with-',1)+'=0' 134f08ee00aSJason Sarich else: 135f08ee00aSJason Sarich head, tail = name.split('=', 1) 136f08ee00aSJason Sarich if tail == '1': tail = '0' 137edf9f831SSatish Balay name = head.replace('disable-','with-',1)+'='+tail 1386293a234SJunchao Zhang if name.lstrip('-').startswith('without-'): 139f08ee00aSJason Sarich if name.find('=') == -1: 140edf9f831SSatish Balay name = name.replace('without-','with-',1)+'=0' 141f08ee00aSJason Sarich else: 142f08ee00aSJason Sarich head, tail = name.split('=', 1) 143f08ee00aSJason Sarich if tail == '1': tail = '0' 144edf9f831SSatish Balay name = head.replace('without-','with-',1)+'='+tail 145edf9f831SSatish Balay sys.argv[l] = name 146f08ee00aSJason Sarich 147f08ee00aSJason Sarichdef chksynonyms(): 148f08ee00aSJason Sarich #replace common configure options with ones that PETSc BuildSystem recognizes 14998d87fb0SBarry Smith simplereplacements = {'F77' : 'FC', 'F90' : 'FC'} 150f08ee00aSJason Sarich for l in range(0,len(sys.argv)): 151f08ee00aSJason Sarich name = sys.argv[l] 152f08ee00aSJason Sarich 15386d91f96SSatish Balay name = name.replace('download-petsc4py','with-petsc4py') 154c58b03afSBarry Smith name = name.replace('with-openmpi','with-mpi') 155c58b03afSBarry Smith name = name.replace('with-mpich','with-mpi') 156c58b03afSBarry Smith name = name.replace('with-blas-lapack','with-blaslapack') 1573bdc3ccdSStefano Zampini name = name.replace('with-cuda-gencodearch','with-cuda-arch') 158c69ce369SMartin Diehl name = name.replace('download-hdf5-fortran-bindings','with-hdf5-fortran-bindings') 159c87df54fSBarry Smith 160ce54fb35SBarry Smith if name.find('with-debug=') >= 0 or name.endswith('with-debug'): 161f08ee00aSJason Sarich if name.find('=') == -1: 162c58b03afSBarry Smith name = name.replace('with-debug','with-debugging')+'=1' 163f08ee00aSJason Sarich else: 164f08ee00aSJason Sarich head, tail = name.split('=', 1) 165c58b03afSBarry Smith name = head.replace('with-debug','with-debugging')+'='+tail 166f08ee00aSJason Sarich 167ce54fb35SBarry Smith if name.find('with-shared=') >= 0 or name.endswith('with-shared'): 168f08ee00aSJason Sarich if name.find('=') == -1: 169c58b03afSBarry Smith name = name.replace('with-shared','with-shared-libraries')+'=1' 170f08ee00aSJason Sarich else: 171f08ee00aSJason Sarich head, tail = name.split('=', 1) 172c58b03afSBarry Smith name = head.replace('with-shared','with-shared-libraries')+'='+tail 173f08ee00aSJason Sarich 1748fd71741SJason Sarich if name.find('with-index-size=') >=0: 1758fd71741SJason Sarich head,tail = name.split('=',1) 1768fd71741SJason Sarich if int(tail)==32: 177c58b03afSBarry Smith name = '--with-64-bit-indices=0' 1788fd71741SJason Sarich elif int(tail)==64: 179c58b03afSBarry Smith name = '--with-64-bit-indices=1' 1808fd71741SJason Sarich else: 1818fd71741SJason Sarich raise RuntimeError('--with-index-size= must be 32 or 64') 182f08ee00aSJason Sarich 1838fd71741SJason Sarich if name.find('with-precision=') >=0: 1848fd71741SJason Sarich head,tail = name.split('=',1) 1858fd71741SJason Sarich if tail.find('quad')>=0: 186c58b03afSBarry Smith name='--with-precision=__float128' 187f08ee00aSJason Sarich 18898d87fb0SBarry Smith for i,j in simplereplacements.items(): 18998d87fb0SBarry Smith if name.find(i+'=') >= 0: 190c58b03afSBarry Smith name = name.replace(i+'=',j+'=') 19198d87fb0SBarry Smith elif name.find('with-'+i.lower()+'=') >= 0: 192c58b03afSBarry Smith name = name.replace(i.lower()+'=',j.lower()+'=') 193c58b03afSBarry Smith 194c58b03afSBarry Smith # restore 'sys.argv[l]' from the intermediate var 'name' 195c58b03afSBarry Smith sys.argv[l] = name 196f08ee00aSJason Sarich 197b917b182SSatish Balaydef chkwincompilerusinglink(): 1986a8f6897SSatish Balay for arg in sys.argv: 199b917b182SSatish Balay if (arg.find('win32fe') >= 0 and (arg.find('f90') >=0 or arg.find('ifort') >=0 or arg.find('icl') >=0)): 2006a8f6897SSatish Balay return 1 2016a8f6897SSatish Balay return 0 2026a8f6897SSatish Balay 2038a4600f2SSatish Balaydef chkdosfiles(): 204360dfd13SSatish Balay # cygwin - but not a hg clone - so check one of files in bin dir 2058fb0cc24SJed Brown if b"\r\n" in open(os.path.join('lib','petsc','bin','petscmpiexec'),"rb").read(): 2065b6bfdb9SJed Brown print('===============================================================================') 2075b6bfdb9SJed Brown print(' *** Scripts are in DOS mode. Was winzip used to extract petsc sources? ****') 2085b6bfdb9SJed Brown print(' *** Please restart with a fresh tarball and use "tar -xzf petsc.tar.gz" ****') 2095b6bfdb9SJed Brown print('===============================================================================') 210db1f124cSVasiliy Kozyrev sys.exit(3) 2118a4600f2SSatish Balay return 2128a4600f2SSatish Balay 2136a8f6897SSatish Balaydef chkcygwinlink(): 214b917b182SSatish Balay if os.path.exists('/usr/bin/cygcheck.exe') and os.path.exists('/usr/bin/link.exe') and chkwincompilerusinglink(): 2156a8f6897SSatish Balay if '--ignore-cygwin-link' in sys.argv: return 0 2165b6bfdb9SJed Brown print('===============================================================================') 217b917b182SSatish Balay print(' *** Cygwin /usr/bin/link detected! Compiles with Intel icl/ifort can break! **') 218a5b23f4aSJose E. Roman print(' *** To workaround do: "mv /usr/bin/link.exe /usr/bin/link-cygwin.exe" **') 219b917b182SSatish Balay print(' *** Or to ignore this check, use configure option: --ignore-cygwin-link. But compiles can fail. **') 2205b6bfdb9SJed Brown print('===============================================================================') 2216a8f6897SSatish Balay sys.exit(3) 2226a8f6897SSatish Balay return 0 2236a8f6897SSatish Balay 22485ef4d1eSSatish Balaydef chkbrokencygwin(): 2259dabcff0SSatish Balay if os.path.exists('/usr/bin/cygcheck.exe'): 2269dabcff0SSatish Balay buf = os.popen('/usr/bin/cygcheck.exe -c cygwin').read() 2279dabcff0SSatish Balay if buf.find('1.5.11-1') > -1: 2285b6bfdb9SJed Brown print('===============================================================================') 2295b6bfdb9SJed Brown print(' *** cygwin-1.5.11-1 detected. ./configure fails with this version ***') 2305b6bfdb9SJed Brown print(' *** Please upgrade to cygwin-1.5.12-1 or newer version. This can ***') 2315b6bfdb9SJed Brown print(' *** be done by running cygwin-setup, selecting "next" all the way.***') 2325b6bfdb9SJed Brown print('===============================================================================') 2331937db7aSSatish Balay sys.exit(3) 2349dabcff0SSatish Balay return 0 2359dabcff0SSatish Balay 236ee76e990SSatish Balaydef chkusingwindowspython(): 237ee76e990SSatish Balay if sys.platform == 'win32': 2385b6bfdb9SJed Brown print('===============================================================================') 2395b6bfdb9SJed Brown print(' *** Windows python detected. Please rerun ./configure with cygwin-python. ***') 2405b6bfdb9SJed Brown print('===============================================================================') 241ee76e990SSatish Balay sys.exit(3) 242ee76e990SSatish Balay return 0 243ee76e990SSatish Balay 24414f5c25cSSatish Balaydef chkcygwinpython(): 2451150532aSSatish Balay if sys.platform == 'cygwin' : 2461150532aSSatish Balay import platform 2471150532aSSatish Balay import re 2481150532aSSatish Balay r=re.compile("([0-9]+).([0-9]+).([0-9]+)") 2491150532aSSatish Balay m=r.match(platform.release()) 2501150532aSSatish Balay major=int(m.group(1)) 2511150532aSSatish Balay minor=int(m.group(2)) 2521150532aSSatish Balay subminor=int(m.group(3)) 2531150532aSSatish Balay if ((major < 1) or (major == 1 and minor < 7) or (major == 1 and minor == 7 and subminor < 34)): 2541937db7aSSatish Balay sys.argv.append('--useThreads=0') 2551937db7aSSatish Balay extraLogs.append('''\ 256a0022257SSatish Balay=============================================================================== 2571150532aSSatish Balay** Cygwin version is older than 1.7.34. Python threads do not work correctly. *** 25814f5c25cSSatish Balay** Disabling thread usage for this run of ./configure ******* 259a0022257SSatish Balay===============================================================================''') 26071384062SSatish Balay return 0 26171384062SSatish Balay 262cfb8f47aSBarry Smithdef chkcygwinwindowscompilers(): 263cfb8f47aSBarry Smith '''Adds win32fe for Microsoft/Intel compilers''' 264cfb8f47aSBarry Smith if os.path.exists('/usr/bin/cygcheck.exe'): 265cfb8f47aSBarry Smith for l in range(1,len(sys.argv)): 266cfb8f47aSBarry Smith option = sys.argv[l] 267cfb8f47aSBarry Smith for i in ['cl','icl','ifort']: 268cfb8f47aSBarry Smith if option.startswith(i): 269cfb8f47aSBarry Smith sys.argv[l] = 'win32fe '+option 270cfb8f47aSBarry Smith break 271cfb8f47aSBarry Smith return 0 272cfb8f47aSBarry Smith 2731937db7aSSatish Balaydef chkrhl9(): 2741937db7aSSatish Balay if os.path.exists('/etc/redhat-release'): 275836c2c52SSatish Balay try: 276594eb360SSatish Balay file = open('/etc/redhat-release','r') 277836c2c52SSatish Balay buf = file.read() 278836c2c52SSatish Balay file.close() 279836c2c52SSatish Balay except: 280836c2c52SSatish Balay # can't read file - assume dangerous RHL9 2811937db7aSSatish Balay buf = 'Shrike' 282836c2c52SSatish Balay if buf.find('Shrike') > -1: 2831937db7aSSatish Balay sys.argv.append('--useThreads=0') 2841937db7aSSatish Balay extraLogs.append('''\ 285a0022257SSatish Balay============================================================================== 2861937db7aSSatish Balay *** RHL9 detected. Threads do not work correctly with this distribution *** 287e2e64c6bSBarry Smith ****** Disabling thread usage for this run of ./configure ********* 288a0022257SSatish Balay===============================================================================''') 289836c2c52SSatish Balay return 0 290836c2c52SSatish Balay 291fd1ac241SSatish Balaydef chktmpnoexec(): 292e08ecd42SSatish Balay if not hasattr(os,'ST_NOEXEC'): return # novermin 293fd1ac241SSatish Balay if 'TMPDIR' in os.environ: tmpDir = os.environ['TMPDIR'] 294fd1ac241SSatish Balay else: tmpDir = '/tmp' 295e08ecd42SSatish Balay if os.statvfs(tmpDir).f_flag & os.ST_NOEXEC: # novermin 296e08ecd42SSatish Balay if os.statvfs(os.path.abspath('.')).f_flag & os.ST_NOEXEC: # novermin 297fd1ac241SSatish Balay print('************************************************************************') 298fd1ac241SSatish Balay print('* TMPDIR '+tmpDir+' has noexec attribute. Same with '+os.path.abspath('.')+' where petsc is built.') 299fd1ac241SSatish Balay print('* Suggest building PETSc in a location without this restriction!') 300fd1ac241SSatish Balay print('* Alternatively, set env variable TMPDIR to a location that is not restricted to run binaries.') 301fd1ac241SSatish Balay print('************************************************************************') 302fd1ac241SSatish Balay sys.exit(4) 303fd1ac241SSatish Balay else: 304fd1ac241SSatish Balay newTmp = os.path.abspath('tmp-petsc') 305fd1ac241SSatish Balay print('************************************************************************') 306fd1ac241SSatish Balay print('* TMPDIR '+tmpDir+' has noexec attribute. Using '+newTmp+' instead.') 307fd1ac241SSatish Balay print('************************************************************************') 308fd1ac241SSatish Balay if not os.path.isdir(newTmp): os.mkdir(os.path.abspath(newTmp)) 309fd1ac241SSatish Balay os.environ['TMPDIR'] = newTmp 310fd1ac241SSatish Balay return 311fd1ac241SSatish Balay 31205f86fb1SBarry Smithdef check_cray_modules(): 31305f86fb1SBarry Smith import script 31405f86fb1SBarry Smith '''For Cray systems check if the cc, CC, ftn compiler suite modules have been set''' 31505f86fb1SBarry Smith cray = os.getenv('CRAY_SITE_LIST_DIR') 31605f86fb1SBarry Smith if not cray: return 31705f86fb1SBarry Smith cray = os.getenv('CRAYPE_DIR') 31805f86fb1SBarry Smith if not cray: 31905f86fb1SBarry Smith print('************************************************************************') 32005f86fb1SBarry Smith print('* You are on a Cray system but no programming environments have been loaded') 32105f86fb1SBarry Smith print('* Perhaps you need:') 32205f86fb1SBarry Smith print('* module load intel ; module load PrgEnv-intel') 32305f86fb1SBarry Smith print('* or module load PrgEnv-cray') 32405f86fb1SBarry Smith print('* or module load PrgEnv-gnu') 325a17b96a8SKyle Gerard Felker print('* See https://petsc.org/release/install/install/#installing-on-large-scale-doe-systems') 32605f86fb1SBarry Smith print('************************************************************************') 32705f86fb1SBarry Smith sys.exit(4) 32805f86fb1SBarry Smith 329da58527dSSatish Balaydef check_broken_configure_log_links(): 330da58527dSSatish Balay '''Sometime symlinks can get broken if the original files are deleted. Delete such broken links''' 331da58527dSSatish Balay import os 332da58527dSSatish Balay for logfile in ['configure.log','configure.log.bkp']: 333da58527dSSatish Balay if os.path.islink(logfile) and not os.path.isfile(logfile): os.remove(logfile) 334da58527dSSatish Balay return 335da58527dSSatish Balay 336da1d79b4SSatish Balaydef move_configure_log(framework): 337af0996ceSBarry Smith '''Move configure.log to PETSC_ARCH/lib/petsc/conf - and update configure.log.bkp in both locations appropriately''' 338b0b472b0SSatish Balay global petsc_arch 339b0b472b0SSatish Balay 340b0b472b0SSatish Balay if hasattr(framework,'arch'): petsc_arch = framework.arch 341b0b472b0SSatish Balay if hasattr(framework,'logName'): curr_file = framework.logName 342b0b472b0SSatish Balay else: curr_file = 'configure.log' 343b0b472b0SSatish Balay 344b0b472b0SSatish Balay if petsc_arch: 345da1d79b4SSatish Balay import shutil 346da1d79b4SSatish Balay import os 347b0b472b0SSatish Balay 348b0b472b0SSatish Balay # Just in case - confdir is not created 349fe998a80SBarry Smith lib_dir = os.path.join(petsc_arch,'lib') 350be5c6b33SBarry Smith petsc_dir = os.path.join(petsc_arch,'lib','petsc') 351af0996ceSBarry Smith conf_dir = os.path.join(petsc_arch,'lib','petsc','conf') 352b0b472b0SSatish Balay if not os.path.isdir(petsc_arch): os.mkdir(petsc_arch) 353fe998a80SBarry Smith if not os.path.isdir(lib_dir): os.mkdir(lib_dir) 354be5c6b33SBarry Smith if not os.path.isdir(petsc_dir): os.mkdir(petsc_dir) 355b0b472b0SSatish Balay if not os.path.isdir(conf_dir): os.mkdir(conf_dir) 356b0b472b0SSatish Balay 357da1d79b4SSatish Balay curr_bkp = curr_file + '.bkp' 358b0b472b0SSatish Balay new_file = os.path.join(conf_dir,curr_file) 359da1d79b4SSatish Balay new_bkp = new_file + '.bkp' 360da1d79b4SSatish Balay 361af0996ceSBarry Smith # Keep backup in $PETSC_ARCH/lib/petsc/conf location 362da1d79b4SSatish Balay if os.path.isfile(new_bkp): os.remove(new_bkp) 363da1d79b4SSatish Balay if os.path.isfile(new_file): os.rename(new_file,new_bkp) 3649e50940cSSatish Balay if os.path.isfile(curr_file): 3659e50940cSSatish Balay shutil.copyfile(curr_file,new_file) 3669e50940cSSatish Balay os.remove(curr_file) 367da58527dSSatish Balay if os.path.isfile(new_file): os.symlink(new_file,curr_file) 368af0996ceSBarry Smith # If the old bkp is using the same PETSC_ARCH/lib/petsc/conf - then update bkp link 369da1d79b4SSatish Balay if os.path.realpath(curr_bkp) == os.path.realpath(new_file): 370da58527dSSatish Balay if os.path.isfile(curr_bkp): os.remove(curr_bkp) 371da58527dSSatish Balay if os.path.isfile(new_bkp): os.symlink(new_bkp,curr_bkp) 372da1d79b4SSatish Balay return 373da1d79b4SSatish Balay 374d93c4beeSSatish Balaydef print_final_timestamp(framework): 375d93c4beeSSatish Balay import time 376d93c4beeSSatish Balay framework.log.write(('='*80)+'\n') 3777a01bd3eSSatish Balay framework.log.write('Finishing configure run at '+time.strftime('%a, %d %b %Y %H:%M:%S %z')+'\n') 378d93c4beeSSatish Balay framework.log.write(('='*80)+'\n') 379d93c4beeSSatish Balay return 380d93c4beeSSatish Balay 3815d5a5a7bSMatthew Knepleydef petsc_configure(configure_options): 382856b83eaSSatish Balay petscdir = os.getcwd() 3836e464aa7SMatthew G. Knepley try: 384c3a89c15SBarry Smith sys.path.append(os.path.join(petscdir,'lib','petsc','bin')) 3854a532159SBarry Smith import petscnagupgrade 3864a532159SBarry Smith file = os.path.join(petscdir,'.nagged') 3874a532159SBarry Smith if not petscnagupgrade.naggedtoday(file): 3884a532159SBarry Smith petscnagupgrade.currentversion(petscdir) 3894a532159SBarry Smith except: 3904a532159SBarry Smith pass 39159e9bfd6SSatish Balay 392a258c2c4SMatthew G Knepley try: 393c43ea0feSSatish Balay # Command line arguments take precedence (but don't destroy argv[0]) 394c43ea0feSSatish Balay sys.argv = sys.argv[:1] + configure_options + sys.argv[1:] 395ccb279e1SMatthew Knepley check_for_option_mistakes(sys.argv) 3962af240f0SSatish Balay check_for_option_changed(sys.argv) 3975b6bfdb9SJed Brown except (TypeError, ValueError) as e: 398a258c2c4SMatthew G Knepley emsg = str(e) 399a258c2c4SMatthew G Knepley if not emsg.endswith('\n'): emsg = emsg+'\n' 4009355304cSJacob Faibussowitsch banner_line = banner_length*'*' 4019355304cSJacob Faibussowitsch msg = '\n'.join([ 4029355304cSJacob Faibussowitsch banner_line, 4039355304cSJacob Faibussowitsch 'ERROR in COMMAND LINE ARGUMENT to ./configure'.center(banner_length), 4049355304cSJacob Faibussowitsch banner_length*'-', 4059355304cSJacob Faibussowitsch emsg, 4069355304cSJacob Faibussowitsch banner_line, 4079355304cSJacob Faibussowitsch '' # to add an additional newline at the end 4089355304cSJacob Faibussowitsch ]) 409a258c2c4SMatthew G Knepley sys.exit(msg) 41059e9bfd6SSatish Balay # check PETSC_ARCH 4112f393ef5SBarry Smith check_for_unsupported_combinations(sys.argv) 41259e9bfd6SSatish Balay check_petsc_arch(sys.argv) 413da58527dSSatish Balay check_broken_configure_log_links() 4145fb2c094SBarry Smith 415f08ee00aSJason Sarich #rename '--enable-' to '--with-' 416f08ee00aSJason Sarich chkenable() 417c22cdea9SBarry Smith # support a few standard configure option types 418f08ee00aSJason Sarich chksynonyms() 4199dabcff0SSatish Balay # Check for broken cygwin 4201937db7aSSatish Balay chkbrokencygwin() 421d65f3bddSMatthew Knepley # Disable threads on RHL9 4221937db7aSSatish Balay chkrhl9() 423ee76e990SSatish Balay # Make sure cygwin-python is used on windows 424ee76e990SSatish Balay chkusingwindowspython() 42514f5c25cSSatish Balay # Threads don't work for cygwin & python... 42614f5c25cSSatish Balay chkcygwinpython() 4276a8f6897SSatish Balay chkcygwinlink() 4288a4600f2SSatish Balay chkdosfiles() 429cfb8f47aSBarry Smith chkcygwinwindowscompilers() 430fd1ac241SSatish Balay chktmpnoexec() 4319dabcff0SSatish Balay 432a9acdec7SBarry Smith for l in range(1,len(sys.argv)): 433a9acdec7SBarry Smith if sys.argv[l].startswith('--with-fc=') and sys.argv[l].endswith('nagfor'): 434a9acdec7SBarry Smith # need a way to save this value and later CC so that petscnagfor may use them 435a9acdec7SBarry Smith name = sys.argv[l].split('=')[1] 436a9acdec7SBarry Smith sys.argv[l] = '--with-fc='+os.path.join(os.path.abspath('.'),'lib','petsc','bin','petscnagfor') 437a9acdec7SBarry Smith break 438a9acdec7SBarry Smith 439a9acdec7SBarry Smith 44087282423SMatthew Knepley # Should be run from the toplevel 441dbca6d9dSSatish Balay configDir = os.path.abspath('config') 442f8833479SBarry Smith bsDir = os.path.join(configDir, 'BuildSystem') 443f8833479SBarry Smith if not os.path.isdir(configDir): 4445d5a5a7bSMatthew Knepley raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.')) 44587282423SMatthew Knepley sys.path.insert(0, bsDir) 446f8833479SBarry Smith sys.path.insert(0, configDir) 447e69ef9dfSMatthew Knepley import config.base 4485d5a5a7bSMatthew Knepley import config.framework 449492432c8SJed Brown import pickle 4504e5e6a77SJed Brown import traceback 4514f8a5b45SBarry 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] 4787d670a3cSBarry Smith emsg = str(e) 47942351d26SSatish Balay if not emsg.endswith('\n'): emsg = emsg+'\n' 480a0022257SSatish Balay msg ='*******************************************************************************\n'\ 481fe09c992SBarry Smith +' UNABLE to CONFIGURE with GIVEN OPTIONS (see configure.log for details):\n' \ 482a0022257SSatish Balay +'-------------------------------------------------------------------------------\n' \ 483a0022257SSatish Balay +emsg+'*******************************************************************************\n' 484e9f3bb17SBarry Smith se = '' 4855b6bfdb9SJed Brown except (TypeError, ValueError) as e: 48638c5b55eSBarry Smith # this exception is automatically deleted by Python so we need to save it to print below 48738c5b55eSBarry Smith tbo = sys.exc_info()[2] 4887d670a3cSBarry Smith emsg = str(e) 48942351d26SSatish Balay if not emsg.endswith('\n'): emsg = emsg+'\n' 490a0022257SSatish Balay msg ='*******************************************************************************\n'\ 491edd0a2d9SBarry Smith +' TypeError or ValueError possibly related to ERROR in COMMAND LINE ARGUMENT while running ./configure \n' \ 492a0022257SSatish Balay +'-------------------------------------------------------------------------------\n' \ 493a0022257SSatish Balay +emsg+'*******************************************************************************\n' 4941a02243aSBarry Smith se = '' 4955b6bfdb9SJed Brown except ImportError as e : 496edd0a2d9SBarry Smith # this exception is automatically deleted by Python so we need to save it to print below 497edd0a2d9SBarry Smith tbo = sys.exc_info()[2] 4987d670a3cSBarry Smith emsg = str(e) 49942351d26SSatish Balay if not emsg.endswith('\n'): emsg = emsg+'\n' 500a0022257SSatish Balay msg ='*******************************************************************************\n'\ 501d5b43468SJose E. Roman +' ImportError while running ./configure \n' \ 502a0022257SSatish Balay +'-------------------------------------------------------------------------------\n' \ 503a0022257SSatish Balay +emsg+'*******************************************************************************\n' 50496dc2fe8SMatthew Knepley se = '' 5055b6bfdb9SJed Brown except OSError as e : 5061a7b8b2eSBarry Smith tbo = sys.exc_info()[2] 50701def6f0SMatthew Knepley emsg = str(e) 50801def6f0SMatthew Knepley if not emsg.endswith('\n'): emsg = emsg+'\n' 509a0022257SSatish Balay msg ='*******************************************************************************\n'\ 510edd0a2d9SBarry Smith +' OSError while running ./configure \n' \ 511a0022257SSatish Balay +'-------------------------------------------------------------------------------\n' \ 512a0022257SSatish Balay +emsg+'*******************************************************************************\n' 51301def6f0SMatthew Knepley se = '' 5145b6bfdb9SJed Brown except SystemExit as e: 5151a7b8b2eSBarry Smith tbo = sys.exc_info()[2] 516d7d3c4beSMatthew Knepley if e.code is None or e.code == 0: 517d7d3c4beSMatthew Knepley return 51841f847afSJed Brown if e.code == 10: 519c524ecbbSBarry Smith sys.exit(10) 520a0022257SSatish Balay msg ='*******************************************************************************\n'\ 521b1dada7fSMatthew Knepley +' CONFIGURATION FAILURE (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \ 522a0022257SSatish Balay +'*******************************************************************************\n' 523d7d3c4beSMatthew Knepley se = str(e) 5245b6bfdb9SJed Brown except Exception as e: 5251a7b8b2eSBarry Smith tbo = sys.exc_info()[2] 526a0022257SSatish Balay msg ='*******************************************************************************\n'\ 527fe09c992SBarry Smith +' CONFIGURATION CRASH (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \ 528a0022257SSatish Balay +'*******************************************************************************\n' 529e9f3bb17SBarry Smith se = str(e) 530e9f3bb17SBarry Smith 53112bc4562SPierre Jolivet print('\n'+msg) 5329dd2fdb1SMatthew Knepley if not framework is None: 5339dd2fdb1SMatthew Knepley framework.logClear() 534e9f3bb17SBarry Smith if hasattr(framework, 'log'): 53522c95ba3SMatthew G Knepley try: 536d71f8ab3SSatish Balay if hasattr(framework,'compilerDefines'): 537bd5137a2SBarry Smith framework.log.write('**** Configure header '+framework.compilerDefines+' ****\n') 538febd46b0SSatish Balay framework.outputHeader(framework.log) 539d71f8ab3SSatish Balay if hasattr(framework,'compilerFixes'): 540bd5137a2SBarry Smith framework.log.write('**** C specific Configure header '+framework.compilerFixes+' ****\n') 541febd46b0SSatish Balay framework.outputCHeader(framework.log) 5425b6bfdb9SJed Brown except Exception as e: 54322c95ba3SMatthew G Knepley framework.log.write('Problem writing headers to log: '+str(e)) 544b1dada7fSMatthew Knepley try: 545f24f64feSBarry Smith framework.log.write(msg+se) 54638c5b55eSBarry Smith traceback.print_tb(tbo, file = framework.log) 547d93c4beeSSatish Balay print_final_timestamp(framework) 548f73e6a6cSSatish Balay if hasattr(framework,'log'): framework.log.close() 549da1d79b4SSatish Balay move_configure_log(framework) 550957f4b51SBarry Smith except Exception as e: 551957f4b51SBarry Smith print('Error printing error message from exception or printing the traceback:'+str(e)) 5521a7b8b2eSBarry Smith traceback.print_tb(sys.exc_info()[2]) 553e9f3bb17SBarry Smith sys.exit(1) 5545a74f024SMatthew Knepley else: 5555b6bfdb9SJed Brown print(se) 5561a7b8b2eSBarry Smith traceback.print_tb(tbo) 557957f4b51SBarry Smith else: 558957f4b51SBarry Smith print(se) 5591a7b8b2eSBarry Smith traceback.print_tb(tbo) 560f73e6a6cSSatish Balay if hasattr(framework,'log'): framework.log.close() 5615d5a5a7bSMatthew Knepley 5625d5a5a7bSMatthew Knepleyif __name__ == '__main__': 563a030c540SBarry Smith petsc_configure([]) 564