Fixed typo in string
[gtk-doc.git] / help / manual / C / index.docbook
blobead063d2aa14e270afbf78926c4370fee525f983
1 <?xml version="1.0" standalone="no"?>
2 <?xml-stylesheet type="text/xml" href="params.xsl"?>
3 <!-- vim: set ai tw=80 ts=3 sw=3: -->
4 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN" "
5 http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
7 <!ENTITY FDL SYSTEM "fdl-appendix.xml">
8 <!ENTITY FDLlink "<link linkend='fdl'>included</link>">
9 ]><!-- =============Document Header ============================= -->
10 <book id="index">
11 <bookinfo>
12 <title>GTK-Doc Manual</title>
13 <edition>1.18.1</edition>
14 <abstract role="description"><para>User manual for developers with instructions of GTK-Doc usage.</para></abstract>
15 <authorgroup>
16 <author>
17 <firstname>Chris</firstname>
18 <surname>Lyttle</surname>
19 <affiliation>
20 <address>
21 <email>chris@wilddev.net</email>
22 </address>
23 </affiliation>
24 </author>
25 <author>
26 <firstname>Dan</firstname>
27 <surname>Mueth</surname>
28 <affiliation>
29 <address>
30 <email>d-mueth@uchicago.edu</email>
31 </address>
32 </affiliation>
33 </author>
34 <author>
35 <firstname>Stefan</firstname>
36 <surname>Kost</surname>
37 <affiliation>
38 <address>
39 <email>ensonic@users.sf.net</email>
40 </address>
41 </affiliation>
42 </author>
43 </authorgroup>
44 <publisher role="maintainer">
45 <publishername>GTK-Doc project</publishername>
46 <address><email>gtk-doc-list@gnome.org</email></address>
47 </publisher>
48 <copyright>
49 <year>2000, 2005</year>
50 <holder>Dan Mueth and Chris Lyttle</holder>
51 </copyright>
52 <copyright>
53 <year>2007-2011</year>
54 <holder>Stefan Sauer (Kost)</holder>
55 </copyright>
57 <!-- translators: uncomment this:
58 <copyright>
59 <year>2000</year>
60 <holder>ME-THE-TRANSLATOR (Latin translation)</holder>
61 </copyright>
62 -->
64 <legalnotice>
65 <para>
66 Permission is granted to copy, distribute and/or modify this
67 document under the terms of the <citetitle>GNU Free Documentation
68 License</citetitle>, Version 1.1 or any later version published
69 by the Free Software Foundation with no Invariant Sections, no
70 Front-Cover Texts, and no Back-Cover Texts. A copy of the license
71 is &FDLlink;.
72 </para>
73 <para>
74 Many of the names used by companies to distinguish their products and
75 services are claimed as trademarks. Where those names appear in any
76 GNOME documentation, and those trademarks are made aware to the members
77 of the GNOME Documentation Project, the names have been printed in caps
78 or initial caps.
79 </para>
80 </legalnotice>
82 <revhistory>
83 <revision>
84 <revnumber>1.19.1</revnumber>
85 <date>05 Jun 2013</date>
86 <authorinitials>ss</authorinitials>
87 <revremark>development version</revremark>
88 </revision>
89 <revision>
90 <revnumber>1.19</revnumber>
91 <date>05 Jun 2013</date>
92 <authorinitials>ss</authorinitials>
93 <revremark>bug fixes</revremark>
94 </revision>
95 <revision>
96 <revnumber>1.18</revnumber>
97 <date>14 Sep 2011</date>
98 <authorinitials>ss</authorinitials>
99 <revremark>bug fixes, speedups, markdown support</revremark>
100 </revision>
101 <revision>
102 <revnumber>1.17</revnumber>
103 <date>26 Feb 2011</date>
104 <authorinitials>sk</authorinitials>
105 <revremark>urgent bug fix update</revremark>
106 </revision>
107 <revision>
108 <revnumber>1.16</revnumber>
109 <date>14 Jan 2011</date>
110 <authorinitials>sk</authorinitials>
111 <revremark>bugfixes, layout improvements</revremark>
112 </revision>
113 <revision>
114 <revnumber>1.15</revnumber>
115 <date>21 May 2010</date>
116 <authorinitials>sk</authorinitials>
117 <revremark>bug and regression fixes</revremark>
118 </revision>
119 <revision>
120 <revnumber>1.14</revnumber>
121 <date>28 March 2010</date>
122 <authorinitials>sk</authorinitials>
123 <revremark>bugfixes and performance improvements</revremark>
124 </revision>
125 <revision>
126 <revnumber>1.13</revnumber>
127 <date>18 December 2009</date>
128 <authorinitials>sk</authorinitials>
129 <revremark>broken tarball update</revremark>
130 </revision>
131 <revision>
132 <revnumber>1.12</revnumber>
133 <date>18 December 2009</date>
134 <authorinitials>sk</authorinitials>
135 <revremark>new tool features and bugfixes</revremark>
136 </revision>
137 <revision>
138 <revnumber>1.11</revnumber>
139 <date>16 November 2008</date>
140 <authorinitials>mal</authorinitials>
141 <revremark>GNOME doc-utils migration</revremark>
142 </revision>
143 </revhistory>
145 </bookinfo>
147 <!-- ======== Chapter 1: Introduction ======================== -->
149 <chapter id="introduction">
150 <title>Introduction</title>
152 <para>
153 This chapter introduces GTK-Doc and gives an overview of what it is and
154 how it is used.
155 </para>
157 <sect1 id="whatisgtkdoc">
158 <title>What is GTK-Doc?</title>
160 <para>
161 GTK-Doc is used to document C code. It is typically used to document the public
162 API of libraries, such as the GTK+ and GNOME libraries. But it can also be
163 used to document application code.
164 </para>
165 </sect1>
167 <sect1 id="howdoesgtkdocwork">
168 <title>How Does GTK-Doc Work?</title>
170 <para>
171 GTK-Doc works by using documentation of functions placed inside the source files in
172 specially-formatted comment blocks, or documentation added to the template files
173 which GTK-Doc uses (though note that GTK-Doc will only document functions that
174 are declared in header files; it won't produce output for static functions).
175 </para>
177 <para>
178 GTK-Doc consists of a number of perl scripts, each performing a different step
179 in the process.
180 </para>
182 <para>
183 There are 5 main steps in the process:
184 </para>
186 <orderedlist>
188 <listitem>
189 <para>
190 <guilabel>Writing the documentation.</guilabel>
192 The author fills in the source files with the documentation for each
193 function, macro, union etc. (In the past information was entered in
194 generated template files, which is not recommended anymore).
195 </para>
196 </listitem>
198 <listitem>
199 <para>
200 <guilabel>Gathering information about the code.</guilabel>
202 <application>gtkdoc-scan</application> scans the header files of the
203 code looking for declarations of functions, macros, enums, structs, and unions.
204 It creates the file <filename>&lt;module&gt;-decl-list.txt</filename> containing a list of the
205 declarations, placing them into sections according to which header file they
206 are in. On the first run this file is copied to <filename>&lt;module&gt;-sections.txt</filename>.
207 The author can rearrange the sections, and the order of the
208 declarations within them, to produce the final desired order.
209 The second file it generates is <filename>&lt;module&gt;-decl.txt</filename>.
210 This file contains the full declarations found by the scanner. If for
211 some reason one would like some symbols to show up in the docs, where
212 the full declaration cannot be found by the scanner or the declaration
213 should appear differently, one can place entities similar to the ones in
214 <filename>&lt;module&gt;-decl.txt</filename> into <filename>&lt;module&gt;-overrides.txt</filename>.
215 </para>
216 <para>
217 <application>gtkdoc-scangobj</application> can also be used to dynamically query a library about
218 any GObject subclasses it exports. It saves information about each
219 object's position in the class hierarchy and about any GObject properties
220 and signals it provides.
221 </para>
222 <para>
223 <application>gtkdoc-scanobj</application> should not be used anymore.
224 It was needed in the past when GObject was still GtkObject inside gtk+.
225 </para>
226 </listitem>
228 <listitem>
229 <para>
230 <guilabel>Generating the "template" files.</guilabel>
232 <application>gtkdoc-mktmpl</application> creates a number of files in
233 the <filename class='directory'>tmpl/</filename> subdirectory, using the
234 information gathered in the first step. (Note that this can be run
235 repeatedly. It will try to ensure that no documentation is ever lost.)
236 </para>
237 <note>
238 <para>
239 Since GTK-Doc 1.9 the templates can be avoided. We encourage people to keep
240 documentation in the code. <application>gtkdocize</application> supports now
241 a <option>--flavour no-tmpl</option> option that chooses a makefile that
242 skips tmpl usage totally.
243 If you have never changed file in tmpl by hand, please remove the directory
244 (e.g. from version control system).
245 </para>
246 </note>
247 </listitem>
249 <listitem>
250 <para>
251 <guilabel>Generating the SGML/XML and HTML/PDF.</guilabel>
253 <application>gtkdoc-mkdb</application> turns the template files into
254 SGML or XML files in the <filename class='directory'>sgml/</filename>
255 or <filename class='directory'>xml/</filename> subdirectory.
256 If the source code contains documentation on functions, using the
257 special comment blocks, it gets merged in here. If there are no tmpl files used
258 it only reads docs from sources and introspection data. We recommend
259 to use Docbook XML.
260 </para>
261 <para>
262 <application>gtkdoc-mkhtml</application> turns the SGML/XML files into HTML
263 files in the <filename class='directory'>html/</filename> subdirectory.
264 Likewise <application>gtkdoc-mkpdf</application> turns the SGML/XML files into a PDF
265 document called <filename>&lt;package&gt;.pdf</filename>.
266 </para>
267 <para>
268 Files in <filename class='directory'>sgml/</filename> or
269 <filename class='directory'>xml/</filename> and <filename class='directory'>html/</filename>
270 directories are always overwritten. One should never edit them directly.
271 </para>
272 </listitem>
274 <listitem>
275 <para>
276 <guilabel>Fixing up cross-references between documents.</guilabel>
278 After installing the HTML files, <application>gtkdoc-fixxref</application> can be run to fix up any
279 cross-references between separate documents. For example, the GTK+
280 documentation contains many cross-references to types documented in the GLib manual.
282 When creating the source tarball for distribution, <application>gtkdoc-rebase</application>
283 turns all external links into web-links. When installing distributed (pregenerated) docs
284 the same application will try to turn links back to local links
285 (where those docs are installed).
286 </para>
287 </listitem>
288 </orderedlist>
290 </sect1>
292 <sect1 id="gettinggtkdoc">
293 <title>Getting GTK-Doc</title>
295 <sect2 id="requirements">
296 <title>Requirements</title>
297 <para>
298 <guilabel>Perl v5</guilabel> - the main scripts are in Perl.
299 </para>
300 <para>
301 <guilabel>DocBook DTD v3.0</guilabel> - This is the DocBook SGML DTD.
302 <ulink url="http://www.ora.com/davenport" type="http">http://www.ora.com/davenport</ulink>
303 </para>
304 <para>
305 <guilabel>Jade v1.1</guilabel> - This is a DSSSL processor for converting SGML to various formats.
306 <ulink url="http://www.jclark.com/jade" type="http">http://www.jclark.com/jade</ulink>
307 </para>
308 <para>
309 <guilabel>Modular DocBook Stylesheets</guilabel>
310 This is the DSSSL code to convert DocBook to HTML (and a few other
311 formats). It's used together with jade.
312 I've customized the DSSSL code slightly, in gtk-doc.dsl, to colour
313 the program code listings/declarations, and to support global
314 cross-reference indices in the generated HTML.
315 <ulink url="http://nwalsh.com/docbook/dsssl" type="http">http://nwalsh.com/docbook/dsssl</ulink>
316 </para>
317 <para>
318 <guilabel>docbook-to-man</guilabel> - if you want to create man pages from the DocBook.
319 I've customized the 'translation spec' slightly, to capitalise section
320 headings and add the 'GTK Library' title at the top of the pages and the
321 revision date at the bottom.
322 There is a link to this on <ulink url="http://www.ora.com/davenport" type="http">http://www.ora.com/davenport</ulink>
323 NOTE: This does not work yet.
324 </para>
325 </sect2>
327 <sect2 id="installation">
328 <title>Installation</title>
329 <para>
330 There is no standard place where the DocBook Modular Stylesheets are installed.
331 </para>
332 <para>
333 GTK-Doc's configure script searches these 3 directories automatically:
334 </para>
335 <para>
336 <filename> /usr/lib/sgml/stylesheets/nwalsh-modular </filename> (used by RedHat)
337 </para>
338 <para>
339 <filename> /usr/lib/dsssl/stylesheets/docbook </filename> (used by Debian)
340 </para>
341 <para>
342 <filename> /usr/share/sgml/docbkdsl </filename> (used by SuSE)
343 </para>
344 <para>
345 If you have the stylesheets installed somewhere else, you need to configure
346 GTK-Doc using the option:
347 <command> --with-dsssl-dir=&lt;PATH_TO_TOPLEVEL_STYLESHEETS_DIR&gt; </command>
348 </para>
349 </sect2>
351 </sect1>
353 <!-- not realy worth a section
354 <sect1 id="whentousegtkdoc">
355 <title>When to Use GTK-Doc</title>
357 <para>
358 (What things GTK-Doc should, and shouldn't, be used for.)
359 (- ???)
360 (- non C-based projects)
361 (+ Tutorials)
362 </para>
364 </sect1>
367 <sect1 id="aboutgtkdoc">
368 <title>About GTK-Doc</title>
370 <para>
371 (FIXME)
372 </para>
374 <para>
375 (History, authors, web pages, license, future plans,
376 comparison with other similar systems.)
377 </para>
379 </sect1>
381 <sect1 id="aboutthismanual">
382 <title>About this Manual</title>
384 <para>
385 (FIXME)
386 </para>
388 <para>
389 (who it is meant for, where you can get it, license)
390 </para>
392 </sect1>
394 </chapter>
396 <chapter id="settingup">
397 <title>Setting up your project</title>
399 <para>
400 The next sections describe what steps to perform to integrate GTK-Doc into
401 your project. Theses sections assume we work on a project called 'meep'.
402 This project contains a library called 'libmeep' and
403 an end-user app called 'meeper'. We also assume you will be using autoconf
404 and automake. In addition section <link linkend="plain_makefiles">plain
405 makefiles or other build systems</link> will describe the basics needed to
406 work in a different build setup.
407 </para>
409 <sect1 id="settingup_docfiles">
410 <title>Setting up a skeleton documentation</title>
412 <para>
413 Under your top-level project directory create folders called docs/reference
414 (this way you can also have docs/help for end-user documentation).
415 It is recommended to create another subdirectory with the name of the doc-package.
416 For packages with just one library this step is not necessary.
417 </para>
419 <para>
420 This can then look as shown below:
421 <example><title>Example directory structure</title>
422 <programlisting>
423 <![CDATA[
424 meep/
425 docs/
426 reference/
427 libmeep/
428 meeper/
429 src/
430 libmeep/
431 meeper/
433 </programlisting>
434 </example>
435 </para>
436 </sect1>
438 <sect1 id="settingup_autoconf">
439 <title>Integration with autoconf</title>
441 <para>
442 Very easy! Just add one line to your <filename>configure.ac</filename> script.
443 </para>
445 <para>
446 <example><title>Integration with autoconf</title>
447 <programlisting>
448 <![CDATA[
449 # check for gtk-doc
450 GTK_DOC_CHECK([1.14],[--flavour no-tmpl])
452 </programlisting>
453 </example>
454 </para>
456 <para>
457 This will require all developers to have gtk-doc installed. If it is
458 okay for your project to have optional api-doc build setup, you can
459 solve this as below. Keep it as is, as gtkdocize is looking for
460 <function>GTK_DOC_CHECK</function> at the start of a line.
461 <example><title>Keep gtk-doc optional</title>
462 <programlisting>
463 <![CDATA[
464 # check for gtk-doc
465 m4_ifdef([GTK_DOC_CHECK], [
466 GTK_DOC_CHECK([1.14],[--flavour no-tmpl])
468 AM_CONDITIONAL([ENABLE_GTK_DOC], false)
471 </programlisting>
472 </example>
473 </para>
475 <para>
476 The first argument is used to check for the gtkdocversion at configure time.
477 The 2nd, optional argument is used by <application>gtkdocize</application>.
478 The <symbol>GTK_DOC_CHECK</symbol> macro also adds several configure switches:
479 </para>
480 <orderedlist>
481 <listitem><para>--with-html-dir=PATH : path to installed docs</para></listitem>
482 <listitem><para>--enable-gtk-doc : use gtk-doc to build documentation [default=no]</para></listitem>
483 <listitem><para>--enable-gtk-doc-html : build documentation in html format [default=yes]</para></listitem>
484 <listitem><para>--enable-gtk-doc-pdf : build documentation in pdf format [default=no]</para></listitem>
485 </orderedlist>
487 <important>
488 <para>
489 GTK-Doc is disabled by default! Remember to pass the option
490 <option>'--enable-gtk-doc'</option> to the next
491 <filename>configure</filename> run. Otherwise pregenerated documentation is installed
492 (which makes sense for users but not for developers).
493 </para>
494 </important>
496 <para>
497 Furthermore it is recommended that you have the following line inside
498 you <filename>configure.ac</filename> script.
499 This allows <application>gtkdocize</application> to automatically copy the
500 macro definition for <function>GTK_DOC_CHECK</function> to your project.
501 </para>
503 <para>
504 <example><title>Preparation for gtkdocize</title>
505 <programlisting>
506 <![CDATA[
507 AC_CONFIG_MACRO_DIR(m4)
509 </programlisting>
510 </example>
511 </para>
512 </sect1>
514 <sect1 id="settingup_automake">
515 <title>Integration with automake</title>
517 <para>
518 First copy the <filename>Makefile.am</filename> from the
519 <filename class='directory'>examples</filename> sub directory of the
520 <ulink url="https://git.gnome.org/browse/gtk-doc/tree/examples/Makefile.am">gtkdoc-sources</ulink>
521 to your project's API documentation directory (
522 <filename class='directory'>./docs/reference/&lt;package&gt;</filename>).
523 A local copy should be available under e.g.
524 <filename>/usr/share/doc/gtk-doc-tools/examples/Makefile.am</filename>.
525 If you have multiple doc-packages repeat this for each one.
526 </para>
528 <para>
529 The next step is to edit the settings inside the <filename>Makefile.am</filename>.
530 All the settings have a comment above that describes their purpose.
531 Most settings are extra flags passed to the respective tools. Every tool
532 has a variable of the form <option>&lt;TOOLNAME&gt;_OPTIONS</option>.
533 All the tools support <option>--help</option> to list the supported
534 parameters.
535 </para>
537 <!-- FIXME: explain options ? -->
539 </sect1>
541 <sect1 id="settingup_autogen">
542 <title>Integration with autogen</title>
544 <para>
545 Most projects will have an <filename>autogen.sh</filename> script to
546 setup the build infrastructure after a checkout from version control
547 system (such as cvs/svn/git). GTK-Doc comes with a tool called
548 <application>gtkdocize</application> which can be used in such a script.
549 It should be run before autoheader, automake or autoconf.
550 </para>
552 <para>
553 <example><title>Running gtkdocize from autogen.sh</title>
554 <programlisting>
555 <![CDATA[
556 gtkdocize || exit 1
558 </programlisting>
559 </example>
560 </para>
562 <para>
563 When running <application>gtkdocize</application> it copies
564 <filename>gtk-doc.make</filename> to your project root (or any directory
565 specified by the <option>--docdir</option> option).
566 It also checks you configure script for the <function>GTK_DOC_CHECK</function>
567 invocation. This macro can be used to pass extra parameters to
568 <application>gtkdocize</application>.
569 </para>
571 <para>
572 Historically GTK-Doc was generating template files where developers entered the docs.
573 This turned out to be not so good (e.g. the need for having generated
574 files under version control).
575 Since GTK-Doc 1.9 the tools can get all the information from source comments
576 and thus the templates can be avoided. We encourage people to keep
577 documentation in the code. <application>gtkdocize</application> supports now
578 a <option>--flavour no-tmpl</option> option that chooses a makefile that skips
579 tmpl usage totally. Besides adding the option directly to the command
580 invocation, they can be added also to an environment variable called <symbol>GTKDOCIZE_FLAGS</symbol>
581 or set as a 2nd parameter in <symbol>GTK_DOC_CHECK</symbol> macro in the configure script.
582 If you have never changed file in tmpl by hand and migrating from older gtkdoc versions,
583 please remove the directory (e.g. from version control system).
584 </para>
585 </sect1>
587 <sect1 id="settingup_firstrun">
588 <title>Running the doc build</title>
590 <para>
591 After the previous steps it's time to run the build. First we need to
592 rerun <filename>autogen.sh</filename>. If this script runs configure for
593 you, then give it the <option>--enable-gtk-doc</option> option.
594 Otherwise manually run <filename>configure</filename> with this option
595 afterwards.
596 </para>
597 <para>
598 The first make run generates several additional files in the doc-directories.
599 The important ones are:
600 <filename>&lt;package&gt;.types</filename>,
601 <filename>&lt;package&gt;-docs.xml</filename> (in the past .sgml),
602 <filename>&lt;package&gt;-sections.txt</filename>.
603 </para>
604 <para>
605 <example><title>Running the doc build</title>
606 <programlisting>
607 <![CDATA[
608 ./autogen.sh --enable-gtk-doc
609 make
611 </programlisting>
612 </example>
613 </para>
614 <para>
615 Now you can point your browser to <filename>docs/reference/&lt;package&gt;/index.html</filename>.
616 Yes, it's a bit disappointing still. But hang-on, during the next chapter we
617 tell you how to fill the pages with life.
618 </para>
619 </sect1>
621 <sect1 id="settingup_vcs">
622 <title>Integration with version control systems</title>
624 <para>
625 As a rule of the thumb, it's those files you edit, that should go under
626 version control. For typical projects it's these files:
627 <filename>&lt;package&gt;.types</filename>,
628 <filename>&lt;package&gt;-docs.xml</filename> (in the past .sgml),
629 <filename>&lt;package&gt;-sections.txt</filename>,
630 <filename>Makefile.am</filename>
631 </para>
632 </sect1>
634 <sect1 id="plain_makefiles">
635 <title>Integration with plain makefiles or other build systems</title>
637 <para>
638 In the case one does not want to use automake and therefore
639 <filename>gtk-doc.mak</filename> one will need to call the gtkdoc tools
640 in the right order in own makefiles (or other build tools).
641 </para>
643 <para>
644 <example><title>Documentation build steps</title>
645 <programlisting>
646 <![CDATA[
647 DOC_MODULE=meep
648 // sources have changed
649 gtkdoc-scan --module=$(DOC_MODULE) --source-dir=...
650 gtkdoc-scangobj --module=$(DOC_MODULE)
651 gtkdoc-mkdb --module=$(DOC_MODULE) --output-format=xml
652 // xml files have changed
653 mkdir html
654 cd html && gtkdoc-mkhtml $(DOC_MODULE) ../meep-docs.xml
655 gtkdoc-fixxref --module=$(DOC_MODULE) --module-dir=html
657 </programlisting>
658 </example>
659 </para>
661 <para>
662 One will need to look at the <filename>Makefile.am</filename> and
663 <filename>gtk-doc.mak</filename> to pick the extra options needed.
664 </para>
665 </sect1>
667 </chapter>
669 <chapter id="documenting">
670 <title>Documenting the code</title>
672 <para>
673 GTK-Doc uses source code comment with a special syntax for code documentation.
674 Further it retrieves information about your project structure from other
675 sources. During the next section you will find all information about the
676 syntax of the comments.
677 </para>
679 <note>
680 <title>Documentation placement</title>
681 <para>
682 In the past most documentation had to be filled into files residing
683 inside the <filename>tmpl</filename> directory. This has the
684 disadvantages that the information is often not updated and also that
685 the file tend to cause conflicts with version control systems.
686 </para>
687 <para>
688 The avoid the aforementioned problems we suggest putting the
689 documentation inside the sources. This manual will only describe this
690 way of documenting code.
691 </para>
692 </note>
694 <para>
695 The scanner can handle the majority of C headers fine. In the case of
696 receiving warnings from the scanner that look like a special case, one can
697 hint GTK-Doc to skip over them.
698 <example><title>GTK-Doc comment block</title>
699 <programlisting>
700 <![CDATA[
701 #ifndef __GTK_DOC_IGNORE__
702 /* unparseable code here */
703 #endif
705 </programlisting>
706 </example>
707 </para>
709 <!-- -->
711 <sect1 id="documenting_syntax">
712 <title>Documentation comments</title>
714 <para>
715 A multiline comment that starts with an additional '*' marks a
716 documentation block that will be processed by the GTK-Doc tools.
717 <example><title>GTK-Doc comment block</title>
718 <programlisting>
719 <![CDATA[
721 * identifier:
722 * documentation ...
725 </programlisting>
726 </example>
727 </para>
729 <para>
730 The 'identifier' is one line with the name of the item the comment is
731 related to. The syntax differs a little depending on the item.
732 (TODO add table showing identifiers)
733 </para>
735 <para>
736 The 'documentation' block is also different for each symbol type. Symbol
737 types that get parameters such as functions or macros have the parameter
738 description first followed by a blank line (just a '*').
739 Afterwards follows the detailed description. All lines (outside program
740 listings and CDATA sections) just containing a ' *' (blank-asterisk) are
741 converted to paragraph breaks.
742 If you don't want a paragraph break, change that into ' * '
743 (blank-asterisk-blank-blank). This is useful in preformatted text (code
744 listings).
745 </para>
747 <tip>
748 <para>
749 When documenting code, describe two aspects:
750 <itemizedlist>
751 <listitem>
752 <para>
753 What it is: The name for a class or function can sometimes
754 be misleading for people coming from a different background.
755 </para>
756 </listitem>
757 <listitem>
758 <para>
759 What it does: Tell about common uses. Put it in relation
760 with the other API.
761 </para>
762 </listitem>
763 </itemizedlist>
764 </para>
765 </tip>
767 <para>
768 One advantage of hyper-text over plain-text is the ability to have links
769 in the document. Writing the correct markup for a link can be tedious
770 though. GTK-Doc comes to help by providing several useful abbreviations.
771 <itemizedlist>
772 <listitem>
773 <para>
774 Use function() to refer to functions or macros which take arguments.
775 </para>
776 </listitem>
777 <listitem>
778 <para>
779 Use @param to refer to parameters. Also use this when referring to
780 parameters of other functions, related to the one being described.
781 </para>
782 </listitem>
783 <listitem>
784 <para>
785 Use %constant to refer to a constant, e.g. %G_TRAVERSE_LEAFS.
786 </para>
787 </listitem>
788 <listitem>
789 <para>
790 Use #symbol to refer to other types of symbol, e.g. structs and
791 enums and macros which don't take arguments.
792 </para>
793 </listitem>
794 <listitem>
795 <para>
796 Use #Object::signal to refer to a GObject signal.
797 </para>
798 </listitem>
799 <listitem>
800 <para>
801 Use #Object:property to refer to a GObject property.
802 </para>
803 </listitem>
804 <listitem>
805 <para>
806 Use #Struct.field to refer to a field inside a structure and
807 #GObjectClass.foo_bar() to refer to a vmethod.
808 </para>
809 </listitem>
810 </itemizedlist>
811 </para>
813 <tip>
814 <para>
815 If you need to use the special characters '&lt;', '&gt;', '()', '@',
816 '%', or '#' in your documentation without GTK-Doc changing them you
817 can use the XML entities "&amp;lt;", "&amp;gt;", "&amp;lpar;",
818 "&amp;rpar;", "&amp;commat;", "&amp;percnt;" and "&amp;num;"
819 respectively or escape them with a backslash '\'.
820 </para>
821 </tip>
823 <para>
824 DocBook can do more than just links. One can also have lists, tables and
825 examples. To enable the usage of docbook SGML/XML tags inside
826 doc-comments you need to have <option>--xml-mode</option> or
827 <option>--sgml-mode</option> in the variable
828 <symbol>MKDB_OPTIONS</symbol> inside <filename>Makefile.am</filename>.
829 </para>
831 <para>
832 Since GTK-Doc-1.18 the tool supports a subset or the
833 <ulink url="http://daringfireball.net/projects/markdown/">markdown language</ulink>.
834 The support has improved a lot with version 1.20. On older GTK-Doc
835 versions the content will be rendered as it (the list items will appear
836 in one line separated by dashes).
837 <example><title>GTK-Doc comment block using markdown</title>
838 <programlisting>
839 <![CDATA[
841 * identifier:
843 * documentation ...
845 * # Sub heading #
847 * more documentation:
848 * - list item 1
849 * - list item 2
851 * Even more docs.
854 </programlisting>
855 </example>
856 </para>
858 <para>
859 More examples of what markdown tags are supported can be found in the
860 <ulink url="http://git.gnome.org/browse/gtk-doc/tree/tests">gtk-doc test suite</ulink>.
861 </para>
863 <tip>
864 <para>
865 As already mentioned earlier GTK-Doc is for documenting public API. Thus
866 one cannot write documentation for static symbols. Nevertheless it is good
867 to comment those symbols too. This helps other to understand you code.
868 Therefore we recommend to comment these using normal comments (without the
869 2nd '*' in the first line).
870 If later the function needs to be made public, all one needs to do is to
871 add another '*' in the comment block and insert the symbol name at the
872 right place inside the sections file.
873 </para>
874 </tip>
875 </sect1>
877 <sect1 id="documenting_sections">
878 <title>Documenting sections</title>
880 <para>
881 Each section of the documentation contains information about one class
882 or module. To introduce the component one can write a section block.
883 The short description is also used inside the table of contents.
884 All the @fields are optional.
885 </para>
887 <para>
888 <example><title>Section comment block</title>
889 <programlisting>
890 <![CDATA[
892 * SECTION:meepapp
893 * @short_description: the application class
894 * @title: Meep application
895 * @section_id:
896 * @see_also: #MeepSettings
897 * @stability: Stable
898 * @include: meep/app.h
899 * @image: application.png
901 * The application class handles ...
904 </programlisting>
905 </example>
906 </para>
908 <variablelist>
909 <varlistentry>
910 <term>SECTION:&lt;name&gt;</term>
911 <listitem>
912 <para>
913 The name links the section documentation to the respective part in
914 the <filename>&lt;package&gt;-sections.txt</filename> file. The
915 name give here should match the &lt;FILE&gt; tag in the
916 <filename>&lt;package&gt;-sections.txt</filename> file.
917 </para>
918 </listitem>
919 </varlistentry>
920 <varlistentry>
921 <term>@short_description</term>
922 <listitem>
923 <para>
924 A one line description of the section, that later will appear after
925 the links in the TOC and at the top of the section page.
926 </para>
927 </listitem>
928 </varlistentry>
929 <varlistentry>
930 <term>@title</term>
931 <listitem>
932 <para>
933 The section title defaults to &lt;name&gt; from the SECTION
934 declaration. It can be overridden with the @title field.
935 </para>
936 </listitem>
937 </varlistentry>
938 <varlistentry>
939 <term>@section_id</term>
940 <listitem>
941 <para>
942 Overrides the use of title as a section identifier. For GObjects
943 the &lt;title&gt; is used as a section_id and for other sections
944 it is &lt;MODULE&gt;-&lt;title&gt;.
945 </para>
946 </listitem>
947 </varlistentry>
948 <varlistentry>
949 <term>@see_also</term>
950 <listitem>
951 <para>
952 A list of symbols that are related to this section.
953 </para>
954 </listitem>
955 </varlistentry>
956 <varlistentry>
957 <term>@stability</term>
958 <listitem>
959 <para>
960 An informal description of the stability level this API has.
961 We recommend the use of one of these terms:
962 <itemizedlist>
963 <listitem>
964 <para>
965 Stable
966 - The intention of a Stable interface is to enable arbitrary
967 third parties to develop applications to these interfaces,
968 release them, and have confidence that they will run on all
969 minor releases of the product (after the one in which the
970 interface was introduced, and within the same major release).
971 Even at a major release, incompatible changes are expected
972 to be rare, and to have strong justifications.
973 </para>
974 </listitem>
975 <listitem>
976 <para>
977 Unstable
978 - Unstable interfaces are experimental or transitional.
979 They are typically used to give outside developers early
980 access to new or rapidly changing technology, or to provide
981 an interim solution to a problem where a more general
982 solution is anticipated.
983 No claims are made about either source or binary
984 compatibility from one minor release to the next.
985 </para>
986 </listitem>
987 <listitem>
988 <para>
989 Private
990 - An interface that can be used within the GNOME stack
991 itself, but that is not documented for end-users. Such
992 functions should only be used in specified and documented
993 ways.
994 </para>
995 </listitem>
996 <listitem>
997 <para>
998 Internal
999 - An interface that is internal to a module and does not
1000 require end-user documentation. Functions that are
1001 undocumented are assumed to be Internal.
1002 </para>
1003 </listitem>
1004 </itemizedlist>
1005 </para>
1006 </listitem>
1007 </varlistentry>
1008 <varlistentry>
1009 <term>@include</term>
1010 <listitem>
1011 <para>
1012 The <literal>#include</literal> files to show in the section
1013 synopsis (a comma separated list), overriding the global
1014 value from the <link linkend="metafiles_sections">section
1015 file</link> or command line. This item is optional.
1016 </para>
1017 </listitem>
1018 </varlistentry>
1019 <varlistentry>
1020 <term>@image</term>
1021 <listitem>
1022 <para>
1023 The image to display at the top of the reference page for this
1024 section. This will often be some sort of a diagram to illustrate
1025 the visual appearance of a class or a diagram of its relationship
1026 to other classes. This item is optional.
1027 </para>
1028 </listitem>
1029 </varlistentry>
1030 </variablelist>
1032 <tip>
1033 <para>
1034 To avoid unnecessary recompilation after doc-changes put the section
1035 docs into the c-source where possible.
1036 </para>
1037 </tip>
1039 </sect1>
1041 <sect1 id="documenting_symbols">
1042 <title>Documenting symbols</title>
1044 <para>
1045 Each symbol (function, macro, struct, enum, signal and property) is
1046 documented in a separate block. The block is best placed close to the
1047 definition of the symbols so that it is easy to keep them in sync.
1048 Thus functions are usually documented in the c-source and macros,
1049 structs and enums in the header file.
1050 </para>
1052 <sect2><title>General tags</title>
1054 <para>
1055 You can add versioning information to all documentation elements to tell
1056 when an API was introduced, or when it was deprecated.
1057 </para>
1059 <variablelist><title>Versioning Tags</title>
1060 <varlistentry><term>Since:</term>
1061 <listitem>
1062 <para>
1063 Description since which version of the code the API is available.
1064 </para>
1065 </listitem>
1066 </varlistentry>
1067 <varlistentry><term>Deprecated:</term>
1068 <listitem>
1069 <para>
1070 Paragraph denoting that this function should no be used anymore.
1071 The description should point the reader to the new API.
1072 </para>
1073 </listitem>
1074 </varlistentry>
1075 </variablelist>
1077 <para>
1078 (FIXME : Stability information)
1079 </para>
1081 <example><title>General tags</title>
1082 <programlisting>
1083 <![CDATA[
1085 * foo_get_bar:
1086 * @foo: some foo
1088 * Retrieves @foo's bar.
1090 * Returns: @foo's bar
1092 * Since: 2.6
1093 * Deprecated: 2.12: Use foo_baz_get_bar() instead.
1095 Bar *
1096 foo_get_bar(Foo *foo)
1100 </programlisting>
1101 </example>
1102 </sect2>
1104 <sect2><title>Function comment block</title>
1106 <para>
1107 Please remember to:
1108 <itemizedlist>
1109 <listitem>
1110 <para>
1111 Document whether returned objects, lists, strings, etc, should be
1112 freed/unrefed/released.
1113 </para>
1114 </listitem>
1115 <listitem>
1116 <para>
1117 Document whether parameters can be NULL, and what happens if they are.
1118 </para>
1119 </listitem>
1120 <listitem>
1121 <para>
1122 Mention interesting pre-conditions and post-conditions where appropriate.
1123 </para>
1124 </listitem>
1125 </itemizedlist>
1126 </para>
1128 <para>
1129 Gtk-doc assumes all symbols (macros, functions) starting with '_' are
1130 private. They are treated like static functions.
1131 </para>
1133 <para>
1134 <!-- FIXME: we should ideally link/describe the gobject introspection
1135 annotation tag -->
1136 Also, take a look at GObject Introspection annotation tags:
1137 http://live.gnome.org/GObjectIntrospection/Annotations
1138 </para>
1140 <example><title>Function comment block</title>
1141 <programlisting>
1142 <![CDATA[
1144 * function_name:
1145 * @par1: description of parameter 1. These can extend over more than
1146 * one line.
1147 * @par2: description of parameter 2
1148 * @...: a %NULL-terminated list of bars
1150 * The function description goes here. You can use @par1 to refer to parameters
1151 * so that they are highlighted in the output. You can also use %constant
1152 * for constants, function_name2() for functions and #GtkWidget for links to
1153 * other declarations (which may be documented elsewhere).
1155 * Returns: an integer.
1157 * Since: 2.2
1158 * Deprecated: 2.18: Use other_function() instead.
1161 </programlisting>
1162 </example>
1164 <variablelist><title>Function tags</title>
1165 <varlistentry><term>Returns:</term>
1166 <listitem>
1167 <para>
1168 Paragraph describing the returned result.
1169 </para>
1170 </listitem>
1171 </varlistentry>
1172 <varlistentry><term>@...:</term>
1173 <listitem>
1174 <para>
1175 In case the function has variadic arguments, you should use this
1176 tag (@Varargs: does also work for historic reasons).
1177 </para>
1178 </listitem>
1179 </varlistentry>
1180 </variablelist>
1182 </sect2>
1184 <sect2><title>Property comment block</title>
1186 <example><title>Property comment block</title>
1187 <programlisting>
1188 <![CDATA[
1190 * SomeWidget:some-property:
1192 * Here you can document a property.
1194 g_object_class_install_property (object_class, PROP_SOME_PROPERTY, ...);
1196 </programlisting>
1197 </example>
1199 </sect2>
1201 <sect2><title>Signal comment block</title>
1203 <para>
1204 Please remember to:
1205 <itemizedlist>
1206 <listitem>
1207 <para>
1208 Document when the signal is emitted and whether it is emitted before
1209 or after other signals.
1210 </para>
1211 </listitem>
1212 <listitem>
1213 <para>
1214 Document what an application might do in the signal handler.
1215 </para>
1216 </listitem>
1217 </itemizedlist>
1218 </para>
1220 <example><title>Signal comment block</title>
1221 <programlisting>
1222 <![CDATA[
1224 * FooWidget::foobarized:
1225 * @widget: the widget that received the signal
1226 * @foo: some foo
1227 * @bar: some bar
1229 * The ::foobarized signal is emitted each time someone tries to foobarize @widget.
1231 foo_signals[FOOBARIZE] =
1232 g_signal_new ("foobarize",
1235 </programlisting>
1236 </example>
1238 </sect2>
1240 <sect2><title>Struct comment block</title>
1241 <example><title>Struct comment block</title>
1242 <programlisting>
1243 <![CDATA[
1245 * FooWidget:
1246 * @bar: some #gboolean
1248 * This is the best widget, ever.
1250 typedef struct _FooWidget {
1251 /*< private >*/
1252 GtkWidget parent;
1254 /*< public >*/
1255 gboolean bar;
1256 } FooWidget;
1258 </programlisting>
1259 </example>
1261 <para>
1262 Use <code>/*&lt; private &gt;*/</code> before the private struct fields
1263 you want to hide. Use <code>/*&lt; public &gt;*/</code> for the reverse
1264 behaviour.
1265 </para>
1267 <para>
1268 Struct comment blocks can also be used for GObjects and GObjectClasses.
1269 It is usually a good idea to add a comment block for a class, if it has
1270 vmethods (as this is how they can be documented). For the GObject
1271 itself one can use the related section docs, having a separate block
1272 for the instance struct would be useful if the instance has public
1273 fields. One disadvantage here is that this creates two index entries
1274 of the same name (the structure and the section).
1275 </para>
1277 </sect2>
1279 <sect2><title>Enum comment block</title>
1280 <example><title>Enum comment block</title>
1281 <programlisting>
1282 <![CDATA[
1284 * Something:
1285 * @SOMETHING_FOO: something foo
1286 * @SOMETHING_BAR: something bar
1288 * Enum values used for the thing, to specify the thing.
1290 typedef enum {
1291 SOMETHING_FOO,
1292 SOMETHING_BAR,
1293 /*< private >*/
1294 SOMETHING_COUNT
1295 } Something;
1297 </programlisting>
1298 </example>
1300 <para>
1301 Use <code>/*&lt; private &gt;*/</code> before the private enum values
1302 you want to hide. Use <code>/*&lt; public &gt;*/</code> for the reverse
1303 behaviour.
1304 </para>
1306 </sect2>
1307 </sect1>
1309 <sect1 id="documenting_docbook">
1310 <title>Useful DocBook tags</title>
1312 <para>
1313 Here are some DocBook tags which are most useful when documenting the
1314 code.
1315 </para>
1317 <para>
1318 To link to another section in the GTK docs:
1320 <informalexample>
1321 <programlisting>
1322 <![CDATA[
1323 <link linkend="glib-Hash-Tables">Hash Tables</link>
1325 </programlisting>
1326 </informalexample>
1327 The linkend is the SGML/XML id on the top item of the page you want to link to.
1328 For most pages this is currently the part ("gtk", "gdk", "glib") and then
1329 the page title ("Hash Tables"). For widgets it is just the class name.
1330 Spaces and underscores are converted to '-' to conform to SGML/XML.
1331 </para>
1333 <para>
1334 To refer to an external function, e.g. a standard C function:
1335 <informalexample>
1336 <programlisting>
1337 <![CDATA[
1338 <function>...</function>
1340 </programlisting>
1341 </informalexample>
1342 </para>
1344 <para>
1345 To include example code:
1346 <informalexample>
1347 <programlisting>
1348 <![CDATA[
1349 <example>
1350 <title>Using a GHashTable.</title>
1351 <programlisting>
1353 </programlisting>
1354 </example>
1356 </programlisting>
1357 </informalexample>
1358 or possibly this, for very short code fragments which don't need a title:
1359 <informalexample>
1360 <programlisting>
1361 <![CDATA[
1362 <informalexample>
1363 <programlisting>
1365 </programlisting>
1366 </informalexample>
1368 </programlisting>
1369 </informalexample>
1370 For the latter GTK-Doc also supports an abbreviation:
1371 <![CDATA[
1376 </para>
1378 <para>
1379 To include bulleted lists:
1380 <informalexample>
1381 <programlisting>
1382 <![CDATA[
1383 <itemizedlist>
1384 <listitem>
1385 <para>
1387 </para>
1388 </listitem>
1389 <listitem>
1390 <para>
1392 </para>
1393 </listitem>
1394 </itemizedlist>
1396 </programlisting>
1397 </informalexample>
1398 </para>
1400 <para>
1401 To include a note which stands out from the text:
1402 <informalexample>
1403 <programlisting>
1404 <![CDATA[
1405 <note>
1406 <para>
1407 Make sure you free the data after use.
1408 </para>
1409 </note>
1411 </programlisting>
1412 </informalexample>
1413 </para>
1415 <para>
1416 To refer to a type:
1417 <informalexample>
1418 <programlisting>
1419 <![CDATA[
1420 <type>unsigned char</type>
1422 </programlisting>
1423 </informalexample>
1424 </para>
1426 <para>
1427 To refer to an external structure (not one described in the GTK docs):
1428 <informalexample>
1429 <programlisting>
1430 <![CDATA[
1431 <structname>XFontStruct</structname>
1433 </programlisting>
1434 </informalexample>
1435 </para>
1437 <para>
1438 To refer to a field of a structure:
1439 <informalexample>
1440 <programlisting>
1441 <![CDATA[
1442 <structfield>len</structfield>
1444 </programlisting>
1445 </informalexample>
1446 </para>
1448 <para>
1449 To refer to a class name, we could possibly use:
1450 <informalexample>
1451 <programlisting>
1452 <![CDATA[
1453 <classname>GtkWidget</classname>
1455 </programlisting>
1456 </informalexample>
1457 but you'll probably be using #GtkWidget instead (to automatically create
1458 a link to the GtkWidget page - see <link linkend="documenting_syntax">the abbreviations</link>).
1459 </para>
1461 <para>
1462 To emphasize text:
1463 <informalexample>
1464 <programlisting>
1465 <![CDATA[
1466 <emphasis>This is important</emphasis>
1468 </programlisting>
1469 </informalexample>
1470 </para>
1472 <para>
1473 For filenames use:
1474 <informalexample>
1475 <programlisting>
1476 <![CDATA[
1477 <filename>/home/user/documents</filename>
1479 </programlisting>
1480 </informalexample>
1481 </para>
1483 <para>
1484 To refer to keys use:
1485 <informalexample>
1486 <programlisting>
1487 <![CDATA[
1488 <keycombo><keycap>Control</keycap><keycap>L</keycap></keycombo>
1490 </programlisting>
1491 </informalexample>
1492 </para>
1494 </sect1>
1495 </chapter>
1497 <chapter id="metafiles">
1498 <title>Filling the extra files</title>
1500 <para>
1501 There are a couple of extra files, that need to be maintained along with
1502 the inline source code comments:
1503 <filename>&lt;package&gt;.types</filename>,
1504 <filename>&lt;package&gt;-docs.xml</filename> (in the past .sgml),
1505 <filename>&lt;package&gt;-sections.txt</filename>.
1506 </para>
1508 <sect1 id="metafiles_types">
1509 <title>Editing the types file</title>
1511 <para>
1512 If your library or application includes GObjects, you want
1513 their signals, arguments/parameters and position in the hierarchy to be
1514 shown in the documentation. All you need to do, is to list the
1515 <function>xxx_get_type</function> functions together with their include
1516 inside the <filename>&lt;package&gt;.types</filename> file.
1517 </para>
1519 <para>
1520 <example><title>Example types file snippet</title>
1521 <programlisting>
1522 <![CDATA[
1523 #include <gtk/gtk.h>
1525 gtk_accel_label_get_type
1526 gtk_adjustment_get_type
1527 gtk_alignment_get_type
1528 gtk_arrow_get_type
1530 </programlisting>
1531 </example>
1532 </para>
1534 <para>
1535 Since GTK-Doc 1.8 <application>gtkdoc-scan</application> can generate this list for you.
1536 Just add "--rebuild-types" to SCAN_OPTIONS in <filename>Makefile.am</filename>. If you
1537 use this approach you should not dist the types file nor have it under version control.
1538 </para>
1540 </sect1>
1542 <sect1 id="metafiles_master">
1543 <title>Editing the master document</title>
1545 <para>
1546 GTK-Doc produces documentation in DocBook SGML/XML. When processing the
1547 inline source comments, the GTK-Doc tools generate one documentation
1548 page per class or module as a separate file. The master document
1549 includes them and place them in an order.
1550 </para>
1552 <para>
1553 While GTK-Doc creates a template master document for you, later run will
1554 not touch it again. This means that one can freely structure the
1555 documentation. That includes grouping pages and adding extra pages.
1556 GTK-Doc has now a test suite, where also the master-document is recreated from scratch.
1557 Its a good idea to look at this from time to time to see if there are some new goodies
1558 introduced there.
1559 </para>
1561 <tip>
1562 <para>
1563 Do not create tutorials as extra documents. Just write extra chapters.
1564 The benefit of directly embedding the tutorial for your library into
1565 the API documentation is that it is easy to link for the tutorial to
1566 symbol documentation. Apart chances are higher that the tutorial gets
1567 updates along with the library.
1568 </para>
1569 </tip>
1571 <para>
1572 So what are the things to change inside the master document? For a start
1573 is only a little. There are some placeholders (text in square brackets)
1574 there which you should take care of.
1575 </para>
1577 <para>
1578 <example><title>Master document header</title>
1579 <programlisting>
1580 <![CDATA[
1581 <bookinfo>
1582 <title>MODULENAME Reference Manual</title>
1583 <releaseinfo>
1584 for MODULENAME [VERSION]
1585 The latest version of this documentation can be found on-line at
1586 <ulink role="online-location" url="http://[SERVER]/MODULENAME/index.html">http://[SERVER]/MODULENAME/</ulink>.
1587 </releaseinfo>
1588 </bookinfo>
1590 <chapter>
1591 <title>[Insert title here]</title>
1593 </programlisting>
1594 </example>
1595 </para>
1597 </sect1>
1599 <sect1 id="metafiles_sections">
1600 <title>Editing the section file</title>
1602 <para>
1603 The section file is used to organise the documentation output by
1604 GTK-Doc. Here one specifies which symbol belongs to which module or
1605 class and control the visibility (public or private).
1606 </para>
1608 <para>
1609 The section file is a plain text file with XML-like syntax (using tags).
1610 Blank lines are ignored and lines starting with a '#' are treated as
1611 comment lines.
1612 </para>
1614 <para>
1615 The &lt;FILE&gt; ... &lt;/FILE&gt; tag is used to specify the file name,
1616 without any suffix. For example, using '&lt;FILE&gt;gnome-config&lt;/FILE&gt;'
1617 will result in the section declarations being output in the template
1618 file <filename>tmpl/gnome-config.sgml</filename>, which will be
1619 converted into the DocBook SGML/XML file <filename>sgml/gnome-config.sgml</filename>
1620 or the DocBook XML file <filename>xml/gnome-config.xml</filename>.
1621 (The name of the HTML file is based on the module name and the section
1622 title, or for GObjects it is based on the GObjects class name converted
1623 to lower case).
1624 </para>
1626 <para>
1627 The &lt;TITLE&gt; ... &lt;/TITLE&gt; tag is used to specify the title of
1628 the section. It is only useful before the templates (if used) are
1629 initially created, since the title set in the template file overrides
1630 this. Also if one uses SECTION comment in the sources, this is obsolete.
1631 </para>
1633 <para>
1634 You can group items in the section by using the &lt;SUBSECTION&gt; tag.
1635 Currently it outputs a blank line between subsections in the synopsis
1636 section.
1637 You can also use &lt;SUBSECTION Standard&gt; for standard GObject
1638 declarations (e.g. the functions like g_object_get_type and macros like
1639 G_OBJECT(), G_IS_OBJECT() etc.).
1640 Currently these are left out of the documentation.
1641 You can also use &lt;SUBSECTION Private&gt; for private declarations
1642 which will not be output (it is a handy way to avoid warning messages
1643 about unused declarations).
1644 If your library contains private types which you don't want to appear in
1645 the object hierarchy and the list of implemented or required interfaces,
1646 add them to a Private subsection.
1647 Whether you would place GObject and GObjectClass like structs in public
1648 or Standard section depends if they have public entries (variables,
1649 vmethods).
1650 </para>
1652 <para>
1653 You can also use &lt;INCLUDE&gt; ... &lt;/INCLUDE&gt; to specify the
1654 #include files which are shown in the synopsis sections.
1655 It contains a comma-separate list of #include files, without the angle
1656 brackets. If you set it outside of any sections, it acts for all
1657 sections until the end of the file. If you set it within a section, it
1658 only applies to that section.
1659 </para>
1661 </sect1>
1663 </chapter>
1665 <chapter id="reports">
1666 <title>Controlling the result</title>
1668 <para>
1669 A GTK-Doc run generates report files inside the documentation directory.
1670 The generated files are named:
1671 <filename>&lt;package&gt;-undocumented.txt</filename>,
1672 <filename>&lt;package&gt;-undeclared.txt</filename> and
1673 <filename>&lt;package&gt;-unused.txt</filename>.
1674 All those are plain text files that can be viewed and postprocessed easily.
1675 </para>
1677 <para>
1678 The <filename>&lt;package&gt;-undocumented.txt</filename> file starts with
1679 the documentation coverage summary. Below are two sections divided by
1680 blank lines. The first section lists undocumented or incomplete symbols.
1681 The second section does the same for section docs. Incomplete entries are
1682 those, which have documentation, but where e.g. a new parameter has been
1683 added.
1684 </para>
1686 <para>
1687 The <filename>&lt;package&gt;-undeclared.txt</filename> file lists symbols
1688 given in the <filename>&lt;package&gt;-sections.txt</filename> but not
1689 found in the sources. Check if they have been removed or if they are
1690 misspelled.
1691 </para>
1693 <para>
1694 The <filename>&lt;package&gt;-unused.txt</filename> file lists symbol
1695 names, where the GTK-Doc scanner has found documentation, but does not
1696 know where to put it. This means that the symbol has not yet been added to
1697 the <filename>&lt;package&gt;-sections.txt</filename> file.
1698 </para>
1700 <tip>
1701 <para>
1702 Enable or add the <option>TESTS=$(GTKDOC_CHECK)</option> line in Makefile.am.
1703 If at least GTK-Doc 1.9 is installed, this will run sanity checks during
1704 <command>make check</command> run.
1705 </para>
1706 </tip>
1708 <para>
1709 One can also look at the files produced by the source code scanner:
1710 <filename>&lt;package&gt;-decl-list.txt</filename> and
1711 <filename>&lt;package&gt;-decl.txt</filename>. The first one can be
1712 compared with the section file if that is manually maintained. The second
1713 lists all declarations from the headers. If a symbol is missing one could
1714 check if this file contains it.
1715 </para>
1717 <para>
1718 If the project is GObject based, one can also look into the files produced
1719 by the object scanner:
1720 <filename>&lt;package&gt;.args.txt</filename>,
1721 <filename>&lt;package&gt;.hierarchy.txt</filename>,
1722 <filename>&lt;package&gt;.interfaces.txt</filename>,
1723 <filename>&lt;package&gt;.prerequisites.txt</filename> and
1724 <filename>&lt;package&gt;.signals.txt</filename>. If there are missing
1725 symbols in any of those, one can ask GTK-Doc to keep the intermediate
1726 scanner file for further analysis, by running it as
1727 <command>GTK_DOC_KEEP_INTERMEDIATE=1 make</command>.
1728 </para>
1729 </chapter>
1731 <chapter id="modernizing">
1732 <title>Modernizing the documentation</title>
1734 <para>
1735 GTK-Doc has been around for quite some time. In this section we list new
1736 features together with the version since when it is available.
1737 </para>
1739 <sect1 id="modernizing-gtk-doc-1-9">
1740 <title>GTK-Doc 1.9</title>
1742 <para>
1743 When using xml instead of sgml, one can actually name the master
1744 document <filename>&lt;package&gt;-docs.xml</filename>.
1745 </para>
1747 <para>
1748 This version supports <option>SCAN_OPTIONS=--rebuild-sections</option>
1749 in <filename>Makefile.am</filename>. When this is enabled, the
1750 <filename>&lt;package&gt;-sections.txt</filename> is autogenerated and
1751 can be removed from the vcs. This only works nicely for projects that
1752 have a very regular structure (e.g. each .{c,h} pair will create new
1753 section. If one organize a project close to that updating a manually
1754 maintained section file can be as simple as running
1755 <code>meld &lt;package&gt;-decl-list.txt &lt;package&gt;-sections.txt</code>.
1756 </para>
1758 <para>
1759 Version 1.8 already introduced the syntax for documenting sections in
1760 the sources instead of the separate files under <filename class='directory'>tmpl</filename>.
1761 This version adds options to switch the whole doc module to not use the
1762 extra tmpl build step at all, by using <option>--flavour no-tmpl</option>
1763 in <filename>configure.ac</filename>.
1764 </para>
1765 </sect1>
1767 <sect1 id="modernizing-gtk-doc-1-10">
1768 <title>GTK-Doc 1.10</title>
1770 <para>
1771 This version supports <option>SCAN_OPTIONS=--rebuild-types</option> in
1772 <filename>Makefile.am</filename>. When this is enabled, the
1773 <filename>&lt;package&gt;.types</filename> is autogenerated and can be
1774 removed from the vcs. When using this feature it is important to also
1775 setup the <varname>IGNORE_HFILES</varname> in
1776 <filename>Makefile.am</filename> for code that is build conditionally.
1777 </para>
1778 </sect1>
1780 <sect1 id="modernizing-gtk-doc-1-16">
1781 <title>GTK-Doc 1.16</title>
1783 <para>
1784 This version includes a new tool called gtkdoc-check. This tool can run
1785 a set of sanity checks on your documentation. It is enabled by adding
1786 these lines to the end of <filename>Makefile.am</filename>.
1787 <example><title>Enable gtkdoc-check</title>
1788 <programlisting>
1789 <![CDATA[
1790 if ENABLE_GTK_DOC
1791 TESTS_ENVIRONMENT = \
1792 DOC_MODULE=$(DOC_MODULE) DOC_MAIN_SGML_FILE=$(DOC_MAIN_SGML_FILE) \
1793 SRCDIR=$(abs_srcdir) BUILDDIR=$(abs_builddir)
1794 TESTS = $(GTKDOC_CHECK)
1795 endif
1797 </programlisting>
1798 </example>
1799 </para>
1800 </sect1>
1802 <sect1 id="modernizing-gtk-doc-1-20">
1803 <title>GTK-Doc 1.20</title>
1805 <para>
1806 Version 1.18 brought some initial markdown support. Using markdown in
1807 doc comments is less intrusive than writing docbook xml. This version
1808 improves a lot on this and add a lot more styles. The section that
1809 explains the <link linkend="documenting_syntax">comment syntax</link>
1810 has all the details.
1811 </para>
1812 </sect1>
1813 </chapter>
1815 <chapter id="documenting-others">
1816 <title>Documenting other interfaces</title>
1818 <para>
1819 So far we have been using GTK-Doc to document the API of code. The next
1820 sections contain suggestions how the tools can be used to document other
1821 interfaces too.
1822 </para>
1824 <sect1 id="commandline-interfaces">
1825 <title>Command line options and man pages</title>
1827 <para>
1828 As one can generate man pages for a docbook refentry as well, it sounds
1829 like a good idea to use it for that purpose. This way the interface is
1830 part of the reference and one gets the man-page for free.
1831 </para>
1833 <sect2 id="commandline-interfaces-file">
1834 <title>Document the tool</title>
1836 <para>
1837 Create one refentry file per tool. Following
1838 <link linkend="settingup_docfiles">our example</link> we would call it
1839 <filename>meep/docs/reference/meeper/meep.xml</filename>. For the xml
1840 tags that should be used and can look at generated file in the xml
1841 subdirectory as well as examples e.g. in glib.
1842 </para>
1843 </sect2>
1845 <sect2 id="commandline-interfaces-configure">
1846 <title>Adding the extra configure check</title>
1848 <para>
1849 <example><title>Extra configure checks</title>
1850 <programlisting>
1851 <![CDATA[
1852 AC_ARG_ENABLE(man,
1853 [AC_HELP_STRING([--enable-man],
1854 [regenerate man pages from Docbook [default=no]])],enable_man=yes,
1855 enable_man=no)
1857 AC_PATH_PROG([XSLTPROC], [xsltproc])
1858 AM_CONDITIONAL(ENABLE_MAN, test x$enable_man != xno)
1860 </programlisting>
1861 </example>
1862 </para>
1863 </sect2>
1865 <sect2 id="commandline-interfaces-make">
1866 <title>Adding the extra makefile rules</title>
1868 <para>
1869 <example><title>Extra configure checks</title>
1870 <programlisting>
1871 <![CDATA[
1872 man_MANS = \
1873 meeper.1
1875 if ENABLE_GTK_DOC
1876 if ENABLE_MAN
1878 %.1 : %.xml
1879 @XSLTPROC@ -nonet http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl $<
1881 endif
1882 endif
1884 BUILT_EXTRA_DIST = $(man_MANS)
1885 EXTRA_DIST += meep.xml
1887 </programlisting>
1888 </example>
1889 </para>
1890 </sect2>
1891 </sect1>
1893 <sect1 id="dbus-interfaces">
1894 <title>DBus interfaces</title>
1896 <para>
1897 (FIXME: http://hal.freedesktop.org/docs/DeviceKit/DeviceKit.html,
1898 http://cgit.freedesktop.org/DeviceKit/DeviceKit/tree/doc/dbus)
1899 </para>
1900 </sect1>
1902 </chapter>
1904 <chapter id="faq">
1905 <title>Frequently asked questions</title>
1907 <segmentedlist>
1908 <?dbhtml list-presentation="list"?>
1909 <segtitle>Question</segtitle>
1910 <segtitle>Answer</segtitle>
1911 <seglistitem>
1912 <seg>No class hierarchy.</seg>
1913 <seg>
1914 The objects <function>xxx_get_type()</function> function has not been
1915 entered into the <filename>&lt;package&gt;.types</filename> file.
1916 </seg>
1917 </seglistitem>
1918 <seglistitem>
1919 <seg>Still no class hierarchy.</seg>
1920 <seg>
1921 Missing or wrong naming in <filename>&lt;package&gt;-sections.txt</filename>
1922 file (see <ulink url="http://mail.gnome.org/archives/gtk-doc-list/2003-October/msg00006.html">explanation</ulink>).
1923 </seg>
1924 </seglistitem>
1925 <seglistitem>
1926 <seg>Damn, I have still no class hierarchy.</seg>
1927 <seg>
1928 Is the object name (name of the instance struct, e.g. <type>GtkWidget</type>)
1929 part of the normal section (don't put this into Standard or Private
1930 subsections).
1931 </seg>
1932 </seglistitem>
1933 <seglistitem>
1934 <seg>No symbol index.</seg>
1935 <seg>
1936 Does the <filename>&lt;package&gt;-docs.{xml,sgml}</filename> contain a
1937 index that xi:includes the generated index?
1938 </seg>
1939 </seglistitem>
1940 <seglistitem>
1941 <seg>Symbols are not linked to their doc-section.</seg>
1942 <seg>
1943 Is the doc-comment using the correct markup (added #,% or ())?
1944 Check if the gtkdoc-fixxref warns about unresolvable xrefs.
1945 </seg>
1946 </seglistitem>
1947 <seglistitem>
1948 <seg>A new class does not appear in the docs.</seg>
1949 <seg>
1950 Is the new page xi:included from
1951 <filename>&lt;package&gt;-docs.{xml,sgml}</filename>.
1952 </seg>
1953 </seglistitem>
1954 <seglistitem>
1955 <seg>A new symbol does not appear in the docs.</seg>
1956 <seg>
1957 Is the doc-comment properly formatted. Check for spelling mistakes in
1958 the begin of the comment. Check if the gtkdoc-fixxref warns about
1959 unresolvable xrefs. Check if the symbol is correctly listed in the
1960 <filename>&lt;package&gt;-sections.txt</filename> in a public subsection.
1961 </seg>
1962 </seglistitem>
1963 <seglistitem>
1964 <seg>A type is missing from the class hierarchy.</seg>
1965 <seg>
1966 If the type is listed in <filename>&lt;package&gt;.hierarchy</filename>
1967 but not in <filename>xml/tree_index.sgml</filename> then double check
1968 that the type is correctly placed in the <filename>&lt;package&gt;-sections.txt</filename>.
1969 If the type instance (e.g. <type>GtkWidget</type>) is not listed or
1970 incidentialy makred private it will not be shown.
1971 </seg>
1972 </seglistitem>
1973 <seglistitem>
1974 <seg>I get foldoc links for all gobject annotations.</seg>
1975 <seg>
1976 Check that <filename>xml/annotation-glossary.xml</filename> is
1977 xi:included from <filename>&lt;package&gt;-docs.{xml,sgml}</filename>.
1978 </seg>
1979 </seglistitem>
1981 <!-- gtk-doc warnings: -->
1982 <seglistitem>
1983 <seg>Parameter described in source code comment block but does not exist</seg>
1984 <seg>Check if the prototype in the header has different parameter names as in the source.</seg>
1985 </seglistitem>
1987 <!-- docbook warnings: -->
1988 <seglistitem>
1989 <seg>multiple "IDs" for constraint linkend: XYZ</seg>
1990 <seg>Symbol XYZ appears twice in <filename>&lt;package&gt;-sections.txt</filename> file.</seg>
1991 </seglistitem>
1992 <seglistitem>
1993 <seg>Element typename in namespace '' encountered in para, but no template matches.</seg>
1994 <seg />
1995 </seglistitem>
1996 </segmentedlist>
1997 </chapter>
1999 <chapter id="contrib">
2000 <title>Tools related to gtk-doc</title>
2002 <para>
2003 GtkDocPlugin - a <ulink url="http://trac-hacks.org/wiki/GtkDocPlugin">Trac GTK-Doc</ulink>
2004 integration plugin, that adds API docs to a trac site and integrates with
2005 the trac search.
2006 </para>
2007 <para>
2008 Gtkdoc-depscan - a tool (part of gtk-doc) to check used API against since
2009 tags in the API to determine the minimum required version.
2010 </para>
2012 </chapter>
2014 <!-- ======== Appendix: FDL ================================== -->
2015 &FDL;
2017 </book>