help/manual: add paragraph about history
[gtk-doc.git] / help / manual / C / index.docbook
blobbc23faddb20e3c1e1d48fa58a41798a559f89088
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" [
6 <!ENTITY FDL SYSTEM "fdl-appendix.xml">
7 <!ENTITY FDLlink "<link linkend='fdl'>included</link>">
8 <!ENTITY % entities SYSTEM "./version.ent">
9 %entities;
12 <book id="index">
13 <bookinfo>
14 <title>GTK-Doc Manual</title>
15 <releaseinfo>
16 This document contains version &package_version; of the GTK-Doc user
17 manual.
18 The latest version of this document can be found online at
19 <ulink role="online-location"
20 url="https://developer.gnome.org/gtk-doc-manual/">
21 https://developer.gnome.org/gtk-doc-manual/</ulink>.
22 </releaseinfo>
23 <edition>&package_version;</edition>
24 <abstract role="description"><para>User manual for developers with instructions of GTK-Doc usage.</para></abstract>
25 <authorgroup>
26 <author>
27 <firstname>Chris</firstname>
28 <surname>Lyttle</surname>
29 <affiliation>
30 <address>
31 <email>chris@wilddev.net</email>
32 </address>
33 </affiliation>
34 </author>
35 <author>
36 <firstname>Dan</firstname>
37 <surname>Mueth</surname>
38 <affiliation>
39 <address>
40 <email>d-mueth@uchicago.edu</email>
41 </address>
42 </affiliation>
43 </author>
44 <author>
45 <firstname>Stefan</firstname>
46 <surname>Sauer (Kost)</surname>
47 <affiliation>
48 <address>
49 <email>ensonic@users.sf.net</email>
50 </address>
51 </affiliation>
52 </author>
53 </authorgroup>
54 <publisher role="maintainer">
55 <publishername>GTK-Doc project</publishername>
56 <address><email>gtk-doc-list@gnome.org</email></address>
57 </publisher>
58 <copyright>
59 <year>2000, 2005</year>
60 <holder>Dan Mueth and Chris Lyttle</holder>
61 </copyright>
62 <copyright>
63 <year>2007-2015</year>
64 <holder>Stefan Sauer (Kost)</holder>
65 </copyright>
67 <!-- translators: uncomment this:
68 <copyright>
69 <year>2000</year>
70 <holder>ME-THE-TRANSLATOR (Latin translation)</holder>
71 </copyright>
72 -->
74 <legalnotice>
75 <para>
76 Permission is granted to copy, distribute and/or modify this
77 document under the terms of the <citetitle>GNU Free Documentation
78 License</citetitle>, Version 1.1 or any later version published
79 by the Free Software Foundation with no Invariant Sections, no
80 Front-Cover Texts, and no Back-Cover Texts. A copy of the license
81 is &FDLlink;.
82 </para>
83 <para>
84 Many of the names used by companies to distinguish their products and
85 services are claimed as trademarks. Where those names appear in any
86 GNOME documentation, and those trademarks are made aware to the members
87 of the GNOME Documentation Project, the names have been printed in caps
88 or initial caps.
89 </para>
90 </legalnotice>
92 <revhistory>
93 <revision>
94 <revnumber>1.28.1</revnumber>
95 <date>24 Mar 2018</date>
96 <authorinitials>ss</authorinitials>
97 <revremark>development</revremark>
98 </revision>
99 <revision>
100 <revnumber>1.28</revnumber>
101 <date>24 Mar 2018</date>
102 <authorinitials>ss</authorinitials>
103 <revremark>bug fixes</revremark>
104 </revision>
105 <revision>
106 <revnumber>1.27</revnumber>
107 <date>07 Dec 2017</date>
108 <authorinitials>ss</authorinitials>
109 <revremark>fine tuning of the python port</revremark>
110 </revision>
111 <revision>
112 <revnumber>1.26</revnumber>
113 <date>11 Aug 2017</date>
114 <authorinitials>ss</authorinitials>
115 <revremark>port all tools from perl/bash to python</revremark>
116 </revision>
117 <revision>
118 <revnumber>1.25</revnumber>
119 <date>21 March 2016</date>
120 <authorinitials>ss</authorinitials>
121 <revremark>bug fixes, test cleanups</revremark>
122 </revision>
123 <revision>
124 <revnumber>1.24</revnumber>
125 <date>29 May 2015</date>
126 <authorinitials>ss</authorinitials>
127 <revremark>bug fix</revremark>
128 </revision>
129 <revision>
130 <revnumber>1.23</revnumber>
131 <date>17 May 2015</date>
132 <authorinitials>ss</authorinitials>
133 <revremark>bug fix</revremark>
134 </revision>
135 <revision>
136 <revnumber>1.22</revnumber>
137 <date>07 May 2015</date>
138 <authorinitials>ss</authorinitials>
139 <revremark>bug fixes, dropping deprecated features</revremark>
140 </revision>
141 <revision>
142 <revnumber>1.21</revnumber>
143 <date>17 Jul 2014</date>
144 <authorinitials>ss</authorinitials>
145 <revremark>bug fixes, dropping deprecated features</revremark>
146 </revision>
147 <revision>
148 <revnumber>1.20</revnumber>
149 <date>16 Feb 2014</date>
150 <authorinitials>ss</authorinitials>
151 <revremark>bug fixes, markdown support, style improvements</revremark>
152 </revision>
153 <revision>
154 <revnumber>1.19</revnumber>
155 <date>05 Jun 2013</date>
156 <authorinitials>ss</authorinitials>
157 <revremark>bug fixes</revremark>
158 </revision>
159 <revision>
160 <revnumber>1.18</revnumber>
161 <date>14 Sep 2011</date>
162 <authorinitials>ss</authorinitials>
163 <revremark>bug fixes, speedups, markdown support</revremark>
164 </revision>
165 <revision>
166 <revnumber>1.17</revnumber>
167 <date>26 Feb 2011</date>
168 <authorinitials>sk</authorinitials>
169 <revremark>urgent bug fix update</revremark>
170 </revision>
171 <revision>
172 <revnumber>1.16</revnumber>
173 <date>14 Jan 2011</date>
174 <authorinitials>sk</authorinitials>
175 <revremark>bugfixes, layout improvements</revremark>
176 </revision>
177 <revision>
178 <revnumber>1.15</revnumber>
179 <date>21 May 2010</date>
180 <authorinitials>sk</authorinitials>
181 <revremark>bug and regression fixes</revremark>
182 </revision>
183 <revision>
184 <revnumber>1.14</revnumber>
185 <date>28 March 2010</date>
186 <authorinitials>sk</authorinitials>
187 <revremark>bugfixes and performance improvements</revremark>
188 </revision>
189 <revision>
190 <revnumber>1.13</revnumber>
191 <date>18 December 2009</date>
192 <authorinitials>sk</authorinitials>
193 <revremark>broken tarball update</revremark>
194 </revision>
195 <revision>
196 <revnumber>1.12</revnumber>
197 <date>18 December 2009</date>
198 <authorinitials>sk</authorinitials>
199 <revremark>new tool features and bugfixes</revremark>
200 </revision>
201 <revision>
202 <revnumber>1.11</revnumber>
203 <date>16 November 2008</date>
204 <authorinitials>mal</authorinitials>
205 <revremark>GNOME doc-utils migration</revremark>
206 </revision>
207 </revhistory>
209 </bookinfo>
211 <!-- ======== Chapter 1: Introduction ======================== -->
213 <chapter id="introduction">
214 <title>Introduction</title>
216 <para>
217 This chapter introduces GTK-Doc and gives an overview of what it is and
218 how it is used.
219 </para>
221 <sect1 id="whatisgtkdoc">
222 <title>What is GTK-Doc?</title>
224 <para>
225 GTK-Doc is used to document C code. It is typically used to document the public
226 API of libraries, such as the GTK+ and GNOME libraries. But it can also be
227 used to document application code.
228 </para>
229 </sect1>
231 <sect1 id="howdoesgtkdocwork">
232 <title>How Does GTK-Doc Work?</title>
234 <para>
235 GTK-Doc works by using documentation of functions placed inside the source files in
236 specially-formatted comment blocks, or documentation added to the template files
237 which GTK-Doc uses (though note that GTK-Doc will only document functions that
238 are declared in header files; it won't produce output for static functions).
239 </para>
241 <para>
242 GTK-Doc consists of a number of python scripts, each performing a different step
243 in the process.
244 </para>
246 <para>
247 There are 5 main steps in the process:
248 </para>
250 <orderedlist>
252 <listitem>
253 <para>
254 <guilabel>Writing the documentation.</guilabel>
256 The author fills in the source files with the documentation for each
257 function, macro, structs or unions, etc.
258 </para>
259 </listitem>
261 <listitem>
262 <para>
263 <guilabel>Gathering information about the code.</guilabel>
265 <application>gtkdoc-scan</application> scans the header files of the
266 code looking for declarations of functions, macros, enums, structs, and unions.
267 It creates the file <filename>&lt;module&gt;-decl-list.txt</filename> containing a list of the
268 declarations, placing them into sections according to which header file they
269 are in. On the first run this file is copied to <filename>&lt;module&gt;-sections.txt</filename>.
270 The author can rearrange the sections, and the order of the
271 declarations within them, to produce the final desired order.
272 The second file it generates is <filename>&lt;module&gt;-decl.txt</filename>.
273 This file contains the full declarations found by the scanner. If for
274 some reason one would like some symbols to show up in the docs, where
275 the full declaration cannot be found by the scanner or the declaration
276 should appear differently, one can place entities similar to the ones in
277 <filename>&lt;module&gt;-decl.txt</filename> into <filename>&lt;module&gt;-overrides.txt</filename>.
278 </para>
279 <para>
280 <application>gtkdoc-scangobj</application> can also be used to dynamically query a library about
281 any GObject subclasses it exports. It saves information about each
282 object's position in the class hierarchy and about any GObject properties
283 and signals it provides.
284 </para>
285 <para>
286 <application>gtkdoc-scanobj</application> should not be used anymore.
287 It was needed in the past when GObject was still GtkObject inside gtk+.
288 </para>
289 </listitem>
291 <listitem>
292 <para>
293 <guilabel>Generating the XML and HTML/PDF.</guilabel>
295 <application>gtkdoc-mkdb</application> turns the template files into
296 XML files in the <filename class='directory'>xml/</filename> subdirectory.
297 If the source code contains documentation on functions, using the
298 special comment blocks, it gets merged in here. If there are no tmpl files used
299 it only reads docs from sources and introspection data.
300 </para>
301 <para>
302 <application>gtkdoc-mkhtml</application> turns the XML files into HTML
303 files in the <filename class='directory'>html/</filename> subdirectory.
304 Likewise <application>gtkdoc-mkpdf</application> turns the XML files into a PDF
305 document called <filename>&lt;package&gt;.pdf</filename>.
306 </para>
307 <para>
308 Files in <filename class='directory'>xml/</filename> and
309 <filename class='directory'>html/</filename> directories are always
310 overwritten. One should never edit them directly.
311 </para>
312 </listitem>
314 <listitem>
315 <para>
316 <guilabel>Fixing up cross-references between documents.</guilabel>
318 After installing the HTML files, <application>gtkdoc-fixxref</application> can be run to fix up any
319 cross-references between separate documents. For example, the GTK+
320 documentation contains many cross-references to types documented in the GLib manual.
322 When creating the source tarball for distribution, <application>gtkdoc-rebase</application>
323 turns all external links into web-links. When installing distributed (pregenerated) docs
324 the same application will try to turn links back to local links
325 (where those docs are installed).
326 </para>
327 </listitem>
328 </orderedlist>
330 </sect1>
332 <sect1 id="gettinggtkdoc">
333 <title>Getting GTK-Doc</title>
335 <sect2 id="requirements">
336 <title>Requirements</title>
337 <para>
338 <guilabel>python 2/3</guilabel> - the main scripts are written in python.
339 </para>
340 <para>
341 <guilabel>xsltproc</guilabel> - the xslt processor from libxslt
342 <ulink url="http://xmlsoft.org/XSLT/" type="http">xmlsoft.org/XSLT/</ulink>
343 </para>
344 <para>
345 <guilabel>docbook-xsl</guilabel> - the docbook xsl stylesheets
346 <ulink url="http://sourceforge.net/projects/docbook/files/docbook-xsl/" type="http">sourceforge.net/projects/docbook/files/docbook-xsl</ulink>
347 </para>
348 <para>
349 One of <guilabel>source-highlight</guilabel>, <guilabel>highlight</guilabel> or
350 <guilabel>vim</guilabel> - optional - used for syntax highlighting of examples
351 </para>
352 </sect2>
353 </sect1>
355 <sect1 id="aboutgtkdoc">
356 <title>About GTK-Doc</title>
358 <para>
359 Historically GTK-Doc was used to generate template files from the soures
360 code. These template files could be used by developers to enter the
361 API documentation. This approach was rather inconvenient because it
362 required to keep the generated files under version control.
363 Since GTK-Doc 1.9 it became possible to place all API information
364 into source comments, which made the template support obsolete.
365 In version 1.26 template support has been.
366 </para>
368 <para>
369 (FIXME)
370 </para>
372 <para>
373 (authors, web pages, mailing list, license, future plans,
374 comparison with other similar systems.)
375 </para>
377 </sect1>
379 <sect1 id="aboutthismanual">
380 <title>About this Manual</title>
382 <para>
383 (FIXME)
384 </para>
386 <para>
387 (who it is meant for, where you can get it, license)
388 </para>
390 </sect1>
392 </chapter>
394 <chapter id="settingup">
395 <title>Project Setup</title>
397 <para>
398 This Chapter describes the steps that are necessary to integrate GTK-Doc
399 into your project. The integration of GTK-Doc into a project includes the
400 following steps:
401 </para>
403 <itemizedlist>
404 <listitem>
405 <para>
406 Preparation of the directory structure and creating required
407 configuration files for your GTK-Doc documentation (see
408 <link linkend="settingup_docfiles">
409 Setting up a skeleton documentation</link>).
410 </para>
411 </listitem>
412 <listitem>
413 <para>
414 Adjusting the build system to build your documentation using the
415 GTK-Doc tools. Multiple build systems are supported, in
416 this manual we describe how to integrate GTK-Doc with
417 <link linkend="settingup_autotools">Autotools</link>,
418 <link linkend="settingup_cmake">CMake</link>, and
419 <link linkend="settingup_plain_makefiles">plain Makefiles</link>.
420 </para>
421 </listitem>
422 <listitem>
423 <para>
424 Adding GTK-Doc specific files to version control and deciding which
425 files to ignore (see <link linkend="settingup_vcs">
426 Integration with version control systems</link>).
427 </para>
428 </listitem>
429 </itemizedlist>
431 <para>
432 The following sections assume we work on a project called
433 <code>meep</code>.
434 This project contains two packages (or modules),
435 a library called <code>libmeep</code> and an end-user app
436 called <code>meeper</code>.
437 </para>
439 <sect1 id="settingup_docfiles">
440 <title>Setting up a skeleton documentation</title>
442 <para>
443 A common convention is to place documentation into a folder called
444 <code>docs</code> inside your top-level project directory.
445 We usually distinguish between <emphasis>reference
446 documentation</emphasis> intended for developers and an
447 <emphasis>user manual</emphasis> intended for end-users.
448 Again the convention is to have separate folders for both.
449 We usually place the reference documentation in a folder named
450 <code>reference</code> and the end-user manual in a folder named
451 <code>help</code> as.
453 According to the above convention the documentation for our
454 <code>libmeep</code> package would be placed into:
455 <code>docs/reference/libmeep</code>.
457 For packages with just one library or application
458 the documentation could also be placed directly into
459 <code>docs/reference</code>.
461 It is not mandatory to use the above convention, but if you
462 choose to use a different directory structure you must adjust
463 your build system configuration to match your directory
464 structure.
465 </para>
467 <para>
468 In the following sections we will assume a directory structure
469 for our <emphasis>meep</emphasis> project that uses the above
470 conventions.
472 <example>
473 <title>Example directory structure of <emphasis>meep</emphasis>
474 project</title>
475 <programlisting><![CDATA[
476 meep/
477 docs/
478 reference/ # reference documentation
479 libmeep/
480 meeper/
481 help/ # optional: user manual
482 meeper/
483 src/
484 libmeep/
485 meeper/
486 ]]></programlisting>
487 </example>
488 </para>
489 </sect1>
491 <sect1 id="settingup_autotools">
492 <title>Integration with Autotools</title>
493 <para>
494 Integration of GTK-Doc into an autotools-based build system requires the
495 following steps:
496 </para>
497 <itemizedlist>
498 <listitem>
499 <para>
500 Ensure that <application>gtkdocize</application> is run once before
501 the <filename>configure</filename> script. If an
502 <filename>autogen.sh</filename> script is present, adjust it to
503 check for GTK-Doc and add a call to
504 <application>gtkdocize</application>.
505 </para>
507 <para>
508 The main purpose of <application>gtkdocize</application> is to
509 make the <filename>gtk-doc.make</filename> Makefile and the
510 <filename>gtk-doc.m4</filename> macro definition file available
511 to the build system, either by copying or linking it
512 into the project.
513 </para>
514 </listitem>
515 <listitem>
516 <para>
517 Add the necessary <application>autoconf</application> macros to
518 <filename>configure.ac</filename> to enable GTK-Doc in your build
519 system to allow configuration of GTK-Doc via the generated
520 <filename>configure</filename> script.
521 </para>
522 <para>
523 Among others with registers the <code>--enable-gtk-doc</code>
524 option with the <filename>configure</filename> script.
525 </para>
526 </listitem>
527 <listitem>
528 <para>
529 Create an <application>automake</application> script for each
530 application or library in your project. In the example used in this
531 documentation this step applies to both <code>meeper</code> and
532 <code>libmeep</code>.
533 </para>
534 </listitem>
535 </itemizedlist>
537 <para>
538 In the following sections, we will perform the above steps in reverse
539 order. We start with the <application>automake</application> scripts
540 and work our way up to <filename>configure.ac</filename> and
541 <filename>autogen.sh</filename>.
542 Then we show how enable Gtk-Doc in the build system and
543 how to build the documentation.
544 </para>
546 <sect2 id="settingup_automake">
547 <title>Integration with automake</title>
549 <para>
550 First copy the <filename>Makefile.am</filename> from the
551 <filename class='directory'>examples</filename> sub-directory of the
552 <ulink url="https://gitlab.gnome.org/GNOME/gtk-doc/raw/master/examples/Makefile.am">
553 gtkdoc-sources</ulink>
554 to your project's reference documentation directory (e.g.
555 <filename class='directory'>docs/reference/&lt;package&gt;</filename>).
556 A local copy should be available under e.g.
557 <filename>/usr/share/doc/gtk-doc-tools/examples/Makefile.am</filename>.
558 If you have multiple packages repeat this for each one.
559 </para>
561 <note>
562 <simpara>
563 Do not forget to add each <filename>Makefile.am</filename>
564 to the <function>AC_CONFIG_FILES</function> macro in
565 <filename>configure.ac</filename>. For
566 <filename>docs/reference/libmeep/Makefile.am</filename> you will
567 need to add the entry
568 <filename>docs/reference/libmeep/Makefile</filename>
569 to <function>AC_CONFIG_FILES</function>.
570 </simpara>
571 </note>
573 <example>
574 <title>
575 Example directory structure with <filename>Makefiles.am</filename>
576 </title>
577 <programlisting>
578 meep/
579 docs/
580 reference/ # reference documentation
581 libmeep/
582 Makefile.am
583 meeper/
584 Makefile.am
585 help/ # optional: user manual
586 meeper/
587 src/
588 libmeep/
589 meeper/
590 </programlisting>
591 </example>
593 <para>
594 Next, you need to customize the copied Makefiles
595 and provide values for the various parameters in each
596 <filename>Makefile.am</filename>.
598 All settings have a comment above them that describes their purpose
599 and how to customize the setting.
601 Most settings are used to supply extra flags to the respective tools
602 to which they apply. Every tool
603 has a variable of the form <option>&lt;TOOLNAME&gt;_OPTIONS</option>
604 (e.g. the tool <application>gtkdoc-mkhtml</application> has
605 an option named <code>MKHTML_OPTIONS</code>).
607 All the tools support <option>--help</option> to list the supported
608 options.
609 </para>
611 <para>
612 The following list explains the most relevant options. Check the
613 example <filename>Makefile.am</filename> for additional options.
615 <itemizedlist>
616 <listitem>
617 <para>
618 <option>DOC_MODULE</option> is used to provide the name of the
619 package that is being documentated (e.g. <code>meeper</code>, or
620 <code>libmeep</code>).
621 </para>
622 </listitem>
623 <listitem>
624 <para>
625 <option>DOC_SOURCE_DIR</option>
626 is used to specify the location
627 of source directory which GTK-Doc searches for your API
628 documentation. This will usually be
629 <code>
630 DOC_SOURCE_DIR=$(top_srcdir)/src
631 </code>
632 or a sub-directory of that directory.
633 </para>
634 </listitem>
636 <listitem>
637 <para>
638 <option>HFILE_GLOB</option>
640 <option>CFILE_GLOB</option>
641 are used for dependencies. Each option take a file-glob (e.g.
642 <code>HFILE_GLOB=$(top_srcdir)/src/*.c</code>).
643 The documentation will be rebuilt if any of the matched files
644 change.
645 </para>
646 </listitem>
648 <listitem>
649 <para>
650 <option>EXTRA_HFILES</option>
651 allows to specify extra header files
652 to include when scanning for API documentation, which are not
653 found under <code>DOC_SOURCE_DIR</code> (e.g. <code>
654 EXTRA_HFILES=$(top_srcdir}/contrib/extra.h</code>).
655 </para>
656 </listitem>
658 <listitem>
659 <para>
660 <option>IGNORE_HFILES</option>
661 allows to specify header files
662 or directories to ignore when scanning for API documentation.
663 Use the basename of the file or directory (e.g. <code>
664 IGNORE_HFILES=gtkdebug.h gtkintl.h private_code_folder</code>).
665 </para>
666 </listitem>
668 <listitem>
669 <para>
670 <option>HTML_IMAGES</option>
671 allows to specify images files which
672 will be copied into the <filename>html/</filename> directory of
673 the generated documentation.
674 If your API documentation includes any images they need to be
675 added to this
676 option (e.g. <code>
677 HTML_IMAGES=$(top_srcdir)/gtk/stock-icons/stock_about_24.png</code>).
678 </para>
679 </listitem>
681 <listitem>
682 <para>
683 <option>content_files</option>
684 allows to specify extra files
685 that are included by
686 <code>$(DOC_MAIN_SGML_FILE)</code>
687 (e.g. <code>
688 content_files=running.xml building.xml changes-2.0.xml</code>).
689 </para>
690 </listitem>
692 <listitem>
693 <para>
694 <option>expand_content_files</option>
695 allows to specify files
696 where <emphasis>gtk-doc abbrevations</emphasis> such as
697 <code>#GtkWidget</code>
698 are expanded (e.g. <code>
699 expand_content_files=running.xml</code>).
700 </para>
701 </listitem>
702 </itemizedlist>
703 </para>
705 </sect2>
707 <sect2 id="settingup_autoconf">
708 <title>Integration with autoconf</title>
710 <para>
711 Integration with <application>autoconf</application> is very simple
712 and includes one required step and an additional optional
713 (but recommended) step.
715 The first step is to add the <function>GTK_DOC_CHECK</function> macro
716 to your <filename>configure.ac</filename> script. This registers
717 several configure options to enable GTK-Doc and allows you
718 to set default arguments for <application>gtkdocize</application>.
719 </para>
721 <warning>
722 <simpara>
723 Make sure that the <code>GTK_DOC_CHECK</code> macro is not indented.
724 The macro must start at the beginning of the line and should not
725 start with whitespace.
726 </simpara>
727 </warning>
729 <para>
730 The second step is to add the <code>AC_CONFIG_MACRO_DIR(m4)</code>
731 to your <filename>configure.ac</filename>. This is not required
732 but helps <application>gtkdocize</application> to automatically copy
733 the macro definition (e.g <filename>gtk-doc.m4</filename>) which
734 contains the <function>GTK_DOC_CHECK</function> macro to your
735 project's macro directory. Without this, the GTK_DOC_CHECK macro
736 might not be found and you would need to explicitly tell the
737 <application>aclocal</application> tool where to find the macro
738 definition file.
739 </para>
741 <para>
742 <example><title>Minimal integration with autoconf</title>
743 <programlisting><![CDATA[
744 # recommended: set m4 directory
745 AC_CONFIG_MACRO_DIR(m4)
746 # optional: register gtk-doc in configure
747 GTK_DOC_CHECK([1.28])
748 ]]></programlisting>
749 </example>
750 </para>
752 <para>
753 The above example works, but will require all developers to have
754 gtk-doc installed. A better way is to make building the documentation
755 optional as shown in the next example:
757 <example>
758 <title>Integration with optional gtk-doc dependency</title>
759 <programlisting><![CDATA[
760 m4_ifdef([GTK_DOC_CHECK], [
761 # recommended: set m4 directory
762 AC_CONFIG_MACRO_DIR(m4)
763 # optional: register gtk-doc in configure
764 GTK_DOC_CHECK([1.28])
766 AM_CONDITIONAL([ENABLE_GTK_DOC], false)
768 ]]></programlisting>
769 </example>
770 </para>
772 <para>
773 The first argument is used to check for the Gtk-Doc version at
774 configure time. The 2nd, optional argument is used by
775 <application>gtkdocize</application>.
776 The <symbol>GTK_DOC_CHECK</symbol> macro also adds several configure
777 switches:
778 </para>
780 <orderedlist>
781 <listitem><para>--with-html-dir=PATH : path to installed docs</para></listitem>
782 <listitem><para>--enable-gtk-doc : use gtk-doc to build documentation [default=no]</para></listitem>
783 <listitem><para>--enable-gtk-doc-html : build documentation in html format [default=yes]</para></listitem>
784 <listitem><para>--enable-gtk-doc-pdf : build documentation in pdf format [default=no]</para></listitem>
785 </orderedlist>
787 <important>
788 <para>
789 GTK-Doc is disabled by default! Remember to pass the option
790 <option>'--enable-gtk-doc'</option> to the next
791 <filename>configure</filename> run. Otherwise pregenerated documentation is installed
792 (which makes sense for users but not for developers).
793 </para>
794 </important>
796 <para>
797 After all changes to <filename>configure.ac</filename> are made,
798 update the <filename>configure</filename> file. This can be done by
799 re-running <code>autogen.sh</code>.
800 </para>
801 </sect2>
803 <sect2 id="settingup_autogen">
804 <title>Integration with autogen</title>
806 <para>
807 Most projects will have an <filename>autogen.sh</filename> script to
808 setup the build infrastructure after the project was checked out from
809 a version control system (such as git or svn). GTK-Doc comes with a
810 script called <application>gtkdocize</application> which can be used
811 to copy the necessary files needed by Gtk-Doc to the source directory.
812 </para>
814 <para>
815 It should be run before autoreconf, autoheader, automake or autoconf.
816 </para>
818 <para>
819 <example><title>Running gtkdocize from autogen.sh</title>
820 <programlisting><![CDATA[
821 gtkdocize || exit 1
822 ]]></programlisting>
823 </example>
824 </para>
826 <para>
827 <example>
828 <title>Conditionally run gtkdocize from autogen.sh</title>
829 <programlisting><![CDATA[
830 GTKDOCIZE=$(which gtkdocize 2>/dev/null)
831 if test $? -ne 0; then
832 echo "No gtk-doc support found. You can't build the docs."
833 else
834 $GTKDOCIZE || exit 1
836 ]]></programlisting>
837 </example>
838 </para>
840 <para>
841 When running <application>gtkdocize</application> it copies
842 <filename>gtk-doc.make</filename> to your project root (or any
843 directory specified by the <option>--docdir</option> option).
844 </para>
846 <para>
847 <application>gtkdocize</application> checks your
848 <filename>configure.ac</filename> script for
849 the <function>GTK_DOC_CHECK</function> macro.
850 The <function>GTK_DOC_CHECK</function> macro can be used to pass
851 extra arguments to the <application>gtkdocize</application> script.
852 the 2nd parameter in the <symbol>GTK_DOC_CHECK</symbol> macro.
853 </para>
855 <para>
856 Alternatively, additional arguments can also be passed to
857 <application>gtkdocize</application> via the
858 <symbol>GTKDOCIZE_FLAGS</symbol> environment variable, or by
859 directly specifying them to <application>gtkdocize</application>
860 in <filename>autogen.sh</filename>.
861 </para>
863 </sect2>
865 <sect2 id="settingup_firstrun">
866 <title>Executing GTK-Doc from the Build System</title>
868 <para>
869 After the previous steps it's time to run the build. First we need to
870 rerun <filename>autogen.sh</filename>. If this script runs configure
871 for you, then give it the <option>--enable-gtk-doc</option> option.
872 Otherwise manually run <filename>configure</filename> with this option
873 afterwards.
874 </para>
875 <para>
876 The first make run generates several additional files in the doc-directories.
877 The important ones are:
878 <filename>&lt;package&gt;.types</filename>,
879 <filename>&lt;package&gt;-docs.xml</filename> (in the past .sgml),
880 <filename>&lt;package&gt;-sections.txt</filename>.
881 </para>
882 <para>
883 <example><title>Running the doc build</title>
884 <programlisting><![CDATA[
885 ./autogen.sh --enable-gtk-doc
886 make
887 ]]></programlisting>
888 </example>
889 </para>
891 <para>
892 Now you can point your browser to
893 <filename>docs/reference/&lt;package&gt;/index.html</filename>.
894 With this initial setup you will only see a very simple document.
895 The next chapter will teach you how to add API documentation to your
896 code via special comment blocks. The Chapter afterwards introduces
897 <link linkend="metafiles">additional files</link> and shows how to
898 edit the <link linkend="metafiles_master">master template</link> to
899 add additional chapters and sections to your documentation files.
900 </para>
902 </sect2>
904 </sect1>
906 <sect1 id="settingup_cmake">
907 <title>Integration with CMake build systems</title>
909 <para>
910 GTK-Doc now provides a <filename>GtkDocConfig.cmake</filename> module
911 (and the corresponding <filename>GtkDocConfigVersion.cmake</filename>
912 module). This provides a <literal>gtk_doc_add_module</literal>
913 command that you can set in your <filename>CMakeLists.txt</filename>
914 file.
915 </para>
917 <para>
918 The following example shows how to use this command.
919 <example><title>Example of using GTK-Doc from CMake</title>
920 <programlisting><![CDATA[
921 find_package(GtkDoc 1.25 REQUIRED)
923 # Create the doc-libmeep target.
924 gtk_doc_add_module(
925 libmeep ${CMAKE_SOURCE_DIR}/libmeep
926 XML meep-docs.xml
927 LIBRARIES libmeep
930 # Build doc-libmeep as part of the default target. Without this, you would
931 # have to explicitly run something like `make doc-libmeep` to build the docs.
932 add_custom_target(documentation ALL DEPENDS doc-libmeep)
934 # Install the docs. (This assumes you're using the GNUInstallDirs CMake module
935 # to set the CMAKE_INSTALL_DOCDIR variable correctly).
936 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/libmeep/html
937 DESTINATION ${CMAKE_INSTALL_DOCDIR})
938 ]]></programlisting>
939 </example>
940 </para>
941 </sect1>
943 <sect1 id="settingup_plain_makefiles">
944 <title>Integration with plain makefiles or other build systems</title>
946 <para>
947 In the case one does not want to use automake and therefore
948 <filename>gtk-doc.mak</filename> one will need to call the gtkdoc tools
949 in the right order in own makefiles (or other build tools).
950 </para>
952 <para>
953 <example><title>Documentation build steps</title>
954 <programlisting><![CDATA[
955 DOC_MODULE=meep
956 // sources have changed
957 gtkdoc-scan --module=$(DOC_MODULE) <source-dir>
958 gtkdoc-scangobj --module=$(DOC_MODULE)
959 gtkdoc-mkdb --module=$(DOC_MODULE) --output-format=xml --source-dir=<source-dir>
960 // xml files have changed
961 mkdir html
962 cd html && gtkdoc-mkhtml $(DOC_MODULE) ../meep-docs.xml
963 gtkdoc-fixxref --module=$(DOC_MODULE) --module-dir=html
964 ]]></programlisting>
965 </example>
966 </para>
968 <para>
969 One will need to look at the <filename>Makefile.am</filename> and
970 <filename>gtk-doc.mak</filename> to pick the extra options needed.
971 </para>
972 </sect1>
974 <sect1 id="settingup_vcs">
975 <title>Integration with version control systems</title>
977 <para>
978 As a rule of thumb, it's the files you edit which should go under
979 version control. For typical projects it's these files:
980 <filename>&lt;package&gt;.types</filename>,
981 <filename>&lt;package&gt;-docs.xml</filename> (in the past .sgml),
982 <filename>&lt;package&gt;-sections.txt</filename>,
983 <filename>Makefile.am</filename>.
984 </para>
985 <para>
986 Files in the <filename>xml/</filename> and <filename>html/</filename>
987 directories should not go under version control. Neither should any of
988 the <filename>.stamp</filename> files.
989 </para>
990 </sect1>
992 </chapter>
994 <chapter id="documenting">
995 <title>Documenting the code</title>
997 <para>
998 GTK-Doc uses source code comment with a special syntax for code documentation.
999 Further it retrieves information about your project structure from other
1000 sources. During the next section you will find all information about the
1001 syntax of the comments.
1002 </para>
1004 <note>
1005 <title>Documentation placement</title>
1006 <para>
1007 In the past most documentation had to be filled into files residing
1008 inside the <filename>tmpl</filename> directory. This has the
1009 disadvantages that the information is often not updated and also that
1010 the file tend to cause conflicts with version control systems.
1011 </para>
1012 <para>
1013 The avoid the aforementioned problems we suggest putting the
1014 documentation inside the sources. This manual will only describe this
1015 way of documenting code.
1016 </para>
1017 </note>
1019 <para>
1020 The scanner can handle the majority of C headers fine. In the case of
1021 receiving warnings from the scanner that look like a special case, one can
1022 hint GTK-Doc to skip over them.
1023 <example><title>GTK-Doc comment block</title>
1024 <programlisting><![CDATA[
1025 #ifndef __GTK_DOC_IGNORE__
1026 /* unparseable code here */
1027 #endif
1028 ]]></programlisting>
1029 </example>
1030 </para>
1032 <note>
1033 <title>Limitations</title>
1034 <para>
1035 Note, that GTK-Doc's supports
1036 <code>#ifndef(__GTK_DOC_IGNORE__)</code> but not
1037 <code>#if !defined(__GTK_DOC_IGNORE__)</code> or other combinations.
1038 </para>
1039 </note>
1041 <!-- -->
1043 <sect1 id="documenting_syntax">
1044 <title>Documentation comments</title>
1046 <para>
1047 A multiline comment that starts with an additional '*' marks a
1048 documentation block that will be processed by the GTK-Doc tools.
1049 <example><title>GTK-Doc comment block</title>
1050 <programlisting><![CDATA[
1052 * identifier:
1053 * documentation ...
1055 ]]></programlisting>
1056 </example>
1057 </para>
1059 <para>
1060 The 'identifier' is one line with the name of the item the comment is
1061 related to. The syntax differs a little depending on the item.
1062 (TODO add table showing identifiers)
1063 </para>
1065 <para>
1066 The 'documentation' block is also different for each symbol type. Symbol
1067 types that get parameters such as functions or macros have the parameter
1068 description first followed by a blank line (just a '*').
1069 Afterwards follows the detailed description. All lines (outside program
1070 listings and CDATA sections) just containing a ' *' (blank-asterisk) are
1071 converted to paragraph breaks.
1072 If you don't want a paragraph break, change that into ' * '
1073 (blank-asterisk-blank-blank). This is useful in preformatted text (code
1074 listings).
1075 </para>
1077 <tip>
1078 <para>
1079 When documenting code, describe two aspects:
1080 <itemizedlist>
1081 <listitem>
1082 <para>
1083 What it is: The name for a class or function can sometimes
1084 be misleading for people coming from a different background.
1085 </para>
1086 </listitem>
1087 <listitem>
1088 <para>
1089 What it does: Tell about common uses. Put it in relation
1090 with the other API.
1091 </para>
1092 </listitem>
1093 </itemizedlist>
1094 </para>
1095 </tip>
1097 <para>
1098 One advantage of hyper-text over plain-text is the ability to have links
1099 in the document. Writing the correct markup for a link can be tedious
1100 though. GTK-Doc comes to help by providing several useful abbreviations.
1101 <itemizedlist>
1102 <listitem>
1103 <para>
1104 Use function() to refer to functions or macros which take arguments.
1105 </para>
1106 </listitem>
1107 <listitem>
1108 <para>
1109 Use @param to refer to parameters. Also use this when referring to
1110 parameters of other functions, related to the one being described.
1111 </para>
1112 </listitem>
1113 <listitem>
1114 <para>
1115 Use %constant to refer to a constant, e.g. %G_TRAVERSE_LEAFS.
1116 </para>
1117 </listitem>
1118 <listitem>
1119 <para>
1120 Use #symbol to refer to other types of symbol, e.g. structs and
1121 enums and macros which don't take arguments.
1122 </para>
1123 </listitem>
1124 <listitem>
1125 <para>
1126 Use #Object::signal to refer to a GObject signal.
1127 </para>
1128 </listitem>
1129 <listitem>
1130 <para>
1131 Use #Object:property to refer to a GObject property.
1132 </para>
1133 </listitem>
1134 <listitem>
1135 <para>
1136 Use #Struct.field to refer to a field inside a structure and
1137 #GObjectClass.foo_bar() to refer to a vmethod.
1138 </para>
1139 </listitem>
1140 </itemizedlist>
1141 </para>
1143 <tip>
1144 <para>
1145 If you need to use the special characters '&lt;', '&gt;', '()', '@',
1146 '%', or '#' in your documentation without GTK-Doc changing them you
1147 can use the XML entities "&amp;lt;", "&amp;gt;", "&amp;lpar;",
1148 "&amp;rpar;", "&amp;commat;", "&amp;percnt;" and "&amp;num;"
1149 respectively or escape them with a backslash '\'.
1150 </para>
1151 </tip>
1153 <para>
1154 DocBook can do more than just links. One can also have lists,
1155 examples, headings, and images. As of version 1.20, the
1156 preferred way is to use a subset of the basic text formatting
1157 syntax called
1158 <ulink url="http://daringfireball.net/projects/markdown/">Markdown</ulink>.
1159 On older GTK-Doc versions any documentation that includes
1160 Markdown will be rendered as is. For example, list items will
1161 appear as lines starting with a dash.
1162 </para>
1164 <para>
1165 While markdown is now preferred one can mix both. One limitation here is
1166 that one can use docbook xml within markdown, but markdown within
1167 docbook xml is not supported.
1168 </para>
1170 <para>
1171 In older GTK-Doc releases, if you need support for additional
1172 formatting, you would need to enable the usage of docbook
1173 XML tags inside doc-comments by putting <option>--xml-mode</option>
1174 (or <option>--sgml-mode</option>) in the variable
1175 <symbol>MKDB_OPTIONS</symbol> inside <filename>Makefile.am</filename>.
1176 </para>
1178 <para>
1179 <example><title>GTK-Doc comment block using Markdown</title>
1180 <programlisting><![CDATA[
1182 * identifier:
1184 * documentation paragraph ...
1186 * # Sub Heading #
1188 * ## Second Sub Heading
1190 * # Sub Heading With a Link Anchor # {#heading-two}
1192 * more documentation:
1194 * - list item 1
1196 * Paragraph inside a list item.
1198 * - list item 2
1200 * 1. numbered list item
1202 * 2. another numbered list item
1204 * Another paragraph. [A Link to the GNOME Website](http://www.gnome.org/)
1206 * ![an inline image](plot-result.png)
1208 * [A link to the heading anchor above][heading-two]
1210 * A C-language example:
1211 * |[<!-- language="C" -->
1212 * GtkWidget *label = gtk_label_new ("Gorgeous!");
1213 * ]|
1215 ]]></programlisting>
1216 </example>
1217 </para>
1219 <para>
1220 More examples of what markdown tags are supported can be found in the
1221 <ulink url="https://wiki.gnome.org/Projects/GTK%2B/DocumentationSyntax/Markdown">GTK+ Documentation Markdown Syntax Reference</ulink>.
1222 </para>
1224 <tip>
1225 <para>
1226 As already mentioned earlier GTK-Doc is for documenting public API. Thus
1227 one cannot write documentation for static symbols. Nevertheless it is good
1228 to comment those symbols too. This helps other to understand you code.
1229 Therefore we recommend to comment these using normal comments (without the
1230 2nd '*' in the first line).
1231 If later the function needs to be made public, all one needs to do is to
1232 add another '*' in the comment block and insert the symbol name at the
1233 right place inside the sections file.
1234 </para>
1235 </tip>
1236 </sect1>
1238 <sect1 id="documenting_sections">
1239 <title>Documenting sections</title>
1241 <para>
1242 Each section of the documentation contains information about one class
1243 or module. To introduce the component one can write a section block.
1244 The short description is also used inside the table of contents.
1245 All the @fields are optional.
1246 </para>
1248 <para>
1249 <example><title>Section comment block</title>
1250 <programlisting><![CDATA[
1252 * SECTION:meepapp
1253 * @short_description: the application class
1254 * @title: Meep application
1255 * @section_id:
1256 * @see_also: #MeepSettings
1257 * @stability: Stable
1258 * @include: meep/app.h
1259 * @image: application.png
1261 * The application class handles ...
1263 ]]></programlisting>
1264 </example>
1265 </para>
1267 <variablelist>
1268 <varlistentry>
1269 <term>SECTION:&lt;name&gt;</term>
1270 <listitem>
1271 <para>
1272 The name links the section documentation to the respective part in
1273 the <filename>&lt;package&gt;-sections.txt</filename> file. The
1274 name given here should match the &lt;FILE&gt; tag in the
1275 <filename>&lt;package&gt;-sections.txt</filename> file.
1276 </para>
1277 </listitem>
1278 </varlistentry>
1279 <varlistentry>
1280 <term>@short_description</term>
1281 <listitem>
1282 <para>
1283 A one line description of the section, that later will appear after
1284 the links in the TOC and at the top of the section page.
1285 </para>
1286 </listitem>
1287 </varlistentry>
1288 <varlistentry>
1289 <term>@title</term>
1290 <listitem>
1291 <para>
1292 The section title defaults to &lt;name&gt; from the SECTION
1293 declaration. It can be overridden with the @title field.
1294 </para>
1295 </listitem>
1296 </varlistentry>
1297 <varlistentry>
1298 <term>@section_id</term>
1299 <listitem>
1300 <para>
1301 Overrides the use of title as a section identifier. For GObjects
1302 the &lt;title&gt; is used as a section_id and for other sections
1303 it is &lt;MODULE&gt;-&lt;title&gt;.
1304 </para>
1305 </listitem>
1306 </varlistentry>
1307 <varlistentry>
1308 <term>@see_also</term>
1309 <listitem>
1310 <para>
1311 A list of symbols that are related to this section.
1312 </para>
1313 </listitem>
1314 </varlistentry>
1315 <varlistentry>
1316 <term>@stability</term>
1317 <listitem>
1318 <para>
1319 An informal description of the stability level this API has.
1320 We recommend the use of one of these terms:
1321 <itemizedlist>
1322 <listitem>
1323 <para>
1324 Stable
1325 - The intention of a Stable interface is to enable arbitrary
1326 third parties to develop applications to these interfaces,
1327 release them, and have confidence that they will run on all
1328 minor releases of the product (after the one in which the
1329 interface was introduced, and within the same major release).
1330 Even at a major release, incompatible changes are expected
1331 to be rare, and to have strong justifications.
1332 </para>
1333 </listitem>
1334 <listitem>
1335 <para>
1336 Unstable
1337 - Unstable interfaces are experimental or transitional.
1338 They are typically used to give outside developers early
1339 access to new or rapidly changing technology, or to provide
1340 an interim solution to a problem where a more general
1341 solution is anticipated.
1342 No claims are made about either source or binary
1343 compatibility from one minor release to the next.
1344 </para>
1345 </listitem>
1346 <listitem>
1347 <para>
1348 Private
1349 - An interface that can be used within the GNOME stack
1350 itself, but that is not documented for end-users. Such
1351 functions should only be used in specified and documented
1352 ways.
1353 </para>
1354 </listitem>
1355 <listitem>
1356 <para>
1357 Internal
1358 - An interface that is internal to a module and does not
1359 require end-user documentation. Functions that are
1360 undocumented are assumed to be Internal.
1361 </para>
1362 </listitem>
1363 </itemizedlist>
1364 </para>
1365 </listitem>
1366 </varlistentry>
1367 <varlistentry>
1368 <term>@include</term>
1369 <listitem>
1370 <para>
1371 The <literal>#include</literal> files to show in the section
1372 synopsis (a comma separated list), overriding the global
1373 value from the <link linkend="metafiles_sections">section
1374 file</link> or command line. This item is optional.
1375 </para>
1376 </listitem>
1377 </varlistentry>
1378 <varlistentry>
1379 <term>@image</term>
1380 <listitem>
1381 <para>
1382 The image to display at the top of the reference page for this
1383 section. This will often be some sort of a diagram to illustrate
1384 the visual appearance of a class or a diagram of its relationship
1385 to other classes. This item is optional.
1386 </para>
1387 </listitem>
1388 </varlistentry>
1389 </variablelist>
1391 <tip>
1392 <para>
1393 To avoid unnecessary recompilation after doc-changes put the section
1394 docs into the c-source where possible.
1395 </para>
1396 </tip>
1398 </sect1>
1400 <sect1 id="documenting_symbols">
1401 <title>Documenting symbols</title>
1403 <para>
1404 Each symbol (function, macro, struct, enum, signal and property) is
1405 documented in a separate block. The block is best placed close to the
1406 definition of the symbols so that it is easy to keep them in sync.
1407 Thus functions are usually documented in the c-source and macros,
1408 structs and enums in the header file.
1409 </para>
1411 <sect2><title>General tags</title>
1413 <para>
1414 You can add versioning information to all documentation elements to tell
1415 when an API was introduced, or when it was deprecated.
1416 </para>
1418 <variablelist><title>Versioning Tags</title>
1419 <varlistentry><term>Since:</term>
1420 <listitem>
1421 <para>
1422 Description since which version of the code the API is available.
1423 </para>
1424 </listitem>
1425 </varlistentry>
1426 <varlistentry><term>Deprecated:</term>
1427 <listitem>
1428 <para>
1429 Paragraph denoting that this function should no be used anymore.
1430 The description should point the reader to the new API.
1431 </para>
1432 </listitem>
1433 </varlistentry>
1434 </variablelist>
1436 <para>
1437 You can also add stability information to all documentation elements
1438 to indicate whether API stability is guaranteed for them for all
1439 future minor releases of the project.
1440 </para>
1442 <para>
1443 The default stability level for all documentation elements can be set
1444 by passing the <option>--default-stability</option> argument to
1445 <application>gtkdoc-mkdb</application> with one of the values below.
1446 </para>
1448 <variablelist><title>Stability Tags</title>
1449 <varlistentry><term>Stability: Stable</term>
1450 <listitem>
1451 <para>
1452 Mark the element as stable. This is for public APIs which are
1453 guaranteed to remain stable for all future minor releases of the
1454 project.
1455 </para>
1456 </listitem>
1457 </varlistentry>
1458 <varlistentry><term>Stability: Unstable</term>
1459 <listitem>
1460 <para>
1461 Mark the element as unstable. This is for public APIs which are
1462 released as a preview before being stabilised.
1463 </para>
1464 </listitem>
1465 </varlistentry>
1466 <varlistentry><term>Stability: Private</term>
1467 <listitem>
1468 <para>
1469 Mark the element as private. This is for interfaces which can be
1470 used by tightly coupled modules, but not by arbitrary third
1471 parties.
1472 </para>
1473 </listitem>
1474 </varlistentry>
1475 </variablelist>
1477 <example><title>General tags</title>
1478 <programlisting><![CDATA[
1480 * foo_get_bar:
1481 * @foo: some foo
1483 * Retrieves @foo's bar.
1485 * Returns: @foo's bar
1487 * Since: 2.6
1488 * Deprecated: 2.12: Use foo_baz_get_bar() instead.
1490 Bar *
1491 foo_get_bar(Foo *foo)
1494 ]]></programlisting>
1495 </example>
1496 </sect2>
1498 <sect2><title>Annotations</title>
1500 <para>
1501 Documentation blocks can contain annotation-tags. These tags will be
1502 rendered with tooltips describing their meaning. The tags are used by
1503 gobject-introspection to generate language bindings. A detailed list
1504 of the supported tags can be found on
1505 <ulink url="http://live.gnome.org/GObjectIntrospection/Annotations" type="http">the wiki</ulink>.
1506 </para>
1508 <example><title>Annotations</title>
1509 <programlisting><![CDATA[
1511 * foo_get_bar: (annotation)
1512 * @foo: (annotation): some foo
1514 * Retrieves @foo's bar.
1516 * Returns: (annotation): @foo's bar
1520 * foo_set_bar_using_the_frobnicator: (annotation) (another annotation)
1521 * (and another annotation)
1522 * @foo: (annotation) (another annotation): some foo
1524 * Sets bar on @foo.
1526 ]]></programlisting>
1527 </example>
1528 </sect2>
1530 <sect2><title>Function comment block</title>
1532 <para>
1533 Please remember to:
1534 <itemizedlist>
1535 <listitem>
1536 <para>
1537 Document whether returned objects, lists, strings, etc, should be
1538 freed/unrefed/released.
1539 </para>
1540 </listitem>
1541 <listitem>
1542 <para>
1543 Document whether parameters can be NULL, and what happens if they are.
1544 </para>
1545 </listitem>
1546 <listitem>
1547 <para>
1548 Mention interesting pre-conditions and post-conditions where appropriate.
1549 </para>
1550 </listitem>
1551 </itemizedlist>
1552 </para>
1554 <para>
1555 Gtk-doc assumes all symbols (macros, functions) starting with '_' are
1556 private. They are treated like static functions.
1557 </para>
1559 <example><title>Function comment block</title>
1560 <programlisting><![CDATA[
1562 * function_name:
1563 * @par1: description of parameter 1. These can extend over more than
1564 * one line.
1565 * @par2: description of parameter 2
1566 * @...: a %NULL-terminated list of bars
1568 * The function description goes here. You can use @par1 to refer to parameters
1569 * so that they are highlighted in the output. You can also use %constant
1570 * for constants, function_name2() for functions and #GtkWidget for links to
1571 * other declarations (which may be documented elsewhere).
1573 * Returns: an integer.
1575 * Since: 2.2
1576 * Deprecated: 2.18: Use other_function() instead.
1578 ]]></programlisting>
1579 </example>
1581 <variablelist><title>Function tags</title>
1582 <varlistentry><term>Returns:</term>
1583 <listitem>
1584 <para>
1585 Paragraph describing the returned result.
1586 </para>
1587 </listitem>
1588 </varlistentry>
1589 <varlistentry><term>@...:</term>
1590 <listitem>
1591 <para>
1592 In case the function has variadic arguments, you should use this
1593 tag (@Varargs: does also work for historic reasons).
1594 </para>
1595 </listitem>
1596 </varlistentry>
1597 </variablelist>
1599 </sect2>
1601 <sect2><title>Property comment block</title>
1603 <example><title>Property comment block</title>
1604 <programlisting><![CDATA[
1606 * SomeWidget:some-property:
1608 * Here you can document a property.
1610 g_object_class_install_property (object_class, PROP_SOME_PROPERTY, ...);
1611 ]]></programlisting>
1612 </example>
1614 </sect2>
1616 <sect2><title>Signal comment block</title>
1618 <para>
1619 Please remember to:
1620 <itemizedlist>
1621 <listitem>
1622 <para>
1623 Document when the signal is emitted and whether it is emitted before
1624 or after other signals.
1625 </para>
1626 </listitem>
1627 <listitem>
1628 <para>
1629 Document what an application might do in the signal handler.
1630 </para>
1631 </listitem>
1632 </itemizedlist>
1633 </para>
1635 <example><title>Signal comment block</title>
1636 <programlisting><![CDATA[
1638 * FooWidget::foobarized:
1639 * @widget: the widget that received the signal
1640 * @foo: some foo
1641 * @bar: some bar
1643 * The ::foobarized signal is emitted each time someone tries to foobarize @widget.
1645 foo_signals[FOOBARIZED] =
1646 g_signal_new ("foobarized",
1648 ]]></programlisting>
1649 </example>
1651 </sect2>
1653 <sect2><title>Struct comment block</title>
1654 <example><title>Struct comment block</title>
1655 <programlisting><![CDATA[
1657 * FooWidget:
1658 * @bar: some #gboolean
1660 * This is the best widget, ever.
1662 typedef struct _FooWidget {
1663 GtkWidget parent_instance;
1665 gboolean bar;
1666 } FooWidget;
1667 ]]></programlisting>
1668 </example>
1670 <para>
1671 Use <code>/*&lt; private &gt;*/</code> before the private struct fields
1672 you want to hide. Use <code>/*&lt; public &gt;*/</code> for the reverse
1673 behaviour.
1674 </para>
1676 <para>
1677 If the first field is "g_iface", "parent_instance" or "parent_class"
1678 it will be considered private automatically and doesn't need to be
1679 mentioned in the comment block.
1680 </para>
1682 <para>
1683 Struct comment blocks can also be used for GObjects and GObjectClasses.
1684 It is usually a good idea to add a comment block for a class, if it has
1685 vmethods (as this is how they can be documented). For the GObject
1686 itself one can use the related section docs, having a separate block
1687 for the instance struct would be useful if the instance has public
1688 fields. One disadvantage here is that this creates two index entries
1689 of the same name (the structure and the section).
1690 </para>
1692 </sect2>
1694 <sect2><title>Enum comment block</title>
1695 <example><title>Enum comment block</title>
1696 <programlisting><![CDATA[
1698 * Something:
1699 * @SOMETHING_FOO: something foo
1700 * @SOMETHING_BAR: something bar
1702 * Enum values used for the thing, to specify the thing.
1704 typedef enum {
1705 SOMETHING_FOO,
1706 SOMETHING_BAR,
1707 /*< private >*/
1708 SOMETHING_COUNT
1709 } Something;
1710 ]]></programlisting>
1711 </example>
1713 <para>
1714 Use <code>/*&lt; private &gt;*/</code> before the private enum values
1715 you want to hide. Use <code>/*&lt; public &gt;*/</code> for the reverse
1716 behaviour.
1717 </para>
1719 </sect2>
1720 </sect1>
1723 <sect1 id="documenting_inline_program">
1724 <title>Inline program documentation</title>
1725 <para>
1726 You can document programs and their commandline interface using inline
1727 documentation.
1728 </para>
1730 <variablelist>
1731 <title>Tags</title>
1733 <varlistentry><term>PROGRAM</term>
1735 <listitem>
1736 <para>
1737 Defines the start of a program documentation.
1738 </para>
1739 </listitem>
1740 </varlistentry>
1742 <varlistentry>
1743 <term>@short_description:</term>
1744 <listitem>
1745 <para>
1746 Defines a short description of the program. (Optional)
1747 </para>
1748 </listitem>
1749 </varlistentry>
1751 <varlistentry>
1752 <term>@synopsis:</term>
1753 <listitem>
1754 <para>
1755 Defines the arguments, or list of arguments that the program can take.
1756 (Optional)
1757 </para>
1758 </listitem>
1759 </varlistentry>
1761 <varlistentry>
1762 <term>@see_also:</term>
1763 <listitem>
1764 <para>
1765 See Also manual page section. (Optional)
1766 </para>
1767 </listitem>
1768 </varlistentry>
1770 <varlistentry>
1771 <term>@arg:</term>
1772 <listitem>
1773 <para>
1774 Argument(s) passed to the program and their description. (Optional)
1775 </para>
1776 </listitem>
1777 </varlistentry>
1779 <varlistentry>
1780 <term>Description:</term>
1781 <listitem>
1782 <para>
1783 A longer description of the program.
1784 </para>
1785 </listitem>
1786 </varlistentry>
1788 <varlistentry>
1789 <term>Returns:</term>
1790 <listitem>
1791 <para>
1792 Specificy what value(s) the program returns. (Optional)
1793 </para>
1794 </listitem>
1795 </varlistentry>
1797 </variablelist>
1799 <sect2>
1800 <title>Example of program documentation.</title>
1801 <example><title>Program documentation block</title>
1802 <programlisting><![CDATA[
1804 * PROGRAM:test-program
1805 * @short_description: A test program
1806 * @synopsis: test-program [*OPTIONS*...] --arg1 *arg* *FILE*
1807 * @see_also: test(1)
1808 * @--arg1 *arg*: set arg1 to *arg*
1809 * @--arg2 *arg*: set arg2 to *arg*
1810 * @-v, --version: Print the version number
1811 * @-h, --help: Print the help message
1813 * Long description of program.
1815 * Returns: Zero on success, non-zero on failure
1817 int main(int argc, char *argv[])
1819 return 0;
1821 ]]></programlisting>
1822 </example>
1824 </sect2>
1825 </sect1>
1827 <sect1 id="documenting_docbook">
1828 <title>Useful DocBook tags</title>
1830 <para>
1831 Here are some DocBook tags which are most useful when documenting the
1832 code.
1833 </para>
1835 <para>
1836 To link to another section in the GTK docs:
1838 <informalexample>
1839 <programlisting><![CDATA[
1840 <link linkend="glib-Hash-Tables">Hash Tables</link>
1841 ]]></programlisting>
1842 </informalexample>
1843 The linkend is the SGML/XML id on the top item of the page you want to link to.
1844 For most pages this is currently the part ("gtk", "gdk", "glib") and then
1845 the page title ("Hash Tables"). For widgets it is just the class name.
1846 Spaces and underscores are converted to '-' to conform to SGML/XML.
1847 </para>
1849 <para>
1850 To refer to an external function, e.g. a standard C function:
1851 <informalexample>
1852 <programlisting><![CDATA[
1853 <function>...</function>
1854 ]]></programlisting>
1855 </informalexample>
1856 </para>
1858 <para>
1859 To include example code:
1860 <informalexample>
1861 <programlisting><![CDATA[
1862 <example>
1863 <title>Using a GHashTable.</title>
1864 <programlisting>
1866 </programlisting>
1867 </example>
1868 ]]></programlisting>
1869 </informalexample>
1870 or possibly this, for very short code fragments which don't need a title:
1871 <informalexample>
1872 <programlisting><![CDATA[
1873 <informalexample>
1874 <programlisting>
1876 </programlisting>
1877 </informalexample>
1878 ]]></programlisting>
1879 </informalexample>
1880 For the latter GTK-Doc also supports an abbreviation:
1881 <![CDATA[
1886 </para>
1888 <para>
1889 To include bulleted lists:
1890 <informalexample>
1891 <programlisting><![CDATA[
1892 <itemizedlist>
1893 <listitem>
1894 <para>
1896 </para>
1897 </listitem>
1898 <listitem>
1899 <para>
1901 </para>
1902 </listitem>
1903 </itemizedlist>
1904 ]]></programlisting>
1905 </informalexample>
1906 </para>
1908 <para>
1909 To include a note which stands out from the text:
1910 <informalexample>
1911 <programlisting><![CDATA[
1912 <note>
1913 <para>
1914 Make sure you free the data after use.
1915 </para>
1916 </note>
1917 ]]></programlisting>
1918 </informalexample>
1919 </para>
1921 <para>
1922 To refer to a type:
1923 <informalexample>
1924 <programlisting><![CDATA[
1925 <type>unsigned char</type>
1926 ]]></programlisting>
1927 </informalexample>
1928 </para>
1930 <para>
1931 To refer to an external structure (not one described in the GTK docs):
1932 <informalexample>
1933 <programlisting><![CDATA[
1934 <structname>XFontStruct</structname>
1935 ]]></programlisting>
1936 </informalexample>
1937 </para>
1939 <para>
1940 To refer to a field of a structure:
1941 <informalexample>
1942 <programlisting><![CDATA[
1943 <structfield>len</structfield>
1944 ]]></programlisting>
1945 </informalexample>
1946 </para>
1948 <para>
1949 To refer to a class name, we could possibly use:
1950 <informalexample>
1951 <programlisting><![CDATA[
1952 <classname>GtkWidget</classname>
1953 ]]></programlisting>
1954 </informalexample>
1955 but you'll probably be using #GtkWidget instead (to automatically create
1956 a link to the GtkWidget page - see <link linkend="documenting_syntax">the abbreviations</link>).
1957 </para>
1959 <para>
1960 To emphasize text:
1961 <informalexample>
1962 <programlisting><![CDATA[
1963 <emphasis>This is important</emphasis>
1964 ]]></programlisting>
1965 </informalexample>
1966 </para>
1968 <para>
1969 For filenames use:
1970 <informalexample>
1971 <programlisting><![CDATA[
1972 <filename>/home/user/documents</filename>
1973 ]]></programlisting>
1974 </informalexample>
1975 </para>
1977 <para>
1978 To refer to keys use:
1979 <informalexample>
1980 <programlisting><![CDATA[
1981 <keycombo><keycap>Control</keycap><keycap>L</keycap></keycombo>
1982 ]]></programlisting>
1983 </informalexample>
1984 </para>
1986 </sect1>
1987 </chapter>
1989 <chapter id="metafiles">
1990 <title>Filling the extra files</title>
1992 <para>
1993 There are a couple of extra files, that need to be maintained along with
1994 the inline source code comments:
1995 <filename>&lt;package&gt;.types</filename>,
1996 <filename>&lt;package&gt;-docs.xml</filename> (in the past .sgml),
1997 <filename>&lt;package&gt;-sections.txt</filename>.
1998 </para>
2000 <sect1 id="metafiles_types">
2001 <title>Editing the types file</title>
2003 <para>
2004 If your library or application includes GObjects, you want
2005 their signals, arguments/parameters and position in the hierarchy to be
2006 shown in the documentation. All you need to do, is to list the
2007 <function>xxx_get_type</function> functions together with their include
2008 inside the <filename>&lt;package&gt;.types</filename> file.
2009 </para>
2011 <para>
2012 <example><title>Example types file snippet</title>
2013 <programlisting><![CDATA[
2014 #include <gtk/gtk.h>
2016 gtk_accel_label_get_type
2017 gtk_adjustment_get_type
2018 gtk_alignment_get_type
2019 gtk_arrow_get_type
2020 ]]></programlisting>
2021 </example>
2022 </para>
2024 <para>
2025 Since GTK-Doc 1.8 <application>gtkdoc-scan</application> can generate this list for you.
2026 Just add "--rebuild-types" to SCAN_OPTIONS in <filename>Makefile.am</filename>. If you
2027 use this approach you should not dist the types file nor have it under version control.
2028 </para>
2030 </sect1>
2032 <sect1 id="metafiles_master">
2033 <title>Editing the master document</title>
2035 <para>
2036 GTK-Doc produces documentation in DocBook SGML/XML. When processing the
2037 inline source comments, the GTK-Doc tools generate one documentation
2038 page per class or module as a separate file. The master document
2039 includes them and place them in an order.
2040 </para>
2042 <para>
2043 While GTK-Doc creates a template master document for you, later runs will
2044 not touch it again. This means that one can freely structure the
2045 documentation. That includes grouping pages and adding extra pages.
2046 GTK-Doc has now a test suite, where also the master-document is recreated from scratch.
2047 Its a good idea to look at this from time to time to see if there are
2048 some new goodies introduced there.
2049 </para>
2051 <tip>
2052 <para>
2053 Do not create tutorials as extra documents. Just write extra chapters.
2054 The benefit of directly embedding the tutorial for your library into
2055 the API documentation is that it is easy to link for the tutorial to
2056 symbol documentation. Apart chances are higher that the tutorial gets
2057 updates along with the library.
2058 </para>
2059 </tip>
2061 <para>
2062 So what are the things to change inside the master document? For a start
2063 is only a little. There are some placeholders (text in square brackets)
2064 there which you should take care of.
2065 </para>
2067 <para>
2068 <example><title>Master document header</title>
2069 <programlisting><![CDATA[
2070 <bookinfo>
2071 <title>MODULENAME Reference Manual</title>
2072 <releaseinfo>
2073 for MODULENAME [VERSION]
2074 The latest version of this documentation can be found on-line at
2075 <ulink role="online-location" url="http://[SERVER]/MODULENAME/index.html">http://[SERVER]/MODULENAME/</ulink>.
2076 </releaseinfo>
2077 </bookinfo>
2079 <chapter>
2080 <title>[Insert title here]</title>
2081 ]]></programlisting>
2082 </example>
2083 </para>
2085 <para>
2086 In addition a few option elements are created in commented form. You can
2087 review these and enable them as you like.
2088 </para>
2090 <para>
2091 <example><title>Optional part in the master document</title>
2092 <programlisting><![CDATA[
2093 <!-- enable this when you use gobject introspection annotations
2094 <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
2096 ]]></programlisting>
2097 </example>
2098 </para>
2100 <para>
2101 Finally you need to add new section whenever you introduce one. The
2102 <link linkend="modernizing-gtk-doc-1-16">gtkdoc-check</link> tool will
2103 remind you of newly generated xml files that are not yet included into
2104 the doc.
2105 </para>
2107 <para>
2108 <example><title>Including generated sections</title>
2109 <programlisting><![CDATA[
2110 <chapter>
2111 <title>my library</title>
2112 <xi:include href="xml/object.xml"/>
2114 ]]></programlisting>
2115 </example>
2116 </para>
2118 </sect1>
2120 <sect1 id="metafiles_sections">
2121 <title>Editing the section file</title>
2123 <para>
2124 The section file is used to organise the documentation output by
2125 GTK-Doc. Here one specifies which symbol belongs to which module or
2126 class and control the visibility (public or private).
2127 </para>
2129 <para>
2130 The section file is a plain text file with tags delimiting sections.
2131 Blank lines are ignored and lines starting with a '#' are treated as
2132 comment lines.
2133 </para>
2135 <note>
2136 <para>
2137 While the tags make the file look like xml, it is not. Please do not
2138 close tags like &lt;SUBSECTION&gt;.
2139 </para>
2140 </note>
2142 <para>
2143 <example><title>Including generated sections</title>
2144 <programlisting><![CDATA[
2145 <INCLUDE>libmeep/meep.h</INCLUDE>
2147 <SECTION>
2148 <FILE>meepapp</FILE>
2149 <TITLE>MeepApp</TITLE>
2150 MeepApp
2151 <SUBSECTION Standard>
2152 MEEP_APP
2154 MeepAppClass
2155 meep_app_get_type
2156 </SECTION>
2157 ]]></programlisting>
2158 </example>
2159 </para>
2161 <para>
2162 The &lt;FILE&gt; ... &lt;/FILE&gt; tag is used to specify the file name,
2163 without any suffix. For example, using '&lt;FILE&gt;gnome-config&lt;/FILE&gt;'
2164 will result in the section declarations being output in the template
2165 file <filename>tmpl/gnome-config.sgml</filename>, which will be
2166 converted into the DocBook XML file <filename>xml/gnome-config.sgml</filename>
2167 or the DocBook XML file <filename>xml/gnome-config.xml</filename>.
2168 (The name of the HTML file is based on the module name and the section
2169 title, or for GObjects it is based on the GObjects class name converted
2170 to lower case).
2171 </para>
2173 <para>
2174 The &lt;TITLE&gt; ... &lt;/TITLE&gt; tag is used to specify the title of
2175 the section. It is only useful before the templates (if used) are
2176 initially created, since the title set in the template file overrides
2177 this. Also if one uses SECTION comment in the sources, this is obsolete.
2178 </para>
2180 <para>
2181 You can group items in the section by using the &lt;SUBSECTION&gt; tag.
2182 Currently it outputs a blank line between subsections in the synopsis
2183 section.
2184 You can also use &lt;SUBSECTION Standard&gt; for standard GObject
2185 declarations (e.g. the functions like g_object_get_type and macros like
2186 G_OBJECT(), G_IS_OBJECT() etc.).
2187 Currently these are left out of the documentation.
2188 You can also use &lt;SUBSECTION Private&gt; for private declarations
2189 which will not be output (it is a handy way to avoid warning messages
2190 about unused declarations).
2191 If your library contains private types which you don't want to appear in
2192 the object hierarchy and the list of implemented or required interfaces,
2193 add them to a Private subsection.
2194 Whether you would place GObject and GObjectClass like structs in public
2195 or Standard section depends if they have public entries (variables,
2196 vmethods).
2197 </para>
2199 <para>
2200 You can also use &lt;INCLUDE&gt; ... &lt;/INCLUDE&gt; to specify the
2201 #include files which are shown in the synopsis sections.
2202 It contains a comma-separate list of #include files, without the angle
2203 brackets. If you set it outside of any sections, it acts for all
2204 sections until the end of the file. If you set it within a section, it
2205 only applies to that section.
2206 </para>
2208 </sect1>
2210 </chapter>
2212 <chapter id="reports">
2213 <title>Controlling the result</title>
2215 <para>
2216 A GTK-Doc run generates report files inside the documentation directory.
2217 The generated files are named:
2218 <filename>&lt;package&gt;-undocumented.txt</filename>,
2219 <filename>&lt;package&gt;-undeclared.txt</filename> and
2220 <filename>&lt;package&gt;-unused.txt</filename>.
2221 All those are plain text files that can be viewed and postprocessed easily.
2222 </para>
2224 <para>
2225 The <filename>&lt;package&gt;-undocumented.txt</filename> file starts with
2226 the documentation coverage summary. Below are two sections divided by
2227 blank lines. The first section lists undocumented or incomplete symbols.
2228 The second section does the same for section docs. Incomplete entries are
2229 those, which have documentation, but where e.g. a new parameter has been
2230 added.
2231 </para>
2233 <para>
2234 The <filename>&lt;package&gt;-undeclared.txt</filename> file lists symbols
2235 given in the <filename>&lt;package&gt;-sections.txt</filename> but not
2236 found in the sources. Check if they have been removed or if they are
2237 misspelled.
2238 </para>
2240 <para>
2241 The <filename>&lt;package&gt;-unused.txt</filename> file lists symbol
2242 names, where the GTK-Doc scanner has found documentation, but does not
2243 know where to put it. This means that the symbol has not yet been added to
2244 the <filename>&lt;package&gt;-sections.txt</filename> file.
2245 </para>
2247 <tip>
2248 <para>
2249 Enable or add the <option>TESTS=$(GTKDOC_CHECK)</option> line in Makefile.am.
2250 If at least GTK-Doc 1.9 is installed, this will run sanity checks during
2251 <command>make check</command> run.
2252 </para>
2253 </tip>
2255 <para>
2256 One can also look at the files produced by the source code scanner:
2257 <filename>&lt;package&gt;-decl-list.txt</filename> and
2258 <filename>&lt;package&gt;-decl.txt</filename>. The first one can be
2259 compared with the section file if that is manually maintained. The second
2260 lists all declarations from the headers. If a symbol is missing one could
2261 check if this file contains it.
2262 </para>
2264 <para>
2265 If the project is GObject based, one can also look into the files produced
2266 by the object scanner:
2267 <filename>&lt;package&gt;.args.txt</filename>,
2268 <filename>&lt;package&gt;.hierarchy.txt</filename>,
2269 <filename>&lt;package&gt;.interfaces.txt</filename>,
2270 <filename>&lt;package&gt;.prerequisites.txt</filename> and
2271 <filename>&lt;package&gt;.signals.txt</filename>. If there are missing
2272 symbols in any of those, one can ask GTK-Doc to keep the intermediate
2273 scanner file for further analysis, by running it as
2274 <command>GTK_DOC_KEEP_INTERMEDIATE=1 make</command>.
2275 </para>
2276 </chapter>
2278 <chapter id="modernizing">
2279 <title>Modernizing the documentation</title>
2281 <para>
2282 GTK-Doc has been around for quite some time. In this section we list new
2283 features together with the version since when it is available.
2284 </para>
2286 <sect1 id="modernizing-gtk-doc-1-9">
2287 <title>GTK-Doc 1.9</title>
2289 <para>
2290 When using xml instead of sgml, one can actually name the master
2291 document <filename>&lt;package&gt;-docs.xml</filename>.
2292 </para>
2294 <para>
2295 This version supports <option>SCAN_OPTIONS=--rebuild-sections</option>
2296 in <filename>Makefile.am</filename>. When this is enabled, the
2297 <filename>&lt;package&gt;-sections.txt</filename> is autogenerated and
2298 can be removed from the vcs. This only works nicely for projects that
2299 have a very regular structure (e.g. each .{c,h} pair will create new
2300 section). If one organize a project close to that updating a manually
2301 maintained section file can be as simple as running
2302 <code>meld &lt;package&gt;-decl-list.txt &lt;package&gt;-sections.txt</code>.
2303 </para>
2305 <para>
2306 Version 1.8 already introduced the syntax for documenting sections in
2307 the sources instead of the separate files under <filename class='directory'>tmpl</filename>.
2308 This version adds options to switch the whole doc module to not use the
2309 extra tmpl build step at all, by using <option>--flavour no-tmpl</option>
2310 in <filename>configure.ac</filename>. If you don't have a <filename class='directory'>tmpl</filename>
2311 checked into your source control system and haven't yet switched, just
2312 add the flag to <filename>configure.ac</filename> and you are done.
2313 </para>
2314 </sect1>
2316 <sect1 id="modernizing-gtk-doc-1-10">
2317 <title>GTK-Doc 1.10</title>
2319 <para>
2320 This version supports <option>SCAN_OPTIONS=--rebuild-types</option> in
2321 <filename>Makefile.am</filename>. When this is enabled, the
2322 <filename>&lt;package&gt;.types</filename> is autogenerated and can be
2323 removed from the vcs. When using this feature it is important to also
2324 setup the <varname>IGNORE_HFILES</varname> in
2325 <filename>Makefile.am</filename> for code that is build conditionally.
2326 </para>
2327 </sect1>
2329 <sect1 id="modernizing-gtk-doc-1-16">
2330 <title>GTK-Doc 1.16</title>
2332 <para>
2333 This version includes a new tool called gtkdoc-check. This tool can run
2334 a set of sanity checks on your documentation. It is enabled by adding
2335 these lines to the end of <filename>Makefile.am</filename>.
2336 <example><title>Enable gtkdoc-check</title>
2337 <programlisting><![CDATA[
2338 if ENABLE_GTK_DOC
2339 TESTS_ENVIRONMENT = \
2340 DOC_MODULE=$(DOC_MODULE) DOC_MAIN_SGML_FILE=$(DOC_MAIN_SGML_FILE) \
2341 SRCDIR=$(abs_srcdir) BUILDDIR=$(abs_builddir)
2342 TESTS = $(GTKDOC_CHECK)
2343 endif
2344 ]]></programlisting>
2345 </example>
2346 </para>
2347 </sect1>
2349 <sect1 id="modernizing-gtk-doc-1-20">
2350 <title>GTK-Doc 1.20</title>
2352 <para>
2353 Version 1.18 brought some initial markdown support. Using markdown in
2354 doc comments is less intrusive than writing docbook xml. This version
2355 improves a lot on this and add a lot more styles. The section that
2356 explains the <link linkend="documenting_syntax">comment syntax</link>
2357 has all the details.
2358 </para>
2359 </sect1>
2361 <sect1 id="modernizing-gtk-doc-1-25">
2362 <title>GTK-Doc 1.25</title>
2364 <para>
2365 The makefiles shipped with this version generate an entity file at <filename>xml/gtkdocentities.ent</filename>,
2366 containing entities for e.g. package_name and package_version. You can
2367 use this e.g. in the main xml file to avoid hardcoding the version
2368 number. Below is an example that shows how the entity file is included
2369 and how the entities are used. The entities can also be used in all
2370 generated files, GTK-Doc will use the same xml header in generated xml
2371 files.
2372 <example><title>Use pre-generated entities</title>
2373 <programlisting><![CDATA[
2374 <?xml version="1.0"?>
2375 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
2376 "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
2378 <!ENTITY % local.common.attrib "xmlns:xi CDATA #FIXED 'http://www.w3.org/2003/XInclude'">
2379 <!ENTITY % gtkdocentities SYSTEM "xml/gtkdocentities.ent">
2380 %gtkdocentities;
2382 <book id="index" xmlns:xi="http://www.w3.org/2003/XInclude">
2383 <bookinfo>
2384 <title>&package_name; Reference Manual</title>
2385 <releaseinfo>
2386 for &package_string;.
2387 The latest version of this documentation can be found on-line at
2388 <ulink role="online-location" url="http://[SERVER]/&package_name;/index.html">http://[SERVER]/&package_name;/</ulink>.
2389 </releaseinfo>
2390 </bookinfo>
2391 ]]></programlisting>
2392 </example>
2393 </para>
2394 </sect1>
2395 </chapter>
2397 <chapter id="documenting-others">
2398 <title>Documenting other interfaces</title>
2400 <para>
2401 So far we have been using GTK-Doc to document the API of code. The next
2402 sections contain suggestions how the tools can be used to document other
2403 interfaces too.
2404 </para>
2406 <sect1 id="commandline-interfaces">
2407 <title>Command line options and man pages</title>
2409 <para>
2410 As one can generate man pages for a docbook refentry as well, it sounds
2411 like a good idea to use it for that purpose. This way the interface is
2412 part of the reference and one gets the man-page for free.
2413 </para>
2415 <sect2 id="commandline-interfaces-file">
2416 <title>Document the tool</title>
2418 <para>
2419 Create one refentry file per tool. Following
2420 <link linkend="settingup_docfiles">our example</link> we would call it
2421 <filename>meep/docs/reference/meeper/meep.xml</filename>. For the xml
2422 tags that should be used and can look at generated file in the xml
2423 subdirectory as well as examples e.g. in glib.
2424 </para>
2425 </sect2>
2427 <sect2 id="commandline-interfaces-configure">
2428 <title>Adding the extra configure check</title>
2430 <para>
2431 <example><title>Extra configure checks</title>
2432 <programlisting><![CDATA[
2433 AC_ARG_ENABLE(man,
2434 [AC_HELP_STRING([--enable-man],
2435 [regenerate man pages from Docbook [default=no]])],enable_man=yes,
2436 enable_man=no)
2438 AC_PATH_PROG([XSLTPROC], [xsltproc])
2439 AM_CONDITIONAL(ENABLE_MAN, test x$enable_man != xno)
2440 ]]></programlisting>
2441 </example>
2442 </para>
2443 </sect2>
2445 <sect2 id="commandline-interfaces-make">
2446 <title>Adding the extra makefile rules</title>
2448 <para>
2449 <example><title>Extra configure checks</title>
2450 <programlisting><![CDATA[
2451 man_MANS = \
2452 meeper.1
2454 if ENABLE_GTK_DOC
2455 if ENABLE_MAN
2457 %.1 : %.xml
2458 @XSLTPROC@ -nonet http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl $<
2460 endif
2461 endif
2463 BUILT_EXTRA_DIST = $(man_MANS)
2464 EXTRA_DIST += meep.xml
2465 ]]></programlisting>
2466 </example>
2467 </para>
2468 </sect2>
2469 </sect1>
2471 <sect1 id="dbus-interfaces">
2472 <title>DBus interfaces</title>
2474 <para>
2475 (FIXME: http://hal.freedesktop.org/docs/DeviceKit/DeviceKit.html,
2476 http://cgit.freedesktop.org/DeviceKit/DeviceKit/tree/doc/dbus)
2477 </para>
2478 </sect1>
2480 </chapter>
2482 <chapter id="faq">
2483 <title>Frequently asked questions</title>
2485 <segmentedlist>
2486 <?dbhtml list-presentation="list"?>
2487 <segtitle>Question</segtitle>
2488 <segtitle>Answer</segtitle>
2489 <seglistitem>
2490 <seg>No class hierarchy.</seg>
2491 <seg>
2492 The objects <function>xxx_get_type()</function> function has not been
2493 entered into the <filename>&lt;package&gt;.types</filename> file.
2494 </seg>
2495 </seglistitem>
2496 <seglistitem>
2497 <seg>Still no class hierarchy.</seg>
2498 <seg>
2499 Missing or wrong naming in <filename>&lt;package&gt;-sections.txt</filename>
2500 file (see <ulink url="http://mail.gnome.org/archives/gtk-doc-list/2003-October/msg00006.html">explanation</ulink>).
2501 </seg>
2502 </seglistitem>
2503 <seglistitem>
2504 <seg>Damn, I have still no class hierarchy.</seg>
2505 <seg>
2506 Is the object name (name of the instance struct, e.g. <type>GtkWidget</type>)
2507 part of the normal section (don't put this into Standard or Private
2508 subsections).
2509 </seg>
2510 </seglistitem>
2511 <seglistitem>
2512 <seg>No symbol index.</seg>
2513 <seg>
2514 Does the <filename>&lt;package&gt;-docs.{xml,sgml}</filename> contain a
2515 index that xi:includes the generated index?
2516 </seg>
2517 </seglistitem>
2518 <seglistitem>
2519 <seg>Symbols are not linked to their doc-section.</seg>
2520 <seg>
2521 Is the doc-comment using the correct markup (added #,% or ())?
2522 Check if the gtkdoc-fixxref warns about unresolvable xrefs.
2523 </seg>
2524 </seglistitem>
2525 <seglistitem>
2526 <seg>A new class does not appear in the docs.</seg>
2527 <seg>
2528 Is the new page xi:included from
2529 <filename>&lt;package&gt;-docs.{xml,sgml}</filename>.
2530 </seg>
2531 </seglistitem>
2532 <seglistitem>
2533 <seg>A new symbol does not appear in the docs.</seg>
2534 <seg>
2535 Is the doc-comment properly formatted. Check for spelling mistakes in
2536 the begin of the comment. Check if the gtkdoc-fixxref warns about
2537 unresolvable xrefs. Check if the symbol is correctly listed in the
2538 <filename>&lt;package&gt;-sections.txt</filename> in a public subsection.
2539 </seg>
2540 </seglistitem>
2541 <seglistitem>
2542 <seg>A type is missing from the class hierarchy.</seg>
2543 <seg>
2544 If the type is listed in <filename>&lt;package&gt;.hierarchy</filename>
2545 but not in <filename>xml/tree_index.sgml</filename> then double check
2546 that the type is correctly placed in the <filename>&lt;package&gt;-sections.txt</filename>.
2547 If the type instance (e.g. <type>GtkWidget</type>) is not listed or
2548 incidentally marked private it will not be shown.
2549 </seg>
2550 </seglistitem>
2551 <seglistitem>
2552 <seg>I get foldoc links for all gobject annotations.</seg>
2553 <seg>
2554 Check that <filename>xml/annotation-glossary.xml</filename> is
2555 xi:included from <filename>&lt;package&gt;-docs.{xml,sgml}</filename>.
2556 </seg>
2557 </seglistitem>
2559 <!-- gtk-doc warnings: -->
2560 <seglistitem>
2561 <seg>Parameter described in source code comment block but does not exist</seg>
2562 <seg>Check if the prototype in the header has different parameter names as in the source.</seg>
2563 </seglistitem>
2565 <!-- docbook warnings: -->
2566 <seglistitem>
2567 <seg>multiple "IDs" for constraint linkend: XYZ</seg>
2568 <seg>Symbol XYZ appears twice in <filename>&lt;package&gt;-sections.txt</filename> file.</seg>
2569 </seglistitem>
2570 <seglistitem>
2571 <seg>Element typename in namespace '' encountered in para, but no template matches.</seg>
2572 <seg />
2573 </seglistitem>
2574 </segmentedlist>
2575 </chapter>
2577 <chapter id="contrib">
2578 <title>Tools related to gtk-doc</title>
2580 <para>
2581 GtkDocPlugin - a <ulink url="http://trac-hacks.org/wiki/GtkDocPlugin">Trac GTK-Doc</ulink>
2582 integration plugin, that adds API docs to a trac site and integrates with
2583 the trac search.
2584 </para>
2585 <para>
2586 Gtkdoc-depscan - a tool (part of gtk-doc) to check used API against since
2587 tags in the API to determine the minimum required version.
2588 </para>
2590 </chapter>
2592 <!-- ======== Appendix: FDL ================================== -->
2593 &FDL;
2595 </book>