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