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 9b9a05632SSatish Balaydef fixLang(lang): 10b9a05632SSatish Balay if lang in os.environ and os.environ[lang] != '': 11b9a05632SSatish Balay lv = os.environ[lang] 12b9a05632SSatish Balay enc = '' 13b9a05632SSatish Balay try: lv,enc = lv.split('.') 14b9a05632SSatish Balay except: pass 15b9a05632SSatish Balay if lv not in ['en_US','C']: lv = 'en_US' 16b9a05632SSatish Balay if enc: lv = lv+'.'+enc 17b9a05632SSatish Balay os.environ[lang] = lv 18b9a05632SSatish Balay 19b9a05632SSatish BalayfixLang('LC_LOCAL') 20b9a05632SSatish BalayfixLang('LANG') 21b9a05632SSatish Balay 2244b0d7f9SSatish Balay 23ccb279e1SMatthew Knepleydef check_for_option_mistakes(opts): 2445faeebdSBarry Smith for opt in opts[1:]: 25cda0060aSMatthew Knepley name = opt.split('=')[0] 265715f7bdSSatish Balay if name.find(' ') >= 0: 275715f7bdSSatish Balay raise ValueError('The option "'+name+'" has a space character in the name - this is likely incorrect usage.'); 28ccb279e1SMatthew Knepley if name.find('_') >= 0: 29ccb279e1SMatthew Knepley exception = False 301de7a49fSSatish 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']: 31ccb279e1SMatthew Knepley if name.find(exc) >= 0: 32ccb279e1SMatthew Knepley exception = True 33ccb279e1SMatthew Knepley if not exception: 34ccb279e1SMatthew Knepley raise ValueError('The option '+name+' should probably be '+name.replace('_', '-')); 35ab610953SSatish Balay if opt.find('=') >=0: 36ab610953SSatish Balay optval = opt.split('=')[1] 37ab610953SSatish Balay if optval == 'ifneeded': 38ab610953SSatish Balay raise ValueError('The option '+opt+' should probably be '+opt.replace('ifneeded', '1')); 39d1fb55d9SBarry Smith for exc in ['mkl_sparse', 'mkl_sparse_optimize', 'mkl_cpardiso', 'mkl_pardiso', 'superlu_dist']: 40d1fb55d9SBarry Smith if name.find(exc.replace('_','-')) > -1: 41d1fb55d9SBarry Smith raise ValueError('The option '+opt+' should be '+opt.replace(exc.replace('_','-'),exc)); 42ccb279e1SMatthew Knepley return 43ccb279e1SMatthew Knepley 442f393ef5SBarry Smithdef check_for_unsupported_combinations(opts): 452f393ef5SBarry Smith if '--with-precision=single' in opts and '--with-clanguage=cxx' in opts and '--with-scalar-type=complex' in opts: 462f393ef5SBarry Smith sys.exit(ValueError('PETSc does not support single precision complex with C++ clanguage, run with --with-clanguage=c')) 472f393ef5SBarry Smith 482af240f0SSatish Balaydef check_for_option_changed(opts): 492af240f0SSatish Balay# Document changes in command line options here. 504544382eSSatish Balay optMap = [('with-64bit-indices','with-64-bit-indices'), 51008db1b6SSatish Balay ('with-mpi-exec','with-mpiexec'), 524544382eSSatish Balay ('c-blas-lapack','f2cblaslapack'), 534544382eSSatish Balay ('cholmod','suitesparse'), 544544382eSSatish Balay ('umfpack','suitesparse'), 5569cdbcb9SBarry Smith ('matlabengine','matlab-engine'), 564544382eSSatish Balay ('f-blas-lapack','fblaslapack'), 574544382eSSatish Balay ('with-cuda-arch', 584544382eSSatish Balay 'CUDAFLAGS=-arch'), 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: 672af240f0SSatish Balay if optname.find(oldname) >=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}' 945bb5b98aSSatish Balay if sys.version_info < (3, 0): 955bb5b98aSSatish Balay en_dash = en_dash.encode('utf-8') 96f08ee00aSJason Sarich for l in range(0,len(sys.argv)): 97f08ee00aSJason Sarich name = sys.argv[l] 98f08ee00aSJason Sarich 995bb5b98aSSatish Balay if name.find(en_dash) >= 0: 1005bb5b98aSSatish Balay sys.argv[l] = name.replace(en_dash,'-') 1012b700d61SJason Sarich if name.find('enable-cxx') >= 0: 1022b700d61SJason Sarich if name.find('=') == -1: 1032b700d61SJason Sarich sys.argv[l] = name.replace('enable-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('enable-cxx','with-clanguage=C') 1082b700d61SJason Sarich else: 1092b700d61SJason Sarich sys.argv[l] = head.replace('enable-cxx','with-clanguage=C++') 1102b700d61SJason Sarich continue 1112b700d61SJason Sarich if name.find('disable-cxx') >= 0: 1122b700d61SJason Sarich if name.find('=') == -1: 1132b700d61SJason Sarich sys.argv[l] = name.replace('disable-cxx','with-clanguage=C') 1142b700d61SJason Sarich else: 1152b700d61SJason Sarich head, tail = name.split('=', 1) 1162b700d61SJason Sarich if tail == '0': 1172b700d61SJason Sarich sys.argv[l] = head.replace('disable-cxx','with-clanguage=C++') 1182b700d61SJason Sarich else: 1192b700d61SJason Sarich sys.argv[l] = head.replace('disable-cxx','with-clanguage=C') 1202b700d61SJason Sarich continue 1212b700d61SJason Sarich 122f08ee00aSJason Sarich 123f08ee00aSJason Sarich if name.find('enable-') >= 0: 124f08ee00aSJason Sarich if name.find('=') == -1: 125f08ee00aSJason Sarich sys.argv[l] = name.replace('enable-','with-')+'=1' 126f08ee00aSJason Sarich else: 127f08ee00aSJason Sarich head, tail = name.split('=', 1) 128f08ee00aSJason Sarich sys.argv[l] = head.replace('enable-','with-')+'='+tail 129f08ee00aSJason Sarich if name.find('disable-') >= 0: 130f08ee00aSJason Sarich if name.find('=') == -1: 131f08ee00aSJason Sarich sys.argv[l] = name.replace('disable-','with-')+'=0' 132f08ee00aSJason Sarich else: 133f08ee00aSJason Sarich head, tail = name.split('=', 1) 134f08ee00aSJason Sarich if tail == '1': tail = '0' 135f08ee00aSJason Sarich sys.argv[l] = head.replace('disable-','with-')+'='+tail 136f08ee00aSJason Sarich if name.find('without-') >= 0: 137f08ee00aSJason Sarich if name.find('=') == -1: 138f08ee00aSJason Sarich sys.argv[l] = name.replace('without-','with-')+'=0' 139f08ee00aSJason Sarich else: 140f08ee00aSJason Sarich head, tail = name.split('=', 1) 141f08ee00aSJason Sarich if tail == '1': tail = '0' 142f08ee00aSJason Sarich sys.argv[l] = head.replace('without-','with-')+'='+tail 143f08ee00aSJason Sarich 144f08ee00aSJason Sarichdef chksynonyms(): 145f08ee00aSJason Sarich #replace common configure options with ones that PETSc BuildSystem recognizes 14698d87fb0SBarry Smith simplereplacements = {'F77' : 'FC', 'F90' : 'FC'} 147f08ee00aSJason Sarich for l in range(0,len(sys.argv)): 148f08ee00aSJason Sarich name = sys.argv[l] 149f08ee00aSJason Sarich 150*c58b03afSBarry Smith name = name.replace('with-openmpi','with-mpi') 151*c58b03afSBarry Smith name = name.replace('with-mpich','with-mpi') 152*c58b03afSBarry Smith name = name.replace('with-blas-lapack','with-blaslapack') 153c87df54fSBarry Smith 154ce54fb35SBarry Smith if name.find('with-debug=') >= 0 or name.endswith('with-debug'): 155f08ee00aSJason Sarich if name.find('=') == -1: 156*c58b03afSBarry Smith name = name.replace('with-debug','with-debugging')+'=1' 157f08ee00aSJason Sarich else: 158f08ee00aSJason Sarich head, tail = name.split('=', 1) 159*c58b03afSBarry Smith name = head.replace('with-debug','with-debugging')+'='+tail 160f08ee00aSJason Sarich 161ce54fb35SBarry Smith if name.find('with-shared=') >= 0 or name.endswith('with-shared'): 162f08ee00aSJason Sarich if name.find('=') == -1: 163*c58b03afSBarry Smith name = name.replace('with-shared','with-shared-libraries')+'=1' 164f08ee00aSJason Sarich else: 165f08ee00aSJason Sarich head, tail = name.split('=', 1) 166*c58b03afSBarry Smith name = head.replace('with-shared','with-shared-libraries')+'='+tail 167f08ee00aSJason Sarich 1688fd71741SJason Sarich if name.find('with-index-size=') >=0: 1698fd71741SJason Sarich head,tail = name.split('=',1) 1708fd71741SJason Sarich if int(tail)==32: 171*c58b03afSBarry Smith name = '--with-64-bit-indices=0' 1728fd71741SJason Sarich elif int(tail)==64: 173*c58b03afSBarry Smith name = '--with-64-bit-indices=1' 1748fd71741SJason Sarich else: 1758fd71741SJason Sarich raise RuntimeError('--with-index-size= must be 32 or 64') 176f08ee00aSJason Sarich 1778fd71741SJason Sarich if name.find('with-precision=') >=0: 1788fd71741SJason Sarich head,tail = name.split('=',1) 1798fd71741SJason Sarich if tail.find('quad')>=0: 180*c58b03afSBarry Smith name='--with-precision=__float128' 181f08ee00aSJason Sarich 18298d87fb0SBarry Smith for i,j in simplereplacements.items(): 18398d87fb0SBarry Smith if name.find(i+'=') >= 0: 184*c58b03afSBarry Smith name = name.replace(i+'=',j+'=') 18598d87fb0SBarry Smith elif name.find('with-'+i.lower()+'=') >= 0: 186*c58b03afSBarry Smith name = name.replace(i.lower()+'=',j.lower()+'=') 187*c58b03afSBarry Smith 188*c58b03afSBarry Smith # restore 'sys.argv[l]' from the intermediate var 'name' 189*c58b03afSBarry Smith sys.argv[l] = name 190f08ee00aSJason Sarich 191b917b182SSatish Balaydef chkwincompilerusinglink(): 1926a8f6897SSatish Balay for arg in sys.argv: 193b917b182SSatish Balay if (arg.find('win32fe') >= 0 and (arg.find('f90') >=0 or arg.find('ifort') >=0 or arg.find('icl') >=0)): 1946a8f6897SSatish Balay return 1 1956a8f6897SSatish Balay return 0 1966a8f6897SSatish Balay 1978a4600f2SSatish Balaydef chkdosfiles(): 198360dfd13SSatish Balay # cygwin - but not a hg clone - so check one of files in bin dir 1998fb0cc24SJed Brown if b"\r\n" in open(os.path.join('lib','petsc','bin','petscmpiexec'),"rb").read(): 2005b6bfdb9SJed Brown print('===============================================================================') 2015b6bfdb9SJed Brown print(' *** Scripts are in DOS mode. Was winzip used to extract petsc sources? ****') 2025b6bfdb9SJed Brown print(' *** Please restart with a fresh tarball and use "tar -xzf petsc.tar.gz" ****') 2035b6bfdb9SJed Brown print('===============================================================================') 204db1f124cSVasiliy Kozyrev sys.exit(3) 2058a4600f2SSatish Balay return 2068a4600f2SSatish Balay 2076a8f6897SSatish Balaydef chkcygwinlink(): 208b917b182SSatish Balay if os.path.exists('/usr/bin/cygcheck.exe') and os.path.exists('/usr/bin/link.exe') and chkwincompilerusinglink(): 2096a8f6897SSatish Balay if '--ignore-cygwin-link' in sys.argv: return 0 2105b6bfdb9SJed Brown print('===============================================================================') 211b917b182SSatish Balay print(' *** Cygwin /usr/bin/link detected! Compiles with Intel icl/ifort can break! **') 2125b6bfdb9SJed Brown print(' *** To workarround do: "mv /usr/bin/link.exe /usr/bin/link-cygwin.exe" **') 213b917b182SSatish Balay print(' *** Or to ignore this check, use configure option: --ignore-cygwin-link. But compiles can fail. **') 2145b6bfdb9SJed Brown print('===============================================================================') 2156a8f6897SSatish Balay sys.exit(3) 2166a8f6897SSatish Balay return 0 2176a8f6897SSatish Balay 21885ef4d1eSSatish Balaydef chkbrokencygwin(): 2199dabcff0SSatish Balay if os.path.exists('/usr/bin/cygcheck.exe'): 2209dabcff0SSatish Balay buf = os.popen('/usr/bin/cygcheck.exe -c cygwin').read() 2219dabcff0SSatish Balay if buf.find('1.5.11-1') > -1: 2225b6bfdb9SJed Brown print('===============================================================================') 2235b6bfdb9SJed Brown print(' *** cygwin-1.5.11-1 detected. ./configure fails with this version ***') 2245b6bfdb9SJed Brown print(' *** Please upgrade to cygwin-1.5.12-1 or newer version. This can ***') 2255b6bfdb9SJed Brown print(' *** be done by running cygwin-setup, selecting "next" all the way.***') 2265b6bfdb9SJed Brown print('===============================================================================') 2271937db7aSSatish Balay sys.exit(3) 2289dabcff0SSatish Balay return 0 2299dabcff0SSatish Balay 230ee76e990SSatish Balaydef chkusingwindowspython(): 231ee76e990SSatish Balay if sys.platform == 'win32': 2325b6bfdb9SJed Brown print('===============================================================================') 2335b6bfdb9SJed Brown print(' *** Windows python detected. Please rerun ./configure with cygwin-python. ***') 2345b6bfdb9SJed Brown print('===============================================================================') 235ee76e990SSatish Balay sys.exit(3) 236ee76e990SSatish Balay return 0 237ee76e990SSatish Balay 23814f5c25cSSatish Balaydef chkcygwinpython(): 2391150532aSSatish Balay if sys.platform == 'cygwin' : 2401150532aSSatish Balay import platform 2411150532aSSatish Balay import re 2421150532aSSatish Balay r=re.compile("([0-9]+).([0-9]+).([0-9]+)") 2431150532aSSatish Balay m=r.match(platform.release()) 2441150532aSSatish Balay major=int(m.group(1)) 2451150532aSSatish Balay minor=int(m.group(2)) 2461150532aSSatish Balay subminor=int(m.group(3)) 2471150532aSSatish Balay if ((major < 1) or (major == 1 and minor < 7) or (major == 1 and minor == 7 and subminor < 34)): 2481937db7aSSatish Balay sys.argv.append('--useThreads=0') 2491937db7aSSatish Balay extraLogs.append('''\ 250a0022257SSatish Balay=============================================================================== 2511150532aSSatish Balay** Cygwin version is older than 1.7.34. Python threads do not work correctly. *** 25214f5c25cSSatish Balay** Disabling thread usage for this run of ./configure ******* 253a0022257SSatish Balay===============================================================================''') 25471384062SSatish Balay return 0 25571384062SSatish Balay 256cfb8f47aSBarry Smithdef chkcygwinwindowscompilers(): 257cfb8f47aSBarry Smith '''Adds win32fe for Microsoft/Intel compilers''' 258cfb8f47aSBarry Smith if os.path.exists('/usr/bin/cygcheck.exe'): 259cfb8f47aSBarry Smith for l in range(1,len(sys.argv)): 260cfb8f47aSBarry Smith option = sys.argv[l] 261cfb8f47aSBarry Smith for i in ['cl','icl','ifort']: 262cfb8f47aSBarry Smith if option.startswith(i): 263cfb8f47aSBarry Smith sys.argv[l] = 'win32fe '+option 264cfb8f47aSBarry Smith break 265cfb8f47aSBarry Smith return 0 266cfb8f47aSBarry Smith 2671937db7aSSatish Balaydef chkrhl9(): 2681937db7aSSatish Balay if os.path.exists('/etc/redhat-release'): 269836c2c52SSatish Balay try: 270594eb360SSatish Balay file = open('/etc/redhat-release','r') 271836c2c52SSatish Balay buf = file.read() 272836c2c52SSatish Balay file.close() 273836c2c52SSatish Balay except: 274836c2c52SSatish Balay # can't read file - assume dangerous RHL9 2751937db7aSSatish Balay buf = 'Shrike' 276836c2c52SSatish Balay if buf.find('Shrike') > -1: 2771937db7aSSatish Balay sys.argv.append('--useThreads=0') 2781937db7aSSatish Balay extraLogs.append('''\ 279a0022257SSatish Balay============================================================================== 2801937db7aSSatish Balay *** RHL9 detected. Threads do not work correctly with this distribution *** 281e2e64c6bSBarry Smith ****** Disabling thread usage for this run of ./configure ********* 282a0022257SSatish Balay===============================================================================''') 283836c2c52SSatish Balay return 0 284836c2c52SSatish Balay 285fd1ac241SSatish Balaydef chktmpnoexec(): 286e08ecd42SSatish Balay if not hasattr(os,'ST_NOEXEC'): return # novermin 287fd1ac241SSatish Balay if 'TMPDIR' in os.environ: tmpDir = os.environ['TMPDIR'] 288fd1ac241SSatish Balay else: tmpDir = '/tmp' 289e08ecd42SSatish Balay if os.statvfs(tmpDir).f_flag & os.ST_NOEXEC: # novermin 290e08ecd42SSatish Balay if os.statvfs(os.path.abspath('.')).f_flag & os.ST_NOEXEC: # novermin 291fd1ac241SSatish Balay print('************************************************************************') 292fd1ac241SSatish Balay print('* TMPDIR '+tmpDir+' has noexec attribute. Same with '+os.path.abspath('.')+' where petsc is built.') 293fd1ac241SSatish Balay print('* Suggest building PETSc in a location without this restriction!') 294fd1ac241SSatish Balay print('* Alternatively, set env variable TMPDIR to a location that is not restricted to run binaries.') 295fd1ac241SSatish Balay print('************************************************************************') 296fd1ac241SSatish Balay sys.exit(4) 297fd1ac241SSatish Balay else: 298fd1ac241SSatish Balay newTmp = os.path.abspath('tmp-petsc') 299fd1ac241SSatish Balay print('************************************************************************') 300fd1ac241SSatish Balay print('* TMPDIR '+tmpDir+' has noexec attribute. Using '+newTmp+' instead.') 301fd1ac241SSatish Balay print('************************************************************************') 302fd1ac241SSatish Balay if not os.path.isdir(newTmp): os.mkdir(os.path.abspath(newTmp)) 303fd1ac241SSatish Balay os.environ['TMPDIR'] = newTmp 304fd1ac241SSatish Balay return 305fd1ac241SSatish Balay 30605f86fb1SBarry Smithdef check_cray_modules(): 30705f86fb1SBarry Smith import script 30805f86fb1SBarry Smith '''For Cray systems check if the cc, CC, ftn compiler suite modules have been set''' 30905f86fb1SBarry Smith cray = os.getenv('CRAY_SITE_LIST_DIR') 31005f86fb1SBarry Smith if not cray: return 31105f86fb1SBarry Smith cray = os.getenv('CRAYPE_DIR') 31205f86fb1SBarry Smith if not cray: 31305f86fb1SBarry Smith print('************************************************************************') 31405f86fb1SBarry Smith print('* You are on a Cray system but no programming environments have been loaded') 31505f86fb1SBarry Smith print('* Perhaps you need:') 31605f86fb1SBarry Smith print('* module load intel ; module load PrgEnv-intel') 31705f86fb1SBarry Smith print('* or module load PrgEnv-cray') 31805f86fb1SBarry Smith print('* or module load PrgEnv-gnu') 31905f86fb1SBarry Smith print('* See https://www.mcs.anl.gov/petsc/documentation/installation.html#doemachines') 32005f86fb1SBarry Smith print('************************************************************************') 32105f86fb1SBarry Smith sys.exit(4) 32205f86fb1SBarry Smith 323da58527dSSatish Balaydef check_broken_configure_log_links(): 324da58527dSSatish Balay '''Sometime symlinks can get broken if the original files are deleted. Delete such broken links''' 325da58527dSSatish Balay import os 326da58527dSSatish Balay for logfile in ['configure.log','configure.log.bkp']: 327da58527dSSatish Balay if os.path.islink(logfile) and not os.path.isfile(logfile): os.remove(logfile) 328da58527dSSatish Balay return 329da58527dSSatish Balay 330da1d79b4SSatish Balaydef move_configure_log(framework): 331af0996ceSBarry Smith '''Move configure.log to PETSC_ARCH/lib/petsc/conf - and update configure.log.bkp in both locations appropriately''' 332b0b472b0SSatish Balay global petsc_arch 333b0b472b0SSatish Balay 334b0b472b0SSatish Balay if hasattr(framework,'arch'): petsc_arch = framework.arch 335b0b472b0SSatish Balay if hasattr(framework,'logName'): curr_file = framework.logName 336b0b472b0SSatish Balay else: curr_file = 'configure.log' 337b0b472b0SSatish Balay 338b0b472b0SSatish Balay if petsc_arch: 339da1d79b4SSatish Balay import shutil 340da1d79b4SSatish Balay import os 341b0b472b0SSatish Balay 342b0b472b0SSatish Balay # Just in case - confdir is not created 343fe998a80SBarry Smith lib_dir = os.path.join(petsc_arch,'lib') 344be5c6b33SBarry Smith petsc_dir = os.path.join(petsc_arch,'lib','petsc') 345af0996ceSBarry Smith conf_dir = os.path.join(petsc_arch,'lib','petsc','conf') 346b0b472b0SSatish Balay if not os.path.isdir(petsc_arch): os.mkdir(petsc_arch) 347fe998a80SBarry Smith if not os.path.isdir(lib_dir): os.mkdir(lib_dir) 348be5c6b33SBarry Smith if not os.path.isdir(petsc_dir): os.mkdir(petsc_dir) 349b0b472b0SSatish Balay if not os.path.isdir(conf_dir): os.mkdir(conf_dir) 350b0b472b0SSatish Balay 351da1d79b4SSatish Balay curr_bkp = curr_file + '.bkp' 352b0b472b0SSatish Balay new_file = os.path.join(conf_dir,curr_file) 353da1d79b4SSatish Balay new_bkp = new_file + '.bkp' 354da1d79b4SSatish Balay 355af0996ceSBarry Smith # Keep backup in $PETSC_ARCH/lib/petsc/conf location 356da1d79b4SSatish Balay if os.path.isfile(new_bkp): os.remove(new_bkp) 357da1d79b4SSatish Balay if os.path.isfile(new_file): os.rename(new_file,new_bkp) 3589e50940cSSatish Balay if os.path.isfile(curr_file): 3599e50940cSSatish Balay shutil.copyfile(curr_file,new_file) 3609e50940cSSatish Balay os.remove(curr_file) 361da58527dSSatish Balay if os.path.isfile(new_file): os.symlink(new_file,curr_file) 362af0996ceSBarry Smith # If the old bkp is using the same PETSC_ARCH/lib/petsc/conf - then update bkp link 363da1d79b4SSatish Balay if os.path.realpath(curr_bkp) == os.path.realpath(new_file): 364da58527dSSatish Balay if os.path.isfile(curr_bkp): os.remove(curr_bkp) 365da58527dSSatish Balay if os.path.isfile(new_bkp): os.symlink(new_bkp,curr_bkp) 366da1d79b4SSatish Balay return 367da1d79b4SSatish Balay 368d93c4beeSSatish Balaydef print_final_timestamp(framework): 369d93c4beeSSatish Balay import time 370d93c4beeSSatish Balay framework.log.write(('='*80)+'\n') 3717a01bd3eSSatish Balay framework.log.write('Finishing configure run at '+time.strftime('%a, %d %b %Y %H:%M:%S %z')+'\n') 372d93c4beeSSatish Balay framework.log.write(('='*80)+'\n') 373d93c4beeSSatish Balay return 374d93c4beeSSatish Balay 3755d5a5a7bSMatthew Knepleydef petsc_configure(configure_options): 3766e464aa7SMatthew G. Knepley if 'PETSC_DIR' in os.environ: 3774a532159SBarry Smith petscdir = os.environ['PETSC_DIR'] 3786e464aa7SMatthew G. Knepley if petscdir.find(' ') > -1: 3796e464aa7SMatthew 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') 3806e464aa7SMatthew G. Knepley try: 381c3a89c15SBarry Smith sys.path.append(os.path.join(petscdir,'lib','petsc','bin')) 3824a532159SBarry Smith import petscnagupgrade 3834a532159SBarry Smith file = os.path.join(petscdir,'.nagged') 3844a532159SBarry Smith if not petscnagupgrade.naggedtoday(file): 3854a532159SBarry Smith petscnagupgrade.currentversion(petscdir) 3864a532159SBarry Smith except: 3874a532159SBarry Smith pass 3885b6bfdb9SJed Brown print('===============================================================================') 3895b6bfdb9SJed Brown print(' Configuring PETSc to compile on your system ') 3905b6bfdb9SJed Brown print('===============================================================================') 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' 400a258c2c4SMatthew G Knepley msg ='*******************************************************************************\n'\ 401a258c2c4SMatthew G Knepley +' ERROR in COMMAND LINE ARGUMENT to ./configure \n' \ 402a258c2c4SMatthew G Knepley +'-------------------------------------------------------------------------------\n' \ 403a258c2c4SMatthew G Knepley +emsg+'*******************************************************************************\n' 404a258c2c4SMatthew G Knepley sys.exit(msg) 40559e9bfd6SSatish Balay # check PETSC_ARCH 4062f393ef5SBarry Smith check_for_unsupported_combinations(sys.argv) 40759e9bfd6SSatish Balay check_petsc_arch(sys.argv) 408da58527dSSatish Balay check_broken_configure_log_links() 4095fb2c094SBarry Smith 410f08ee00aSJason Sarich #rename '--enable-' to '--with-' 411f08ee00aSJason Sarich chkenable() 412c22cdea9SBarry Smith # support a few standard configure option types 413f08ee00aSJason Sarich chksynonyms() 4149dabcff0SSatish Balay # Check for broken cygwin 4151937db7aSSatish Balay chkbrokencygwin() 416d65f3bddSMatthew Knepley # Disable threads on RHL9 4171937db7aSSatish Balay chkrhl9() 418ee76e990SSatish Balay # Make sure cygwin-python is used on windows 419ee76e990SSatish Balay chkusingwindowspython() 42014f5c25cSSatish Balay # Threads don't work for cygwin & python... 42114f5c25cSSatish Balay chkcygwinpython() 4226a8f6897SSatish Balay chkcygwinlink() 4238a4600f2SSatish Balay chkdosfiles() 424cfb8f47aSBarry Smith chkcygwinwindowscompilers() 425fd1ac241SSatish Balay chktmpnoexec() 4269dabcff0SSatish Balay 427a9acdec7SBarry Smith for l in range(1,len(sys.argv)): 428a9acdec7SBarry Smith if sys.argv[l].startswith('--with-fc=') and sys.argv[l].endswith('nagfor'): 429a9acdec7SBarry Smith # need a way to save this value and later CC so that petscnagfor may use them 430a9acdec7SBarry Smith name = sys.argv[l].split('=')[1] 431a9acdec7SBarry Smith sys.argv[l] = '--with-fc='+os.path.join(os.path.abspath('.'),'lib','petsc','bin','petscnagfor') 432a9acdec7SBarry Smith break 433a9acdec7SBarry Smith 434a9acdec7SBarry Smith 43587282423SMatthew Knepley # Should be run from the toplevel 436dbca6d9dSSatish Balay configDir = os.path.abspath('config') 437f8833479SBarry Smith bsDir = os.path.join(configDir, 'BuildSystem') 438f8833479SBarry Smith if not os.path.isdir(configDir): 4395d5a5a7bSMatthew Knepley raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.')) 44087282423SMatthew Knepley sys.path.insert(0, bsDir) 441f8833479SBarry Smith sys.path.insert(0, configDir) 442e69ef9dfSMatthew Knepley import config.base 4435d5a5a7bSMatthew Knepley import config.framework 444492432c8SJed Brown import pickle 4454e5e6a77SJed Brown import traceback 4464f8a5b45SBarry Smith 44705f86fb1SBarry Smith # Check Cray without modules 44805f86fb1SBarry Smith check_cray_modules() 44905f86fb1SBarry Smith 45038c5b55eSBarry Smith tbo = None 4519dd2fdb1SMatthew Knepley framework = None 4529dd2fdb1SMatthew Knepley try: 45323a19ef1SSatish Balay framework = config.framework.Framework(['--configModules=PETSc.Configure','--optionsModule=config.compilerOptions']+sys.argv[1:], loadArgDB = 0) 454d65f3bddSMatthew Knepley framework.setup() 455d65f3bddSMatthew Knepley framework.logPrint('\n'.join(extraLogs)) 456f24f64feSBarry Smith framework.configure(out = sys.stdout) 457358ebc22SMatthew Knepley framework.storeSubstitutions(framework.argDB) 458492432c8SJed Brown framework.argDB['configureCache'] = pickle.dumps(framework) 4597c939e48SSatish Balay framework.printSummary() 46012c1d45bSMatthew G Knepley framework.argDB.save(force = True) 4617cfd0b05SBarry Smith framework.logClear() 462d93c4beeSSatish Balay print_final_timestamp(framework) 463eefa2c0fSBarry Smith framework.closeLog() 4649e50940cSSatish Balay try: 465da1d79b4SSatish Balay move_configure_log(framework) 4669e50940cSSatish Balay except: 4679e50940cSSatish Balay # perhaps print an error about unable to shuffle logs? 4689e50940cSSatish Balay pass 469dd50d019SBarry Smith return 0 4705b6bfdb9SJed Brown except (RuntimeError, config.base.ConfigureSetupError) as e: 4711a7b8b2eSBarry Smith tbo = sys.exc_info()[2] 4727d670a3cSBarry Smith emsg = str(e) 47342351d26SSatish Balay if not emsg.endswith('\n'): emsg = emsg+'\n' 474a0022257SSatish Balay msg ='*******************************************************************************\n'\ 475fe09c992SBarry Smith +' UNABLE to CONFIGURE with GIVEN OPTIONS (see configure.log for details):\n' \ 476a0022257SSatish Balay +'-------------------------------------------------------------------------------\n' \ 477a0022257SSatish Balay +emsg+'*******************************************************************************\n' 478e9f3bb17SBarry Smith se = '' 4795b6bfdb9SJed Brown except (TypeError, ValueError) as e: 48038c5b55eSBarry Smith # this exception is automatically deleted by Python so we need to save it to print below 48138c5b55eSBarry Smith tbo = sys.exc_info()[2] 4827d670a3cSBarry Smith emsg = str(e) 48342351d26SSatish Balay if not emsg.endswith('\n'): emsg = emsg+'\n' 484a0022257SSatish Balay msg ='*******************************************************************************\n'\ 485edd0a2d9SBarry Smith +' TypeError or ValueError possibly related to ERROR in COMMAND LINE ARGUMENT while running ./configure \n' \ 486a0022257SSatish Balay +'-------------------------------------------------------------------------------\n' \ 487a0022257SSatish Balay +emsg+'*******************************************************************************\n' 4881a02243aSBarry Smith se = '' 4895b6bfdb9SJed Brown except ImportError as e : 490edd0a2d9SBarry Smith # this exception is automatically deleted by Python so we need to save it to print below 491edd0a2d9SBarry Smith tbo = sys.exc_info()[2] 4927d670a3cSBarry Smith emsg = str(e) 49342351d26SSatish Balay if not emsg.endswith('\n'): emsg = emsg+'\n' 494a0022257SSatish Balay msg ='*******************************************************************************\n'\ 495edd0a2d9SBarry Smith +' ImportError while runing ./configure \n' \ 496a0022257SSatish Balay +'-------------------------------------------------------------------------------\n' \ 497a0022257SSatish Balay +emsg+'*******************************************************************************\n' 49896dc2fe8SMatthew Knepley se = '' 4995b6bfdb9SJed Brown except OSError as e : 5001a7b8b2eSBarry Smith tbo = sys.exc_info()[2] 50101def6f0SMatthew Knepley emsg = str(e) 50201def6f0SMatthew Knepley if not emsg.endswith('\n'): emsg = emsg+'\n' 503a0022257SSatish Balay msg ='*******************************************************************************\n'\ 504edd0a2d9SBarry Smith +' OSError while running ./configure \n' \ 505a0022257SSatish Balay +'-------------------------------------------------------------------------------\n' \ 506a0022257SSatish Balay +emsg+'*******************************************************************************\n' 50701def6f0SMatthew Knepley se = '' 5085b6bfdb9SJed Brown except SystemExit as e: 5091a7b8b2eSBarry Smith tbo = sys.exc_info()[2] 510d7d3c4beSMatthew Knepley if e.code is None or e.code == 0: 511d7d3c4beSMatthew Knepley return 51241f847afSJed Brown if e.code == 10: 513c524ecbbSBarry Smith sys.exit(10) 514a0022257SSatish Balay msg ='*******************************************************************************\n'\ 515b1dada7fSMatthew Knepley +' CONFIGURATION FAILURE (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \ 516a0022257SSatish Balay +'*******************************************************************************\n' 517d7d3c4beSMatthew Knepley se = str(e) 5185b6bfdb9SJed Brown except Exception as e: 5191a7b8b2eSBarry Smith tbo = sys.exc_info()[2] 520a0022257SSatish Balay msg ='*******************************************************************************\n'\ 521fe09c992SBarry Smith +' CONFIGURATION CRASH (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \ 522a0022257SSatish Balay +'*******************************************************************************\n' 523e9f3bb17SBarry Smith se = str(e) 524e9f3bb17SBarry Smith 5255b6bfdb9SJed Brown print(msg) 5269dd2fdb1SMatthew Knepley if not framework is None: 5279dd2fdb1SMatthew Knepley framework.logClear() 528e9f3bb17SBarry Smith if hasattr(framework, 'log'): 52922c95ba3SMatthew G Knepley try: 530d71f8ab3SSatish Balay if hasattr(framework,'compilerDefines'): 531bd5137a2SBarry Smith framework.log.write('**** Configure header '+framework.compilerDefines+' ****\n') 532febd46b0SSatish Balay framework.outputHeader(framework.log) 533d71f8ab3SSatish Balay if hasattr(framework,'compilerFixes'): 534bd5137a2SBarry Smith framework.log.write('**** C specific Configure header '+framework.compilerFixes+' ****\n') 535febd46b0SSatish Balay framework.outputCHeader(framework.log) 5365b6bfdb9SJed Brown except Exception as e: 53722c95ba3SMatthew G Knepley framework.log.write('Problem writing headers to log: '+str(e)) 538b1dada7fSMatthew Knepley try: 539f24f64feSBarry Smith framework.log.write(msg+se) 54038c5b55eSBarry Smith traceback.print_tb(tbo, file = framework.log) 541d93c4beeSSatish Balay print_final_timestamp(framework) 542f73e6a6cSSatish Balay if hasattr(framework,'log'): framework.log.close() 543da1d79b4SSatish Balay move_configure_log(framework) 544957f4b51SBarry Smith except Exception as e: 545957f4b51SBarry Smith print('Error printing error message from exception or printing the traceback:'+str(e)) 5461a7b8b2eSBarry Smith traceback.print_tb(sys.exc_info()[2]) 547e9f3bb17SBarry Smith sys.exit(1) 5485a74f024SMatthew Knepley else: 5495b6bfdb9SJed Brown print(se) 5501a7b8b2eSBarry Smith traceback.print_tb(tbo) 551957f4b51SBarry Smith else: 552957f4b51SBarry Smith print(se) 5531a7b8b2eSBarry Smith traceback.print_tb(tbo) 554f73e6a6cSSatish Balay if hasattr(framework,'log'): framework.log.close() 5555d5a5a7bSMatthew Knepley 5565d5a5a7bSMatthew Knepleyif __name__ == '__main__': 557a030c540SBarry Smith petsc_configure([]) 558759acf64SBarry Smith 559