# GTK-Doc 手册

1.18.1

为开发人员提供 GTK-Doc 用法说明的用户手册。

Chris Lyttle

     chris@wilddev.net

Dan Mueth

     d-mueth@uchicago.edu

Stefan Kost

     ensonic@users.sf.net

GTK-Doc 项目

    gtk-doc-list@gnome.org

2000, 2005 Dan Mueth and Chris Lyttle
2007-2011 Stefan Sauer (Kost)

允许在GNU 自由文档认证书的规范下复制，发布或者／并且修改本文档，由自由软件基金会出版的1.1版或更新版本的无变更的部分，无封面文本，以及无背面文本。取得证书的制件included.

公司使用的区别于它们的许多产品及服务的名字就称为商标. 这些名字出现在任何GNOME文档中, 而且那些商标会提示GNOME文档项目成员, 那些名字会打印在封面或初始页面中.

1.19
05 Jun 2013
ss bug fixes
1.18
14 Sep 2011
ss bug fixes, speedups, markdown support
1.17
2011年2月26
sk 紧急问题修复更新
1.16
2011年1月14
sk 修复问题，布局改进
1.15
2010年5月21
sk 问题和退化修复
1.14
2010年3月28
sk 问题修复和性能提高
1.13
2009年10月18
sk 损坏的档案包更新
1.12
2009年10月18
sk 新工具功能和问题修复
1.11
2008年10月16
mal GNOME doc-utils 迁移
LuYanbo 767344148@qq.com
2011 LuYanbo
黄世海 rochester_h@163.com
2012 黄世海
Wylmer Wang wantinghard@gmail.com
2012 Wylmer Wang

## 介绍

本章介绍 GTK-Doc，并概述了它是什么以及如何使用它。

### 什么是 GTK-Doc？

GTK-Doc 用于为C代码编写文档。典型地用于编写库的公共API，如GTK+与GNOME库。不过它也可以用于书写应用程序代码文档。

### GTK Doc 是怎样工作的？

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由一些perl脚本组成，每个脚本完成这一过程中不同的步骤。

这个进程有五个主要步骤：

1. 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).

2. 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+.

3. 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 directory (e.g. from version control system).

4. 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.

5. 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).

### 获取 GTK-Doc

#### 要求

Perl v5- 主脚本是Perl格式。

DocBook DTD v3.0 - 这是DocBook SGML DTD的链接. http://www.ora.com/davenport

Jade v1.1 -这是一个DSSSL处理器，用来把SGML转换为各种格式。http://www.jclark.com/jade

Modular DocBook Stylesheets This is the DSSSL code to convert DocBook to HTML (and a few other formats). It's used together with jade. I've customized the DSSSL code slightly, in gtk-doc.dsl, to colour the program code listings/declarations, and to support global cross-reference indices in the generated HTML. http://nwalsh.com/docbook/dsssl

docbook-to-man - if you want to create man pages from the DocBook. I've customized the 'translation spec' slightly, to capitalise section headings and add the 'GTK Library' title at the top of the pages and the revision date at the bottom. There is a link to this on http://www.ora.com/davenport NOTE: This does not work yet.

#### 安装

DocBook Modular Stylesheets没有标准的安装位置。

GTK-Doc 的配置脚本会自动地查找这三个目录：

`/usr/lib/sgml/stylesheets/nwalsh-modular` (在 RedHat 中使用)

`/usr/lib/dsssl/stylesheets/docbook` (在 Debian 中使用)

`/usr/share/sgml/docbkdsl` (在 SuSE 中使用)

如果把样式表安装在其它地方，您必须用这个选项来配置GTK-Doc：`--with-dsssl-dir=<PATH_TO_TOPLEVEL_STYLESHEETS_DIR>` 。

### 关于 GTK-Doc

(FIXME)

(History, authors, web pages, license, future plans, comparison with other similar systems.)

### 关于此手册

(FIXME)

(它意味着什么，你可以从哪里获得它, 许可证)

## 设置您的项目

The next sections describe what steps to perform to integrate GTK-Doc into your project. Theses sections assume we work on a project called 'meep'. This project contains a library called 'libmeep' and an end-user app called 'meeper'. We also assume you will be using autoconf and automake. In addition section plain makefiles or other build systems will describe the basics needed to work in a different build setup.

### 设置一个框架文档

Under your top-level project directory create folders called docs/reference (this way you can also have docs/help for end-user documentation). It is recommended to create another subdirectory with the name of the doc-package. For packages with just one library this step is not necessary.

