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