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