目录结构将会如下所示：

范例目录结构

    meep/
      docs/
        reference/
          libmeep/
          meeper/
      src/
        libmeep/
        meeper/

### 与autoconf集成

非常容易！只需在您的 `configure.ac` 脚本中添加一行。

与autoconf集成

    # 检查 gtk-doc
    GTK_DOC_CHECK([1.14],[--flavour no-tmpl])

This will require all developers to have gtk-doc installed. If it is okay for your project to have optional api-doc build setup, you can solve this as below. Keep it as is, as gtkdocize is looking for `GTK_DOC_CHECK` at the start of a line.

Keep gtk-doc optional

    # check for gtk-doc
    m4_ifdef([GTK_DOC_CHECK], [
    GTK_DOC_CHECK([1.14],[--flavour no-tmpl])
    ],[
    AM_CONDITIONAL([ENABLE_GTK_DOC], false)
    ])

The first argument is used to check for the gtkdocversion at configure time. The 2nd, optional argument is used by gtkdocize. The GTK_DOC_CHECK macro also adds several configure switches:

1. --with-html-dir=PATH : 安装文档的路径

2. --enable-gtk-doc : 用gtk-doc构建文档［默认值：no］

3. --enable-gtk-doc-html :用html格式构建文档［默认值：yes］

4. --enable-gtk-doc-pdf : 以PDF格式构建文档［默认值：no］

GTK-Doc在默认情况下是关闭的！请记得给文本`configure`运作时传递`'--enable-gtk-doc'`选项。否则，将会安装预先生成的文档（对用户有意义但对开发人员没用处）。

而且建议你在`configure.ac`脚本里拥有这样一行。它允许gtkdocize将`GTK_DOC_CHECK`的宏定义复制到您的项目中去。

准备gtkdocize

    AC_CONFIG_MACRO_DIR(m4)

### 与automake集成

First copy the `Makefile.am` from the examples subdirectory of the gtkdoc-sources to your project's API documentation directory ( `./docs/reference/<package>`). If you have multiple doc-packages repeat this for each one.

The next step is to edit the settings inside the `Makefile.am`. All the settings have a comment above that describes their purpose. Most settings are extra flags passed to the respective tools. Every tool has a variable of the form `<TOOLNAME>_OPTIONS`. All the tools support `--help` to list the supported parameters.

You may also want to enable GTK-Doc for the distcheck make target. Just add the one line shown in the next example to your top-level `Makefile.am`:

在make distcheck过程中启用GTK-Doc

    DISTCHECK_CONFIGURE_FLAGS=--enable-gtk-doc

### 与autogen集成

Most projects will have an `autogen.sh` script to setup the build infrastructure after a checkout from version control system (such as cvs/svn/git). GTK-Doc comes with a tool called gtkdocize which can be used in such a script. It should be run before autoheader, automake or autoconf.

从autogen.sh中运行gtkdocize

    gtkdocize || exit 1

When running gtkdocize it copies `gtk-doc.make` to your project root (or any directory specified by the `--docdir` option). It also checks you configure script for the `GTK_DOC_CHECK` invocation. This macro can be used to pass extra parameters to gtkdocize.

Historically GTK-Doc was generating template files where developers entered the docs. This turned out to be not so good (e.g. the need for having generated files under version control). Since GTK-Doc 1.9 the tools can get all the information from source comments and thus 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. Besides adding the option directly to the command invocation, they can be added also to an environment variable called GTKDOCIZE_FLAGS or set as a 2nd parameter in GTK_DOC_CHECK macro in the configure script. If you have never changed file in tmpl by hand and migrating from older gtkdoc versions, please remove the directory (e.g. from version control 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 `--enable-gtk-doc` 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`.

运行文档构建

    ./autogen.sh --enable-gtk-doc
    make

Now you can point your browser to `docs/reference/<package>/index.html`. Yes, it's a bit disappointing still. But hang-on, during the next chapter we tell you how to fill the pages with life.

### 与版本控制系统集成

As a rule of the thumb, it's those files you edit, that 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`

### 与普通makefile或其它构建系统整合

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).

文档构建步骤

    DOC_MODULE=meep
    // sources have changed
    gtkdoc-scan --module=$(DOC_MODULE) --source-dir=...
    gtkdoc-scangobj --module=$(DOC_MODULE)
    gtkdoc-mkdb --module=$(DOC_MODULE) --output-format=xml
    // xml files have changed
    mkdir html
    cd html && gtkdoc-mkhtml $(DOC_MODULE) ../meep-docs.xml
    gtkdoc-fixxref --module=$(DOC_MODULE) --module-dir=html

