Update French translation
[gtk-doc.git] / help / manual / C / index.docbook
blob00b9bf6f69c78952113424a8fbb4917bb4f4fe04
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 <function>GTK_DOC_CHECK</function> macro.
853 </para>
855 <para>
856 Alternatively, additional arguments can also be passed to
857 <application>gtkdocize</application> via the
858 <function>GTKDOCIZE_FLAGS</function> 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 <para>
1005 The GTK-Doc scanner can handle the majority of C headers fine. In the
1006 case of receiving warnings from the scanner that look like a special
1007 case, one can hint GTK-Doc to skip over them.
1008 <example><title>GTK-Doc comment block</title>
1009 <programlisting><![CDATA[
1010 #ifndef __GTK_DOC_IGNORE__
1011 /* unparseable code here */
1012 #endif
1013 ]]></programlisting>
1014 </example>
1015 </para>
1017 <note>
1018 <title>Limitations</title>
1019 <para>
1020 Note, that GTK-Doc's supports
1021 <code>#ifndef(__GTK_DOC_IGNORE__)</code> but not
1022 <code>#if !defined(__GTK_DOC_IGNORE__)</code> or other combinations.
1023 </para>
1024 </note>
1026 <!-- -->
1028 <sect1 id="documenting_syntax">
1029 <title>Documentation comments</title>
1031 <para>
1032 A multiline comment that starts with an additional '*' marks a
1033 documentation block that will be processed by the GTK-Doc tools.
1034 <example><title>GTK-Doc comment block</title>
1035 <programlisting><![CDATA[
1037 * identifier:
1038 * documentation ...
1040 ]]></programlisting>
1041 </example>
1042 </para>
1044 <para>
1045 The 'identifier' is one line with the name of the item the comment is
1046 related to. The syntax differs a little depending on the item.
1047 (TODO add table showing identifiers)
1048 </para>
1050 <para>
1051 The 'documentation' block is also different for each symbol type. Symbol
1052 types that get parameters such as functions or macros have the parameter
1053 description first followed by a blank line (just a '*').
1054 Afterwards follows the detailed description. All lines (outside program
1055 listings and CDATA sections) just containing a ' *' (blank-asterisk) are
1056 converted to paragraph breaks.
1057 If you don't want a paragraph break, change that into ' * '
1058 (blank-asterisk-blank-blank). This is useful in preformatted text (code
1059 listings).
1060 </para>
1062 <tip>
1063 <para>
1064 When documenting code, describe two aspects:
1065 <itemizedlist>
1066 <listitem>
1067 <para>
1068 What it is: The name for a class or function can sometimes
1069 be misleading for people coming from a different background.
1070 </para>
1071 </listitem>
1072 <listitem>
1073 <para>
1074 What it does: Tell about common uses. Put it in relation
1075 with the other API.
1076 </para>
1077 </listitem>
1078 </itemizedlist>
1079 </para>
1080 </tip>
1082 <para>
1083 One advantage of hyper-text over plain-text is the ability to have links
1084 in the document. Writing the correct markup for a link can be tedious
1085 though. GTK-Doc comes to help by providing several useful abbreviations.
1086 <itemizedlist>
1087 <listitem>
1088 <para>
1089 Use function() to refer to functions or macros which take arguments.
1090 </para>
1091 </listitem>
1092 <listitem>
1093 <para>
1094 Use @param to refer to parameters. Also use this when referring to
1095 parameters of other functions, related to the one being described.
1096 </para>
1097 </listitem>
1098 <listitem>
1099 <para>
1100 Use %constant to refer to a constant, e.g. %G_TRAVERSE_LEAFS.
1101 </para>
1102 </listitem>
1103 <listitem>
1104 <para>
1105 Use #symbol to refer to other types of symbol, e.g. structs and
1106 enums and macros which don't take arguments.
1107 </para>
1108 </listitem>
1109 <listitem>
1110 <para>
1111 Use #Object::signal to refer to a GObject signal.
1112 </para>
1113 </listitem>
1114 <listitem>
1115 <para>
1116 Use #Object:property to refer to a GObject property.
1117 </para>
1118 </listitem>
1119 <listitem>
1120 <para>
1121 Use #Struct.field to refer to a field inside a structure and
1122 #GObjectClass.foo_bar() to refer to a vmethod.
1123 </para>
1124 </listitem>
1125 </itemizedlist>
1126 </para>
1128 <tip>
1129 <para>
1130 If you need to use the special characters '&lt;', '&gt;', '()', '@',
1131 '%', or '#' in your documentation without GTK-Doc changing them you
1132 can use the XML entities "&amp;lt;", "&amp;gt;", "&amp;lpar;",
1133 "&amp;rpar;", "&amp;commat;", "&amp;percnt;" and "&amp;num;"
1134 respectively or escape them with a backslash '\'.
1135 </para>
1136 </tip>
1138 <para>
1139 DocBook can do more than just links. One can also have lists,
1140 examples, headings, and images. As of version 1.20, the
1141 preferred way is to use a subset of the basic text formatting
1142 syntax called
1143 <ulink url="http://daringfireball.net/projects/markdown/">Markdown</ulink>.
1144 On older GTK-Doc versions any documentation that includes
1145 Markdown will be rendered as is. For example, list items will
1146 appear as lines starting with a dash.
1147 </para>
1149 <para>
1150 While markdown is now preferred one can mix both. One limitation here is
1151 that one can use docbook xml within markdown, but markdown within
1152 docbook xml is not supported.
1153 </para>
1155 <para>
1156 In older GTK-Doc releases, if you need support for additional
1157 formatting, you would need to enable the usage of docbook
1158 XML tags inside doc-comments by putting <option>--xml-mode</option>
1159 (or <option>--sgml-mode</option>) in the variable
1160 <symbol>MKDB_OPTIONS</symbol> inside <filename>Makefile.am</filename>.
1161 </para>
1163 <para>
1164 <example><title>GTK-Doc comment block using Markdown</title>
1165 <programlisting><![CDATA[
1167 * identifier:
1169 * documentation paragraph ...
1171 * # Sub Heading #
1173 * ## Second Sub Heading
1175 * # Sub Heading With a Link Anchor # {#heading-two}
1177 * more documentation:
1179 * - list item 1
1181 * Paragraph inside a list item.
1183 * - list item 2
1185 * 1. numbered list item
1187 * 2. another numbered list item
1189 * Another paragraph. [A Link to the GNOME Website](http://www.gnome.org/)
1191 * ![an inline image](plot-result.png)
1193 * [A link to the heading anchor above][heading-two]
1195 * A C-language example:
1196 * |[<!-- language="C" -->
1197 * GtkWidget *label = gtk_label_new ("Gorgeous!");
1198 * ]|
1200 ]]></programlisting>
1201 </example>
1202 </para>
1204 <para>
1205 More examples of what markdown tags are supported can be found in the
1206 <ulink url="https://wiki.gnome.org/Projects/GTK%2B/DocumentationSyntax/Markdown">GTK+ Documentation Markdown Syntax Reference</ulink>.
1207 </para>
1209 <tip>
1210 <para>
1211 As already mentioned earlier GTK-Doc is for documenting public API. Thus
1212 one cannot write documentation for static symbols. Nevertheless it is good
1213 to comment those symbols too. This helps other developers to understand
1214 your code.
1215 Therefore we recommend to comment these using normal comments (without the
1216 2nd '*' in the first line).
1217 If later the function needs to be made public, all one needs to do is to
1218 add another '*' in the comment block and insert the symbol name at the
1219 right place inside the sections file.
1220 </para>
1221 </tip>
1222 </sect1>
1224 <sect1 id="documenting_sections">
1225 <title>Documenting sections</title>
1227 <para>
1228 Each section of the documentation contains information about one class
1229 or module. To introduce the component one can write a section block.
1230 The short description is also used inside the table of contents.
1231 All the @fields are optional.
1232 </para>
1234 <para>
1235 <example><title>Section comment block</title>
1236 <programlisting><![CDATA[
1238 * SECTION:meepapp
1239 * @short_description: the application class
1240 * @title: Meep application
1241 * @section_id:
1242 * @see_also: #MeepSettings
1243 * @stability: Stable
1244 * @include: meep/app.h
1245 * @image: application.png
1247 * The application class handles ...
1249 ]]></programlisting>
1250 </example>
1251 </para>
1253 <variablelist>
1254 <varlistentry>
1255 <term>SECTION:&lt;name&gt;</term>
1256 <listitem>
1257 <para>
1258 The name links the section documentation to the respective part in
1259 the <filename>&lt;package&gt;-sections.txt</filename> file. The
1260 name given here should match the &lt;FILE&gt; tag in the
1261 <filename>&lt;package&gt;-sections.txt</filename> file.
1262 </para>
1263 </listitem>
1264 </varlistentry>
1265 <varlistentry>
1266 <term>@short_description</term>
1267 <listitem>
1268 <para>
1269 A one line description of the section, that later will appear after
1270 the links in the TOC and at the top of the section page.
1271 </para>
1272 </listitem>
1273 </varlistentry>
1274 <varlistentry>
1275 <term>@title</term>
1276 <listitem>
1277 <para>
1278 The section title defaults to &lt;name&gt; from the SECTION
1279 declaration. It can be overridden with the @title field.
1280 </para>
1281 </listitem>
1282 </varlistentry>
1283 <varlistentry>
1284 <term>@section_id</term>
1285 <listitem>
1286 <para>
1287 Overrides the use of title as a section identifier. For GObjects
1288 the &lt;title&gt; is used as a section_id and for other sections
1289 it is &lt;MODULE&gt;-&lt;title&gt;.
1290 </para>
1291 </listitem>
1292 </varlistentry>
1293 <varlistentry>
1294 <term>@see_also</term>
1295 <listitem>
1296 <para>
1297 A list of symbols that are related to this section.
1298 </para>
1299 </listitem>
1300 </varlistentry>
1301 <varlistentry>
1302 <term>@stability</term>
1303 <listitem>
1304 <para>
1305 An informal description of the stability level this API has.
1306 We recommend the use of one of these terms:
1307 <itemizedlist>
1308 <listitem>
1309 <para>
1310 Stable
1311 - The intention of a Stable interface is to enable arbitrary
1312 third parties to develop applications to these interfaces,
1313 release them, and have confidence that they will run on all
1314 minor releases of the product (after the one in which the
1315 interface was introduced, and within the same major release).
1316 Even at a major release, incompatible changes are expected
1317 to be rare, and to have strong justifications.
1318 </para>
1319 </listitem>
1320 <listitem>
1321 <para>
1322 Unstable
1323 - Unstable interfaces are experimental or transitional.
1324 They are typically used to give outside developers early
1325 access to new or rapidly changing technology, or to provide
1326 an interim solution to a problem where a more general
1327 solution is anticipated.
1328 No claims are made about either source or binary
1329 compatibility from one minor release to the next.
1330 </para>
1331 </listitem>
1332 <listitem>
1333 <para>
1334 Private
1335 - An interface that can be used within the GNOME stack
1336 itself, but that is not documented for end-users. Such
1337 functions should only be used in specified and documented
1338 ways.
1339 </para>
1340 </listitem>
1341 <listitem>
1342 <para>
1343 Internal
1344 - An interface that is internal to a module and does not
1345 require end-user documentation. Functions that are
1346 undocumented are assumed to be Internal.
1347 </para>
1348 </listitem>
1349 </itemizedlist>
1350 </para>
1351 </listitem>
1352 </varlistentry>
1353 <varlistentry>
1354 <term>@include</term>
1355 <listitem>
1356 <para>
1357 The <literal>#include</literal> files to show in the section
1358 synopsis (a comma separated list), overriding the global
1359 value from the <link linkend="metafiles_sections">section
1360 file</link> or command line. This item is optional.
1361 </para>
1362 </listitem>
1363 </varlistentry>
1364 <varlistentry>
1365 <term>@image</term>
1366 <listitem>
1367 <para>
1368 The image to display at the top of the reference page for this
1369 section. This will often be some sort of a diagram to illustrate
1370 the visual appearance of a class or a diagram of its relationship
1371 to other classes. This item is optional.
1372 </para>
1373 </listitem>
1374 </varlistentry>
1375 </variablelist>
1377 <tip>
1378 <para>
1379 To avoid unnecessary recompilation after doc-changes put the section
1380 docs into the c-source where possible.
1381 </para>
1382 </tip>
1384 </sect1>
1386 <sect1 id="documenting_symbols">
1387 <title>Documenting symbols</title>
1389 <para>
1390 Each symbol (function, macro, struct, enum, signal and property) is
1391 documented in a separate block. The block is best placed close to the
1392 definition of the symbols so that it is easy to keep them in sync.
1393 Thus functions are usually documented in the c-source and macros,
1394 structs and enums in the header file.
1395 </para>
1397 <sect2><title>General tags</title>
1399 <para>
1400 You can add versioning information to all documentation elements to tell
1401 when an API was introduced, or when it was deprecated.
1402 </para>
1404 <variablelist><title>Versioning Tags</title>
1405 <varlistentry><term>Since:</term>
1406 <listitem>
1407 <para>
1408 Description since which version of the code the API is available.
1409 </para>
1410 </listitem>
1411 </varlistentry>
1412 <varlistentry><term>Deprecated:</term>
1413 <listitem>
1414 <para>
1415 Paragraph denoting that this function should no be used anymore.
1416 The description should point the reader to the new API.
1417 </para>
1418 </listitem>
1419 </varlistentry>
1420 </variablelist>
1422 <para>
1423 You can also add stability information to all documentation elements
1424 to indicate whether API stability is guaranteed for them for all
1425 future minor releases of the project.
1426 </para>
1428 <para>
1429 The default stability level for all documentation elements can be set
1430 by passing the <option>--default-stability</option> argument to
1431 <application>gtkdoc-mkdb</application> with one of the values below.
1432 </para>
1434 <variablelist><title>Stability Tags</title>
1435 <varlistentry><term>Stability: Stable</term>
1436 <listitem>
1437 <para>
1438 Mark the element as stable. This is for public APIs which are
1439 guaranteed to remain stable for all future minor releases of the
1440 project.
1441 </para>
1442 </listitem>
1443 </varlistentry>
1444 <varlistentry><term>Stability: Unstable</term>
1445 <listitem>
1446 <para>
1447 Mark the element as unstable. This is for public APIs which are
1448 released as a preview before being stabilised.
1449 </para>
1450 </listitem>
1451 </varlistentry>
1452 <varlistentry><term>Stability: Private</term>
1453 <listitem>
1454 <para>
1455 Mark the element as private. This is for interfaces which can be
1456 used by tightly coupled modules, but not by arbitrary third
1457 parties.
1458 </para>
1459 </listitem>
1460 </varlistentry>
1461 </variablelist>
1463 <example><title>General tags</title>
1464 <programlisting><![CDATA[
1466 * foo_get_bar:
1467 * @foo: some foo
1469 * Retrieves @foo's bar.
1471 * Returns: @foo's bar
1473 * Since: 2.6
1474 * Deprecated: 2.12: Use foo_baz_get_bar() instead.
1476 Bar *
1477 foo_get_bar(Foo *foo)
1480 ]]></programlisting>
1481 </example>
1482 </sect2>
1484 <sect2><title>Annotations</title>
1486 <para>
1487 Documentation blocks can contain annotation-tags. These tags will be
1488 rendered with tooltips describing their meaning. The tags are used by
1489 gobject-introspection to generate language bindings. A detailed list
1490 of the supported tags can be found on
1491 <ulink url="http://live.gnome.org/GObjectIntrospection/Annotations" type="http">the wiki</ulink>.
1492 </para>
1494 <example><title>Annotations</title>
1495 <programlisting><![CDATA[
1497 * foo_get_bar: (annotation)
1498 * @foo: (annotation): some foo
1500 * Retrieves @foo's bar.
1502 * Returns: (annotation): @foo's bar
1506 * foo_set_bar_using_the_frobnicator: (annotation) (another annotation)
1507 * (and another annotation)
1508 * @foo: (annotation) (another annotation): some foo
1510 * Sets bar on @foo.
1512 ]]></programlisting>
1513 </example>
1514 </sect2>
1516 <sect2><title>Function comment block</title>
1518 <para>
1519 Please remember to:
1520 <itemizedlist>
1521 <listitem>
1522 <para>
1523 Document whether returned objects, lists, strings, etc, should be
1524 freed/unrefed/released.
1525 </para>
1526 </listitem>
1527 <listitem>
1528 <para>
1529 Document whether parameters can be NULL, and what happens if they are.
1530 </para>
1531 </listitem>
1532 <listitem>
1533 <para>
1534 Mention interesting pre-conditions and post-conditions where appropriate.
1535 </para>
1536 </listitem>
1537 </itemizedlist>
1538 </para>
1540 <para>
1541 Gtk-doc assumes all symbols (macros, functions) starting with '_' are
1542 private. They are treated like static functions.
1543 </para>
1545 <example><title>Function comment block</title>
1546 <programlisting><![CDATA[
1548 * function_name:
1549 * @par1: description of parameter 1. These can extend over more than
1550 * one line.
1551 * @par2: description of parameter 2
1552 * @...: a %NULL-terminated list of bars
1554 * The function description goes here. You can use @par1 to refer to parameters
1555 * so that they are highlighted in the output. You can also use %constant
1556 * for constants, function_name2() for functions and #GtkWidget for links to
1557 * other declarations (which may be documented elsewhere).
1559 * Returns: an integer.
1561 * Since: 2.2
1562 * Deprecated: 2.18: Use other_function() instead.
1564 ]]></programlisting>
1565 </example>
1567 <variablelist><title>Function tags</title>
1568 <varlistentry><term>Returns:</term>
1569 <listitem>
1570 <para>
1571 Paragraph describing the returned result.
1572 </para>
1573 </listitem>
1574 </varlistentry>
1575 <varlistentry><term>@...:</term>
1576 <listitem>
1577 <para>
1578 In case the function has variadic arguments, you should use this
1579 tag (@Varargs: does also work for historic reasons).
1580 </para>
1581 </listitem>
1582 </varlistentry>
1583 </variablelist>
1585 </sect2>
1587 <sect2><title>Property comment block</title>
1589 <example><title>Property comment block</title>
1590 <programlisting><![CDATA[
1592 * SomeWidget:some-property:
1594 * Here you can document a property.
1596 g_object_class_install_property (object_class, PROP_SOME_PROPERTY, ...);
1597 ]]></programlisting>
1598 </example>
1600 </sect2>
1602 <sect2><title>Signal comment block</title>
1604 <para>
1605 Please remember to:
1606 <itemizedlist>
1607 <listitem>
1608 <para>
1609 Document when the signal is emitted and whether it is emitted before
1610 or after other signals.
1611 </para>
1612 </listitem>
1613 <listitem>
1614 <para>
1615 Document what an application might do in the signal handler.
1616 </para>
1617 </listitem>
1618 </itemizedlist>
1619 </para>
1621 <example><title>Signal comment block</title>
1622 <programlisting><![CDATA[
1624 * FooWidget::foobarized:
1625 * @widget: the widget that received the signal
1626 * @foo: some foo
1627 * @bar: some bar
1629 * The ::foobarized signal is emitted each time someone tries to foobarize @widget.
1631 foo_signals[FOOBARIZED] =
1632 g_signal_new ("foobarized",
1634 ]]></programlisting>
1635 </example>
1637 </sect2>
1639 <sect2><title>Struct comment block</title>
1640 <example><title>Struct comment block</title>
1641 <programlisting><![CDATA[
1643 * FooWidget:
1644 * @bar: some #gboolean
1646 * This is the best widget, ever.
1648 typedef struct _FooWidget {
1649 GtkWidget parent_instance;
1651 gboolean bar;
1652 } FooWidget;
1653 ]]></programlisting>
1654 </example>
1656 <para>
1657 Use <code>/*&lt; private &gt;*/</code> before the private struct fields
1658 you want to hide. Use <code>/*&lt; public &gt;*/</code> for the reverse
1659 behaviour.
1660 </para>
1662 <para>
1663 If the first field is "g_iface", "parent_instance" or "parent_class"
1664 it will be considered private automatically and doesn't need to be
1665 mentioned in the comment block.
1666 </para>
1668 <para>
1669 Struct comment blocks can also be used for GObjects and GObjectClasses.
1670 It is usually a good idea to add a comment block for a class, if it has
1671 vmethods (as this is how they can be documented). For the GObject
1672 itself one can use the related section docs, having a separate block
1673 for the instance struct would be useful if the instance has public
1674 fields. One disadvantage here is that this creates two index entries
1675 of the same name (the structure and the section).
1676 </para>
1678 </sect2>
1680 <sect2><title>Enum comment block</title>
1681 <example><title>Enum comment block</title>
1682 <programlisting><![CDATA[
1684 * Something:
1685 * @SOMETHING_FOO: something foo
1686 * @SOMETHING_BAR: something bar
1688 * Enum values used for the thing, to specify the thing.
1690 typedef enum {
1691 SOMETHING_FOO,
1692 SOMETHING_BAR,
1693 /*< private >*/
1694 SOMETHING_COUNT
1695 } Something;
1696 ]]></programlisting>
1697 </example>
1699 <para>
1700 Use <code>/*&lt; private &gt;*/</code> before the private enum values
1701 you want to hide. Use <code>/*&lt; public &gt;*/</code> for the reverse
1702 behaviour.
1703 </para>
1705 </sect2>
1706 </sect1>
1709 <sect1 id="documenting_inline_program">
1710 <title>Inline program documentation</title>
1711 <para>
1712 You can document programs and their commandline interface using inline
1713 documentation.
1714 </para>
1716 <variablelist>
1717 <title>Tags</title>
1719 <varlistentry><term>PROGRAM</term>
1721 <listitem>
1722 <para>
1723 Defines the start of a program documentation.
1724 </para>
1725 </listitem>
1726 </varlistentry>
1728 <varlistentry>
1729 <term>@short_description:</term>
1730 <listitem>
1731 <para>
1732 Defines a short description of the program. (Optional)
1733 </para>
1734 </listitem>
1735 </varlistentry>
1737 <varlistentry>
1738 <term>@synopsis:</term>
1739 <listitem>
1740 <para>
1741 Defines the arguments, or list of arguments that the program can take.
1742 (Optional)
1743 </para>
1744 </listitem>
1745 </varlistentry>
1747 <varlistentry>
1748 <term>@see_also:</term>
1749 <listitem>
1750 <para>
1751 See Also manual page section. (Optional)
1752 </para>
1753 </listitem>
1754 </varlistentry>
1756 <varlistentry>
1757 <term>@arg:</term>
1758 <listitem>
1759 <para>
1760 Argument(s) passed to the program and their description. (Optional)
1761 </para>
1762 </listitem>
1763 </varlistentry>
1765 <varlistentry>
1766 <term>Description:</term>
1767 <listitem>
1768 <para>
1769 A longer description of the program.
1770 </para>
1771 </listitem>
1772 </varlistentry>
1774 <varlistentry>
1775 <term>Returns:</term>
1776 <listitem>
1777 <para>
1778 Specificy what value(s) the program returns. (Optional)
1779 </para>
1780 </listitem>
1781 </varlistentry>
1783 </variablelist>
1785 <sect2>
1786 <title>Example of program documentation.</title>
1787 <example><title>Program documentation block</title>
1788 <programlisting><![CDATA[
1790 * PROGRAM:test-program
1791 * @short_description: A test program
1792 * @synopsis: test-program [*OPTIONS*...] --arg1 *arg* *FILE*
1793 * @see_also: test(1)
1794 * @--arg1 *arg*: set arg1 to *arg*
1795 * @--arg2 *arg*: set arg2 to *arg*
1796 * @-v, --version: Print the version number
1797 * @-h, --help: Print the help message
1799 * Long description of program.
1801 * Returns: Zero on success, non-zero on failure
1803 int main(int argc, char *argv[])
1805 return 0;
1807 ]]></programlisting>
1808 </example>
1810 </sect2>
1811 </sect1>
1813 <sect1 id="documenting_docbook">
1814 <title>Useful DocBook tags</title>
1816 <para>
1817 Here are some DocBook tags which are most useful when documenting the
1818 code.
1819 </para>
1821 <para>
1822 To link to another section in the GTK docs:
1824 <informalexample>
1825 <programlisting><![CDATA[
1826 <link linkend="glib-Hash-Tables">Hash Tables</link>
1827 ]]></programlisting>
1828 </informalexample>
1829 The linkend is the SGML/XML id on the top item of the page you want to link to.
1830 For most pages this is currently the part ("gtk", "gdk", "glib") and then
1831 the page title ("Hash Tables"). For widgets it is just the class name.
1832 Spaces and underscores are converted to '-' to conform to SGML/XML.
1833 </para>
1835 <para>
1836 To refer to an external function, e.g. a standard C function:
1837 <informalexample>
1838 <programlisting><![CDATA[
1839 <function>...</function>
1840 ]]></programlisting>
1841 </informalexample>
1842 </para>
1844 <para>
1845 To include example code:
1846 <informalexample>
1847 <programlisting><![CDATA[
1848 <example>
1849 <title>Using a GHashTable.</title>
1850 <programlisting>
1852 </programlisting>
1853 </example>
1854 ]]></programlisting>
1855 </informalexample>
1856 or possibly this, for very short code fragments which don't need a title:
1857 <informalexample>
1858 <programlisting><![CDATA[
1859 <informalexample>
1860 <programlisting>
1862 </programlisting>
1863 </informalexample>
1864 ]]></programlisting>
1865 </informalexample>
1866 For the latter GTK-Doc also supports an abbreviation:
1867 <![CDATA[
1872 </para>
1874 <para>
1875 To include bulleted lists:
1876 <informalexample>
1877 <programlisting><![CDATA[
1878 <itemizedlist>
1879 <listitem>
1880 <para>
1882 </para>
1883 </listitem>
1884 <listitem>
1885 <para>
1887 </para>
1888 </listitem>
1889 </itemizedlist>
1890 ]]></programlisting>
1891 </informalexample>
1892 </para>
1894 <para>
1895 To include a note which stands out from the text:
1896 <informalexample>
1897 <programlisting><![CDATA[
1898 <note>
1899 <para>
1900 Make sure you free the data after use.
1901 </para>
1902 </note>
1903 ]]></programlisting>
1904 </informalexample>
1905 </para>
1907 <para>
1908 To refer to a type:
1909 <informalexample>
1910 <programlisting><![CDATA[
1911 <type>unsigned char</type>
1912 ]]></programlisting>
1913 </informalexample>
1914 </para>
1916 <para>
1917 To refer to an external structure (not one described in the GTK docs):
1918 <informalexample>
1919 <programlisting><![CDATA[
1920 <structname>XFontStruct</structname>
1921 ]]></programlisting>
1922 </informalexample>
1923 </para>
1925 <para>
1926 To refer to a field of a structure:
1927 <informalexample>
1928 <programlisting><![CDATA[
1929 <structfield>len</structfield>
1930 ]]></programlisting>
1931 </informalexample>
1932 </para>
1934 <para>
1935 To refer to a class name, we could possibly use:
1936 <informalexample>
1937 <programlisting><![CDATA[
1938 <classname>GtkWidget</classname>
1939 ]]></programlisting>
1940 </informalexample>
1941 but you'll probably be using #GtkWidget instead (to automatically create
1942 a link to the GtkWidget page - see <link linkend="documenting_syntax">the abbreviations</link>).
1943 </para>
1945 <para>
1946 To emphasize text:
1947 <informalexample>
1948 <programlisting><![CDATA[
1949 <emphasis>This is important</emphasis>
1950 ]]></programlisting>
1951 </informalexample>
1952 </para>
1954 <para>
1955 For filenames use:
1956 <informalexample>
1957 <programlisting><![CDATA[
1958 <filename>/home/user/documents</filename>
1959 ]]></programlisting>
1960 </informalexample>
1961 </para>
1963 <para>
1964 To refer to keys use:
1965 <informalexample>
1966 <programlisting><![CDATA[
1967 <keycombo><keycap>Control</keycap><keycap>L</keycap></keycombo>
1968 ]]></programlisting>
1969 </informalexample>
1970 </para>
1972 </sect1>
1973 </chapter>
1975 <chapter id="metafiles">
1976 <title>Filling the extra files</title>
1978 <para>
1979 There are a couple of extra files, that need to be maintained along with
1980 the inline source code comments:
1981 <filename>&lt;package&gt;.types</filename>,
1982 <filename>&lt;package&gt;-docs.xml</filename> (in the past .sgml),
1983 <filename>&lt;package&gt;-sections.txt</filename>.
1984 </para>
1986 <sect1 id="metafiles_types">
1987 <title>Editing the types file</title>
1989 <para>
1990 If your library or application includes GObjects, you want
1991 their signals, arguments/parameters and position in the hierarchy to be
1992 shown in the documentation. All you need to do, is to list the
1993 <function>xxx_get_type</function> functions together with their include
1994 inside the <filename>&lt;package&gt;.types</filename> file.
1995 </para>
1997 <para>
1998 <example><title>Example &lt;package&gt;.types file</title>
1999 <programlisting><![CDATA[
2000 #include <gtk/gtk.h>
2002 gtk_accel_label_get_type
2003 gtk_adjustment_get_type
2004 gtk_alignment_get_type
2005 gtk_arrow_get_type
2006 ]]></programlisting>
2007 </example>
2008 </para>
2010 <para>
2011 Since GTK-Doc 1.8 <application>gtkdoc-scan</application> can generate this list for you.
2012 Just add "--rebuild-types" to SCAN_OPTIONS in <filename>Makefile.am</filename>. If you
2013 use this approach you should not dist the types file nor have it under version control.
2014 </para>
2016 </sect1>
2018 <sect1 id="metafiles_master">
2019 <title>Editing the master document</title>
2021 <para>
2022 GTK-Doc produces documentation in DocBook SGML/XML. When processing the
2023 inline source comments, the GTK-Doc tools generate one documentation
2024 page per class or module as a separate file. The master document
2025 includes them and place them in an order.
2026 </para>
2028 <para>
2029 While GTK-Doc creates a template master document for you, later runs will
2030 not touch it again. This means that one can freely structure the
2031 documentation. That includes grouping pages and adding extra pages.
2032 GTK-Doc has now a test suite, where also the master-document is recreated from scratch.
2033 Its a good idea to look at this from time to time to see if there are
2034 some new goodies introduced there.
2035 </para>
2037 <tip>
2038 <para>
2039 Do not create tutorials as extra documents. Just write extra chapters.
2040 The benefit of directly embedding the tutorial for your library into
2041 the API documentation is that it is easy to link for the tutorial to
2042 symbol documentation. Apart chances are higher that the tutorial gets
2043 updates along with the library.
2044 </para>
2045 </tip>
2047 <para>
2048 So what are the things to change inside the master document? For a start
2049 is only a little. There are some placeholders (text in square brackets)
2050 there which you should take care of.
2051 </para>
2053 <para>
2054 <example><title>Master document header</title>
2055 <programlisting><![CDATA[
2056 <bookinfo>
2057 <title>MODULENAME Reference Manual</title>
2058 <releaseinfo>
2059 for MODULENAME [VERSION]
2060 The latest version of this documentation can be found on-line at
2061 <ulink role="online-location" url="http://[SERVER]/MODULENAME/index.html">http://[SERVER]/MODULENAME/</ulink>.
2062 </releaseinfo>
2063 </bookinfo>
2065 <chapter>
2066 <title>[Insert title here]</title>
2067 ]]></programlisting>
2068 </example>
2069 </para>
2071 <para>
2072 In addition a few option elements are created in commented form. You can
2073 review these and enable them as you like.
2074 </para>
2076 <para>
2077 <example><title>Optional part in the master document</title>
2078 <programlisting><![CDATA[
2079 <!-- enable this when you use gobject introspection annotations
2080 <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
2082 ]]></programlisting>
2083 </example>
2084 </para>
2086 <para>
2087 Finally you need to add new section whenever you introduce one. The
2088 <link linkend="modernizing-gtk-doc-1-16">gtkdoc-check</link> tool will
2089 remind you of newly generated xml files that are not yet included into
2090 the doc.
2091 </para>
2093 <para>
2094 <example><title>Including generated sections</title>
2095 <programlisting><![CDATA[
2096 <chapter>
2097 <title>my library</title>
2098 <xi:include href="xml/object.xml"/>
2100 ]]></programlisting>
2101 </example>
2102 </para>
2104 </sect1>
2106 <sect1 id="metafiles_sections">
2107 <title>Editing the section file</title>
2109 <para>
2110 The section file is used to organise the documentation output by
2111 GTK-Doc. Here one specifies which symbol belongs to which module or
2112 class and control the visibility (public or private).
2113 </para>
2115 <para>
2116 The section file is a plain text file with tags delimiting sections.
2117 Blank lines are ignored and lines starting with a '#' are treated as
2118 comment lines.
2119 </para>
2121 <note>
2122 <para>
2123 While the tags make the file look like xml, it is not. Please do not
2124 close tags like &lt;SUBSECTION&gt;.
2125 </para>
2126 </note>
2128 <para>
2129 <example><title>Including generated sections</title>
2130 <programlisting><![CDATA[
2131 <INCLUDE>libmeep/meep.h</INCLUDE>
2133 <SECTION>
2134 <FILE>meepapp</FILE>
2135 <TITLE>MeepApp</TITLE>
2136 MeepApp
2137 <SUBSECTION Standard>
2138 MEEP_APP
2140 MeepAppClass
2141 meep_app_get_type
2142 </SECTION>
2143 ]]></programlisting>
2144 </example>
2145 </para>
2147 <para>
2148 The &lt;FILE&gt; ... &lt;/FILE&gt; tag is used to specify the file name,
2149 without any suffix. For example, using '&lt;FILE&gt;gnome-config&lt;/FILE&gt;'
2150 will result in the section declarations being output in the template
2151 file <filename>tmpl/gnome-config.sgml</filename>, which will be
2152 converted into the DocBook XML file <filename>xml/gnome-config.sgml</filename>
2153 or the DocBook XML file <filename>xml/gnome-config.xml</filename>.
2154 (The name of the HTML file is based on the module name and the section
2155 title, or for GObjects it is based on the GObjects class name converted
2156 to lower case).
2157 </para>
2159 <para>
2160 The &lt;TITLE&gt; ... &lt;/TITLE&gt; tag is used to specify the title of
2161 the section. It is only useful before the templates (if used) are
2162 initially created, since the title set in the template file overrides
2163 this. Also if one uses SECTION comment in the sources, this is obsolete.
2164 </para>
2166 <para>
2167 You can group items in the section by using the &lt;SUBSECTION&gt; tag.
2168 Currently it outputs a blank line between subsections in the synopsis
2169 section.
2170 You can also use &lt;SUBSECTION Standard&gt; for standard GObject
2171 declarations (e.g. the functions like g_object_get_type and macros like
2172 G_OBJECT(), G_IS_OBJECT() etc.).
2173 Currently these are left out of the documentation.
2174 You can also use &lt;SUBSECTION Private&gt; for private declarations
2175 which will not be output (it is a handy way to avoid warning messages
2176 about unused declarations).
2177 If your library contains private types which you don't want to appear in
2178 the object hierarchy and the list of implemented or required interfaces,
2179 add them to a Private subsection.
2180 Whether you would place GObject and GObjectClass like structs in public
2181 or Standard section depends if they have public entries (variables,
2182 vmethods).
2183 </para>
2185 <para>
2186 You can also use &lt;INCLUDE&gt; ... &lt;/INCLUDE&gt; to specify the
2187 #include files which are shown in the synopsis sections.
2188 It contains a comma-separate list of #include files, without the angle
2189 brackets. If you set it outside of any sections, it acts for all
2190 sections until the end of the file. If you set it within a section, it
2191 only applies to that section.
2192 </para>
2194 </sect1>
2196 </chapter>
2198 <chapter id="reports">
2199 <title>Controlling the result</title>
2201 <para>
2202 A GTK-Doc run generates report files inside the documentation directory.
2203 The generated files are named:
2204 <filename>&lt;package&gt;-undocumented.txt</filename>,
2205 <filename>&lt;package&gt;-undeclared.txt</filename> and
2206 <filename>&lt;package&gt;-unused.txt</filename>.
2207 All those are plain text files that can be viewed and postprocessed easily.
2208 </para>
2210 <para>
2211 The <filename>&lt;package&gt;-undocumented.txt</filename> file starts with
2212 the documentation coverage summary. Below are two sections divided by
2213 blank lines. The first section lists undocumented or incomplete symbols.
2214 The second section does the same for section docs. Incomplete entries are
2215 those, which have documentation, but where e.g. a new parameter has been
2216 added.
2217 </para>
2219 <para>
2220 The <filename>&lt;package&gt;-undeclared.txt</filename> file lists symbols
2221 given in the <filename>&lt;package&gt;-sections.txt</filename> but not
2222 found in the sources. Check if they have been removed or if they are
2223 misspelled.
2224 </para>
2226 <para>
2227 The <filename>&lt;package&gt;-unused.txt</filename> file lists symbol
2228 names, where the GTK-Doc scanner has found documentation, but does not
2229 know where to put it. This means that the symbol has not yet been added to
2230 the <filename>&lt;package&gt;-sections.txt</filename> file.
2231 </para>
2233 <tip>
2234 <para>
2235 Enable or add the <option>TESTS=$(GTKDOC_CHECK)</option> line in Makefile.am.
2236 If at least GTK-Doc 1.9 is installed, this will run sanity checks during
2237 <command>make check</command> run.
2238 </para>
2239 </tip>
2241 <para>
2242 One can also look at the files produced by the source code scanner:
2243 <filename>&lt;package&gt;-decl-list.txt</filename> and
2244 <filename>&lt;package&gt;-decl.txt</filename>. The first one can be
2245 compared with the section file if that is manually maintained. The second
2246 lists all declarations from the headers. If a symbol is missing one could
2247 check if this file contains it.
2248 </para>
2250 <para>
2251 If the project is GObject based, one can also look into the files produced
2252 by the object scanner:
2253 <filename>&lt;package&gt;.args.txt</filename>,
2254 <filename>&lt;package&gt;.hierarchy.txt</filename>,
2255 <filename>&lt;package&gt;.interfaces.txt</filename>,
2256 <filename>&lt;package&gt;.prerequisites.txt</filename> and
2257 <filename>&lt;package&gt;.signals.txt</filename>. If there are missing
2258 symbols in any of those, one can ask GTK-Doc to keep the intermediate
2259 scanner file for further analysis, by running it as
2260 <command>GTK_DOC_KEEP_INTERMEDIATE=1 make</command>.
2261 </para>
2262 </chapter>
2264 <chapter id="modernizing">
2265 <title>Modernizing the documentation</title>
2267 <para>
2268 GTK-Doc has been around for quite some time. In this section we list new
2269 features together with the version since when it is available.
2270 </para>
2272 <sect1 id="modernizing-gtk-doc-1-9">
2273 <title>GTK-Doc 1.9</title>
2275 <para>
2276 When using xml instead of sgml, one can actually name the master
2277 document <filename>&lt;package&gt;-docs.xml</filename>.
2278 </para>
2280 <para>
2281 This version supports <option>SCAN_OPTIONS=--rebuild-sections</option>
2282 in <filename>Makefile.am</filename>. When this is enabled, the
2283 <filename>&lt;package&gt;-sections.txt</filename> is autogenerated and
2284 can be removed from the vcs. This only works nicely for projects that
2285 have a very regular structure (e.g. each .{c,h} pair will create new
2286 section). If one organize a project close to that updating a manually
2287 maintained section file can be as simple as running
2288 <code>meld &lt;package&gt;-decl-list.txt &lt;package&gt;-sections.txt</code>.
2289 </para>
2291 <para>
2292 Version 1.8 already introduced the syntax for documenting sections in
2293 the sources instead of the separate files under <filename class='directory'>tmpl</filename>.
2294 This version adds options to switch the whole doc module to not use the
2295 extra tmpl build step at all, by using <option>--flavour no-tmpl</option>
2296 in <filename>configure.ac</filename>. If you don't have a <filename class='directory'>tmpl</filename>
2297 checked into your source control system and haven't yet switched, just
2298 add the flag to <filename>configure.ac</filename> and you are done.
2299 </para>
2300 </sect1>
2302 <sect1 id="modernizing-gtk-doc-1-10">
2303 <title>GTK-Doc 1.10</title>
2305 <para>
2306 This version supports <option>SCAN_OPTIONS=--rebuild-types</option> in
2307 <filename>Makefile.am</filename>. When this is enabled, the
2308 <filename>&lt;package&gt;.types</filename> is autogenerated and can be
2309 removed from the vcs. When using this feature it is important to also
2310 setup the <varname>IGNORE_HFILES</varname> in
2311 <filename>Makefile.am</filename> for code that is build conditionally.
2312 </para>
2313 </sect1>
2315 <sect1 id="modernizing-gtk-doc-1-16">
2316 <title>GTK-Doc 1.16</title>
2318 <para>
2319 This version includes a new tool called gtkdoc-check. This tool can run
2320 a set of sanity checks on your documentation. It is enabled by adding
2321 these lines to the end of <filename>Makefile.am</filename>.
2322 <example><title>Enable gtkdoc-check</title>
2323 <programlisting><![CDATA[
2324 if ENABLE_GTK_DOC
2325 TESTS_ENVIRONMENT = \
2326 DOC_MODULE=$(DOC_MODULE) DOC_MAIN_SGML_FILE=$(DOC_MAIN_SGML_FILE) \
2327 SRCDIR=$(abs_srcdir) BUILDDIR=$(abs_builddir)
2328 TESTS = $(GTKDOC_CHECK)
2329 endif
2330 ]]></programlisting>
2331 </example>
2332 </para>
2333 </sect1>
2335 <sect1 id="modernizing-gtk-doc-1-20">
2336 <title>GTK-Doc 1.20</title>
2338 <para>
2339 Version 1.18 brought some initial markdown support. Using markdown in
2340 doc comments is less intrusive than writing docbook xml. This version
2341 improves a lot on this and add a lot more styles. The section that
2342 explains the <link linkend="documenting_syntax">comment syntax</link>
2343 has all the details.
2344 </para>
2345 </sect1>
2347 <sect1 id="modernizing-gtk-doc-1-25">
2348 <title>GTK-Doc 1.25</title>
2350 <para>
2351 The makefiles shipped with this version generate an entity file at <filename>xml/gtkdocentities.ent</filename>,
2352 containing entities for e.g. package_name and package_version. You can
2353 use this e.g. in the main xml file to avoid hardcoding the version
2354 number. Below is an example that shows how the entity file is included
2355 in the master template and how the entities are used.
2356 The entities can also be used in all
2357 generated files, GTK-Doc will use the same xml header in generated xml
2358 files.
2359 <example><title>Use pre-generated entities</title>
2360 <programlisting><![CDATA[
2361 <?xml version="1.0"?>
2362 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
2363 "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
2365 <!ENTITY % local.common.attrib "xmlns:xi CDATA #FIXED 'http://www.w3.org/2003/XInclude'">
2366 <!ENTITY % gtkdocentities SYSTEM "xml/gtkdocentities.ent">
2367 %gtkdocentities;
2369 <book id="index" xmlns:xi="http://www.w3.org/2003/XInclude">
2370 <bookinfo>
2371 <title>&package_name; Reference Manual</title>
2372 <releaseinfo>
2373 for &package_string;.
2374 The latest version of this documentation can be found on-line at
2375 <ulink role="online-location" url="http://[SERVER]/&package_name;/index.html">http://[SERVER]/&package_name;/</ulink>.
2376 </releaseinfo>
2377 </bookinfo>
2378 ]]></programlisting>
2379 </example>
2380 </para>
2381 </sect1>
2382 </chapter>
2384 <chapter id="documenting-others">
2385 <title>Documenting other interfaces</title>
2387 <para>
2388 So far we have been using GTK-Doc to document the API of code. The next
2389 sections contain suggestions how the tools can be used to document other
2390 interfaces too.
2391 </para>
2393 <sect1 id="commandline-interfaces">
2394 <title>Command line options and man pages</title>
2396 <para>
2397 As one can generate man pages for a docbook refentry as well, it sounds
2398 like a good idea to use it for that purpose. This way the interface is
2399 part of the reference and one gets the man-page for free.
2400 </para>
2402 <sect2 id="commandline-interfaces-file">
2403 <title>Document the tool</title>
2405 <para>
2406 Create one refentry file per tool. Following
2407 <link linkend="settingup_docfiles">our example</link> we would call it
2408 <filename>meep/docs/reference/meeper/meep.xml</filename>. For the xml
2409 tags that should be used and can look at generated file in the xml
2410 subdirectory as well as examples e.g. in glib.
2411 </para>
2412 </sect2>
2414 <sect2 id="commandline-interfaces-configure">
2415 <title>Adding the extra configure check</title>
2417 <para>
2418 <example><title>Extra configure checks</title>
2419 <programlisting><![CDATA[
2420 AC_ARG_ENABLE(man,
2421 [AC_HELP_STRING([--enable-man],
2422 [regenerate man pages from Docbook [default=no]])],enable_man=yes,
2423 enable_man=no)
2425 AC_PATH_PROG([XSLTPROC], [xsltproc])
2426 AM_CONDITIONAL(ENABLE_MAN, test x$enable_man != xno)
2427 ]]></programlisting>
2428 </example>
2429 </para>
2430 </sect2>
2432 <sect2 id="commandline-interfaces-make">
2433 <title>Adding the extra makefile rules</title>
2435 <para>
2436 <example><title>Extra configure checks</title>
2437 <programlisting><![CDATA[
2438 man_MANS = \
2439 meeper.1
2441 if ENABLE_GTK_DOC
2442 if ENABLE_MAN
2444 %.1 : %.xml
2445 @XSLTPROC@ -nonet http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl $<
2447 endif
2448 endif
2450 BUILT_EXTRA_DIST = $(man_MANS)
2451 EXTRA_DIST += meep.xml
2452 ]]></programlisting>
2453 </example>
2454 </para>
2455 </sect2>
2456 </sect1>
2458 <sect1 id="dbus-interfaces">
2459 <title>DBus interfaces</title>
2461 <para>
2462 (FIXME: http://hal.freedesktop.org/docs/DeviceKit/DeviceKit.html,
2463 http://cgit.freedesktop.org/DeviceKit/DeviceKit/tree/doc/dbus)
2464 </para>
2465 </sect1>
2467 </chapter>
2469 <chapter id="faq">
2470 <title>Frequently asked questions</title>
2472 <segmentedlist>
2473 <?dbhtml list-presentation="list"?>
2474 <segtitle>Question</segtitle>
2475 <segtitle>Answer</segtitle>
2476 <seglistitem>
2477 <seg>No class hierarchy.</seg>
2478 <seg>
2479 The objects <function>xxx_get_type()</function> function has not been
2480 entered into the <filename>&lt;package&gt;.types</filename> file.
2481 </seg>
2482 </seglistitem>
2483 <seglistitem>
2484 <seg>Still no class hierarchy.</seg>
2485 <seg>
2486 Missing or wrong naming in <filename>&lt;package&gt;-sections.txt</filename>
2487 file (see <ulink url="http://mail.gnome.org/archives/gtk-doc-list/2003-October/msg00006.html">explanation</ulink>).
2488 </seg>
2489 </seglistitem>
2490 <seglistitem>
2491 <seg>Damn, I have still no class hierarchy.</seg>
2492 <seg>
2493 Is the object name (name of the instance struct, e.g. <type>GtkWidget</type>)
2494 part of the normal section (don't put this into Standard or Private
2495 subsections).
2496 </seg>
2497 </seglistitem>
2498 <seglistitem>
2499 <seg>No symbol index.</seg>
2500 <seg>
2501 Does the <filename>&lt;package&gt;-docs.{xml,sgml}</filename> contain a
2502 index that xi:includes the generated index?
2503 </seg>
2504 </seglistitem>
2505 <seglistitem>
2506 <seg>Symbols are not linked to their doc-section.</seg>
2507 <seg>
2508 Is the doc-comment using the correct markup (added #,% or ())?
2509 Check if the gtkdoc-fixxref warns about unresolvable xrefs.
2510 </seg>
2511 </seglistitem>
2512 <seglistitem>
2513 <seg>A new class does not appear in the docs.</seg>
2514 <seg>
2515 Is the new page xi:included from
2516 <filename>&lt;package&gt;-docs.{xml,sgml}</filename>.
2517 </seg>
2518 </seglistitem>
2519 <seglistitem>
2520 <seg>A new symbol does not appear in the docs.</seg>
2521 <seg>
2522 Is the doc-comment properly formatted. Check for spelling mistakes in
2523 the begin of the comment. Check if the gtkdoc-fixxref warns about
2524 unresolvable xrefs. Check if the symbol is correctly listed in the
2525 <filename>&lt;package&gt;-sections.txt</filename> in a public subsection.
2526 </seg>
2527 </seglistitem>
2528 <seglistitem>
2529 <seg>A type is missing from the class hierarchy.</seg>
2530 <seg>
2531 If the type is listed in <filename>&lt;package&gt;.hierarchy</filename>
2532 but not in <filename>xml/tree_index.sgml</filename> then double check
2533 that the type is correctly placed in the <filename>&lt;package&gt;-sections.txt</filename>.
2534 If the type instance (e.g. <type>GtkWidget</type>) is not listed or
2535 incidentally marked private it will not be shown.
2536 </seg>
2537 </seglistitem>
2538 <seglistitem>
2539 <seg>I get foldoc links for all gobject annotations.</seg>
2540 <seg>
2541 Check that <filename>xml/annotation-glossary.xml</filename> is
2542 xi:included from <filename>&lt;package&gt;-docs.{xml,sgml}</filename>.
2543 </seg>
2544 </seglistitem>
2546 <!-- gtk-doc warnings: -->
2547 <seglistitem>
2548 <seg>Parameter described in source code comment block but does not exist</seg>
2549 <seg>Check if the prototype in the header has different parameter names as in the source.</seg>
2550 </seglistitem>
2552 <!-- docbook warnings: -->
2553 <seglistitem>
2554 <seg>multiple "IDs" for constraint linkend: XYZ</seg>
2555 <seg>Symbol XYZ appears twice in <filename>&lt;package&gt;-sections.txt</filename> file.</seg>
2556 </seglistitem>
2557 <seglistitem>
2558 <seg>Element typename in namespace '' encountered in para, but no template matches.</seg>
2559 <seg />
2560 </seglistitem>
2561 </segmentedlist>
2562 </chapter>
2564 <chapter id="contrib">
2565 <title>Tools related to gtk-doc</title>
2567 <para>
2568 GtkDocPlugin - a <ulink url="http://trac-hacks.org/wiki/GtkDocPlugin">Trac GTK-Doc</ulink>
2569 integration plugin, that adds API docs to a trac site and integrates with
2570 the trac search.
2571 </para>
2572 <para>
2573 Gtkdoc-depscan - a tool (part of gtk-doc) to check used API against since
2574 tags in the API to determine the minimum required version.
2575 </para>
2577 </chapter>
2579 <!-- ======== Appendix: FDL ================================== -->
2580 &FDL;
2582 </book>