How Does GTK-Doc Work?
GTK-Doc works by using documentation of functions placed inside the source files in specially-formatted comment blocks, or documentation added to the template files which GTK-Doc uses (though note that GTK-Doc will only document functions that are declared in header files; it won't produce output for static functions).
GTK-Doc consists of a number of perl scripts, each performing a different step in the process.
There are 5 main steps in the process:
-
Writing the documentation. The author fills in the source files with the documentation for each function, macro, union etc. (In the past information was entered in generated template files, which is not recommended anymore).
-
Gathering information about the code. gtkdoc-scan scans the header files of the code looking for declarations of functions, macros, enums, structs, and unions. It creates the file <module>-decl-list.txt containg a list of the declarations, placing them into sections according to which header file they are in. On the first run this file is copied to <module>-sections.txt. The author can rearrange the sections, and the order of the declarations within them, to produce the final desired order. The second file it generates is <module>-decl.txt. This file contains the full declarations found by the scanner. If for some reason one would like some symbols to show up in the docs, where the full declaration cannot be found by the scanner or the declaration should appear differently, one can place enties similar to the ones in <module>-decl.txt into <module>-overrides.txt. gtkdoc-scanobj can also be used to dynamically query a library about any GtkObject subclasses it exports. It saves information about each object's position in the class hierarchy and about any GTK Args and Signals it provides.
-
Generating the "template" files. gtkdoc-mktmpl creates a number of files in the tmpl/ subdirectory, using the information gathered in the first step. (Note that this can be run repeatedly. It will try to ensure that no documentation is ever lost.)
Since GTK-Doc 1.9 the templates can be avoided. We encourage people to keep documentation in the code. gtkdocize supports now a --flavour no-tmpl option that chooses a makefile that skips tmpl usage totally. If you have never changed file in tmpl by hand, please remove the dir (e.g. from version control system).
-
Generating the SGML/XML and HTML/PDF. gtkdoc-mkdb turns the template files into SGML or XML files in the sgml/ or xml/ subdirectory. If the source code contains documentation on functions, using the special comment blocks, it gets merged in here. If there are no tmpl files used it only reads docs from sources and introspection data. We recommend to use Docbook XML.
gtkdoc-mkhtml turns the SGML/XML files into HTML files in the html/ subdirectory. Likewise gtkdoc-mkpdf turns the SGML/XML files into a PDF document called <package>.pdf.
Files in sgml/ or xml/ and html/ directories are always overwritten. One should never edit them directly.
-
Fixing up cross-references between documents. After installing the HTML files, gtkdoc-fixxref can be run to fix up any cross-references between separate documents. For example, the GTK+ documentation contains many cross-references to types documented in the GLib manual. When creating the source tarball for distribution, gtkdoc-rebase turns all external links into web-links. When installing distributed (pregenerated) docs the same application will try to turn links back to local links (where those docs are installed).