1c6267af9SBarry Smith#!/usr/bin/env python3 2c6267af9SBarry Smith""" Configure PETSc and build and place the generated manual pages (as .md files) and html source (as .html files)""" 3c6267af9SBarry Smith 4c6267af9SBarry Smithimport os 5c6267af9SBarry Smithimport errno 6c6267af9SBarry Smithimport subprocess 7c6267af9SBarry Smithimport shutil 8c6267af9SBarry Smithimport argparse 9c6267af9SBarry Smithimport re 10c6267af9SBarry Smith 11c6267af9SBarry Smithrawhtml = ['include', 'src'] 12c6267af9SBarry Smithpetsc_arch = 'arch-docs' 13c6267af9SBarry SmithTHIS_DIR = os.path.dirname(os.path.abspath(__file__)) 14c6267af9SBarry Smith 15c6267af9SBarry Smithdef main(stage,outdir): 16c6267af9SBarry Smith """ Operations to provide data for PETSc manual pages and c2html files. """ 17c6267af9SBarry Smith import time 18c6267af9SBarry Smith petsc_dir = os.path.abspath(os.path.join(THIS_DIR, "..")) # abspath essential since classic 'html' target uses sed to modify paths from the source to target tree 19c6267af9SBarry Smith if stage == "pre": 20c6267af9SBarry Smith if 'PETSC_ARCH' in os.environ: del os.environ['PETSC_ARCH'] 21c6267af9SBarry Smith if 'MAKEFLAGS' in os.environ: del os.environ['MAKEFLAGS'] 22c6267af9SBarry Smith command = ['./configure', 23c6267af9SBarry Smith '--with-coverage-exec=0', 24c6267af9SBarry Smith '--with-mpi=0', 25c6267af9SBarry Smith '--with-cxx=0', 26c6267af9SBarry Smith '--with-syclc=0', 27c6267af9SBarry Smith '--with-hipc=0', 28c6267af9SBarry Smith '--with-cudac=0', 29c6267af9SBarry Smith '--with-x=0', 30c6267af9SBarry Smith '--with-bison=0', 31c6267af9SBarry Smith '--with-cmake=0', 32c6267af9SBarry Smith '--with-pthread=0', 33c6267af9SBarry Smith '--with-regex=0', 34c6267af9SBarry Smith '--with-mkl_sparse_optimize=0', 35c6267af9SBarry Smith '--with-mkl_sparse=0', 36c6267af9SBarry Smith '--with-debugging=0', 37*07f25ad1SSatish Balay '--download-sowing=1', 38c6267af9SBarry Smith 'COPTFLAS=-O0', 39c6267af9SBarry Smith '--with-petsc4py', 40c6267af9SBarry Smith 'PETSC_ARCH=' + petsc_arch, 41c6267af9SBarry Smith ] 42c6267af9SBarry Smith if 'PETSCBUIDTARBALL' in os.environ: 43c6267af9SBarry Smith command.append('--download-c2html') 44c6267af9SBarry Smith command.append('--download-sowing') 45c6267af9SBarry Smith c2html = None 46c6267af9SBarry Smith doctext = None 47c6267af9SBarry Smith else: 48c6267af9SBarry Smith command.append('--with-fc=0') 49c6267af9SBarry Smith c2html = shutil.which('c2html') 50c6267af9SBarry Smith if c2html: command.append('--with-c2html') 51c6267af9SBarry Smith else: command.append('--download-c2html') 52c6267af9SBarry Smith doctext = shutil.which('doctext') 53c6267af9SBarry Smith if doctext: command.append('--with-sowing') 54c6267af9SBarry Smith else: command.append('--download-sowing') 55c6267af9SBarry Smith 56c6267af9SBarry Smith x = time.clock_gettime(time.CLOCK_REALTIME) 57c6267af9SBarry Smith print('==================================================================') 58c6267af9SBarry Smith print('Running configure') 59c6267af9SBarry Smith subprocess.run(command, cwd=petsc_dir, check=True) 60c6267af9SBarry Smith print("Time: "+str(time.clock_gettime(time.CLOCK_REALTIME) - x)) 61c6267af9SBarry Smith print('==================================================================') 62c6267af9SBarry Smith if not doctext: 63c6267af9SBarry Smith with open(os.path.join(petsc_dir,petsc_arch,'lib','petsc','conf','petscvariables')) as f: 64c6267af9SBarry Smith doctext = [line for line in f if line.find('DOCTEXT ') > -1] 65c6267af9SBarry Smith doctext = re.sub('[ ]*DOCTEXT[ ]*=[ ]*','',doctext[0]).strip('\n').strip() 66c6267af9SBarry Smith print('Using DOCTEXT:', doctext) 67c6267af9SBarry Smith 68c6267af9SBarry Smith import build_man_pages 69c6267af9SBarry Smith x = time.clock_gettime(time.CLOCK_REALTIME) 70c6267af9SBarry Smith print('============================================') 71c6267af9SBarry Smith print('Building all manual pages') 72c6267af9SBarry Smith build_man_pages.main(petsc_dir,doctext) 73c6267af9SBarry Smith print("Time: "+str(time.clock_gettime(time.CLOCK_REALTIME) - x)) 74c6267af9SBarry Smith print('============================================') 75c6267af9SBarry Smith 76c6267af9SBarry Smith import build_man_examples_links 77c6267af9SBarry Smith x = time.clock_gettime(time.CLOCK_REALTIME) 78c6267af9SBarry Smith print('============================================') 79c6267af9SBarry Smith print('Building manual page links to tutorials') 80c6267af9SBarry Smith build_man_examples_links.main(petsc_dir) 81c6267af9SBarry Smith print("Time: "+str(time.clock_gettime(time.CLOCK_REALTIME) - x)) 82c6267af9SBarry Smith print('============================================') 83c6267af9SBarry Smith 84c6267af9SBarry Smith import build_man_impls_links 85c6267af9SBarry Smith x = time.clock_gettime(time.CLOCK_REALTIME) 86c6267af9SBarry Smith print('============================================') 87c6267af9SBarry Smith print('Building manual page links to implementations') 88c6267af9SBarry Smith build_man_impls_links.main(petsc_dir) 89c6267af9SBarry Smith print("Time: "+str(time.clock_gettime(time.CLOCK_REALTIME) - x)) 90c6267af9SBarry Smith print('============================================') 91c6267af9SBarry Smith 92c6267af9SBarry Smith import build_man_index 93c6267af9SBarry Smith x = time.clock_gettime(time.CLOCK_REALTIME) 94c6267af9SBarry Smith print('============================================') 95c6267af9SBarry Smith print('Building manual page indices') 96c6267af9SBarry Smith build_man_index.main(petsc_dir) 97c6267af9SBarry Smith print("Time: "+str(time.clock_gettime(time.CLOCK_REALTIME) - x)) 98c6267af9SBarry Smith print('============================================') 99c6267af9SBarry Smith else: 100c6267af9SBarry Smith if not os.path.isfile(os.path.join(petsc_dir, "configure.log")): raise Exception("Expected PETSc configuration not found") 101c6267af9SBarry Smith c2html = shutil.which('c2html') 102c6267af9SBarry Smith if not c2html: 103c6267af9SBarry Smith with open(os.path.join(petsc_dir,petsc_arch,'lib','petsc','conf','petscvariables')) as f: 104c6267af9SBarry Smith c2html = [line for line in f if line.find('C2HTML ') > -1] 105c6267af9SBarry Smith c2html = re.sub('[ ]*C2HTML[ ]*=[ ]*','',c2html[0]).strip('\n').strip() 106c6267af9SBarry Smith print('Using C2HTML:', c2html) 107c6267af9SBarry Smith mapnames = shutil.which('mapnames') 108c6267af9SBarry Smith if not mapnames: 109c6267af9SBarry Smith with open(os.path.join(petsc_dir,petsc_arch,'lib','petsc','conf','petscvariables')) as f: 110c6267af9SBarry Smith mapnames = [line for line in f if line.find('MAPNAMES ') > -1] 111c6267af9SBarry Smith mapnames = re.sub('[ ]*MAPNAMES[ ]*=[ ]*','',mapnames[0]).strip('\n').strip() 112c6267af9SBarry Smith print('Using MAPNAMES:', mapnames) 113c6267af9SBarry Smith import build_c2html 114c6267af9SBarry Smith x = time.clock_gettime(time.CLOCK_REALTIME) 115c6267af9SBarry Smith print('============================================') 116c6267af9SBarry Smith print('Building c2html') 117c6267af9SBarry Smith build_c2html.main(petsc_dir,outdir,c2html,mapnames) 118c6267af9SBarry Smith print("Time: "+str(time.clock_gettime(time.CLOCK_REALTIME) - x)) 119c6267af9SBarry Smith print('============================================') 120