您必须查阅`Makefile.am` 和 `gtk-doc.mak`以获取所须的额外选项。

## 编写代码文档

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.

文档位置

在过去，多数文档不得不写入驻留在`tmpl`目录的文件中。这样会出现一些糟糕的情况：其信息常常没有更新，而且文件也倾向于与版本控制系统发生冲突。

为避免上述的问题，我们建议把注释文档放入源代码中去。本手册仅描述此种编写代码文档的方法。

The 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

    #ifndef __GTK_DOC_IGNORE__
    /* unparseable code here */
    #endif

### 文档注释

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

    /**
     * identifier:
     * documentation ...
     */

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.

与纯文本相比，超文本的优势在于可以在文档内部有链接。但为一个链接编写正确的标记可能是件枯燥的差事。GTK-Doc提供了几个有用的简化方法帮你解决这个麻烦。

- 用function()来指示带有参数的函数或宏。

- 用@param指示参数。同样也可以指示其它函数的参数，与所描述的对象有关。

- 用%constant指示常量，比如：%G_TRAVERSE_LEAFS。

- 用#symbol指示其它符号类型，比如：结构，枚举与不带参数的宏。

- Use #Object::signal to refer to a GObject signal.

- Use #Object:property to refer to a GObject property.

- 用#Struct.field指示结构体的字段。

如果你要在文档里面使用一些特殊的字符'<', '>', '()', '@', '%', or '#' 且不用GTK-Doc来修改它们，你可以相应地用XML 实体 "&lt;", "&gt;", "&lpar;", "&rpar;", "&commat;", "&percnt;" 以及 "&num;"或者用一个反斜线'\'来转义它们。

DocBook可以做比链接多得多的事情。你可以有列表，表格和示例。要在doc-comments中激活docbook SGML/XML标识的使用，你得往`Makefile.am`文件中的变量MKDB_OPTIONS上加入`--xml-mode` 或 `--sgml-mode`选项。

从 GTK-Doc-1.18 版本开始，该工具支持 markdown 标记语言 的一个子集。可以用它定义小标题和简单的项目列表。在较早的 GTK-Doc 版本中，内容会原样渲染(列表项会显示在一行，以短划线隔开)。

使用markdown进行GTK-Doc块注释

    /**
     * 标识符:
     *
     * 文档内容 ...
     *
     * # 小标题 #
     *
     * 更多文档：
     * - 列表项1
     * - 列表项2
     *
     * 其余更多文档。
     */

如早先所述，GTK-Doc是为编写公共的API而作的。所以你不能够为静态符号编写文档。尽管如此，它也可以很好地为那些符号作注释。这有助于他人理解你的代码。因此我们建议你用普通的注释来注释它们（不使用第一行的第二个'*'号）。如果以后函数须要作为public，你须做的只是在注释块中加入另一个 '*'号并且在区段文件里插入正确的标识符名称。

### 文档章节

文档的每个章节都包含着关于一个类或模块的信息。要介绍它的组件，你可以编写一节注释块。在内容表格中也可以使用简短的描述。所有的@fields都是可选的。

节注释块

    /**
     * SECTION:meepapp
     * @short_description: the application class
     * @title: Meep application
     * @section_id:
     * @see_also: #MeepSettings
     * @stability: Stable
     * @include: meep/app.h
     * @image: application.png
     *
     * The application class handles ...
     */

SECTION:<name>

  名字链接这节文档到文件`<package>-sections.txt`中对应的部分。这里的名字应匹配`<package>-sections.txt`文件中的<FILE>标识。

@short_description

  该节的单行描述，不久将出现在TOC里的链接后和该节页面的顶部。

@title

  段落的标题在SECTION声明里默认是 <name> 。它可以由@title字段替换。

@section_id

  替换标题的用途作为一个段落指示器。对于GObjects，<title>用作section_id且对于其它的段落它是<MODULE>-<title>。

@see_also

  与本节相关的标识符。

@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

  本章节的参考页顶部显示的图像。这常常是某些用于阐释一个类或者图表与其它类之间关系的可视化图示。这个项是可选的。

为避免不必要的重编译，在文档改动后尽可能把段落文档放入C代码中合适的位置。

### 编写符号文档

每个符号（函数，宏，结构，枚举，信号及属性）都在各自独立的块中描述。这些块最好放置于接近标识符定义的地方，这样可以容易地让它们保持同步。因此函数通常在C代码中定义，宏和结构及枚举在头文件里定义。

