1 <?xml version="1.0" standalone="no"?>
2 <?xml-stylesheet type="text/xml" href="params.xsl"?>
3 <!-- vim: set ai tw=80 ts=3 sw=3: -->
4 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN" "
5 http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
7 <!ENTITY FDL SYSTEM "fdl-appendix.xml">
8 <!ENTITY FDLlink "<link linkend='fdl'>included</link>">
9 ]><!-- =============Document Header ============================= -->
12 <title>GTK-Doc Manual</title>
13 <edition>1.15</edition>
14 <abstract role="description"><para>User manual for developers with instructions of GTK-Doc usage.</para></abstract>
17 <firstname>Chris</firstname>
18 <surname>Lyttle</surname>
21 <email>chris@wilddev.net</email>
26 <firstname>Dan</firstname>
27 <surname>Mueth</surname>
30 <email>d-mueth@uchicago.edu</email>
35 <firstname>Stefan</firstname>
36 <surname>Kost</surname>
39 <email>ensonic@users.sf.net</email>
44 <publisher role="maintainer">
45 <publishername>GTK-Doc project</publishername>
46 <address><email>gtk-doc-list@gnome.org</email></address>
49 <year>2000, 2005, 2007-2009</year>
50 <holder>Dan Mueth and Chris Lyttle and Stefan Kost</holder>
53 <!-- translators: uncomment this:
56 <holder>ME-THE-TRANSLATOR (Latin translation)</holder>
62 Permission is granted to copy, distribute and/or modify this
63 document under the terms of the <citetitle>GNU Free Documentation
64 License</citetitle>, Version 1.1 or any later version published
65 by the Free Software Foundation with no Invariant Sections, no
66 Front-Cover Texts, and no Back-Cover Texts. A copy of the license
70 Many of the names used by companies to distinguish their products and
71 services are claimed as trademarks. Where those names appear in any
72 GNOME documentation, and those trademarks are made aware to the members
73 of the GNOME Documentation Project, the names have been printed in caps
80 <revnumber>1.16</revnumber>
81 <date>14 Jan 2011</date>
82 <authorinitials>sk</authorinitials>
83 <revremark>bugfixes, layout improvements</revremark>
86 <revnumber>1.15</revnumber>
87 <date>21 May 2010</date>
88 <authorinitials>sk</authorinitials>
89 <revremark>bug and regression fixes</revremark>
92 <revnumber>1.14</revnumber>
93 <date>28 March 2010</date>
94 <authorinitials>sk</authorinitials>
95 <revremark>bugfixes and performance improvements</revremark>
98 <revnumber>1.13</revnumber>
99 <date>18 December 2009</date>
100 <authorinitials>sk</authorinitials>
101 <revremark>broken tarball update</revremark>
104 <revnumber>1.12</revnumber>
105 <date>18 December 2009</date>
106 <authorinitials>sk</authorinitials>
107 <revremark>new tool features and bugfixes</revremark>
110 <revnumber>1.11</revnumber>
111 <date>16 Novemebr 2008</date>
112 <authorinitials>mal</authorinitials>
113 <revremark>GNOME doc-utils migration</revremark>
119 <!-- ======== Chapter 1: Introduction ======================== -->
121 <chapter id="introduction">
122 <title>Introduction</title>
125 This chapter introduces GTK-Doc and gives an overview of what it is and
129 <sect1 id="whatisgtkdoc">
130 <title>What is GTK-Doc?</title>
133 GTK-Doc is used to document C code. It is typically used to document the public
134 API of libraries, such as the GTK+ and GNOME libraries. But it can also be
135 used to document application code.
139 <sect1 id="howdoesgtkdocwork">
140 <title>How Does GTK-Doc Work?</title>
143 GTK-Doc works by using documentation of functions placed inside the source files in
144 specially-formatted comment blocks, or documentation added to the template files
145 which GTK-Doc uses (though note that GTK-Doc will only document functions that
146 are declared in header files; it won't produce output for static functions).
150 GTK-Doc consists of a number of perl scripts, each performing a different step
155 There are 5 main steps in the process:
162 <guilabel>Writing the documentation.</guilabel>
164 The author fills in the source files with the documentation for each
165 function, macro, union etc. (In the past information was entered in
166 generated template files, which is not recommended anymore).
172 <guilabel>Gathering information about the code.</guilabel>
174 <application>gtkdoc-scan</application> scans the header files of the
175 code looking for declarations of functions, macros, enums, structs, and unions.
176 It creates the file <filename><module>-decl-list.txt</filename> containg a list of the
177 declarations, placing them into sections according to which header file they
178 are in. On the first run this file is copied to <filename><module>-sections.txt</filename>.
179 The author can rearrange the sections, and the order of the
180 declarations within them, to produce the final desired order.
181 The second file it generates is <filename><module>-decl.txt</filename>.
182 This file contains the full declarations found by the scanner. If for
183 some reason one would like some symbols to show up in the docs, where
184 the full declaration cannot be found by the scanner or the declaration
185 should appear differently, one can place enties similar to the ones in
186 <filename><module>-decl.txt</filename> into <filename><module>-overrides.txt</filename>.
188 <application>gtkdoc-scanobj</application> can also be used to dynamically query a library about
189 any GtkObject subclasses it exports. It saves information about each
190 object's position in the class hierarchy and about any GTK Args and Signals it
197 <guilabel>Generating the "template" files.</guilabel>
199 <application>gtkdoc-mktmpl</application> creates a number of files in
200 the <filename class='directory'>tmpl/</filename> subdirectory, using the
201 information gathered in the first step. (Note that this can be run
202 repeatedly. It will try to ensure that no documentation is ever lost.)
206 Since GTK-Doc 1.9 the templates can be avoided. We encourage people to keep
207 documentation in the code. <application>gtkdocize</application> supports now
208 a <option>--flavour no-tmpl</option> option that chooses a makefile that
209 skips tmpl usage totally.
210 If you have never changed file in tmpl by hand, please remove the dir
211 (e.g. from version control system).
218 <guilabel>Generating the SGML/XML and HTML/PDF.</guilabel>
220 <application>gtkdoc-mkdb</application> turns the template files into
221 SGML or XML files in the <filename class='directory'>sgml/</filename>
222 or <filename class='directory'>xml/</filename> subdirectory.
223 If the source code contains documentation on functions, using the
224 special comment blocks, it gets merged in here. If there are no tmpl files used
225 it only reads docs from sources and introspection data. We recommend
229 <application>gtkdoc-mkhtml</application> turns the SGML/XML files into HTML
230 files in the <filename class='directory'>html/</filename> subdirectory.
231 Likewise <application>gtkdoc-mkpdf</application> turns the SGML/XML files into a PDF
232 document called <filename><package>.pdf</filename>.
235 Files in <filename class='directory'>sgml/</filename> or
236 <filename class='directory'>xml/</filename> and <filename class='directory'>html/</filename>
237 directories are always overwritten. One should never edit them directly.
243 <guilabel>Fixing up cross-references between documents.</guilabel>
245 After installing the HTML files, <application>gtkdoc-fixxref</application> can be run to fix up any
246 cross-references between separate documents. For example, the GTK+
247 documentation contains many cross-references to types documented in the GLib manual.
249 When creating the source tarball for distribution, <application>gtkdoc-rebase</application>
250 turns all external links into web-links. When installing distributed (pregenerated) docs
251 the same application will try to turn links back to local links
252 (where those docs are installed).
259 <sect1 id="gettinggtkdoc">
260 <title>Getting GTK-Doc</title>
262 <sect2 id="requirements">
263 <title>Requirements</title>
265 <guilabel>Perl v5</guilabel> - the main scripts are in Perl.
268 <guilabel>DocBook DTD v3.0</guilabel> - This is the DocBook SGML DTD.
269 <ulink url="http://www.ora.com/davenport" type="http">http://www.ora.com/davenport</ulink>
272 <guilabel>Jade v1.1</guilabel> - This is a DSSSL processor for converting SGML to various formats.
273 <ulink url="http://www.jclark.com/jade" type="http">http://www.jclark.com/jade</ulink>
276 <guilabel>Modular DocBook Stylesheets</guilabel>
277 This is the DSSSL code to convert DocBook to HTML (and a few other
278 formats). It's used together with jade.
279 I've customized the DSSSL code slightly, in gtk-doc.dsl, to colour
280 the program code listings/declarations, and to support global
281 cross-reference indices in the generated HTML.
282 <ulink url="http://nwalsh.com/docbook/dsssl" type="http">http://nwalsh.com/docbook/dsssl</ulink>
285 <guilabel>docbook-to-man</guilabel> - if you want to create man pages from the DocBook.
286 I've customized the 'translation spec' slightly, to capitalise section
287 headings and add the 'GTK Library' title at the top of the pages and the
288 revision date at the bottom.
289 There is a link to this on <ulink url="http://www.ora.com/davenport" type="http">http://www.ora.com/davenport</ulink>
290 NOTE: This does not work yet.
294 <sect2 id="installation">
295 <title>Installation</title>
297 There is no standard place where the DocBook Modular Stylesheets are installed.
300 GTK-Doc's configure script searches these 3 directories automatically:
303 <filename> /usr/lib/sgml/stylesheets/nwalsh-modular </filename> (used by RedHat)
306 <filename> /usr/lib/dsssl/stylesheets/docbook </filename> (used by Debian)
309 <filename> /usr/share/sgml/docbkdsl </filename> (used by SuSE)
312 If you have the stylesheets installed somewhere else, you need to configure
313 GTK-Doc using the option:
314 <command> --with-dsssl-dir=<PATH_TO_TOPLEVEL_STYLESHEETS_DIR> </command>
320 <!-- not realy worth a section
321 <sect1 id="whentousegtkdoc">
322 <title>When to Use GTK-Doc</title>
325 (What things GTK-Doc should, and shouldn't, be used for.)
327 (- non C-based projects)
334 <sect1 id="aboutgtkdoc">
335 <title>About GTK-Doc</title>
342 (History, authors, web pages, license, future plans,
343 comparison with other similar systems.)
348 <sect1 id="aboutthismanual">
349 <title>About this Manual</title>
356 (who it is meant for, where you can get it, license)
363 <chapter id="settingup">
364 <title>Setting up your project</title>
367 The next sections describe what steps to perform to integrate GTK-Doc into
368 your project. Theses sections assume we work on a project called 'meep'.
369 This project contains a library called 'libmeep' and
370 an end-user app called 'meeper'.
373 <sect1 id="settingup_docfiles">
374 <title>Setting up a skeleton documentation</title>
377 Under your top-level project directory create folders called docs/reference
378 (this way you can also have docs/help for end-user documentation).
379 It is recommended to create another subdirectory with the name of the doc-package.
380 For packages with just one library this step is not necessary.
384 This can then look as shown below:
385 <example><title>Example directory structure</title>
402 <sect1 id="settingup_autoconf">
403 <title>Integration with autoconf</title>
406 Very easy! Just add one line to your <filename>configure.ac</filename> script.
410 <example><title>Integration with autoconf</title>
414 GTK_DOC_CHECK([1.14],[--flavour no-tmpl])
421 This will require all developers to have gtk-doc installed. If it is
422 okay for your project to have optional api-doc build setup, you can
423 solve this as below. Keep it as is, as gtkdocize is looking for
424 <function>GTK_DOC_CHECK</function> at the start of a line.
425 <example><title>Keep gtk-doc optional</title>
429 m4_ifdef([GTK_DOC_CHECK], [
430 GTK_DOC_CHECK([1.14],[--flavour no-tmpl])
432 AM_CONDITIONAL([ENABLE_GTK_DOC], false)
440 The first argument is used to check for the gtkdocversion at configure time.
441 The 2nd, optional argument is used by <application>gtkdocize</application>.
442 The <symbol>GTK_DOC_CHECK</symbol> macro also adds several configure switches:
445 <listitem><para>--with-html-dir=PATH : path to installed docs</para></listitem>
446 <listitem><para>--enable-gtk-doc : use gtk-doc to build documentation [default=no]</para></listitem>
447 <listitem><para>--enable-gtk-doc-html : build documentation in html format [default=yes]</para></listitem>
448 <listitem><para>--enable-gtk-doc-pdf : build documentation in pdf format [default=no]</para></listitem>
453 GTK-Doc is disabled by default! Remember to pass the option
454 <option>'--enable-gtk-doc'</option> to the next
455 <filename>configure</filename> run. Otherwise pregenerated documentation is installed
456 (which makes sense for users but not for developers).
461 Furthermore it is recommended that you have the following line inside
462 you <filename>configure.ac</filename> script.
463 This allows <application>gtkdocize</application> to automatically copy the
464 macro definition for <function>GTK_DOC_CHECK</function> to your project.
468 <example><title>Preparation for gtkdocize</title>
471 AC_CONFIG_MACRO_DIR(m4)
478 <sect1 id="settingup_automake">
479 <title>Integration with automake</title>
482 First copy the <filename>Makefile.am</filename> from the examples subdirectory of the gtkdoc-sources
483 to your project's API documentation directory (
484 <filename class='directory'>./docs/reference/<package></filename>).
485 If you have multiple doc-packages repeat this for each one.
489 The next step is to edit the settings inside the <filename>Makefile.am</filename>.
490 All the settings have a comment above that describes their purpose.
491 Most settings are extra flags passed to the respective tools. Every tool
492 has a variable of the form <option><TOOLNAME>_OPTIONS</option>.
493 All the tools support <option>--help</option> to list the supported
497 <!-- FIXME: explain options ? -->
500 You may also want to enable GTK-Doc for the distcheck make target. Just
501 add the one line shown in the next example to your top-level
502 <filename>Makefile.am</filename>:
506 <example><title>Enable GTK-Doc during make distcheck</title>
509 DISTCHECK_CONFIGURE_FLAGS=--enable-gtk-doc
517 <sect1 id="settingup_autogen">
518 <title>Integration with autogen</title>
521 Most projects will have an <filename>autogen.sh</filename> script to
522 setup the build infrastructure after a checkout from version control
523 system (such as cvs/svn/git). GTK-Doc comes with a tool called
524 <application>gtkdocize</application> which can be used in such a script.
525 It should be run before autoheader, automake or autoconf.
529 <example><title>Running gtkdocize from autogen.sh</title>
539 When running <application>gtkdocize</application> it copies
540 <filename>gtk-doc.make</filename> to your project root (or any directory
541 specified by the <option>--docdir</option> option).
542 It also checks you configure script for the <function>GTK_DOC_CHECK</function>
543 invocation. This macro can be used to pass extra parameters to
544 <application>gtkdocize</application>.
548 Historically GTK-Doc was generating template files where developers entered the docs.
549 This turned out to be not so good (e.g. the need for having generated
550 files under version control).
551 Since GTK-Doc 1.9 the tools can get all the information from source comments
552 and thus the templates can be avoided. We encourage people to keep
553 documentation in the code. <application>gtkdocize</application> supports now
554 a <option>--flavour no-tmpl</option> option that chooses a makefile that skips
555 tmpl usage totally. Besides adding the option directly to the command
556 invocation, they can be added also to an environment variable called <symbol>GTKDOCIZE_FLAGS</symbol>
557 or set as a 2nd parameter in <symbol>GTK_DOC_CHECK</symbol> macro in the configure script.
558 If you have never changed file in tmpl by hand and migrating from older gtkdoc versions,
559 please remove the dir (e.g. from version control system).
563 <sect1 id="settingup_firstrun">
564 <title>Running the doc build</title>
567 After the previous steps it's time to run the build. First we need to
568 rerun <filename>autogen.sh</filename>. If this script runs configure for
569 you, then give it the <option>--enable-gtk-doc</option> option.
570 Otherwise manually run <filename>configure</filename> with this option
574 The first make run generates several additional files in the doc-dirs.
575 The important ones are:
576 <filename><package>.types</filename>,
577 <filename><package>-docs.sgml</filename>,
578 <filename><package>-sections.txt</filename>.
581 <example><title>Running the doc build</title>
584 ./autogen.sh --enable-gtk-doc
591 Now you can point your browser to <filename>docs/reference/<package>/index.html</filename>.
592 Yes, it's a bit disappointing still. But hang-on, during the next chapter we
593 tell you how to fill the pages with life.
597 <sect1 id="settingup_vcs">
598 <title>Integration with version control systems</title>
601 As a rule of the thumb, it's those files you edit, that should go under
602 version control. For typical projects it's these files:
603 <filename><package>.types</filename>
604 <filename><package>-docs.sgml</filename>
605 <filename><package>-sections.txt</filename>
606 <filename>Makefile.am</filename>
612 <chapter id="documenting">
613 <title>Documenting the code</title>
616 GTK-Doc uses source code comment with a special syntax for code documentation.
617 Further it retrieves information about your project structure from other
618 sources. During the next section you will find all information about the
619 syntax of the comments.
623 <title>Documentation placement</title>
625 In the past most documentation had to be filled into files residing
626 inside the <filename>tmpl</filename> directory. This has the
627 disadvantages that the information is often not updated and also that
628 the file tend to cause conflicts with version control systems.
631 The avoid the aforementioned problems we suggest putting the
632 documentation inside the sources. This manual will only describe this
633 way of documenting code.
638 The scanner can handle the majority of c headers fine. In the case of
639 receiving warnings from the scanner that look like a special case, one can
640 hint GTK-Doc to skip over them.
641 <example><title>GTK-Doc comment block</title>
644 #ifndef __GTK_DOC_IGNORE__
645 /* unparseable code here */
654 <sect1 id="documenting_syntax">
655 <title>Documentation comments</title>
658 A multiline comment that starts with an additional '*' marks a
659 documentation block that will be processed by the GTK-Doc tools.
660 <example><title>GTK-Doc comment block</title>
673 The 'identifier' is one line with the name of the item the comment is
674 related to. The syntax differs a little depending on the item.
675 (TODO add table showing identifiers)
679 The 'documentation' block is also different for each symbol type. Symbol
680 types that get parameters such as functions or macros have the parameter
681 description first followed by a blank line (just a '*').
682 Afterwards follows the detailed description. All lines (outside program-
683 listings and CDATA sections) just containing a ' *' (blank-asterisk) are
684 converted to paragraph breaks.
685 If you don't want a paragraph break, change that into ' * '
686 (blank-asterisk-blank-blank).
690 One advantage of hyper-text over plain-text is the ability to have links
691 in the document. Writing the correct markup for a link can be tedious
692 though. GTK-Doc comes to help by providing several useful abbreviations.
696 Use function() to refer to functions or macros which take arguments.
701 Use @param to refer to parameters. Also use this when referring to
702 parameters of other functions, related to the one being described.
707 Use %constant to refer to a constant, e.g. %G_TRAVERSE_LEAFS.
712 Use #symbol to refer to other types of symbol, e.g. structs and
713 enums and macros which don't take arguments.
718 Use #Object::signal to refer to a GObject signal
723 Use #Object:property to refer to a GObject property
728 Use #Struct.field to refer to a field inside a structure.
736 If you need to use the special characters '<', '>', '()', '@',
737 '%', or '#' in your documentation without GTK-Doc changing them you
738 can use the XML entities "&lt;", "&gt;", "&lpar;",
739 "&rpar;", "&commat;", "&percnt;" and "&num;"
740 respectively or escape them with a backslash '\'.
745 DocBook can do more that just links. One can also have lists, tables and
746 examples. To enable the usage of SGML/XML tags inside doc-comments you
747 need to have <option>--xml-mode</option> or <option>--sgml-mode</option>
748 in the variable <symbol>MKDB_OPTIONS</symbol> inside
749 <filename>Makefile.am</filename>.
754 As already mentioned earlier GTK-Doc is for documenting public API. Thus
755 one cannot write documentation for static symbols. Nevertheless it is good
756 to comment those symbols too. This helps other to understand you code.
757 Therefore we recommend to comment these using normal comments (without the
758 2nd '*' in the first line).
759 If later the function needs to be made public, all one needs to do is to
760 add another '*' in the comment block and insert the symbol name at the
761 right place inside the sections file.
766 <sect1 id="documenting_sections">
767 <title>Documenting sections</title>
770 Each section of the documentation contains information about one class
771 or module. To introduce the component one can write a section block.
772 The short description is also used inside the table of contents.
773 All the @fields are optional.
777 <example><title>Section comment block</title>
782 * @short_description: the application class
783 * @title: Meep application
785 * @see_also: #MeepSettings
787 * @include: meep/app.h
788 * @image: application.png
790 * The application class handles ...
799 <term>SECTION:<name></term>
802 The name links the section documentation to the respective part in
803 the <filename><package>-sections.txt</filename> file. The
804 name give here should match the <FILE> tag in the
805 <filename><package>-sections.txt</filename> file.
810 <term>@short_description</term>
813 A one line description of the section, that later will appear after
814 the links in the TOC and at the top of the section page.
822 The section title defaults to <name> from the SECTION
823 declaration. It can be overridden with the @title field.
828 <term>@section_id</term>
831 Overrides the use of title as a section identifier. For GObjects
832 the <title> is used as a section_id and for other sections
833 it is <MODULE>-<title>.
838 <term>@see_also</term>
841 A list of symbols that are related to this section.
846 <term>@stability</term>
849 A informal description of the stability level this API has.
850 We recommend the use of one of these terms:
855 - The intention of a Stable interface is to enable arbitrary
856 third parties to develop applications to these interfaces,
857 release them, and have confidence that they will run on all
858 minor releases of the product (after the one in which the
859 interface was introduced, and within the same major release).
860 Even at a major release, incompatible changes are expected
861 to be rare, and to have strong justifications.
867 - Unstable interfaces are experimental or transitional.
868 They are typically used to give outside developers early
869 access to new or rapidly changing technology, or to provide
870 an interim solution to a problem where a more general
871 solution is anticipated.
872 No claims are made about either source or binary
873 compatibility from one minor release to the next.
879 - An interface that can be used within the GNOME stack
880 itself, but that is not documented for end-users. Such
881 functions should only be used in specified and documented
888 - An interface that is internal to a module and does not
889 require end-user documentation. Functions that are
890 undocumented are assumed to be Internal.
898 <term>@include</term>
901 The <literal>#include</literal> files to show in the section
902 synopsis (a comma separated list), overriding the global
903 value from the <link linkend="metafiles_sections">section
904 file</link> or command line. This item is optional.
912 The image to display at the top of the reference page for this
913 section. This will often be some sort of a diagram to illustrate
914 the visual appearance of a class or a diagram of its relationship
915 to other classes. This item is optional.
923 To avoid unnecessary recompilation after doc-changes put the section
924 docs into the c-source where possible.
930 <sect1 id="documenting_symbols">
931 <title>Documenting symbols</title>
934 Each symbol (function, macro, struct, enum, signal and property) is
935 documented in a separate block. The block is best placed close to the
936 definition of the symbols so that it is easy to keep them in sync.
937 Thus functions are usually documented in the c-source and macros,
938 structs and enums in the header file.
941 <sect2><title>General tags</title>
944 You can add versioning information to all documentation elements to tell
945 when an api was introduced, or when it was deprecated.
948 <variablelist><title>Versioning Tags</title>
949 <varlistentry><term>Since:</term>
952 Description since which version of the code the API is available.
956 <varlistentry><term>Deprecated:</term>
959 Paragraph denoting that this function should no be used anymore.
960 The description should point the reader to the new API.
967 (FIXME : Stability information)
970 <example><title>General tags</title>
977 * Retrieves @foo's bar.
979 * Returns: @foo's bar
982 * Deprecated: 2.12: Use foo_baz_get_bar() instead.
985 foo_get_bar(Foo *foo)
993 <sect2><title>Function comment block</title>
1000 Document whether returned objects, lists, strings, etc, should be
1001 freed/unrefed/released.
1006 Document whether parameters can be NULL, and what happens if they are.
1011 Mention interesting pre-conditions and post-conditions where appropriate.
1018 Gtk-doc assumes all symbols (macros, functions) starting with '_' are
1019 private. They are treated like static functions.
1023 <!-- FIXME: we should ideally link/describe the gobject introspection
1025 Also, take a look at gobject introspection annotation tags:
1026 http://live.gnome.org/GObjectIntrospection/Annotations
1029 <example><title>Function comment block</title>
1034 * @par1: description of parameter 1. These can extend over more than
1036 * @par2: description of parameter 2
1037 * @...: a %NULL-terminated list of bars
1039 * The function description goes here. You can use @par1 to refer to parameters
1040 * so that they are highlighted in the output. You can also use %constant
1041 * for constants, function_name2() for functions and #GtkWidget for links to
1042 * other declarations (which may be documented elsewhere).
1044 * Returns: an integer.
1047 * Deprecated: 2.18: Use other_function() instead.
1053 <variablelist><title>Function tags</title>
1054 <varlistentry><term>Returns:</term>
1057 Paragraph describing the returned result.
1061 <varlistentry><term>@...:</term>
1064 In case the function has variadic arguments, you should use this
1065 tag (@Varargs: does also work for historic reasons).
1073 <sect2><title>Property comment block</title>
1075 <example><title>Property comment block</title>
1079 * SomeWidget:some-property:
1081 * Here you can document a property.
1083 g_object_class_install_property (object_class, PROP_SOME_PROPERTY, ...);
1090 <sect2><title>Signal comment block</title>
1097 Document when the signal is emitted and whether it is emitted before
1098 or after other signals.
1103 Document what an application might do in the signal handler.
1109 <example><title>Signal comment block</title>
1113 * FooWidget::foobarized:
1114 * @widget: the widget that received the signal
1118 * The ::foobarized signal is emitted each time someone tries to foobarize @widget.
1120 foo_signals[FOOBARIZE] =
1121 g_signal_new ("foobarize",
1129 <sect2><title>Struct comment block</title>
1130 <example><title>Struct comment block</title>
1135 * @bar: some #gboolean
1137 * This is the best widget, ever.
1139 typedef struct _FooWidget {
1151 Use <code>/*< private >*/</code> before the private struct fields
1152 you want to hide. Use <code>/*< public >*/</code> for the reverse
1157 Struct comment blocks can also be used for GObjects and GObjectClasses.
1158 It is usualy a good idea to add a comment blco for a class, if it has
1159 vmethods (as this is how they can be documented). For the GObject
1160 itself one can use the related section docs, having a separate block
1161 for the instance struct would be useful if the instance has public
1162 fields. One disadvantage here is that this creates two index entries
1163 of the same name (the structure and the section).
1168 <sect2><title>Enum comment block</title>
1169 <example><title>Enum comment block</title>
1174 * @SOMETHING_FOO: something foo
1175 * @SOMETHING_BAR: something bar
1177 * Enum values used for the thing, to specify the thing.
1191 Use <code>/*< private >*/</code> before the private enum values
1192 you want to hide. Use <code>/*< public >*/</code> for the reverse
1199 <sect1 id="documenting_docbook">
1200 <title>Useful DocBook tags</title>
1203 Here are some DocBook tags which are most useful when documenting the
1208 To link to another section in the GTK docs:
1213 <link linkend="glib-Hash-Tables">Hash Tables</link>
1217 The linkend is the SGML/XML id on the top item of the page you want to link to.
1218 For most pages this is currently the part ("gtk", "gdk", "glib") and then
1219 the page title ("Hash Tables"). For widgets it is just the class name.
1220 Spaces and underscores are converted to '-' to conform to SGML/XML.
1224 To refer to an external function, e.g. a standard C function:
1228 <function>...</function>
1235 To include example code:
1240 <title>Using a GHashTable.</title>
1248 or possibly this, for very short code fragments which don't need a title:
1260 For the latter GTK-Doc also supports an abbreviation:
1269 To include bulleted lists:
1291 To include a note which stands out from the text:
1297 Make sure you free the data after use.
1310 <type>unsigned char</type>
1317 To refer to an external structure (not one described in the GTK docs):
1321 <structname>XFontStruct</structname>
1328 To refer to a field of a structure:
1332 <structfield>len</structfield>
1339 To refer to a class name, we could possibly use:
1343 <classname>GtkWidget</classname>
1347 but you'll probably be using #GtkWidget instead (to automatically create
1348 a link to the GtkWidget page - see <link linkend="documenting_syntax">the abbreviations</link>).
1356 <emphasis>This is important</emphasis>
1367 <filename>/home/user/documents</filename>
1374 To refer to keys use:
1378 <keycombo><keycap>Control</keycap><keycap>L</keycap></keycombo>
1387 <chapter id="metafiles">
1388 <title>Filling the extra files</title>
1391 There are a couple of extra files, that need to be maintained along with
1392 the inline source code comments:
1393 <filename><package>.types</filename>,
1394 <filename><package>-docs.sgml</filename>,
1395 <filename><package>-sections.txt</filename>.
1398 <sect1 id="metafiles_types">
1399 <title>Editing the types file</title>
1402 If your library or application includes GtkObjects/GObjects, you want
1403 their signals, arguments/parameters and position in the hierarchy to be
1404 shown in the documentation. All you need to do, is to list the
1405 <function>xxx_get_type</function> functions together with their include
1406 inside the <filename><package>.types</filename> file.
1410 <example><title>Example types file snippet</title>
1413 #include <gtk/gtk.h>
1415 gtk_accel_label_get_type
1416 gtk_adjustment_get_type
1417 gtk_alignment_get_type
1425 Since GTK-Doc 1.8 <application>gtkdoc-scan</application> can generate this list for you.
1426 Just add "--rebuild-types" to SCAN_OPTIONS in <filename>Makefile.am</filename>. If you
1427 use this approach you should not dist the types file nor have it under version control.
1432 <sect1 id="metafiles_master">
1433 <title>Editing the master document</title>
1436 GTK-Doc produces documentation in DocBook SGML/XML. When processing the
1437 inline source comments, the GTK-Doc tools generate one documentation
1438 page per class or module as a separate file. The master document
1439 includes them and place them in an order.
1443 While GTK-Doc creates a template master document for you, later run will
1444 not touch it again. This means that one can freely structure the
1445 documentation. That includes grouping pages and adding extra pages.
1446 GTK-Doc has now a test suite, where also the master-document is recreated from scratch.
1447 Its a good idea to look at this from time to time to see if there are some new goodies
1453 Do not create tutorials as extra documents. Just write extra chapters.
1454 The benefit of directly embedding the tutorial for your library into
1455 the API documentation is that it is easy to link for the tutorial to
1456 symbol documentation. Apart chances are higher that the tutorial gets
1457 updates along with the library.
1462 So what are the things to change inside the master document? For a start
1463 is only a little. There are some placeholders (text in square brackets)
1464 there which you should take care of.
1468 <example><title>Master document header</title>
1472 <title>MODULENAME Reference Manual</title>
1474 for MODULENAME [VERSION]
1475 The latest version of this documentation can be found on-line at
1476 <ulink role="online-location" url="http://[SERVER]/MODULENAME/index.html">http://[SERVER]/MODULENAME/</ulink>.
1481 <title>[Insert title here]</title>
1489 <sect1 id="metafiles_sections">
1490 <title>Editing the section file</title>
1493 The section file is used to organise the documentation output by
1494 GTK-Doc. Here one specifies which symbol belongs to which module or
1495 class and control the visibility (public or private).
1499 The section file is a plain test file with xml like syntax (using tags).
1500 Blank lines are ignored and lines starting with a '#' are treated as
1505 The <FILE> ... </FILE> tag is used to specify the file name,
1506 without any suffix. For example, using '<FILE>gnome-config</FILE>'
1507 will result in the section declarations being output in the template
1508 file <filename>tmpl/gnome-config.sgml</filename>, which will be
1509 converted into the DocBook SGML/XML file <filename>sgml/gnome-config.sgml</filename>
1510 or .DocBook XML file <filename>xml/gnome-config.xml</filename>.
1511 (The name of the html file is based on the module name and the section
1512 title, or for gobjects it is based on the gobjects class name converted
1517 The <TITLE> ... </TITLE> tag is used to specify the title of
1518 the section. It is only useful before the templates (if used) are
1519 initially created, since the title set in the template file overrides
1520 this. Also if one uses SECTION comment in the sources, this is obsolete.
1524 You can group items in the section by using the <SUBSECTION> tag.
1525 Currently it outputs a blank line between subsections in the synopsis
1527 You can also use <SUBSECTION Standard> for standard GObject
1528 declarations (e.g. the functions like g_object_get_type and macros like
1529 G_OBJECT(), G_IS_OBJECT() etc.).
1530 Currently these are left out of the documentation.
1531 You can also use <SUBSECTION Private> for private declarations
1532 which will not be output (It is a handy way to avoid warning messages
1533 about unused declarations.).
1534 If your library contains private types which you don't want to appear in
1535 the object hierarchy and the list of implemented or required interfaces,
1536 add them to a Private subsection.
1537 Wheter you would place GObject and GObjectClass like structs in public
1538 or Standard section depends if they have public entries (variables,
1543 You can also use <INCLUDE> ... </INCLUDE> to specify the
1544 #include files which are shown in the synopsis sections.
1545 It contains a comma-separate list of #include files, without the angle
1546 brackets. If you set it outside of any sections, it acts for all
1547 sections until the end of the file. If you set it within a section, it
1548 only applies to that section.
1555 <chapter id="reports">
1556 <title>Controlling the result</title>
1559 A GTK-Doc run generates report files inside the documentation directory.
1560 The generated files are named:
1561 <filename><package>-undocumented.txt</filename>,
1562 <filename><package>-undeclared.txt</filename> and
1563 <filename><package>-unused.txt</filename>.
1564 All those are plain text files that can be viewed and postprocessed easily.
1568 The <filename><package>-undocumented.txt</filename> file starts with
1569 the documentation coverage summary. Below are two sections divided by
1570 blank lines. The first section lists undocumented or incomplete symbols.
1571 The second section does the same for section docs. Incomplete entries are
1572 those, which have documentation, but where e.g. a new parameter has been
1577 The <filename><package>-undeclared.txt</filename> file lists symbols
1578 given in the <filename><package>-sections.txt</filename> but not
1579 found in the sources. Check if they have been removed or if they are
1584 The <filename><package>-unused.txt</filename> file lists symbol
1585 names, where the GTK-Doc scanner has found documentation, but does not
1586 know where to put it. This means that the symbol has not yet been added to
1587 the <filename><package>-sections.txt</filename> file.
1592 Enable or add the <option>TESTS=$(GTKDOC_CHECK)</option> line in Makefile.am.
1593 If at least GTK-Doc 1.9 is installed, this will run sanity checks during
1594 <command>make check</command> run.
1599 One can also look at the files produced by the source code scanner:
1600 <filename><package>-decl-list.txt</filename> and
1601 <filename><package>-decl.txt</filename>. The first one can be
1602 compared with the section file if that is manualy maintained. The second
1603 lists all declarations fromt he headers If a symbol is missing one could
1604 check if this file contains it.
1608 If the project is GObject based, one can also look into the files produced
1609 by the object scanner:
1610 <filename><package>.args.txt</filename>,
1611 <filename><package>.hierarchy.txt</filename>,
1612 <filename><package>.interfaces.txt</filename>,
1613 <filename><package>.prerequisites.txt</filename> and
1614 <filename><package>.signals.txt</filename>. If there are missing
1615 symbols in any of those, one can ask gtkdoc to keep the intermedia scanner
1616 file for further analysis, but running it as
1617 <command>GTK_DOC_KEEP_INTERMEDIATE=1 make</command>.
1621 <chapter id="documenting-others">
1622 <title>Documenting other interfaces</title>
1625 So far we have been using GTK-Doc to document the API of code. The next
1626 sections contain suggestions how the tools can be used to document other
1630 <sect1 id="commandline-interfaces">
1631 <title>Commandline options and man pages</title>
1634 As one can generate man pages for a docbook refentry as well, it sounds
1635 like a good idea to use it for that purpose. This way the interface is
1636 part of the reference and one gets the man-page for free.
1639 <sect2 id="commandline-interfaces-file">
1640 <title>Document the tool</title>
1643 Create one refentry file per tool. Following
1644 <link linkend="settingup_docfiles">our example</link> we would call it
1645 <filename>meep/docs/reference/meeper/meep.xml</filename>. For the xml
1646 tags that should be used and can look at generated file in the xml
1647 subdirectory as well as examples e.g. in glib.
1651 <sect2 id="commandline-interfaces-configure">
1652 <title>Adding the extra configure check</title>
1655 <example><title>Extra configure checks</title>
1659 [AC_HELP_STRING([--enable-man],
1660 [regenerate man pages from Docbook [default=no]])],enable_man=yes,
1663 AC_PATH_PROG([XSLTPROC], [xsltproc])
1664 AM_CONDITIONAL(ENABLE_MAN, test x$enable_man != xno)
1671 <sect2 id="commandline-interfaces-make">
1672 <title>Adding the extra makefile rules</title>
1675 <example><title>Extra configure checks</title>
1685 @XSLTPROC@ -nonet http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl $<
1690 BUILT_EXTRA_DIST = $(man_MANS)
1691 EXTRA_DIST += meep.xml
1699 <sect1 id="dbus-interfaces">
1700 <title>DBus interfaces</title>
1703 (FIXME: http://hal.freedesktop.org/docs/DeviceKit/DeviceKit.html,
1704 http://cgit.freedesktop.org/DeviceKit/DeviceKit/tree/doc/dbus)
1711 <title>Frequently asked questions</title>
1714 <?dbhtml list-presentation="list"?>
1715 <segtitle>Question</segtitle>
1716 <segtitle>Answer</segtitle>
1718 <seg>No class hierarchy.</seg>
1720 The objects <function>xxx_get_type()</function> function has not been
1721 entered into the <filename><package>.types</filename> file.
1725 <seg>Still no class hierarchy.</seg>
1727 Missing or wrong naming in <filename><package>-sections.txt</filename>
1728 file (see <ulink url="http://mail.gnome.org/archives/gtk-doc-list/2003-October/msg00006.html">explanation</ulink>).
1732 <seg>Damn, I have still no class hierarchy.</seg>
1734 Is the object name (name of the instance struct, e.g. <type>GtkWidget</type>)
1735 part of the normal section (don't put this into Standard or Private
1740 <seg>No symbol index.</seg>
1742 Does the <filename><package>-docs.{xml,sgml}</filename> contain a
1743 index that xi:includes the generated index?
1747 <seg>Symbols are not linked to their doc-section.</seg>
1749 Is the doc-comment using the correct markup (added #,% or ())?
1750 Check if the gtkdoc-fixxref warns about unresolvable xrefs.
1754 <seg>A new class does not appear in the docs.</seg>
1756 Is the new page xi:included from
1757 <filename><package>-docs.{xml,sgml}</filename>.
1761 <seg>A new symbol does not appear in the docs.</seg>
1763 Is the doc-comment properly formatted. Check for spelling mistakes in
1764 the begin of the comment. Check if the gtkdoc-fixxref warns about
1765 unresolvable xrefs. Check if the symbol is correctly listed in the
1766 <filename><package>-sections.txt</filename> in a public subsection.
1770 <seg>A type is missing from the class hierarchy.</seg>
1772 If the type is listed in <filename><package>.hierarchy</filename>
1773 but not in <filename>xml/tree_index.sgml</filename> then double check
1774 that the type is correctly placed in the <filename><package>-sections.txt</filename>.
1775 If the type instance (e.g. <type>GtkWidget</type>) is not listed or
1776 incidentialy makred private it will not be shown.
1780 <seg>I get foldoc links for all gobject annotations.</seg>
1782 Check that <filename>xml/annotation-glossary.xml</filename> is
1783 xi:included from <filename><package>-docs.{xml,sgml}</filename>.
1787 <!-- gtk-doc warnings: -->
1789 <seg>Parameter described in source code comment block but does not exist</seg>
1790 <seg>Check if the prototype in the header has different parameter names as in the source.</seg>
1793 <!-- docbook warnings: -->
1795 <seg>multiple "IDs" for constraint linkend: XYZ</seg>
1796 <seg>Symbol XYZ appears twice in <filename><package>-sections.txt</filename> file.</seg>
1799 <seg>Element typename in namespace '' encountered in para, but no template matches.</seg>
1805 <!-- ======== Appendix: FDL ================================== -->