The Linux kernel uses Sphinx to generate pretty documentation from
reStructuredText files under
Documentation. To build the documentation in
HTML or PDF formats, use
make htmldocs or
make pdfdocs. The generated
documentation is placed in
The reStructuredText files may contain directives to include structured documentation comments, or kernel-doc comments, from source files. Usually these are used to describe the functions and types and design of the code. The kernel-doc comments have some special structure and formatting, but beyond that they are also treated as reStructuredText.
There is also the deprecated DocBook toolchain to generate documentation from
DocBook XML template files under
Documentation/DocBook. The DocBook files
are to be converted to reStructuredText, and the toolchain is slated to be
Finally, there are thousands of plain text documentation files scattered around
Documentation. Some of these will likely be converted to reStructuredText
over time, but the bulk of them will remain in plain text.
The usual way to generate the documentation is to run
make htmldocs or
make pdfdocs. There are also other formats available, see the documentation
make help. The generated documentation is placed in
format-specific subdirectories under
To generate documentation, Sphinx (
sphinx-build) must obviously be
installed. For prettier HTML output, the Read the Docs Sphinx theme
sphinx_rtd_theme) is used if available. For PDF output,
rst2pdf is also
needed. All of these are widely available and packaged in distributions.
To pass extra options to Sphinx, you can use the
variable. For example, use
make SPHINXOPTS=-v htmldocs to get more verbose
To remove the generated documentation, run
Adding new documentation can be as simple as:
- Add a new
.rstfile somewhere under
- Refer to it from the Sphinx main TOC tree in
This is usually good enough for simple documentation (like the one you’re
reading right now), but for larger documents it may be advisable to create a
subdirectory (or use an existing one). For example, the graphics subsystem
documentation is under
Documentation/gpu, split to several
and has a separate
index.rst (with a
toctree of its own) referenced from
the main index.
See the documentation for Sphinx and reStructuredText on what you can do with them. In particular, the Sphinx reStructuredText Primer is a good place to get started with reStructuredText. There are also some Sphinx specific markup constructs.
Specific guidelines for the kernel documentation¶
Here are some specific guidelines for the kernel documentation:
Please don’t go overboard with reStructuredText markup. Keep it simple.
Please stick to this order of heading adornments:
=with overline for document title:
============== Document title ==============
Although RST doesn’t mandate a specific order (“Rather than imposing a fixed number and order of section title adornment styles, the order enforced will be the order as encountered.”), having the higher levels the same overall makes it easier to follow the documents.
the C domain¶
The `Sphinx C Domain`_ (name c) is suited for documentation of C API. E.g. a function prototype:
.. c:function:: int ioctl( int fd, int request )
The C domain of the kernel-doc has some additional features. E.g. you can
rename the reference name of a function with a common name like
.. c:function:: int ioctl( int fd, int request ) :name: VIDIOC_LOG_STATUS
The func-name (e.g. ioctl) remains in the output but the ref-name changed from
VIDIOC_LOG_STATUS. The index entry for this function is also
VIDIOC_LOG_STATUS and the function can now referenced by:
We recommend the use of list table formats. The list table formats are double-stage lists. Compared to the ASCII-art they might not be as comfortable for readers of the text files. Their advantage is that they are easy to create or modify and that the diff of a modification is much more meaningful, because it is limited to the modified content.
flat-table is a double-stage list similar to the
some additional features:
- column-span: with the role
cspana cell can be extended through additional columns
- row-span: with the role
rspana cell can be extended through additional rows
- auto span rightmost cell of a table row over the missing cells on the right
side of that table-row. With Option
:fill-cells:this behavior can changed from auto span to auto fill, which automatically inserts (empty) cells instead of spanning the last cell.
:header-rows:[int] count of header rows
:stub-columns:[int] count of stub columns
:widths:[[int] [int] ... ] widths of columns
:fill-cells:instead of auto-spanning missing cells, insert missing cells
:cspan:[int] additional columns (morecols)
:rspan:[int] additional rows (morerows)
The example below shows how to use this markup. The first level of the staged
list is the table-row. In the table-row there is only one markup allowed,
the list of the cells in this table-row. Exceptions are comments (
and targets (e.g. a ref to
:ref:`last row <last row>` / last row).
.. flat-table:: table title :widths: 2 1 1 3 * - head col 1 - head col 2 - head col 3 - head col 4 * - column 1 - field 1.1 - field 1.2 with autospan * - column 2 - field 2.1 - :rspan:`1` :cspan:`1` field 2.2 - 3.3 * .. _`last row`: - column 3
¶ head col 1 head col 2 head col 3 head col 4 column 1 field 1.1 field 1.2 with autospan column 2 field 2.1 field 2.2 - 3.3