included"> ]> GTK-Doc Manual 1.24.1 User manual for developers with instructions of GTK-Doc usage. Chris Lyttle
chris@wilddev.net
Dan Mueth
d-mueth@uchicago.edu
Stefan Sauer (Kost)
ensonic@users.sf.net
GTK-Doc project
gtk-doc-list@gnome.org
2000, 2005 Dan Mueth and Chris Lyttle 2007-2019 Stefan Sauer (Kost) Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is &FDLlink;. Many of the names used by companies to distinguish their products and services are claimed as trademarks. Where those names appear in any GNOME documentation, and those trademarks are made aware to the members of the GNOME Documentation Project, the names have been printed in caps or initial caps. 1.33.0 1 Oct 2020 mc gtk4 version 1.32.1 15 Aug 2019 ss dev version 1.32 15 Aug 2019 ss hotfix release 1.31 05 Aug 2019 ss refactorings and more test coverage 1.30 08 May 2019 ss more test coverage 1.29 28 Aug 2018 ss bug fixes 1.28 24 Mar 2018 ss bug fixes 1.27 07 Dec 2017 ss fine tuning of the python port 1.26 11 Aug 2017 ss port all tools from perl/bash to python 1.25 21 March 2016 ss bug fixes, test cleanups 1.24 29 May 2015 ss bug fix 1.23 17 May 2015 ss bug fix 1.22 07 May 2015 ss bug fixes, dropping deprecated features 1.21 17 Jul 2014 ss bug fixes, dropping deprecated features 1.20 16 Feb 2014 ss bug fixes, markdown support, style improvements 1.19 05 Jun 2013 ss bug fixes 1.18 14 Sep 2011 ss bug fixes, speedups, markdown support 1.17 26 Feb 2011 sk urgent bug fix update 1.16 14 Jan 2011 sk bugfixes, layout improvements 1.15 21 May 2010 sk bug and regression fixes 1.14 28 March 2010 sk bugfixes and performance improvements 1.13 18 December 2009 sk broken tarball update 1.12 18 December 2009 sk new tool features and bugfixes 1.11 16 November 2008 mal GNOME doc-utils migration
Introduction This chapter introduces GTK-Doc and gives an overview of what it is and how it is used. What is GTK-Doc? GTK-Doc is used to document C code. It is typically used to document the public API of libraries, such as GLib-based libraries, but it can also be used to document application code. How Does GTK-Doc Work? GTK-Doc works by reading specially-formatted comment blocks placed inside the source files to document symbols such as functions, macros, structs, enums, etc. (though note that for most kind of symbols GTK-Doc will only document the symbols that are declared in header files; for example it won't produce output for static functions). GTK-Doc also reads template files where documentation can be added there as well. GTK-Doc consists of a number of programs, each performing a different step in the process. The main steps are: Writing the documentation. The author fills in the source files with the documentation for each function, macro, structs or unions, etc. 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 containing 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 entities similar to the ones in <module>-decl.txt into <module>-overrides.txt. gtkdoc-scangobj can also be used to dynamically query a library about any GObject subclasses it exports. It saves information about each object's position in the class hierarchy and about any GObject properties and signals it provides. gtkdoc-scanobj should not be used anymore. It was needed in the past when GObject was still GtkObject inside GTK. Generating the XML and HTML/PDF. gtkdoc-mkdb turns the template files into XML files in the xml/ subdirectory. If the source code contains documentation for symbols, 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. gtkdoc-mkhtml turns the XML files into HTML files in the html/ subdirectory. Likewise gtkdoc-mkpdf turns the XML files into a PDF document called <package>.pdf. Files in 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). Getting GTK-Doc Requirements python 2/3 - the main scripts are written in python. xsltproc - the xslt processor from libxslt xmlsoft.org/XSLT/ docbook-xsl - the docbook xsl stylesheets sourceforge.net/projects/docbook/files/docbook-xsl One of source-highlight, highlight or vim - optional - used for syntax highlighting of examples About GTK-Doc Historically GTK-Doc was used to generate template files from the sources code. These template files could be used by developers to enter the API documentation. This approach was rather inconvenient because it required to keep the generated files under version control. Since GTK-Doc 1.9 it became possible to place all API information into source comments, which made the template support obsolete. In version 1.26 template support has been removed. (FIXME) (authors, web pages, mailing list, license, future plans, comparison with other similar systems.) About this Manual (FIXME) (who it is meant for, where you can get it, license) Project Setup This Chapter describes the steps that are necessary to integrate GTK-Doc into your project. The integration of GTK-Doc into a project includes the following steps: Preparation of the directory structure and creating required configuration files for your GTK-Doc documentation (see Setting up a skeleton documentation). Adjusting the build system to build your documentation using the GTK-Doc tools. Multiple build systems are supported, in this manual we describe how to integrate GTK-Doc with Autotools, CMake, and plain Makefiles. Adding GTK-Doc specific files to version control and deciding which files to ignore (see Integration with version control systems). The following sections assume we work on a project called meep. This project contains two packages (or modules), a library called libmeep and an end-user app called meeper. Setting up a skeleton documentation A common convention is to place documentation into a folder called docs inside your top-level project directory. We usually distinguish between reference documentation intended for developers and an user manual intended for end-users. Again the convention is to have separate folders for both. We usually place the reference documentation in a folder named reference and the end-user manual in a folder named help as. According to the above convention the documentation for our libmeep package would be placed into: docs/reference/libmeep. For packages with just one library or application the documentation could also be placed directly into docs/reference. It is not mandatory to use the above convention, but if you choose to use a different directory structure you must adjust your build system configuration to match your directory structure. In the following sections we will assume a directory structure for our meep project that uses the above conventions. Example directory structure of <emphasis>meep</emphasis> project Integration with Autotools Integration of GTK-Doc into an autotools-based build system requires the following steps: Ensure that gtkdocize is run once before the configure script. If an autogen.sh script is present, adjust it to check for GTK-Doc and add a call to gtkdocize. The main purpose of gtkdocize is to make the gtk-doc.make Makefile and the gtk-doc.m4 macro definition file available to the build system, either by copying or linking it into the project. Add the necessary autoconf macros to configure.ac to enable GTK-Doc in your build system to allow configuration of GTK-Doc via the generated configure script. Among others with registers the --enable-gtk-doc option with the configure script. Create an automake script for each application or library in your project. In the example used in this documentation this step applies to both meeper and libmeep. In the following sections, we will perform the above steps in reverse order. We start with the automake scripts and work our way up to configure.ac and autogen.sh. Then we show how enable Gtk-Doc in the build system and how to build the documentation. Integration with automake First copy the Makefile.am from the examples sub-directory of the gtkdoc-sources to your project's reference documentation directory (e.g. docs/reference/<package>). A local copy should be available under e.g. /usr/share/doc/gtk-doc-tools/examples/Makefile.am. If you have multiple packages repeat this for each one. Do not forget to add each Makefile.am to the AC_CONFIG_FILES macro in configure.ac. For docs/reference/libmeep/Makefile.am you will need to add the entry docs/reference/libmeep/Makefile to AC_CONFIG_FILES. Example directory structure with <filename>Makefiles.am</filename> meep/ docs/ reference/ # reference documentation libmeep/ Makefile.am meeper/ Makefile.am help/ # optional: user manual meeper/ src/ libmeep/ meeper/ Next, you need to customize the copied Makefiles and provide values for the various parameters in each Makefile.am. All settings have a comment above them that describes their purpose and how to customize the setting. Most settings are used to supply extra flags to the respective tools to which they apply. Every tool has a variable of the form (e.g. the tool gtkdoc-mkhtml has an option named MKHTML_OPTIONS). All the tools support to list the supported options. The following list explains the most relevant options. Check the example Makefile.am for additional options. is used to provide the name of the package that is being documentated (e.g. meeper, or libmeep). is used to specify the location of source directory which GTK-Doc searches for your API documentation. This will usually be DOC_SOURCE_DIR=$(top_srcdir)/src or a sub-directory of that directory. and are used for dependencies. Each option take a file-glob (e.g. HFILE_GLOB=$(top_srcdir)/src/*.c). The documentation will be rebuilt if any of the matched files change. allows to specify extra header files to include when scanning for API documentation, which are not found under DOC_SOURCE_DIR (e.g. EXTRA_HFILES=$(top_srcdir}/contrib/extra.h). allows to specify header files or directories to ignore when scanning for API documentation. Use the basename of the file or directory (e.g. IGNORE_HFILES=gtkdebug.h gtkintl.h private_code_folder). allows to specify images files which will be copied into the html/ directory of the generated documentation. If your API documentation includes any images they need to be added to this option (e.g. HTML_IMAGES=$(top_srcdir)/gtk/stock-icons/stock_about_24.png). allows to specify extra files that are included by $(DOC_MAIN_SGML_FILE) (e.g. content_files=running.xml building.xml changes-2.0.xml). allows to specify files where gtk-doc abbreviations such as #GtkWidget are expanded (e.g. expand_content_files=running.xml). Integration with autoconf Integration with autoconf is very simple and includes one required step and an additional optional (but recommended) step. The first step is to add the GTK_DOC_CHECK macro to your configure.ac script. This registers several configure options to enable GTK-Doc and allows you to set default arguments for gtkdocize. Make sure that the GTK_DOC_CHECK macro is not indented. The macro must start at the beginning of the line and should not start with whitespace. The second step is to add the AC_CONFIG_MACRO_DIR(m4) to your configure.ac. This is not required but helps gtkdocize to automatically copy the macro definition (e.g gtk-doc.m4) which contains the GTK_DOC_CHECK macro to your project's macro directory. Without this, the GTK_DOC_CHECK macro might not be found and you would need to explicitly tell the aclocal tool where to find the macro definition file. Minimal integration with autoconf The above example works, but will require all developers to have gtk-doc installed. A better way is to make building the documentation optional as shown in the next example: Integration with optional gtk-doc dependency The first argument is used to check for the Gtk-Doc version at configure time. The 2nd, optional argument is used by gtkdocize. The GTK_DOC_CHECK macro also adds several configure switches: --with-html-dir=PATH : path to installed docs --enable-gtk-doc : use gtk-doc to build documentation [default=no] --enable-gtk-doc-html : build documentation in html format [default=yes] --enable-gtk-doc-pdf : build documentation in pdf format [default=no] GTK-Doc is disabled by default! Remember to pass the option to the next configure run. Otherwise pregenerated documentation is installed (which makes sense for users but not for developers). After all changes to configure.ac are made, update the configure file. This can be done by re-running autogen.sh. Integration with autogen Most projects will have an autogen.sh script to setup the build infrastructure after the project was checked out from a version control system (such as git or svn). GTK-Doc comes with a script called gtkdocize which can be used to copy the necessary files needed by Gtk-Doc to the source directory. It should be run before autoreconf, autoheader, automake or autoconf. Running gtkdocize from autogen.sh Conditionally run gtkdocize from autogen.sh /dev/null) if test $? -ne 0; then echo "No gtk-doc support found. You can't build the docs." else $GTKDOCIZE || exit 1 fi ]]> When running gtkdocize it copies gtk-doc.make to your project root (or any directory specified by the option). gtkdocize checks your configure.ac script for the GTK_DOC_CHECK macro. The GTK_DOC_CHECK macro can be used to pass extra arguments to the gtkdocize script. the 2nd parameter in the GTK_DOC_CHECK macro. Alternatively, additional arguments can also be passed to gtkdocize via the GTKDOCIZE_FLAGS environment variable, or by directly specifying them to gtkdocize in autogen.sh. Executing GTK-Doc from the Build System After the previous steps it's time to run the build. First we need to rerun autogen.sh. If this script runs configure for you, then give it the option. Otherwise manually run configure with this option afterwards. The first make run generates several additional files in the doc-directories. The important ones are: <package>.types, <package>-docs.xml (in the past .sgml), <package>-sections.txt. Running the doc build Now you can point your browser to docs/reference/<package>/index.html. With this initial setup you will only see a very simple document. The next chapter will teach you how to add API documentation to your code via special comment blocks. The Chapter afterwards introduces additional files and shows how to edit the master template to add additional chapters and sections to your documentation files. Integration with CMake build systems GTK-Doc now provides a GtkDocConfig.cmake module (and the corresponding GtkDocConfigVersion.cmake module). This provides a gtk_doc_add_module command that you can set in your CMakeLists.txt file. The following example shows how to use this command. Example of using GTK-Doc from CMake Integration with plain makefiles or other build systems In the case one does not want to use automake and therefore gtk-doc.mak one will need to call the gtkdoc tools in the right order in own makefiles (or other build tools). Documentation build steps gtkdoc-scangobj --module=$(DOC_MODULE) gtkdoc-mkdb --module=$(DOC_MODULE) --output-format=xml --source-dir= // xml files have changed mkdir html cd html && gtkdoc-mkhtml $(DOC_MODULE) ../meep-docs.xml gtkdoc-fixxref --module=$(DOC_MODULE) --module-dir=html ]]> One will need to look at the Makefile.am and gtk-doc.mak to pick the extra options needed. Integration with version control systems As a rule of thumb, it's the files you edit which should go under version control. For typical projects it's these files: <package>.types, <package>-docs.xml (in the past .sgml), <package>-sections.txt, Makefile.am. Files in the xml/ and html/ directories should not go under version control. Neither should any of the .stamp files. Documenting the code GTK-Doc uses source code comment with a special syntax for code documentation. Further it retrieves information about your project structure from other sources. During the next section you will find all information about the syntax of the comments. The GTK-Doc scanner can handle the majority of C headers fine. In the case of receiving warnings from the scanner that look like a special case, one can hint GTK-Doc to skip over them. GTK-Doc comment block Limitations Note, that GTK-Doc's supports #ifndef(__GTK_DOC_IGNORE__) but not #if !defined(__GTK_DOC_IGNORE__) or other combinations. Documentation comments A multiline comment that starts with an additional '*' marks a documentation block that will be processed by the GTK-Doc tools. GTK-Doc comment block The 'identifier' is one line with the name of the item the comment is related to. The syntax differs a little depending on the item. (TODO add table showing identifiers) The 'documentation' block is also different for each symbol type. Symbol types that get parameters such as functions or macros have the parameter description first followed by a blank line (just a '*'). Afterwards follows the detailed description. All lines (outside program listings and CDATA sections) just containing a ' *' (blank-asterisk) are converted to paragraph breaks. If you don't want a paragraph break, change that into ' * ' (blank-asterisk-blank-blank). This is useful in preformatted text (code listings). When documenting code, describe two aspects: What it is: The name for a class or function can sometimes be misleading for people coming from a different background. What it does: Tell about common uses. Put it in relation with the other API. One advantage of hyper-text over plain-text is the ability to have links in the document. Writing the correct markup for a link can be tedious though. GTK-Doc comes to help by providing several useful abbreviations. Use function() to refer to functions or macros which take arguments. Use @param to refer to parameters. Also use this when referring to parameters of other functions, related to the one being described. Use %constant to refer to a constant, e.g. %G_TRAVERSE_LEAFS. Use #symbol to refer to other types of symbol, e.g. structs and enums and macros which don't take arguments. Use #Object::signal to refer to a GObject signal. Use #Object:property to refer to a GObject property. Use #Struct.field to refer to a field inside a structure and #GObjectClass.foo_bar() to refer to a vmethod. If you need to use the special characters '<', '>', '()', '@', '%', or '#' in your documentation without GTK-Doc changing them you can use the XML entities "&lt;", "&gt;", "&lpar;", "&rpar;", "&commat;", "&percnt;" and "&num;" respectively or escape them with a backslash '\'. DocBook can do more than just links. One can also have lists, examples, headings, and images. As of version 1.20, the preferred way is to use a subset of the basic text formatting syntax called Markdown. On older GTK-Doc versions any documentation that includes Markdown will be rendered as is. For example, list items will appear as lines starting with a dash. While markdown is now preferred one can mix both. One limitation here is that one can use docbook xml within markdown, but markdown within docbook xml is not supported. In older GTK-Doc releases, if you need support for additional formatting, you would need to enable the usage of docbook XML tags inside doc-comments by putting (or ) in the variable MKDB_OPTIONS inside Makefile.am. GTK-Doc comment block using Markdown * GtkWidget *label = gtk_label_new ("Gorgeous!"); * ]| */ ]]> More examples of what markdown tags are supported can be found in the GTK Documentation Markdown Syntax Reference. As already mentioned earlier GTK-Doc is for documenting public API. Thus one cannot write documentation for static symbols. Nevertheless it is good to comment those symbols too. This helps other developers to understand your code. Therefore we recommend to comment these using normal comments (without the 2nd '*' in the first line). If later the function needs to be made public, all one needs to do is to add another '*' in the comment block and insert the symbol name at the right place inside the sections file. Documenting sections Each section of the documentation contains information about one class or module. To introduce the component one can write a section block. The short description is also used inside the table of contents. All the @fields are optional. Section comment block SECTION:<name> The name links the section documentation to the respective part in the <package>-sections.txt file. The name given here should match the <FILE> tag in the <package>-sections.txt file. @short_description A one line description of the section, that later will appear after the links in the TOC and at the top of the section page. @title The section title defaults to <name> from the SECTION declaration. It can be overridden with the @title field. @section_id Overrides the use of title as a section identifier. For GObjects the <title> is used as a section_id and for other sections it is <MODULE>-<title>. @see_also A list of symbols that are related to this section. @stability An informal description of the stability level this API has. We recommend the use of one of these terms: Stable - The intention of a Stable interface is to enable arbitrary third parties to develop applications to these interfaces, release them, and have confidence that they will run on all minor releases of the product (after the one in which the interface was introduced, and within the same major release). Even at a major release, incompatible changes are expected to be rare, and to have strong justifications. Unstable - Unstable interfaces are experimental or transitional. They are typically used to give outside developers early access to new or rapidly changing technology, or to provide an interim solution to a problem where a more general solution is anticipated. No claims are made about either source or binary compatibility from one minor release to the next. Private - An interface that can be used within the GNOME stack itself, but that is not documented for end-users. Such functions should only be used in specified and documented ways. Internal - An interface that is internal to a module and does not require end-user documentation. Functions that are undocumented are assumed to be Internal. @include The #include files to show in the section synopsis (a comma separated list), overriding the global value from the section file or command line. This item is optional. @image The image to display at the top of the reference page for this section. This will often be some sort of a diagram to illustrate the visual appearance of a class or a diagram of its relationship to other classes. This item is optional. To avoid unnecessary recompilation after doc-changes put the section docs into the c-source where possible. Documenting symbols Each symbol (function, macro, struct, enum, signal and property) is documented in a separate block. The block is best placed close to the definition of the symbols so that it is easy to keep them in sync. Thus functions are usually documented in the c-source and macros, structs and enums in the header file. General tags You can add versioning information to all documentation elements to tell when an API was introduced, or when it was deprecated. Versioning Tags Since: Description since which version of the code the API is available. Deprecated: Paragraph denoting that this function should no be used anymore. The description should point the reader to the new API. You can also add stability information to all documentation elements to indicate whether API stability is guaranteed for them for all future minor releases of the project. The default stability level for all documentation elements can be set by passing the argument to gtkdoc-mkdb with one of the values below. Stability Tags Stability: Stable Mark the element as stable. This is for public APIs which are guaranteed to remain stable for all future minor releases of the project. Stability: Unstable Mark the element as unstable. This is for public APIs which are released as a preview before being stabilised. Stability: Private Mark the element as private. This is for interfaces which can be used by tightly coupled modules, but not by arbitrary third parties. General tags Annotations Documentation blocks can contain annotation-tags. These tags will be rendered with tooltips describing their meaning. The tags are used by GObject Introspection to generate language bindings. A detailed list of the supported tags can be found in the GObject Introspection documentation. Annotations Function comment block Please remember to: Document whether returned objects, lists, strings, etc, should be freed/unrefed/released. Document whether parameters can be NULL, and what happens if they are. Mention interesting pre-conditions and post-conditions where appropriate. Gtk-doc assumes all symbols (macros, functions) starting with '_' are private. They are treated like static functions. Function comment block Function tags Returns: Paragraph describing the returned result. @...: In case the function has variadic arguments, you should use this tag (@Varargs: does also work for historic reasons). Property comment block Property comment block Signal comment block Please remember to: Document when the signal is emitted and whether it is emitted before or after other signals. Document what an application might do in the signal handler. Signal comment block Struct comment block Struct comment block Use /*< private >*/ before the private struct fields you want to hide. Use /*< public >*/ for the reverse behaviour. If the first field is "g_iface", "parent_instance" or "parent_class" it will be considered private automatically and doesn't need to be mentioned in the comment block. Struct comment blocks can also be used for GObjects and GObjectClasses. It is usually a good idea to add a comment block for a class, if it has vmethods (as this is how they can be documented). For the GObject itself one can use the related section docs, having a separate block for the instance struct would be useful if the instance has public fields. One disadvantage here is that this creates two index entries of the same name (the structure and the section). Enum comment block Enum comment block */ SOMETHING_COUNT } Something; ]]> Use /*< private >*/ before the private enum values you want to hide. Use /*< public >*/ for the reverse behaviour. Inline program documentation You can document programs and their commandline interface using inline documentation. Tags PROGRAM Defines the start of a program documentation. @short_description: Defines a short description of the program. (Optional) @synopsis: Defines the arguments, or list of arguments that the program can take. (Optional) @see_also: See Also manual page section. (Optional) @arg: Argument(s) passed to the program and their description. (Optional) Description: A longer description of the program. Returns: Specify what value(s) the program returns. (Optional) Example of program documentation. Program documentation block Useful DocBook tags Here are some DocBook tags which are most useful when documenting the code. To link to another section in the GTK docs: Hash Tables ]]> The linkend is the SGML/XML id on the top item of the page you want to link to. For most pages this is currently the part ("gtk", "gdk", "glib") and then the page title ("Hash Tables"). For widgets it is just the class name. Spaces and underscores are converted to '-' to conform to SGML/XML. To refer to an external function, e.g. a standard C function: ... ]]> To include example code: Using a GHashTable. ... ]]> or possibly this, for very short code fragments which don't need a title: ... ]]> In both cases, the language attribute is optional and is used as a hint to the syntax highlighting engine (pygments for html output). For the latter GTK-Doc also supports an abbreviation: ... ]| ]]> To include bulleted lists: ... ... ]]> To include a note which stands out from the text: Make sure you free the data after use. ]]> To refer to a type: unsigned char ]]> To refer to an external structure (not one described in the GTK docs): XFontStruct ]]> To refer to a field of a structure: len ]]> To refer to a class name, we could possibly use: GtkWidget ]]> but you'll probably be using #GtkWidget instead (to automatically create a link to the GtkWidget page - see the abbreviations). To emphasize text: This is important ]]> For filenames use: /home/user/documents ]]> To refer to keys use: ControlL ]]> Filling the extra files There are a couple of extra files, that need to be maintained along with the inline source code comments: <package>.types, <package>-docs.xml (in the past .sgml), <package>-sections.txt. Editing the types file If your library or application includes GObjects, you want their signals, arguments/parameters and position in the hierarchy to be shown in the documentation. All you need to do, is to list the xxx_get_type functions together with their include inside the <package>.types file. Example <package>.types file gtk_accel_label_get_type gtk_adjustment_get_type gtk_alignment_get_type gtk_arrow_get_type ]]> Since GTK-Doc 1.8 gtkdoc-scan can generate this list for you. Just add "--rebuild-types" to SCAN_OPTIONS in Makefile.am. If you use this approach you should not dist the types file nor have it under version control. Editing the master document GTK-Doc produces documentation in DocBook SGML/XML. When processing the inline source comments, the GTK-Doc tools generate one documentation page per class or module as a separate file. The master document includes them and place them in an order. While GTK-Doc creates a template master document for you, later runs will not touch it again. This means that one can freely structure the documentation. That includes grouping pages and adding extra pages. GTK-Doc has now a test suite, where also the master-document is recreated from scratch. Its a good idea to look at this from time to time to see if there are some new goodies introduced there. Do not create tutorials as extra documents. Just write extra chapters. The benefit of directly embedding the tutorial for your library into the API documentation is that it is easy to link for the tutorial to symbol documentation. Apart chances are higher that the tutorial gets updates along with the library. So what are the things to change inside the master document? For a start is only a little. There are some placeholders (text in square brackets) there which you should take care of. Master document header MODULENAME Reference Manual for MODULENAME [VERSION] The latest version of this documentation can be found on-line at http://[SERVER]/MODULENAME/. [Insert title here] ]]> In addition a few option elements are created in commented form. You can review these and enable them as you like. Optional part in the master document --> ]]> Finally you need to add new section whenever you introduce one. The gtkdoc-check tool will remind you of newly generated xml files that are not yet included into the doc. Including generated sections my library ... ]]> Editing the section file The section file is used to organise the documentation output by GTK-Doc. Here one specifies which symbol belongs to which module or class and control the visibility (public or private). The section file is a plain text file with tags delimiting sections. Blank lines are ignored and lines starting with a '#' are treated as comment lines. While the tags make the file look like xml, it is not. Please do not close tags like <SUBSECTION>. Including generated sections libmeep/meep.h
meepapp MeepApp MeepApp MEEP_APP ... MeepAppClass meep_app_get_type
]]>
The <FILE> ... </FILE> tag is used to specify the file name, without any suffix. For example, using '<FILE>gnome-config</FILE>' will result in the section declarations being output in the template file tmpl/gnome-config.sgml, which will be converted into the DocBook XML file xml/gnome-config.sgml or the DocBook XML file xml/gnome-config.xml. (The name of the HTML file is based on the module name and the section title, or for GObjects it is based on the GObjects class name converted to lower case). The <TITLE> ... </TITLE> tag is used to specify the title of the section. It is only useful before the templates (if used) are initially created, since the title set in the template file overrides this. Also if one uses SECTION comment in the sources, this is obsolete. You can group items in the section by using the <SUBSECTION> tag. Currently it outputs a blank line between subsections in the synopsis section. You can also use <SUBSECTION Standard> for standard GObject declarations (e.g. the functions like g_object_get_type and macros like G_OBJECT(), G_IS_OBJECT() etc.). Currently these are left out of the documentation. You can also use <SUBSECTION Private> for private declarations which will not be output (it is a handy way to avoid warning messages about unused declarations). If your library contains private types which you don't want to appear in the object hierarchy and the list of implemented or required interfaces, add them to a Private subsection. Whether you would place GObject and GObjectClass like structs in public or Standard section depends if they have public entries (variables, vmethods). You can also use <INCLUDE> ... </INCLUDE> to specify the #include files which are shown in the synopsis sections. It contains a comma-separate list of #include files, without the angle brackets. If you set it outside of any sections, it acts for all sections until the end of the file. If you set it within a section, it only applies to that section.
Controlling the result A GTK-Doc run generates report files inside the documentation directory. The generated files are named: <package>-undocumented.txt, <package>-undeclared.txt and <package>-unused.txt. All those are plain text files that can be viewed and postprocessed easily. The <package>-undocumented.txt file starts with the documentation coverage summary. Below are two sections divided by blank lines. The first section lists undocumented or incomplete symbols. The second section does the same for section docs. Incomplete entries are those, which have documentation, but where e.g. a new parameter has been added. The <package>-undeclared.txt file lists symbols given in the <package>-sections.txt but not found in the sources. Check if they have been removed or if they are misspelled. The <package>-unused.txt file lists symbol names, where the GTK-Doc scanner has found documentation, but does not know where to put it. This means that the symbol has not yet been added to the <package>-sections.txt file. Enable or add the line in Makefile.am. If at least GTK-Doc 1.9 is installed, this will run sanity checks during make check run. One can also look at the files produced by the source code scanner: <package>-decl-list.txt and <package>-decl.txt. The first one can be compared with the section file if that is manually maintained. The second lists all declarations from the headers. If a symbol is missing one could check if this file contains it. If the project is GObject based, one can also look into the files produced by the object scanner: <package>.args.txt, <package>.hierarchy.txt, <package>.interfaces.txt, <package>.prerequisites.txt and <package>.signals.txt. If there are missing symbols in any of those, one can ask GTK-Doc to keep the intermediate scanner file for further analysis, by running it as GTK_DOC_KEEP_INTERMEDIATE=1 make. Modernizing the documentation GTK-Doc has been around for quite some time. In this section we list new features together with the version since when it is available. GTK-Doc 1.9 When using xml instead of sgml, one can actually name the master document <package>-docs.xml. This version supports in Makefile.am. When this is enabled, the <package>-sections.txt is autogenerated and can be removed from the vcs. This only works nicely for projects that have a very regular structure (e.g. each .{c,h} pair will create new section). If one organize a project close to that updating a manually maintained section file can be as simple as running meld <package>-decl-list.txt <package>-sections.txt. Version 1.8 already introduced the syntax for documenting sections in the sources instead of the separate files under tmpl. This version adds options to switch the whole doc module to not use the extra tmpl build step at all, by using in configure.ac. If you don't have a tmpl checked into your source control system and haven't yet switched, just add the flag to configure.ac and you are done. GTK-Doc 1.10 This version supports in Makefile.am. When this is enabled, the <package>.types is autogenerated and can be removed from the vcs. When using this feature it is important to also setup the IGNORE_HFILES in Makefile.am for code that is build conditionally. GTK-Doc 1.16 This version includes a new tool called gtkdoc-check. This tool can run a set of sanity checks on your documentation. It is enabled by adding these lines to the end of Makefile.am. Enable gtkdoc-check GTK-Doc 1.20 Version 1.18 brought some initial markdown support. Using markdown in doc comments is less intrusive than writing docbook xml. This version improves a lot on this and add a lot more styles. The section that explains the comment syntax has all the details. GTK-Doc 1.25 The makefiles shipped with this version generate an entity file at xml/gtkdocentities.ent, containing entities for e.g. package_name and package_version. You can use this e.g. in the main xml file to avoid hardcoding the version number. Below is an example that shows how the entity file is included in the master template and how the entities are used. The entities can also be used in all generated files, GTK-Doc will use the same xml header in generated xml files. Use pre-generated entities %gtkdocentities; ]> &package_name; Reference Manual for &package_string;. The latest version of this documentation can be found on-line at http://[SERVER]/&package_name;/. ]]> Documenting other interfaces So far we have been using GTK-Doc to document the API of code. The next sections contain suggestions how the tools can be used to document other interfaces too. Command line options and man pages As one can generate man pages for a docbook refentry as well, it sounds like a good idea to use it for that purpose. This way the interface is part of the reference and one gets the man-page for free. Document the tool Create one refentry file per tool. Following our example we would call it meep/docs/reference/meeper/meep.xml. For the xml tags that should be used and can look at generated file in the xml subdirectory as well as examples e.g. in glib. Adding the extra configure check Extra configure checks Adding the extra makefile rules Extra configure checks DBus interfaces (FIXME: http://hal.freedesktop.org/docs/DeviceKit/DeviceKit.html, http://cgit.freedesktop.org/DeviceKit/DeviceKit/tree/doc/dbus) Frequently asked questions Question Answer No class hierarchy. The objects xxx_get_type() function has not been entered into the <package>.types file. Still no class hierarchy. Missing or wrong naming in <package>-sections.txt file (see explanation). Damn, I have still no class hierarchy. Is the object name (name of the instance struct, e.g. GtkWidget) part of the normal section (don't put this into Standard or Private subsections). No symbol index. Does the <package>-docs.{xml,sgml} contain a index that xi:includes the generated index? Symbols are not linked to their doc-section. Is the doc-comment using the correct markup (added #,% or ())? Check if the gtkdoc-fixxref warns about unresolvable xrefs. A new class does not appear in the docs. Is the new page xi:included from <package>-docs.{xml,sgml}. A new symbol does not appear in the docs. Is the doc-comment properly formatted. Check for spelling mistakes in the begin of the comment. Check if the gtkdoc-fixxref warns about unresolvable xrefs. Check if the symbol is correctly listed in the <package>-sections.txt in a public subsection. A type is missing from the class hierarchy. If the type is listed in <package>.hierarchy but not in xml/tree_index.sgml then double check that the type is correctly placed in the <package>-sections.txt. If the type instance (e.g. GtkWidget) is not listed or incidentally marked private it will not be shown. I get foldoc links for all gobject annotations. Check that xml/annotation-glossary.xml is xi:included from <package>-docs.{xml,sgml}. Parameter described in source code comment block but does not exist Check if the prototype in the header has different parameter names as in the source. multiple "IDs" for constraint linkend: XYZ Symbol XYZ appears twice in <package>-sections.txt file. Element typename in namespace '' encountered in para, but no template matches. Tools related to gtk-doc GtkDocPlugin - a Trac GTK-Doc integration plugin, that adds API docs to a trac site and integrates with the trac search. Gtkdoc-depscan - a tool (part of gtk-doc) to check used API against since tags in the API to determine the minimum required version. &FDL;