#### 一般标记

你可以为所有的文档元素加入版本信息，表明何时引入或废弃了某个API。

版本标记

始于：

  描述从哪个版本的代码开始加入了该API。

废弃：

  表明这个函数不应再使用的一段文档。描述文字应向读者介绍新的API。

(FIXME : 稳定性信息)

一般标记

    /**
     * foo_get_bar:
     * @foo: some foo
     *
     * Retrieves @foo's bar.
     *
     * Returns: @foo's bar
     *
     * Since: 2.6
     * Deprecated: 2.12: Use foo_baz_get_bar() instead.
     */
    Bar *
    foo_get_bar(Foo *foo)
    {
    ...

#### 函数注释块

请记得：

- 描述返回的对象、列表、字符串等是否应释放内存(freed)/解除引用/释放(released)。

- 描述参数可否为NULL，如果是的话会发生什么。

- 在适当时提及相关的前提条件与后续条件。

Gtk-doc 假定所有以'_'符开头的符号（宏，函数）是私有的并视它们为静态函数。

Also, take a look at GObject Introspection annotation tags: http://live.gnome.org/GObjectIntrospection/Annotations

函数注释块

    /**
     * function_name:
     * @par1:  对参数 1 的描述。
     * 可超过一行。
     * @par2:  对参数 2 的描述
     * @...: 一个以 %NULL 终止的 bars 列表
     *
     * 这里是函数描述。您可以用 @par1 引用参数，这样在输出中它们会突出显示。
     * 您也可以使用 %constant 代表常量，function_name2() 代表函数，#GtkWidget
     * 代表指向指向其他声明的链接(可能在其他位置描述)。
     *
     * 返回值: 一个整型值。
     *
     * 始于: 2.2
     * 废弃: 2.18: 请转用 other_function()。
     */

函数标记

返回值：

  描述返回结果的段落。

@...:

  如果函数有变长参数列表，你应当使用这个标记（@Varargs: 由于历史原因确实也管用）。

#### 属性注释块

属性注释块

    /**
     * SomeWidget:some-property:
     *
     * 这里您可以描述一个属性。
     */
    g_object_class_install_property (object_class, PROP_SOME_PROPERTY, ...);

#### 信号注释块

请记得：

- 描述信号何时发射(emitted)及在其它信号之前还是之后发射。

- 描述应用程序在信号处理函数中能做些什么。

信号注释块

    /**
     * FooWidget::foobarized:
     * @widget: 接受信号的窗口部件
     * @foo: some foo
     * @bar: some bar
     *
     * ::foobarized 信号在每次有人尝试 foobarize @widget 时发射。
     */
    foo_signals[FOOBARIZE] =
      g_signal_new ("foobarize",
                    ...

#### 结构注释块

结构注释块

    /**
     * FooWidget:
     * @bar: some #gboolean
     *
     * 这是史上最好的窗口部件。
     */
    typedef struct _FooWidget {
      /*< private >*/
      GtkWidget parent;

      /*< public >*/
      gboolean bar;
    } FooWidget;

在你需要隐藏的私有结构字段之前使用`/*< private >*/` 。反之使用`/*< public >*/`.

结构注释块也可以用于GObjects与GObjectClasses。为一个类添加注释块通常是个极好的主意，如果它有vmethod（因为这是怎样制作它的文档的方法）。对于GObject自身而言，你可以使用相关的章节文档，如果对象实例有公共字段，为每个实例结构体单独块注释是非常有用的。缺点是这会为同一名字创建两个索引记录（结构与章节）。

#### 枚举注释块

枚举注释块

    /**
     * Something:
     * @SOMETHING_FOO: something foo
     * @SOMETHING_BAR: something bar
     *
     * Enum values used for the thing, to specify the thing.
     */
    typedef enum {
      SOMETHING_FOO,
      SOMETHING_BAR,
      /*< private >*/
      SOMETHING_COUNT
    } Something;

在你要隐藏的枚举数值前使用`/*< private >*/`。反之使用`/*< public >*/` 。

### 有用的DocBook标记

这些是在编写代码文档时非常有用处的DocBook标记。

To link to another section in the GTK docs:

    <link linkend="glib-Hash-Tables">Hash Tables</link>

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.

引用一个外部函数，比如一个标准 C 函数：

    <function>...</function>

要包含示例代码：

    <example>
      <title>Using a GHashTable.</title>
      <programlisting>
          ...
      </programlisting>
    </example>

或类似的，很短的不需要标题的代码段：

    <informalexample>
      <programlisting>
      ...
      </programlisting>
    </informalexample>

对后者，GTK-Doc 还支持一种缩写方式：|[ ... ]|

要包含符号列表：

    <itemizedlist>
      <listitem>
        <para>
          ...
        </para>
      </listitem>
      <listitem>
        <para>
          ...
        </para>
      </listitem>
    </itemizedlist>

要包含一条文字中突出显示的注解：

    <note>
      <para>
        Make sure you free the data after use.
      </para>
    </note>

要引用一个类型：

    <type>unsigned char</type>

引用一个外部结构（不是在GTK 文档中描述的）：

    <structname>XFontStruct</structname>

要引用一个结构字段：

    <structfield>len</structfield>

要引用一个类的名字，你可能会使用：

    <classname>GtkWidget</classname>

但是你可能正在使用#GtkWidget（要自动创建一个到GtkWidget 页面的链接－请参阅缩写）。

要强调文本：

    <emphasis>This is important</emphasis>

对于文件名，使用：

    <filename>/home/user/documents</filename>

要引用键值，使用：

    <keycombo><keycap>Control</keycap><keycap>L</keycap></keycombo>

## 填充额外的文件

另有几个文件要和内嵌源代码注释一起维护：`<package>.types`, `<package>-docs.xml` (原为 .sgml), `<package>-sections.txt`。

### 编辑类型文件

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.

示例类型文件代码段

    #include <gtk/gtk.h>

    gtk_accel_label_get_type
    gtk_adjustment_get_type
    gtk_alignment_get_type
    gtk_arrow_get_type

从GTK-Doc 1.8开始gtkdoc-scan能够自动生成这个列表。只要往`Makefile.am`文件中的SCAN_OPTIONS项加入“--rebuild-types”即可。如果你要使用它请保证不发行类型文件也不将它置于版本控制系统的管理之下。

### 编辑主文档

GTK-Doc 以 DocBook SGML/XML 格式生成文档。当处理源代码内嵌注释时， GTK-Doc 工具以独立文件为每个类或模块生成一个文档页。主文档包含了它们并且将它们按顺序排列。

GTK-Doc为你创建一个模板主文档，之后的运行就不会再动它了。这意味着你可以自由地组织这个文档，包括分组页和加入的额外页面。GTK-Doc现在有一个测试套件，它的主文档也重新生成。建议您经常关注它，又了解是否引入了新的功能特性。

不要把教程(tutorial)当作额外的文档来编写。写成额外的章节即可。把你的库教程直接放入API文档的好处就是教程与符号文档之间的链接很容易。另外教程与库一同升级时分离的机会也更高。

那么什么是主文档内部要修改的东西呢？开始只是一点点东西。有一些占位标识（在方括号内部的文本）你应当多留意。

主文档头部

    <bookinfo>
      <title>MODULENAME Reference Manual</title>
      <releaseinfo>
        for MODULENAME [VERSION]
        The latest version of this documentation can be found on-line at
        <ulink role="online-location" url="http://[SERVER]/MODULENAME/index.html">http://[SERVER]/MODULENAME/</ulink>.
      </releaseinfo>
    </bookinfo>

    <chapter>
      <title>[Insert title here]</title>

### 编辑节文件(section file)

节文件用于组织由GTK-Doc输出的文档。在此你指定哪个符号属于哪个类或模块，并控制它是否可见(公共的或私有的)。

The section file is a plain text file with XML-like syntax (using tags). Blank lines are ignored and lines starting with a '#' are treated as comment lines.

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 SGML/XML file `sgml/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).

<TITLE> ... </TITLE>标记用于节的标题。它只在模板（如果使用的话）最初创建之前有用，因为设置在模板文件内的标题覆盖了它。或者如果你在源代码中使用了SECTION注释（此功能已过时）。

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.

## 控制结果

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 `TESTS=$(GTKDOC_CHECK)` 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 gtkdoc to keep the intermediate scanner file for further analysis, by running it as `GTK_DOC_KEEP_INTERMEDIATE=1 make`.

## 为其它接口书写文档

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.

### 命令行选项与 man 页面

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.

#### 为工具书写文档

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.

#### 添加额外的配置检查

额外的配置检查

    AC_ARG_ENABLE(man,
                  [AC_HELP_STRING([--enable-man],
                                  [regenerate man pages from Docbook [default=no]])],enable_man=yes,
                  enable_man=no)

    AC_PATH_PROG([XSLTPROC], [xsltproc])
    AM_CONDITIONAL(ENABLE_MAN, test x$enable_man != xno)

#### 添加额外的makefile规则

额外的配置检查

    man_MANS = \
           meeper.1

    if ENABLE_GTK_DOC
    if ENABLE_MAN

    %.1 : %.xml
            @XSLTPROC@ -nonet http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl $<

    endif
    endif

    BUILT_EXTRA_DIST = $(man_MANS)
    EXTRA_DIST += meep.xml

### DBus接口

(FIXME: http://hal.freedesktop.org/docs/DeviceKit/DeviceKit.html, http://cgit.freedesktop.org/DeviceKit/DeviceKit/tree/doc/dbus)

## 常见问题

问题 答案
- 无类继承关系。 对象的 `xxx_get_type()` 函数未进入 `<package>.types` 文件。
- 仍无类继承关系。 Missing or wrong naming in `<package>-sections.txt` file (see explanation).
- 该死，我仍然没有类继承关系。 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).
- 无标识符索引。 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 incidentialy makred 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.

Version 1.1, March 2000
2000 Free Software Foundation, Inc.

    Free Software Foundation, Inc. 51 Franklin Street,
            Suite 330, Boston, MA
            02110-1301  USA

Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.

## GNU 自由文档许可证

### 0. PREAMBLE

The purpose of this License is to make a manual, textbook, or other written document free in the sense of freedom: to assure everyone the effective freedom to copy and redistribute it, with or without modifying it, either commercially or noncommercially. Secondarily, this License preserves for the author and publisher a way to get credit for their work, while not being considered responsible for modifications made by others.

This License is a kind of copyleft, which means that derivative works of the document must themselves be free in the same sense. It complements the GNU General Public License, which is a copyleft license designed for free software.

We have designed this License in order to use it for manuals for free software, because free software needs free documentation: a free program should come with manuals providing the same freedoms that the software does. But this License is not limited to software manuals; it can be used for any textual work, regardless of subject matter or whether it is published as a printed book. We recommend this License principally for works whose purpose is instruction or reference.

### 1. APPLICABILITY AND DEFINITIONS

This License applies to any manual or other work that contains a notice placed by the copyright holder saying it can be distributed under the terms of this License. The Document, below, refers to any such manual or work. Any member of the public is a licensee, and is addressed as you.

A Modified Version of the Document means any work containing the Document or a portion of it, either copied verbatim, or with modifications and/or translated into another language.

A Secondary Section is a named appendix or a front-matter section of the Document that deals exclusively with the relationship of the publishers or authors of the Document to the Document's overall subject (or to related matters) and contains nothing that could fall directly within that overall subject. (For example, if the Document is in part a textbook of mathematics, a Secondary Section may not explain any mathematics.) The relationship could be a matter of historical connection with the subject or with related matters, or of legal, commercial, philosophical, ethical or political position regarding them.

The Invariant Sections are certain Secondary Sections whose titles are designated, as being those of Invariant Sections, in the notice that says that the Document is released under this License.

The Cover Texts are certain short passages of text that are listed, as Front-Cover Texts or Back-Cover Texts, in the notice that says that the Document is released under this License.

A Transparent copy of the Document means a machine-readable copy, represented in a format whose specification is available to the general public, whose contents can be viewed and edited directly and straightforwardly with generic text editors or (for images composed of pixels) generic paint programs or (for drawings) some widely available drawing editor, and that is suitable for input to text formatters or for automatic translation to a variety of formats suitable for input to text formatters. A copy made in an otherwise Transparent file format whose markup has been designed to thwart or discourage subsequent modification by readers is not Transparent. A copy that is not Transparent is called Opaque.

Examples of suitable formats for Transparent copies include plain ASCII without markup, Texinfo input format, LaTeX input format, SGML or XML using a publicly available DTD, and standard-conforming simple HTML designed for human modification. Opaque formats include PostScript, PDF, proprietary formats that can be read and edited only by proprietary word processors, SGML or XML for which the DTD and/or processing tools are not generally available, and the machine-generated HTML produced by some word processors for output purposes only.

The Title Page means, for a printed book, the title page itself, plus such following pages as are needed to hold, legibly, the material this License requires to appear in the title page. For works in formats which do not have any title page as such, Title Page means the text near the most prominent appearance of the work's title, preceding the beginning of the body of the text.

### 2. VERBATIM COPYING

You may copy and distribute the Document in any medium, either commercially or noncommercially, provided that this License, the copyright notices, and the license notice saying this License applies to the Document are reproduced in all copies, and that you add no other conditions whatsoever to those of this License. You may not use technical measures to obstruct or control the reading or further copying of the copies you make or distribute. However, you may accept compensation in exchange for copies. If you distribute a large enough number of copies you must also follow the conditions in section 3.

You may also lend copies, under the same conditions stated above, and you may publicly display copies.

### 3. COPYING IN QUANTITY

If you publish printed copies of the Document numbering more than 100, and the Document's license notice requires Cover Texts, you must enclose the copies in covers that carry, clearly and legibly, all these Cover Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on the back cover. Both covers must also clearly and legibly identify you as the publisher of these copies. The front cover must present the full title with all words of the title equally prominent and visible. You may add other material on the covers in addition. Copying with changes limited to the covers, as long as they preserve the title of the Document and satisfy these conditions, can be treated as verbatim copying in other respects.

If the required texts for either cover are too voluminous to fit legibly, you should put the first ones listed (as many as fit reasonably) on the actual cover, and continue the rest onto adjacent pages.

If you publish or distribute Opaque copies of the Document numbering more than 100, you must either include a machine-readable Transparent copy along with each Opaque copy, or state in or with each Opaque copy a publicly-accessible computer-network location containing a complete Transparent copy of the Document, free of added material, which the general network-using public has access to download anonymously at no charge using public-standard network protocols. If you use the latter option, you must take reasonably prudent steps, when you begin distribution of Opaque copies in quantity, to ensure that this Transparent copy will remain thus accessible at the stated location until at least one year after the last time you distribute an Opaque copy (directly or through your agents or retailers) of that edition to the public.

It is requested, but not required, that you contact the authors of the Document well before redistributing any large number of copies, to give them a chance to provide you with an updated version of the Document.

### 4. 修改

You may copy and distribute a Modified Version of the Document under the conditions of sections 2 and 3 above, provided that you release the Modified Version under precisely this License, with the Modified Version filling the role of the Document, thus licensing distribution and modification of the Modified Version to whoever possesses a copy of it. In addition, you must do these things in the Modified Version:

- A

  Use in the Title Page (and on the covers, if any) a title distinct from that of the Document, and from those of previous versions (which should, if there were any, be listed in the History section of the Document). You may use the same title as a previous version if the original publisher of that version gives permission.

- B

  List on the Title Page, as authors, one or more persons or entities responsible for authorship of the modifications in the Modified Version, together with at least five of the principal authors of the Document (all of its principal authors, if it has less than five).

- C

  State on the Title Page the name of the publisher of the Modified Version, as the publisher.

- D

  Preserve all the copyright notices of the Document.

- E

  Add an appropriate copyright notice for your modifications adjacent to the other copyright notices.

- F

  Include, immediately after the copyright notices, a license notice giving the public permission to use the Modified Version under the terms of this License, in the form shown in the Addendum below.

- G

  Preserve in that license notice the full lists of Invariant Sections and required Cover Texts given in the Document's license notice.

- H

  Include an unaltered copy of this License.

- I

  Preserve the section entitled History, and its title, and add to it an item stating at least the title, year, new authors, and publisher of the Modified Version as given on the Title Page. If there is no section entitled History in the Document, create one stating the title, year, authors, and publisher of the Document as given on its Title Page, then add an item describing the Modified Version as stated in the previous sentence.

- J

  Preserve the network location, if any, given in the Document for public access to a Transparent copy of the Document, and likewise the network locations given in the Document for previous versions it was based on. These may be placed in the History section. You may omit a network location for a work that was published at least four years before the Document itself, or if the original publisher of the version it refers to gives permission.

- K

  In any section entitled Acknowledgements or Dedications, preserve the section's title, and preserve in the section all the substance and tone of each of the contributor acknowledgements and/or dedications given therein.

- L

  Preserve all the Invariant Sections of the Document, unaltered in their text and in their titles. Section numbers or the equivalent are not considered part of the section titles.

- M

  Delete any section entitled Endorsements. Such a section may not be included in the Modified Version.

- N

  Do not retitle any existing section as Endorsements or to conflict in title with any Invariant Section.

If the Modified Version includes new front-matter sections or appendices that qualify as Secondary Sections and contain no material copied from the Document, you may at your option designate some or all of these sections as invariant. To do this, add their titles to the list of Invariant Sections in the Modified Version's license notice. These titles must be distinct from any other section titles.

You may add a section entitled Endorsements, provided it contains nothing but endorsements of your Modified Version by various parties--for example, statements of peer review or that the text has been approved by an organization as the authoritative definition of a standard.

You may add a passage of up to five words as a Front-Cover Text, and a passage of up to 25 words as a Back-Cover Text, to the end of the list of Cover Texts in the Modified Version. Only one passage of Front-Cover Text and one of Back-Cover Text may be added by (or through arrangements made by) any one entity. If the Document already includes a cover text for the same cover, previously added by you or by arrangement made by the same entity you are acting on behalf of, you may not add another; but you may replace the old one, on explicit permission from the previous publisher that added the old one.

The author(s) and publisher(s) of the Document do not by this License give permission to use their names for publicity for or to assert or imply endorsement of any Modified Version .

### 5. COMBINING DOCUMENTS

You may combine the Document with other documents released under this License, under the terms defined in section 4 above for modified versions, provided that you include in the combination all of the Invariant Sections of all of the original documents, unmodified, and list them all as Invariant Sections of your combined work in its license notice.

The combined work need only contain one copy of this License, and multiple identical Invariant Sections may be replaced with a single copy. If there are multiple Invariant Sections with the same name but different contents, make the title of each such section unique by adding at the end of it, in parentheses, the name of the original author or publisher of that section if known, or else a unique number. Make the same adjustment to the section titles in the list of Invariant Sections in the license notice of the combined work.

In the combination, you must combine any sections entitled History in the various original documents, forming one section entitled History; likewise combine any sections entitled Acknowledgements, and any sections entitled Dedications. You must delete all sections entitled Endorsements.

### 6. COLLECTIONS OF DOCUMENTS

You may make a collection consisting of the Document and other documents released under this License, and replace the individual copies of this License in the various documents with a single copy that is included in the collection, provided that you follow the rules of this License for verbatim copying of each of the documents in all other respects.

You may extract a single document from such a collection, and dispbibute it individually under this License, provided you insert a copy of this License into the extracted document, and follow this License in all other respects regarding verbatim copying of that document.

### 7. AGGREGATION WITH INDEPENDENT WORKS

A compilation of the Document or its derivatives with other separate and independent documents or works, in or on a volume of a storage or distribution medium, does not as a whole count as a Modified Version of the Document, provided no compilation copyright is claimed for the compilation. Such a compilation is called an aggregate, and this License does not apply to the other self-contained works thus compiled with the Document , on account of their being thus compiled, if they are not themselves derivative works of the Document. If the Cover Text requirement of section 3 is applicable to these copies of the Document, then if the Document is less than one quarter of the entire aggregate, the Document's Cover Texts may be placed on covers that surround only the Document within the aggregate. Otherwise they must appear on covers around the whole aggregate.

### 8. TRANSLATION

Translation is considered a kind of modification, so you may distribute translations of the Document under the terms of section 4. Replacing Invariant Sections with translations requires special permission from their copyright holders, but you may include translations of some or all Invariant Sections in addition to the original versions of these Invariant Sections. You may include a translation of this License provided that you also include the original English version of this License. In case of a disagreement between the translation and the original English version of this License, the original English version will prevail.

### 9. TERMINATION

You may not copy, modify, sublicense, or distribute the Document except as expressly provided for under this License. Any other attempt to copy, modify, sublicense or distribute the Document is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.

### 10. FUTURE REVISIONS OF THIS LICENSE

The Free Software Foundation may publish new, revised versions of the GNU Free Documentation License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. See http://www.gnu.org/copyleft/.

Each version of the License is given a distinguishing version number. If the Document specifies that a particular numbered version of this License or any later version applies to it, you have the option of following the terms and conditions either of that specified version or of any later version that has been published (not as a draft) by the Free Software Foundation. If the Document does not specify a version number of this License, you may choose any version ever published (not as a draft) by the Free Software Foundation.

### Addendum

To use this License in a document you have written, include a copy of the License in the document and put the following copyright and license notices just after the title page:

> Copyright YEAR YOUR NAME.

> 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 the Invariant Sections being LIST THEIR TITLES, with the Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST. A copy of the license is included in the section entitled GNU Free Documentation License.

If you have no Invariant Sections, write with no Invariant Sections instead of saying which ones are invariant. If you have no Front-Cover Texts, write no Front-Cover Texts instead of Front-Cover Texts being LIST; likewise for Back-Cover Texts.

If your document contains nontrivial examples of program code, we recommend releasing these examples in parallel under your choice of free software license, such as the GNU General Public License, to permit their use in free software.