diff options
author | Jonathan Corbet <corbet@lwn.net> | 2016-11-19 12:28:58 -0500 |
---|---|---|
committer | Jonathan Corbet <corbet@lwn.net> | 2016-11-19 12:28:58 -0500 |
commit | ca9667fcc855676aa5c35978f201034d38790829 (patch) | |
tree | f52523e399b6938fd79b0b0c25b3c55e27600e55 /Documentation/doc-guide | |
parent | 38f985e3c9bb33d5422103807eb0a54f4ad39a0d (diff) | |
parent | 2dde123b23ceba4b6d0d780b4e9fdcfb94621747 (diff) |
Merge branch 'mauro-doc' into docs-next
Diffstat (limited to 'Documentation/doc-guide')
-rw-r--r-- | Documentation/doc-guide/conf.py | 10 | ||||
-rw-r--r-- | Documentation/doc-guide/docbook.rst | 90 | ||||
-rw-r--r-- | Documentation/doc-guide/index.rst | 20 | ||||
-rw-r--r-- | Documentation/doc-guide/kernel-doc.rst | 368 | ||||
-rw-r--r-- | Documentation/doc-guide/parse-headers.rst | 208 | ||||
-rw-r--r-- | Documentation/doc-guide/sphinx.rst | 219 |
6 files changed, 915 insertions, 0 deletions
diff --git a/Documentation/doc-guide/conf.py b/Documentation/doc-guide/conf.py new file mode 100644 index 000000000000..fd3731182d5a --- /dev/null +++ b/Documentation/doc-guide/conf.py | |||
@@ -0,0 +1,10 @@ | |||
1 | # -*- coding: utf-8; mode: python -*- | ||
2 | |||
3 | project = 'Linux Kernel Documentation Guide' | ||
4 | |||
5 | tags.add("subproject") | ||
6 | |||
7 | latex_documents = [ | ||
8 | ('index', 'kernel-doc-guide.tex', 'Linux Kernel Documentation Guide', | ||
9 | 'The kernel development community', 'manual'), | ||
10 | ] | ||
diff --git a/Documentation/doc-guide/docbook.rst b/Documentation/doc-guide/docbook.rst new file mode 100644 index 000000000000..d8bf04308b43 --- /dev/null +++ b/Documentation/doc-guide/docbook.rst | |||
@@ -0,0 +1,90 @@ | |||
1 | DocBook XML [DEPRECATED] | ||
2 | ======================== | ||
3 | |||
4 | .. attention:: | ||
5 | |||
6 | This section describes the deprecated DocBook XML toolchain. Please do not | ||
7 | create new DocBook XML template files. Please consider converting existing | ||
8 | DocBook XML templates files to Sphinx/reStructuredText. | ||
9 | |||
10 | Converting DocBook to Sphinx | ||
11 | ---------------------------- | ||
12 | |||
13 | Over time, we expect all of the documents under ``Documentation/DocBook`` to be | ||
14 | converted to Sphinx and reStructuredText. For most DocBook XML documents, a good | ||
15 | enough solution is to use the simple ``Documentation/sphinx/tmplcvt`` script, | ||
16 | which uses ``pandoc`` under the hood. For example:: | ||
17 | |||
18 | $ cd Documentation/sphinx | ||
19 | $ ./tmplcvt ../DocBook/in.tmpl ../out.rst | ||
20 | |||
21 | Then edit the resulting rst files to fix any remaining issues, and add the | ||
22 | document in the ``toctree`` in ``Documentation/index.rst``. | ||
23 | |||
24 | Components of the kernel-doc system | ||
25 | ----------------------------------- | ||
26 | |||
27 | Many places in the source tree have extractable documentation in the form of | ||
28 | block comments above functions. The components of this system are: | ||
29 | |||
30 | - ``scripts/kernel-doc`` | ||
31 | |||
32 | This is a perl script that hunts for the block comments and can mark them up | ||
33 | directly into reStructuredText, DocBook, man, text, and HTML. (No, not | ||
34 | texinfo.) | ||
35 | |||
36 | - ``Documentation/DocBook/*.tmpl`` | ||
37 | |||
38 | These are XML template files, which are normal XML files with special | ||
39 | place-holders for where the extracted documentation should go. | ||
40 | |||
41 | - ``scripts/docproc.c`` | ||
42 | |||
43 | This is a program for converting XML template files into XML files. When a | ||
44 | file is referenced it is searched for symbols exported (EXPORT_SYMBOL), to be | ||
45 | able to distinguish between internal and external functions. | ||
46 | |||
47 | It invokes kernel-doc, giving it the list of functions that are to be | ||
48 | documented. | ||
49 | |||
50 | Additionally it is used to scan the XML template files to locate all the files | ||
51 | referenced herein. This is used to generate dependency information as used by | ||
52 | make. | ||
53 | |||
54 | - ``Makefile`` | ||
55 | |||
56 | The targets 'xmldocs', 'psdocs', 'pdfdocs', and 'htmldocs' are used to build | ||
57 | DocBook XML files, PostScript files, PDF files, and html files in | ||
58 | Documentation/DocBook. The older target 'sgmldocs' is equivalent to 'xmldocs'. | ||
59 | |||
60 | - ``Documentation/DocBook/Makefile`` | ||
61 | |||
62 | This is where C files are associated with SGML templates. | ||
63 | |||
64 | How to use kernel-doc comments in DocBook XML template files | ||
65 | ------------------------------------------------------------ | ||
66 | |||
67 | DocBook XML template files (\*.tmpl) are like normal XML files, except that they | ||
68 | can contain escape sequences where extracted documentation should be inserted. | ||
69 | |||
70 | ``!E<filename>`` is replaced by the documentation, in ``<filename>``, for | ||
71 | functions that are exported using ``EXPORT_SYMBOL``: the function list is | ||
72 | collected from files listed in ``Documentation/DocBook/Makefile``. | ||
73 | |||
74 | ``!I<filename>`` is replaced by the documentation for functions that are **not** | ||
75 | exported using ``EXPORT_SYMBOL``. | ||
76 | |||
77 | ``!D<filename>`` is used to name additional files to search for functions | ||
78 | exported using ``EXPORT_SYMBOL``. | ||
79 | |||
80 | ``!F<filename> <function [functions...]>`` is replaced by the documentation, in | ||
81 | ``<filename>``, for the functions listed. | ||
82 | |||
83 | ``!P<filename> <section title>`` is replaced by the contents of the ``DOC:`` | ||
84 | section titled ``<section title>`` from ``<filename>``. Spaces are allowed in | ||
85 | ``<section title>``; do not quote the ``<section title>``. | ||
86 | |||
87 | ``!C<filename>`` is replaced by nothing, but makes the tools check that all DOC: | ||
88 | sections and documented functions, symbols, etc. are used. This makes sense to | ||
89 | use when you use ``!F`` or ``!P`` only and want to verify that all documentation | ||
90 | is included. | ||
diff --git a/Documentation/doc-guide/index.rst b/Documentation/doc-guide/index.rst new file mode 100644 index 000000000000..6fff4024606e --- /dev/null +++ b/Documentation/doc-guide/index.rst | |||
@@ -0,0 +1,20 @@ | |||
1 | .. _doc_guide: | ||
2 | |||
3 | ================================= | ||
4 | How to write kernel documentation | ||
5 | ================================= | ||
6 | |||
7 | .. toctree:: | ||
8 | :maxdepth: 1 | ||
9 | |||
10 | sphinx.rst | ||
11 | kernel-doc.rst | ||
12 | parse-headers.rst | ||
13 | docbook.rst | ||
14 | |||
15 | .. only:: subproject and html | ||
16 | |||
17 | Indices | ||
18 | ======= | ||
19 | |||
20 | * :ref:`genindex` | ||
diff --git a/Documentation/doc-guide/kernel-doc.rst b/Documentation/doc-guide/kernel-doc.rst new file mode 100644 index 000000000000..b32e4813ff6f --- /dev/null +++ b/Documentation/doc-guide/kernel-doc.rst | |||
@@ -0,0 +1,368 @@ | |||
1 | Including kernel-doc comments | ||
2 | ============================= | ||
3 | |||
4 | The Linux kernel source files may contain structured documentation comments, or | ||
5 | kernel-doc comments to describe the functions and types and design of the | ||
6 | code. The documentation comments may be included to any of the reStructuredText | ||
7 | documents using a dedicated kernel-doc Sphinx directive extension. | ||
8 | |||
9 | The kernel-doc directive is of the format:: | ||
10 | |||
11 | .. kernel-doc:: source | ||
12 | :option: | ||
13 | |||
14 | The *source* is the path to a source file, relative to the kernel source | ||
15 | tree. The following directive options are supported: | ||
16 | |||
17 | export: *[source-pattern ...]* | ||
18 | Include documentation for all functions in *source* that have been exported | ||
19 | using ``EXPORT_SYMBOL`` or ``EXPORT_SYMBOL_GPL`` either in *source* or in any | ||
20 | of the files specified by *source-pattern*. | ||
21 | |||
22 | The *source-pattern* is useful when the kernel-doc comments have been placed | ||
23 | in header files, while ``EXPORT_SYMBOL`` and ``EXPORT_SYMBOL_GPL`` are next to | ||
24 | the function definitions. | ||
25 | |||
26 | Examples:: | ||
27 | |||
28 | .. kernel-doc:: lib/bitmap.c | ||
29 | :export: | ||
30 | |||
31 | .. kernel-doc:: include/net/mac80211.h | ||
32 | :export: net/mac80211/*.c | ||
33 | |||
34 | internal: *[source-pattern ...]* | ||
35 | Include documentation for all functions and types in *source* that have | ||
36 | **not** been exported using ``EXPORT_SYMBOL`` or ``EXPORT_SYMBOL_GPL`` either | ||
37 | in *source* or in any of the files specified by *source-pattern*. | ||
38 | |||
39 | Example:: | ||
40 | |||
41 | .. kernel-doc:: drivers/gpu/drm/i915/intel_audio.c | ||
42 | :internal: | ||
43 | |||
44 | doc: *title* | ||
45 | Include documentation for the ``DOC:`` paragraph identified by *title* in | ||
46 | *source*. Spaces are allowed in *title*; do not quote the *title*. The *title* | ||
47 | is only used as an identifier for the paragraph, and is not included in the | ||
48 | output. Please make sure to have an appropriate heading in the enclosing | ||
49 | reStructuredText document. | ||
50 | |||
51 | Example:: | ||
52 | |||
53 | .. kernel-doc:: drivers/gpu/drm/i915/intel_audio.c | ||
54 | :doc: High Definition Audio over HDMI and Display Port | ||
55 | |||
56 | functions: *function* *[...]* | ||
57 | Include documentation for each *function* in *source*. | ||
58 | |||
59 | Example:: | ||
60 | |||
61 | .. kernel-doc:: lib/bitmap.c | ||
62 | :functions: bitmap_parselist bitmap_parselist_user | ||
63 | |||
64 | Without options, the kernel-doc directive includes all documentation comments | ||
65 | from the source file. | ||
66 | |||
67 | The kernel-doc extension is included in the kernel source tree, at | ||
68 | ``Documentation/sphinx/kernel-doc.py``. Internally, it uses the | ||
69 | ``scripts/kernel-doc`` script to extract the documentation comments from the | ||
70 | source. | ||
71 | |||
72 | .. _kernel_doc: | ||
73 | |||
74 | Writing kernel-doc comments | ||
75 | =========================== | ||
76 | |||
77 | In order to provide embedded, "C" friendly, easy to maintain, but consistent and | ||
78 | extractable overview, function and type documentation, the Linux kernel has | ||
79 | adopted a consistent style for documentation comments. The format for this | ||
80 | documentation is called the kernel-doc format, described below. This style | ||
81 | embeds the documentation within the source files, using a few simple conventions | ||
82 | for adding documentation paragraphs and documenting functions and their | ||
83 | parameters, structures and unions and their members, enumerations, and typedefs. | ||
84 | |||
85 | .. note:: The kernel-doc format is deceptively similar to gtk-doc or Doxygen, | ||
86 | yet distinctively different, for historical reasons. The kernel source | ||
87 | contains tens of thousands of kernel-doc comments. Please stick to the style | ||
88 | described here. | ||
89 | |||
90 | The ``scripts/kernel-doc`` script is used by the Sphinx kernel-doc extension in | ||
91 | the documentation build to extract this embedded documentation into the various | ||
92 | HTML, PDF, and other format documents. | ||
93 | |||
94 | In order to provide good documentation of kernel functions and data structures, | ||
95 | please use the following conventions to format your kernel-doc comments in the | ||
96 | Linux kernel source. | ||
97 | |||
98 | How to format kernel-doc comments | ||
99 | --------------------------------- | ||
100 | |||
101 | The opening comment mark ``/**`` is reserved for kernel-doc comments. Only | ||
102 | comments so marked will be considered by the ``kernel-doc`` tool. Use it only | ||
103 | for comment blocks that contain kernel-doc formatted comments. The usual ``*/`` | ||
104 | should be used as the closing comment marker. The lines in between should be | ||
105 | prefixed by ``Â *Â `` (space star space). | ||
106 | |||
107 | The function and type kernel-doc comments should be placed just before the | ||
108 | function or type being described. The overview kernel-doc comments may be freely | ||
109 | placed at the top indentation level. | ||
110 | |||
111 | Example kernel-doc function comment:: | ||
112 | |||
113 | /** | ||
114 | * foobar() - Brief description of foobar. | ||
115 | * @arg: Description of argument of foobar. | ||
116 | * | ||
117 | * Longer description of foobar. | ||
118 | * | ||
119 | * Return: Description of return value of foobar. | ||
120 | */ | ||
121 | int foobar(int arg) | ||
122 | |||
123 | The format is similar for documentation for structures, enums, paragraphs, | ||
124 | etc. See the sections below for details. | ||
125 | |||
126 | The kernel-doc structure is extracted from the comments, and proper `Sphinx C | ||
127 | Domain`_ function and type descriptions with anchors are generated for them. The | ||
128 | descriptions are filtered for special kernel-doc highlights and | ||
129 | cross-references. See below for details. | ||
130 | |||
131 | .. _Sphinx C Domain: http://www.sphinx-doc.org/en/stable/domains.html | ||
132 | |||
133 | Highlights and cross-references | ||
134 | ------------------------------- | ||
135 | |||
136 | The following special patterns are recognized in the kernel-doc comment | ||
137 | descriptive text and converted to proper reStructuredText markup and `Sphinx C | ||
138 | Domain`_ references. | ||
139 | |||
140 | .. attention:: The below are **only** recognized within kernel-doc comments, | ||
141 | **not** within normal reStructuredText documents. | ||
142 | |||
143 | ``funcname()`` | ||
144 | Function reference. | ||
145 | |||
146 | ``@parameter`` | ||
147 | Name of a function parameter. (No cross-referencing, just formatting.) | ||
148 | |||
149 | ``%CONST`` | ||
150 | Name of a constant. (No cross-referencing, just formatting.) | ||
151 | |||
152 | ``$ENVVAR`` | ||
153 | Name of an environment variable. (No cross-referencing, just formatting.) | ||
154 | |||
155 | ``&struct name`` | ||
156 | Structure reference. | ||
157 | |||
158 | ``&enum name`` | ||
159 | Enum reference. | ||
160 | |||
161 | ``&typedef name`` | ||
162 | Typedef reference. | ||
163 | |||
164 | ``&struct_name->member`` or ``&struct_name.member`` | ||
165 | Structure or union member reference. The cross-reference will be to the struct | ||
166 | or union definition, not the member directly. | ||
167 | |||
168 | ``&name`` | ||
169 | A generic type reference. Prefer using the full reference described above | ||
170 | instead. This is mostly for legacy comments. | ||
171 | |||
172 | Cross-referencing from reStructuredText | ||
173 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
174 | |||
175 | To cross-reference the functions and types defined in the kernel-doc comments | ||
176 | from reStructuredText documents, please use the `Sphinx C Domain`_ | ||
177 | references. For example:: | ||
178 | |||
179 | See function :c:func:`foo` and struct/union/enum/typedef :c:type:`bar`. | ||
180 | |||
181 | While the type reference works with just the type name, without the | ||
182 | struct/union/enum/typedef part in front, you may want to use:: | ||
183 | |||
184 | See :c:type:`struct foo <foo>`. | ||
185 | See :c:type:`union bar <bar>`. | ||
186 | See :c:type:`enum baz <baz>`. | ||
187 | See :c:type:`typedef meh <meh>`. | ||
188 | |||
189 | This will produce prettier links, and is in line with how kernel-doc does the | ||
190 | cross-references. | ||
191 | |||
192 | For further details, please refer to the `Sphinx C Domain`_ documentation. | ||
193 | |||
194 | Function documentation | ||
195 | ---------------------- | ||
196 | |||
197 | The general format of a function and function-like macro kernel-doc comment is:: | ||
198 | |||
199 | /** | ||
200 | * function_name() - Brief description of function. | ||
201 | * @arg1: Describe the first argument. | ||
202 | * @arg2: Describe the second argument. | ||
203 | * One can provide multiple line descriptions | ||
204 | * for arguments. | ||
205 | * | ||
206 | * A longer description, with more discussion of the function function_name() | ||
207 | * that might be useful to those using or modifying it. Begins with an | ||
208 | * empty comment line, and may include additional embedded empty | ||
209 | * comment lines. | ||
210 | * | ||
211 | * The longer description may have multiple paragraphs. | ||
212 | * | ||
213 | * Return: Describe the return value of foobar. | ||
214 | * | ||
215 | * The return value description can also have multiple paragraphs, and should | ||
216 | * be placed at the end of the comment block. | ||
217 | */ | ||
218 | |||
219 | The brief description following the function name may span multiple lines, and | ||
220 | ends with an ``@argument:`` description, a blank comment line, or the end of the | ||
221 | comment block. | ||
222 | |||
223 | The kernel-doc function comments describe each parameter to the function, in | ||
224 | order, with the ``@argument:`` descriptions. The ``@argument:`` descriptions | ||
225 | must begin on the very next line following the opening brief function | ||
226 | description line, with no intervening blank comment lines. The ``@argument:`` | ||
227 | descriptions may span multiple lines. The continuation lines may contain | ||
228 | indentation. If a function parameter is ``...`` (varargs), it should be listed | ||
229 | in kernel-doc notation as: ``@...:``. | ||
230 | |||
231 | The return value, if any, should be described in a dedicated section at the end | ||
232 | of the comment starting with "Return:". | ||
233 | |||
234 | Structure, union, and enumeration documentation | ||
235 | ----------------------------------------------- | ||
236 | |||
237 | The general format of a struct, union, and enum kernel-doc comment is:: | ||
238 | |||
239 | /** | ||
240 | * struct struct_name - Brief description. | ||
241 | * @member_name: Description of member member_name. | ||
242 | * | ||
243 | * Description of the structure. | ||
244 | */ | ||
245 | |||
246 | Below, "struct" is used to mean structs, unions and enums, and "member" is used | ||
247 | to mean struct and union members as well as enumerations in an enum. | ||
248 | |||
249 | The brief description following the structure name may span multiple lines, and | ||
250 | ends with a ``@member:`` description, a blank comment line, or the end of the | ||
251 | comment block. | ||
252 | |||
253 | The kernel-doc data structure comments describe each member of the structure, in | ||
254 | order, with the ``@member:`` descriptions. The ``@member:`` descriptions must | ||
255 | begin on the very next line following the opening brief function description | ||
256 | line, with no intervening blank comment lines. The ``@member:`` descriptions may | ||
257 | span multiple lines. The continuation lines may contain indentation. | ||
258 | |||
259 | In-line member documentation comments | ||
260 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
261 | |||
262 | The structure members may also be documented in-line within the definition. | ||
263 | There are two styles, single-line comments where both the opening ``/**`` and | ||
264 | closing ``*/`` are on the same line, and multi-line comments where they are each | ||
265 | on a line of their own, like all other kernel-doc comments:: | ||
266 | |||
267 | /** | ||
268 | * struct foo - Brief description. | ||
269 | * @foo: The Foo member. | ||
270 | */ | ||
271 | struct foo { | ||
272 | int foo; | ||
273 | /** | ||
274 | * @bar: The Bar member. | ||
275 | */ | ||
276 | int bar; | ||
277 | /** | ||
278 | * @baz: The Baz member. | ||
279 | * | ||
280 | * Here, the member description may contain several paragraphs. | ||
281 | */ | ||
282 | int baz; | ||
283 | /** @foobar: Single line description. */ | ||
284 | int foobar; | ||
285 | } | ||
286 | |||
287 | Private members | ||
288 | ~~~~~~~~~~~~~~~ | ||
289 | |||
290 | Inside a struct description, you can use the "private:" and "public:" comment | ||
291 | tags. Structure fields that are inside a "private:" area are not listed in the | ||
292 | generated output documentation. The "private:" and "public:" tags must begin | ||
293 | immediately following a ``/*`` comment marker. They may optionally include | ||
294 | comments between the ``:`` and the ending ``*/`` marker. | ||
295 | |||
296 | Example:: | ||
297 | |||
298 | /** | ||
299 | * struct my_struct - short description | ||
300 | * @a: first member | ||
301 | * @b: second member | ||
302 | * | ||
303 | * Longer description | ||
304 | */ | ||
305 | struct my_struct { | ||
306 | int a; | ||
307 | int b; | ||
308 | /* private: internal use only */ | ||
309 | int c; | ||
310 | }; | ||
311 | |||
312 | |||
313 | Typedef documentation | ||
314 | --------------------- | ||
315 | |||
316 | The general format of a typedef kernel-doc comment is:: | ||
317 | |||
318 | /** | ||
319 | * typedef type_name - Brief description. | ||
320 | * | ||
321 | * Description of the type. | ||
322 | */ | ||
323 | |||
324 | Overview documentation comments | ||
325 | ------------------------------- | ||
326 | |||
327 | To facilitate having source code and comments close together, you can include | ||
328 | kernel-doc documentation blocks that are free-form comments instead of being | ||
329 | kernel-doc for functions, structures, unions, enums, or typedefs. This could be | ||
330 | used for something like a theory of operation for a driver or library code, for | ||
331 | example. | ||
332 | |||
333 | This is done by using a ``DOC:`` section keyword with a section title. | ||
334 | |||
335 | The general format of an overview or high-level documentation comment is:: | ||
336 | |||
337 | /** | ||
338 | * DOC: Theory of Operation | ||
339 | * | ||
340 | * The whizbang foobar is a dilly of a gizmo. It can do whatever you | ||
341 | * want it to do, at any time. It reads your mind. Here's how it works. | ||
342 | * | ||
343 | * foo bar splat | ||
344 | * | ||
345 | * The only drawback to this gizmo is that is can sometimes damage | ||
346 | * hardware, software, or its subject(s). | ||
347 | */ | ||
348 | |||
349 | The title following ``DOC:`` acts as a heading within the source file, but also | ||
350 | as an identifier for extracting the documentation comment. Thus, the title must | ||
351 | be unique within the file. | ||
352 | |||
353 | Recommendations | ||
354 | --------------- | ||
355 | |||
356 | We definitely need kernel-doc formatted documentation for functions that are | ||
357 | exported to loadable modules using ``EXPORT_SYMBOL`` or ``EXPORT_SYMBOL_GPL``. | ||
358 | |||
359 | We also look to provide kernel-doc formatted documentation for functions | ||
360 | externally visible to other kernel files (not marked "static"). | ||
361 | |||
362 | We also recommend providing kernel-doc formatted documentation for private (file | ||
363 | "static") routines, for consistency of kernel source code layout. But this is | ||
364 | lower priority and at the discretion of the MAINTAINER of that kernel source | ||
365 | file. | ||
366 | |||
367 | Data structures visible in kernel include files should also be documented using | ||
368 | kernel-doc formatted comments. | ||
diff --git a/Documentation/doc-guide/parse-headers.rst b/Documentation/doc-guide/parse-headers.rst new file mode 100644 index 000000000000..615e25ec64bb --- /dev/null +++ b/Documentation/doc-guide/parse-headers.rst | |||
@@ -0,0 +1,208 @@ | |||
1 | =========================== | ||
2 | Including uAPI header files | ||
3 | =========================== | ||
4 | |||
5 | Sometimes, it is useful to include header files and C example codes in | ||
6 | order to describe the userspace API and to generate cross-references | ||
7 | between the code and the documentation. Adding cross-references for | ||
8 | userspace API files has an additional vantage: Sphinx will generate warnings | ||
9 | if a symbol is not found at the documentation. That helps to keep the | ||
10 | uAPI documentation in sync with the Kernel changes. | ||
11 | The :ref:`parse_headers.pl <parse_headers>` provide a way to generate such | ||
12 | cross-references. It has to be called via Makefile, while building the | ||
13 | documentation. Please see ``Documentation/media/Makefile`` for an example | ||
14 | about how to use it inside the Kernel tree. | ||
15 | |||
16 | .. _parse_headers: | ||
17 | |||
18 | parse_headers.pl | ||
19 | ^^^^^^^^^^^^^^^^ | ||
20 | |||
21 | .. NOTE: the man pages below were generated using pod2rst tool: | ||
22 | .. http://search.cpan.org/~dowens/Pod-POM-View-Restructured-0.02/bin/pod2rst | ||
23 | .. If you need to change anything below this point, please do the changes | ||
24 | .. at parse-headers.pl directly, re-run the script and paste the output of | ||
25 | .. the script here. | ||
26 | |||
27 | **** | ||
28 | NAME | ||
29 | **** | ||
30 | |||
31 | |||
32 | parse_headers.pl - parse a C file, in order to identify functions, structs, | ||
33 | enums and defines and create cross-references to a Sphinx book. | ||
34 | |||
35 | |||
36 | ******** | ||
37 | SYNOPSIS | ||
38 | ******** | ||
39 | |||
40 | |||
41 | \ **parse_headers.pl**\ [<options>] <C_FILE> <OUT_FILE> [<EXCEPTIONS_FILE>] | ||
42 | |||
43 | Where <options> can be: --debug, --help or --man. | ||
44 | |||
45 | |||
46 | ******* | ||
47 | OPTIONS | ||
48 | ******* | ||
49 | |||
50 | |||
51 | |||
52 | \ **--debug**\ | ||
53 | |||
54 | Put the script in verbose mode, useful for debugging. | ||
55 | |||
56 | |||
57 | |||
58 | \ **--help**\ | ||
59 | |||
60 | Prints a brief help message and exits. | ||
61 | |||
62 | |||
63 | |||
64 | \ **--man**\ | ||
65 | |||
66 | Prints the manual page and exits. | ||
67 | |||
68 | |||
69 | |||
70 | |||
71 | *********** | ||
72 | DESCRIPTION | ||
73 | *********** | ||
74 | |||
75 | |||
76 | Convert a C header or source file (C_FILE), into a ReStructured Text | ||
77 | included via ..parsed-literal block with cross-references for the | ||
78 | documentation files that describe the API. It accepts an optional | ||
79 | EXCEPTIONS_FILE with describes what elements will be either ignored or | ||
80 | be pointed to a non-default reference. | ||
81 | |||
82 | The output is written at the (OUT_FILE). | ||
83 | |||
84 | It is capable of identifying defines, functions, structs, typedefs, | ||
85 | enums and enum symbols and create cross-references for all of them. | ||
86 | It is also capable of distinguish #define used for specifying a Linux | ||
87 | ioctl. | ||
88 | |||
89 | The EXCEPTIONS_FILE contain two types of statements: \ **ignore**\ or \ **replace**\ . | ||
90 | |||
91 | The syntax for the ignore tag is: | ||
92 | |||
93 | |||
94 | ignore \ **type**\ \ **name**\ | ||
95 | |||
96 | The \ **ignore**\ means that it won't generate cross references for a | ||
97 | \ **name**\ symbol of type \ **type**\ . | ||
98 | |||
99 | The syntax for the replace tag is: | ||
100 | |||
101 | |||
102 | replace \ **type**\ \ **name**\ \ **new_value**\ | ||
103 | |||
104 | The \ **replace**\ means that it will generate cross references for a | ||
105 | \ **name**\ symbol of type \ **type**\ , but, instead of using the default | ||
106 | replacement rule, it will use \ **new_value**\ . | ||
107 | |||
108 | For both statements, \ **type**\ can be either one of the following: | ||
109 | |||
110 | |||
111 | \ **ioctl**\ | ||
112 | |||
113 | The ignore or replace statement will apply to ioctl definitions like: | ||
114 | |||
115 | #define VIDIOC_DBG_S_REGISTER _IOW('V', 79, struct v4l2_dbg_register) | ||
116 | |||
117 | |||
118 | |||
119 | \ **define**\ | ||
120 | |||
121 | The ignore or replace statement will apply to any other #define found | ||
122 | at C_FILE. | ||
123 | |||
124 | |||
125 | |||
126 | \ **typedef**\ | ||
127 | |||
128 | The ignore or replace statement will apply to typedef statements at C_FILE. | ||
129 | |||
130 | |||
131 | |||
132 | \ **struct**\ | ||
133 | |||
134 | The ignore or replace statement will apply to the name of struct statements | ||
135 | at C_FILE. | ||
136 | |||
137 | |||
138 | |||
139 | \ **enum**\ | ||
140 | |||
141 | The ignore or replace statement will apply to the name of enum statements | ||
142 | at C_FILE. | ||
143 | |||
144 | |||
145 | |||
146 | \ **symbol**\ | ||
147 | |||
148 | The ignore or replace statement will apply to the name of enum statements | ||
149 | at C_FILE. | ||
150 | |||
151 | For replace statements, \ **new_value**\ will automatically use :c:type: | ||
152 | references for \ **typedef**\ , \ **enum**\ and \ **struct**\ types. It will use :ref: | ||
153 | for \ **ioctl**\ , \ **define**\ and \ **symbol**\ types. The type of reference can | ||
154 | also be explicitly defined at the replace statement. | ||
155 | |||
156 | |||
157 | |||
158 | |||
159 | ******** | ||
160 | EXAMPLES | ||
161 | ******** | ||
162 | |||
163 | |||
164 | ignore define _VIDEODEV2_H | ||
165 | |||
166 | |||
167 | Ignore a #define _VIDEODEV2_H at the C_FILE. | ||
168 | |||
169 | ignore symbol PRIVATE | ||
170 | |||
171 | |||
172 | On a struct like: | ||
173 | |||
174 | enum foo { BAR1, BAR2, PRIVATE }; | ||
175 | |||
176 | It won't generate cross-references for \ **PRIVATE**\ . | ||
177 | |||
178 | replace symbol BAR1 :c:type:\`foo\` | ||
179 | replace symbol BAR2 :c:type:\`foo\` | ||
180 | |||
181 | |||
182 | On a struct like: | ||
183 | |||
184 | enum foo { BAR1, BAR2, PRIVATE }; | ||
185 | |||
186 | It will make the BAR1 and BAR2 enum symbols to cross reference the foo | ||
187 | symbol at the C domain. | ||
188 | |||
189 | |||
190 | **** | ||
191 | BUGS | ||
192 | **** | ||
193 | |||
194 | |||
195 | Report bugs to Mauro Carvalho Chehab <mchehab@s-opensource.com> | ||
196 | |||
197 | |||
198 | ********* | ||
199 | COPYRIGHT | ||
200 | ********* | ||
201 | |||
202 | |||
203 | Copyright (c) 2016 by Mauro Carvalho Chehab <mchehab@s-opensource.com>. | ||
204 | |||
205 | License GPLv2: GNU GPL version 2 <http://gnu.org/licenses/gpl.html>. | ||
206 | |||
207 | This is free software: you are free to change and redistribute it. | ||
208 | There is NO WARRANTY, to the extent permitted by law. | ||
diff --git a/Documentation/doc-guide/sphinx.rst b/Documentation/doc-guide/sphinx.rst new file mode 100644 index 000000000000..96fe7ccb2c67 --- /dev/null +++ b/Documentation/doc-guide/sphinx.rst | |||
@@ -0,0 +1,219 @@ | |||
1 | Introduction | ||
2 | ============ | ||
3 | |||
4 | The Linux kernel uses `Sphinx`_ to generate pretty documentation from | ||
5 | `reStructuredText`_ files under ``Documentation``. To build the documentation in | ||
6 | HTML or PDF formats, use ``make htmldocs`` or ``make pdfdocs``. The generated | ||
7 | documentation is placed in ``Documentation/output``. | ||
8 | |||
9 | .. _Sphinx: http://www.sphinx-doc.org/ | ||
10 | .. _reStructuredText: http://docutils.sourceforge.net/rst.html | ||
11 | |||
12 | The reStructuredText files may contain directives to include structured | ||
13 | documentation comments, or kernel-doc comments, from source files. Usually these | ||
14 | are used to describe the functions and types and design of the code. The | ||
15 | kernel-doc comments have some special structure and formatting, but beyond that | ||
16 | they are also treated as reStructuredText. | ||
17 | |||
18 | There is also the deprecated DocBook toolchain to generate documentation from | ||
19 | DocBook XML template files under ``Documentation/DocBook``. The DocBook files | ||
20 | are to be converted to reStructuredText, and the toolchain is slated to be | ||
21 | removed. | ||
22 | |||
23 | Finally, there are thousands of plain text documentation files scattered around | ||
24 | ``Documentation``. Some of these will likely be converted to reStructuredText | ||
25 | over time, but the bulk of them will remain in plain text. | ||
26 | |||
27 | Sphinx Build | ||
28 | ============ | ||
29 | |||
30 | The usual way to generate the documentation is to run ``make htmldocs`` or | ||
31 | ``make pdfdocs``. There are also other formats available, see the documentation | ||
32 | section of ``make help``. The generated documentation is placed in | ||
33 | format-specific subdirectories under ``Documentation/output``. | ||
34 | |||
35 | To generate documentation, Sphinx (``sphinx-build``) must obviously be | ||
36 | installed. For prettier HTML output, the Read the Docs Sphinx theme | ||
37 | (``sphinx_rtd_theme``) is used if available. For PDF output, ``rst2pdf`` is also | ||
38 | needed. All of these are widely available and packaged in distributions. | ||
39 | |||
40 | To pass extra options to Sphinx, you can use the ``SPHINXOPTS`` make | ||
41 | variable. For example, use ``make SPHINXOPTS=-v htmldocs`` to get more verbose | ||
42 | output. | ||
43 | |||
44 | To remove the generated documentation, run ``make cleandocs``. | ||
45 | |||
46 | Writing Documentation | ||
47 | ===================== | ||
48 | |||
49 | Adding new documentation can be as simple as: | ||
50 | |||
51 | 1. Add a new ``.rst`` file somewhere under ``Documentation``. | ||
52 | 2. Refer to it from the Sphinx main `TOC tree`_ in ``Documentation/index.rst``. | ||
53 | |||
54 | .. _TOC tree: http://www.sphinx-doc.org/en/stable/markup/toctree.html | ||
55 | |||
56 | This is usually good enough for simple documentation (like the one you're | ||
57 | reading right now), but for larger documents it may be advisable to create a | ||
58 | subdirectory (or use an existing one). For example, the graphics subsystem | ||
59 | documentation is under ``Documentation/gpu``, split to several ``.rst`` files, | ||
60 | and has a separate ``index.rst`` (with a ``toctree`` of its own) referenced from | ||
61 | the main index. | ||
62 | |||
63 | See the documentation for `Sphinx`_ and `reStructuredText`_ on what you can do | ||
64 | with them. In particular, the Sphinx `reStructuredText Primer`_ is a good place | ||
65 | to get started with reStructuredText. There are also some `Sphinx specific | ||
66 | markup constructs`_. | ||
67 | |||
68 | .. _reStructuredText Primer: http://www.sphinx-doc.org/en/stable/rest.html | ||
69 | .. _Sphinx specific markup constructs: http://www.sphinx-doc.org/en/stable/markup/index.html | ||
70 | |||
71 | Specific guidelines for the kernel documentation | ||
72 | ------------------------------------------------ | ||
73 | |||
74 | Here are some specific guidelines for the kernel documentation: | ||
75 | |||
76 | * Please don't go overboard with reStructuredText markup. Keep it simple. | ||
77 | |||
78 | * Please stick to this order of heading adornments: | ||
79 | |||
80 | 1. ``=`` with overline for document title:: | ||
81 | |||
82 | ============== | ||
83 | Document title | ||
84 | ============== | ||
85 | |||
86 | 2. ``=`` for chapters:: | ||
87 | |||
88 | Chapters | ||
89 | ======== | ||
90 | |||
91 | 3. ``-`` for sections:: | ||
92 | |||
93 | Section | ||
94 | ------- | ||
95 | |||
96 | 4. ``~`` for subsections:: | ||
97 | |||
98 | Subsection | ||
99 | ~~~~~~~~~~ | ||
100 | |||
101 | Although RST doesn't mandate a specific order ("Rather than imposing a fixed | ||
102 | number and order of section title adornment styles, the order enforced will be | ||
103 | the order as encountered."), having the higher levels the same overall makes | ||
104 | it easier to follow the documents. | ||
105 | |||
106 | |||
107 | the C domain | ||
108 | ------------ | ||
109 | |||
110 | The `Sphinx C Domain`_ (name c) is suited for documentation of C API. E.g. a | ||
111 | function prototype: | ||
112 | |||
113 | .. code-block:: rst | ||
114 | |||
115 | .. c:function:: int ioctl( int fd, int request ) | ||
116 | |||
117 | The C domain of the kernel-doc has some additional features. E.g. you can | ||
118 | *rename* the reference name of a function with a common name like ``open`` or | ||
119 | ``ioctl``: | ||
120 | |||
121 | .. code-block:: rst | ||
122 | |||
123 | .. c:function:: int ioctl( int fd, int request ) | ||
124 | :name: VIDIOC_LOG_STATUS | ||
125 | |||
126 | The func-name (e.g. ioctl) remains in the output but the ref-name changed from | ||
127 | ``ioctl`` to ``VIDIOC_LOG_STATUS``. The index entry for this function is also | ||
128 | changed to ``VIDIOC_LOG_STATUS`` and the function can now referenced by: | ||
129 | |||
130 | .. code-block:: rst | ||
131 | |||
132 | :c:func:`VIDIOC_LOG_STATUS` | ||
133 | |||
134 | |||
135 | list tables | ||
136 | ----------- | ||
137 | |||
138 | We recommend the use of *list table* formats. The *list table* formats are | ||
139 | double-stage lists. Compared to the ASCII-art they might not be as | ||
140 | comfortable for | ||
141 | readers of the text files. Their advantage is that they are easy to | ||
142 | create or modify and that the diff of a modification is much more meaningful, | ||
143 | because it is limited to the modified content. | ||
144 | |||
145 | The ``flat-table`` is a double-stage list similar to the ``list-table`` with | ||
146 | some additional features: | ||
147 | |||
148 | * column-span: with the role ``cspan`` a cell can be extended through | ||
149 | additional columns | ||
150 | |||
151 | * row-span: with the role ``rspan`` a cell can be extended through | ||
152 | additional rows | ||
153 | |||
154 | * auto span rightmost cell of a table row over the missing cells on the right | ||
155 | side of that table-row. With Option ``:fill-cells:`` this behavior can | ||
156 | changed from *auto span* to *auto fill*, which automatically inserts (empty) | ||
157 | cells instead of spanning the last cell. | ||
158 | |||
159 | options: | ||
160 | |||
161 | * ``:header-rows:`` [int] count of header rows | ||
162 | * ``:stub-columns:`` [int] count of stub columns | ||
163 | * ``:widths:`` [[int] [int] ... ] widths of columns | ||
164 | * ``:fill-cells:`` instead of auto-spanning missing cells, insert missing cells | ||
165 | |||
166 | roles: | ||
167 | |||
168 | * ``:cspan:`` [int] additional columns (*morecols*) | ||
169 | * ``:rspan:`` [int] additional rows (*morerows*) | ||
170 | |||
171 | The example below shows how to use this markup. The first level of the staged | ||
172 | list is the *table-row*. In the *table-row* there is only one markup allowed, | ||
173 | the list of the cells in this *table-row*. Exceptions are *comments* ( ``..`` ) | ||
174 | and *targets* (e.g. a ref to ``:ref:`last row <last row>``` / :ref:`last row | ||
175 | <last row>`). | ||
176 | |||
177 | .. code-block:: rst | ||
178 | |||
179 | .. flat-table:: table title | ||
180 | :widths: 2 1 1 3 | ||
181 | |||
182 | * - head col 1 | ||
183 | - head col 2 | ||
184 | - head col 3 | ||
185 | - head col 4 | ||
186 | |||
187 | * - column 1 | ||
188 | - field 1.1 | ||
189 | - field 1.2 with autospan | ||
190 | |||
191 | * - column 2 | ||
192 | - field 2.1 | ||
193 | - :rspan:`1` :cspan:`1` field 2.2 - 3.3 | ||
194 | |||
195 | * .. _`last row`: | ||
196 | |||
197 | - column 3 | ||
198 | |||
199 | Rendered as: | ||
200 | |||
201 | .. flat-table:: table title | ||
202 | :widths: 2 1 1 3 | ||
203 | |||
204 | * - head col 1 | ||
205 | - head col 2 | ||
206 | - head col 3 | ||
207 | - head col 4 | ||
208 | |||
209 | * - column 1 | ||
210 | - field 1.1 | ||
211 | - field 1.2 with autospan | ||
212 | |||
213 | * - column 2 | ||
214 | - field 2.1 | ||
215 | - :rspan:`1` :cspan:`1` field 2.2 - 3.3 | ||
216 | |||
217 | * .. _`last row`: | ||
218 | |||
219 | - column 3 | ||