Summary

• Use gtk-doc with up-to-date settings for API documentation. (gtk-doc)
• Use XML entities for including external symbols into the documentation. (Build system)
• Use a consistent, standard, table of contents for all API documentation to maintain familiarity. (Standard layout)
• Use gdbus-codegen to generate D-Bus API documentation to include in the gtk-doc build. (D-Bus APIs)
• Add introspection annotations to all API documentation. (Introspection annotations)
• Add Since lines to all API documentation. (Symbol versioning)
• Enable gtk-doc tests. (Keeping documentation up to date)

gtk-doc

API documentation should be generated by gtk-doc, which collects specially formatted documentation comments from C and header files, and reformats them to generate DocBook and HTML output. The DocBook output can be used by Devhelp.

Using gtk-doc requires two things:

• The gtk-doc build system code to be integrated, which is a one-time operation.
• Documentation comments to be added to all public APIs, and kept up to date.

Build system

To integrate gtk-doc into a project’s build system, follow the instructions in the gtk-doc manual. Note that while the sections.txt file is automatically generated the first time gtk-doc is run, it is not generated subsequently, and should be kept up to date manually. It should also be in version control.

gtk-doc’s no-tmpl flavour should be used, and XML mode should be used instead of SGML. (tmpl mode and SGML are both outdated and slower than XML.)

If the package version is needed to be substituted into the documentation, create a file named docs/version.xml.in, containing:

 1  @PACKAGE_VERSION@ 

Add it to AC_CONFIG_FILES in configure.ac, then include it into the main documentation file (*-docs.xml) using:

 1   

in the DOCTYPE at the top of the document. The package version can then be used inline as &version;.

Standard layout

Using a standard layout for the table of contents, sections, appendices, etc. means the same *-docs.xml template can be reused with few changes between projects. It also means the documentation layout is similar across all projects, making it more familiar to developers.

The following layout is suggested:

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74   ]> [project] Reference Manual For [project] &version;. The latest version of this documentation can be found on-line at http://[server]/[project]/. [project] Overview Object Hierarchy D-Bus Interfaces D-Bus Interfaces D-Bus interface definitions for the project. C Interfaces C wrappers for the project D-Bus interfaces. Appendices API Index Index of deprecated symbols Index of new symbols in 1.0.0 

D-Bus APIs

D-Bus interface descriptions contain documentation comments, and these can be extracted from the XML using gdbus-codegen, and turned into DocBook files to be included by gtk-doc. Generate the documentation using the rules described in the D-Bus services guidelines.

The DocBook files can be included in the main *-docs.xml file using:

 1 2 3 4 5 6 7 8 9   C Interfaces C wrappers for the D-Bus interfaces. 

The generated XML files must be included in the content_files variable in docs/reference/Makefile.am, otherwise the build will fail. (This is to fix situations where the builddir does not equal the srcdir.)

Introspection annotations

Each gtk-doc comment should have appropriate GObject introspection annotations. These are useful for two reasons:

1. They add important information about parameter types, nullability and memory management to the C API documentation generated by gtk-doc.
2. They allow public APIs to be automatically bound in other languages, such as Python.

Introspection annotations add information to APIs (functions, function parameters, function return values, structures, GObject properties, GObject signals) which is otherwise not present in the machine readable C API and only exists in the form of human readable documentation or convention. They are very important.

In gtk-doc comments, annotations should be preferred over human-readable equivalents. For example, when documenting a function parameter which may be NULL, use the (nullable) annotation rather than some text:

 1 2 3 4 5 6  /** * my_function: * @parameter: (nullable): some parameter which affects something * * Body of the function documentation. */ 

 1 2 3 4 5 6  /** * my_bad_function: * @parameter: some parameter which affects something, or %NULL to ignore * * Bad body of the function documentation. */ 

Symbol versioning

Whenever a symbol is added to the public API, it should have a documentation comment added. This comment should always contain a Since line with the package version number of the release which will first contain the new API. This should be the number currently in configure.ac if post-release version incrementing is being used.

e.g.

 1 2 3 4 5 6 7 8  /** * my_function: * @param: some parameter * * Body of the function documentation. * * Since: 0.5.0 */ 

gtk-doc uses this information to generate indexes of the APIs added in each release. These should be added to the main *-docs.xml as an appendix:

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17   Appendices API Index Index of deprecated symbols Index of new symbols in 0.1.0 

Keeping documentation up to date

gtk-doc comes with support for checking the documentation with some basic tests. These check that all version indexes are included in the main *-docs.xml file and that all symbols are documented, amongst other things.

These tests should always be enabled, by adding the following to docs/Makefile.am:

 1  TESTS = \$(GTKDOC_CHECK) 

They will then be run as part of make check.