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