Debian Codegraph @

gcc/ada/doc/share/conf.py

raw
1 # -*- coding: utf-8 -*-
2 # Style_Check:Python_Fragment (meaning no pyflakes check)
3 #
4 # GNAT build configuration file
5
6 import sys
7 import os
8 import time
9 import re
10
11 sys.path.append('.')
12
13 import ada_pygments
14 import latex_elements
15
16 # Some configuration values for the various documentation handled by
17 # this conf.py
18
19 DOCS = {
20 'gnat_rm': {
21 'title': 'GNAT Reference Manual'},
22 'gnat_ugn': {
23 'title': 'GNAT User\'s Guide for Native Platforms'},
24 'gnat-style': {
25 'title': 'GNAT Coding Style: A Guide for GNAT Developers'}}
26
27 # Then retrieve the source directory
28 root_source_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
29 gnatvsn_spec = os.path.join(root_source_dir, '..', 'gnatvsn.ads')
30 basever = os.path.join(root_source_dir, '..', '..', 'BASE-VER')
31 texi_fsf = True # Set to False when FSF doc is switched to sphinx by default
32
33 with open(gnatvsn_spec, 'r') as fd:
34 gnatvsn_content = fd.read()
35
36
37 def get_copyright():
38 return '2008-%s, Free Software Foundation' % time.strftime('%Y')
39
40
41 def get_gnat_version():
42 m = re.search(r'Gnat_Static_Version_String : ' +
43 r'constant String := "([^\(\)]+)\(.*\)?";',
44 gnatvsn_content)
45 if m:
46 return m.group(1).strip()
47 else:
48 if texi_fsf and os.path.exists(basever):
49 return ''
50
51 try:
52 with open(basever) as fd:
53 return fd.read()
54 except Exception:
55 pass
56
57 print('cannot find GNAT version in gnatvsn.ads or in ' + basever)
58 sys.exit(1)
59
60
61 def get_gnat_build_type():
62 m = re.search(r'Build_Type : constant Gnat_Build_Type := (.+);',
63 gnatvsn_content)
64 if m:
65 return {'Gnatpro': 'PRO',
66 'FSF': 'FSF',
67 'GPL': 'GPL'}[m.group(1).strip()]
68 else:
69 print('cannot compute GNAT build type')
70 sys.exit(1)
71
72
73 # First retrieve the name of the documentation we are building
74 doc_name = os.environ.get('DOC_NAME', None)
75 if doc_name is None:
76 print('DOC_NAME environment variable should be set')
77 sys.exit(1)
78
79 if doc_name not in DOCS:
80 print('%s is not a valid documentation name' % doc_name)
81 sys.exit(1)
82
83
84 # Exclude sources that are not part of the current documentation
85 exclude_patterns = []
86 for d in os.listdir(root_source_dir):
87 if d not in ('share', doc_name, doc_name + '.rst'):
88 exclude_patterns.append(d)
89 print('ignoring %s' % d)
90
91 if doc_name == 'gnat_rm':
92 exclude_patterns.append('share/gnat_project_manager.rst')
93 print('ignoring share/gnat_project_manager.rst')
94
95 extensions = []
96 templates_path = ['_templates']
97 source_suffix = '.rst'
98 master_doc = doc_name
99
100 # General information about the project.
101 project = DOCS[doc_name]['title']
102
103 copyright = get_copyright()
104
105 version = get_gnat_version()
106 release = get_gnat_version()
107
108 pygments_style = None
109 tags.add(get_gnat_build_type())
110 html_theme = 'sphinxdoc'
111 if os.path.isfile('adacore_transparent.png'):
112 html_logo = 'adacore_transparent.png'
113 if os.path.isfile('favicon.ico'):
114 html_favicon = 'favicon.ico'
115
116 html_static_path = ['_static']
117
118 latex_additional_files = ['gnat.sty']
119
120 copyright_macros = {
121 'date': time.strftime("%b %d, %Y"),
122 'edition': 'GNAT %s Edition' % 'Pro' if get_gnat_build_type() == 'PRO'
123 else 'GPL',
124 'name': 'GNU Ada',
125 'tool': 'GNAT',
126 'version': version}
127
128 latex_elements = {
129 'preamble': '\\usepackage{gnat}\n' +
130 latex_elements.TOC_DEPTH +
131 latex_elements.PAGE_BLANK +
132 latex_elements.TOC_CMD +
133 latex_elements.LATEX_HYPHEN +
134 latex_elements.doc_settings(DOCS[doc_name]['title'],
135 get_gnat_version()),
136 'tableofcontents': latex_elements.TOC % copyright_macros}
137
138 latex_documents = [
139 (master_doc, '%s.tex' % doc_name, project, 'AdaCore', 'manual')]
140
141 texinfo_documents = [
142 (master_doc, doc_name, project,
143 'AdaCore', doc_name, doc_name, '')]
144
145
146 def setup(app):
147 app.add_lexer('ada', ada_pygments.AdaLexer)
148 app.add_lexer('gpr', ada_pygments.GNATProjectLexer)