]> git.ipfire.org Git - thirdparty/gcc.git/blob
421f91003e8a2816eb5049acb98f3da28621dfc1
[thirdparty/gcc.git] /
1 ..
2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
5
6 .. _building_documentation:
7
8 Building Documentation
9 ^^^^^^^^^^^^^^^^^^^^^^
10
11 The main GCC documentation uses `Sphinx`_ to generate pretty documentation
12 from `reStructuredText`_ format.
13 These are input for Manual pages format (:command:`make man`),
14 Info format (:command:`make info`), HTML format (:command:`make html`)
15 and PDF format (:command:`make pdf`).
16
17 .. _Sphinx: http://www.sphinx-doc.org/
18 .. _reStructuredText: http://docutils.sourceforge.net/rst.html
19
20 .. _sphinx_install:
21
22 Sphinx Install
23 ==============
24
25 The ReST markups currently used by the documentation files are meant to be
26 built with ``Sphinx`` version |needs_sphinx| or higher.
27
28 Most distributions are shipped with Sphinx, but its toolchain is fragile,
29 and it is not uncommon that upgrading it or some other Python packages
30 on your machine would cause the documentation build to break.
31
32 A way to avoid that is to use a different version than the one shipped
33 with your distributions. In order to do so, it is recommended to install
34 Sphinx inside a virtual environment, using ``virtualenv-3``
35 or ``virtualenv``, depending on how your distribution packaged Python 3.
36
37 .. code-block:: shell-session
38
39 $ virtualenv /tmp/venv
40 $ source /tmp/venv/bin/activate
41 $ pip install -r requirements.txt
42
43 Note the :file:`requirements.txt` file is placed in :rst:dir:`gcc/doc` folder and contains the following packages:
44
45 .. literalinclude:: ../../../../../doc/requirements.txt
46 :caption: requirements.txt
47
48 Then the virtualenv can be provided to the configure script :option:`install:--with-sphinx-build`
49 and will be used by the build system:
50
51 .. code-block:: shell-session
52
53 $ configure --with-sphinx-build=/tmp/venv/bin/sphinx-build
54
55 If you want to build the PDF documentation, you will need ``python3-Sphinx-latex`` sub-package.
56
57 .. note::
58
59 When building **manual** and **info** pages (built by default), the only dependency
60 is Sphinx package and one can ignore other dependencies mentioned in :file:`requirements.txt`.
61
62 Writing Documentation
63 =====================
64
65 Adding new documentation can be as simple as:
66
67 1. Add a new ``.rst`` file somewhere under a ``doc`` subfolder.
68 2. Refer to it from the Sphinx main `TOC tree`_ in a ``index.rst`` file.
69
70 .. _TOC tree: http://www.sphinx-doc.org/en/stable/markup/toctree.html
71
72 This is usually good enough for simple documentation (like the one you're
73 reading right now), but for larger documents it may be advisable to create a
74 subdirectory (or use an existing one).
75
76 See the documentation for `Sphinx`_ and `reStructuredText`_ on what you can do
77 with them. In particular, the Sphinx `reStructuredText Primer`_ is a good place
78 to get started with reStructuredText. There are also some `Sphinx specific
79 markup constructs`_ and `Usefull RST cheatsheet`_.
80
81 .. _reStructuredText Primer: http://www.sphinx-doc.org/en/stable/rest.html
82 .. _Sphinx specific markup constructs: http://www.sphinx-doc.org/en/stable/markup/index.html
83 .. _Usefull RST cheatsheet: https://github.com/ralsina/rst-cheatsheet/blob/master/rst-cheatsheet.rst
84
85 Specific guidelines for the GCC documentation
86 ---------------------------------------------
87
88 Here are some specific guidelines for the GCC documentation:
89
90 * Please stick to this order of heading adornments:
91
92 1. ``=`` with overline for document title:
93
94 .. code-block:: rst
95
96 ==============
97 Document title
98 ==============
99
100 2. ``-`` for chapters:
101
102 .. code-block:: rst
103
104 Chapter
105 -------
106
107 3. ``*`` for sections:
108
109 .. code-block:: rst
110
111 Section
112 *******
113
114 4. ``^`` for subsections:
115
116 .. code-block:: rst
117
118 Subsection
119 ^^^^^^^^^^
120
121 5. ``~`` for subsubsections:
122
123 .. code-block:: rst
124
125 Subsubsection
126 ~~~~~~~~~~~~~
127
128 Although RST doesn't mandate a specific order ("Rather than imposing a fixed
129 number and order of section title adornment styles, the order enforced will be
130 the order as encountered."), having the higher levels the same overall makes
131 it easier to follow the documents.
132
133 * For inserting fixed width text blocks (for code examples, use case
134 examples, etc.), use ``::`` for anything that doesn't really benefit
135 from syntax highlighting, especially short snippets. Use
136 ``.. code-block:: <language>`` for longer code blocks that benefit
137 from highlighting. For a short snippet of code embedded in the text, use ````code snippet````.
138
139 * For parts of documentation that needs to be written or enhanced, use ``.. todo::`` directive
140 (part of the official ``sphinx.ext.todo`` extension). In development mode, all items
141 are listed at the very end of the documentation for easier navigation.
142
143 GCC-specific directives and roles
144 ---------------------------------
145
146 GCC uses its own extension (:file:`gcc_sphinx.py`) that defined various directives. For the complete
147 list of target-specific attributes, please take a look at the extension definition:
148
149 .. list-table::
150 :header-rows: 1
151
152 * - Directive
153 - Description
154
155 * - ``gcc-attr``
156 - Generic GCC attribute
157 * - ``fn-attr``
158 - Function attribute
159 * - ``var-attr``
160 - Variable attribute
161 * - ``type-attr``
162 - Type attribute
163 * - ``enum-attr``
164 - Enumeral attribute
165 * - ``label-attr``
166 - Label attribute
167 * - ``$target-fn-attr``
168 - Target-specific function attribute (e.g. ``.. x86-fn-attr:: interrupt``)
169 * - ``$target-var-attr``
170 - Target-specific variable attribute
171 * - ``$target-type-attr``
172 - Target-specific type attribute
173 * - ``gcc-param``
174 - GCC parameter directive, (e.g. ``.. gcc-param: inline-unit-growth``)
175
176 Apart from the directives, we also define various inline roles:
177
178 .. list-table::
179 :header-rows: 1
180
181 * - Role
182 - Description
183
184 * - ``:P:`$num```
185 - Link to WG21 - The C++ Standards Committee (e.g. ``:P:`2003```)
186 * - ``:PR:`$num```
187 - Link to GCC bugzilla entry
188 * - ``:openmp:`$version```
189 - Link to OpenMP documentation version ``$version`` (e.g. ``:openmp:`4.5```)
190 * - ``:openacc:`$version```
191 - Link to OpenACC documentation version ``$version``
192 * - ``|gcc_version|``
193 - Version of the documentation (e.g. |gcc_version|, taken from :file:`BASE-VER`)
194 * - ``|needs_sphinx|``
195 - Minimal required Sphinx version (e.g. |needs_sphinx|, taken from :file:`baseconf.py`)
196 * - ``|bugurl|``
197 - URL to bugzilla instance (e.g. |bugurl|)
198 * - ``|package_version|``
199 - Package version (e.g. |package_version|)
200 * - ``|gol|``
201 - Line break used for PDF version
202 * - ``|nbsp|``
203 - Non-breaking space character
204
205 .. _miscellaneous-docs:
206
207 Miscellaneous Documentation
208 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
209
210 In addition to the formal documentation that is installed by GCC,
211 there are several other text files in the :samp:`gcc` subdirectory
212 with miscellaneous documentation:
213
214 :samp:`ABOUT-GCC-NLS`
215 Notes on GCC's Native Language Support.
216
217 .. todo:: this should be part of this manual rather than a separate file
218
219 :samp:`ABOUT-NLS`
220 Notes on the Free Translation Project.
221
222 :samp:`COPYING`
223 The GNU General Public License, Versions 2 and 3.
224
225 :samp:`COPYING.LIB` :samp:`COPYING3.LIB`
226 The GNU Lesser General Public License, Versions 2.1 and 3.
227
228 :samp:`*ChangeLog*` :samp:`*/ChangeLog*`
229 Change log files for various parts of GCC.
230
231 :samp:`LANGUAGES`
232 Details of a few changes to the GCC front-end interface.
233
234 .. todo:: the information in this file should be part of general documentation of
235 the front-end interface in this manual.
236
237 :samp:`ONEWS`
238 Information about new features in old versions of GCC. (For recent
239 versions, the information is on the GCC web site.)
240
241 :samp:`README.Portability`
242 Information about portability issues when writing code in GCC.
243
244 .. todo:: why isn't this part of this manual or of the GCC Coding Conventions?
245
246 .. todo:: document such files in subdirectories, at least :samp:`config`,
247 :samp:`c`, :samp:`cp`, :samp:`objc`, :samp:`testsuite`.