~ubuntu-branches/ubuntu/trusty/gtk-doc/trusty-proposed

« back to all changes in this revision

Viewing changes to help/manual/C/gtk-doc-manual.xml

  • Committer: Martin Pitt
  • Date: 2011-01-27 14:41:59 UTC
  • mfrom: (1.2.12 upstream)
  • Revision ID: martin.pitt@canonical.com-20110127144159-wagev8l04yc5b8jc
New upstream release with lots of bug fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
<book id="index">
11
11
  <bookinfo>
12
12
    <title>GTK-Doc Manual</title>
13
 
    <edition>1.12</edition>
 
13
    <edition>1.15</edition>
14
14
    <abstract role="description"><para>User manual for developers with instructions of GTK-Doc usage.</para></abstract>
15
15
    <authorgroup>
16
16
      <author>
77
77
    
78
78
    <revhistory>
79
79
      <revision>
 
80
        <revnumber>1.16</revnumber>
 
81
        <date>14 Jan 2011</date>
 
82
        <authorinitials>sk</authorinitials>
 
83
        <revremark>bugfixes, layout improvements</revremark>
 
84
      </revision>
 
85
      <revision>
80
86
        <revnumber>1.15</revnumber>
81
87
        <date>21 May 2010</date>
82
88
        <authorinitials>sk</authorinitials>
169
175
            code looking for declarations of functions, macros, enums, structs, and unions.
170
176
            It creates the file <filename>&lt;module&gt;-decl-list.txt</filename> containg a list of the
171
177
            declarations, placing them into sections according to which header file they
172
 
            are in. On the first run this file is copied to <filename>&lt;module&gt;-sections.txt</filename>
 
178
            are in. On the first run this file is copied to <filename>&lt;module&gt;-sections.txt</filename>.
173
179
            The author can rearrange the sections, and the order of the
174
180
            declarations within them, to produce the final desired order.
175
181
            The second file it generates is <filename>&lt;module&gt;-decl.txt</filename>.
176
182
            This file contains the full declarations found by the scanner. If for
177
 
            some reason one would like some sybols to show up in the docs, where
178
 
            the full declaration cannot be found by th scanner or the declaration
 
183
            some reason one would like some symbols to show up in the docs, where
 
184
            the full declaration cannot be found by the scanner or the declaration
179
185
            should appear differently, one can place enties similar to the ones in
180
186
            <filename>&lt;module&gt;-decl.txt</filename> into <filename>&lt;module&gt;-overrides.txt</filename>.
181
187
 
216
222
            or <filename class='directory'>xml/</filename> subdirectory.
217
223
            If the source code contains documentation on functions, using the
218
224
            special comment blocks, it gets merged in here. If there are no tmpl files used
219
 
            it only reads takes docs from sources and introspection data.
 
225
            it only reads docs from sources and introspection data. We recommend
 
226
            to use Docbook XML.
220
227
          </para>
221
228
          <para>
222
229
            <application>gtkdoc-mkhtml</application> turns the SGML/XML files into HTML
223
230
            files in the <filename class='directory'>html/</filename> subdirectory.
224
231
            Likewise <application>gtkdoc-mkpdf</application> turns the SGML/XML files into a PDF
225
 
            docuemnt called <filename>&lt;package&gt;.pdf</filename>.
 
232
            document called <filename>&lt;package&gt;.pdf</filename>.
226
233
          </para>
227
234
          <para>
228
235
            Files in <filename class='directory'>sgml/</filename> or
358
365
 
359
366
    <para>
360
367
      The next sections describe what steps to perform to integrate GTK-Doc into
361
 
      your project. Theses section assume we work on a project called 'meep'.
 
368
      your project. Theses sections assume we work on a project called 'meep'.
362
369
      This project contains a library called 'libmeep' and
363
370
      an end-user app called 'meeper'.
364
371
    </para>
374
381
      </para>
375
382
 
376
383
      <para>
377
 
        This can then look as show below:
 
384
        This can then look as shown below:
378
385
        <example><title>Example directory structure</title>
379
386
          <programlisting>
380
387
<![CDATA[
411
418
      </para>
412
419
      
413
420
      <para>
 
421
        This will require all developers to have gtk-doc installed. If it is
 
422
        okay for your project to have optional api-doc build setup, you can
 
423
        solve this as below. Keep it as is, as gtkdocize is looking for
 
424
        <function>GTK_DOC_CHECK</function>  at the start of a line.
 
425
        <example><title>Keep gtk-doc optional</title>
 
426
          <programlisting>
 
427
<![CDATA[
 
428
# check for gtk-doc
 
429
m4_ifdef([GTK_DOC_CHECK], [
 
430
GTK_DOC_CHECK([1.14],[--flavour no-tmpl])
 
431
],[
 
432
AM_CONDITIONAL([ENABLE_GTK_DOC], false)
 
433
])
 
434
]]>
 
435
          </programlisting>
 
436
        </example>
 
437
      </para>
 
438
      
 
439
      <para>
414
440
        The first argument is used to check for the gtkdocversion at configure time.
415
441
        The 2nd, optional argument is used by <application>gtkdocize</application>.
416
442
        The <symbol>GTK_DOC_CHECK</symbol> macro also adds several configure switches:
460
486
      </para>
461
487
 
462
488
      <para>
463
 
        The next step is to edit the setting inside the <filename>Makefile.am</filename>.
 
489
        The next step is to edit the settings inside the <filename>Makefile.am</filename>.
464
490
        All the settings have a comment above that describes their purpose.
465
491
        Most settings are extra flags passed to the respective tools. Every tool
466
492
        has a variable of the form <option>&lt;TOOLNAME&gt;_OPTIONS</option>.
471
497
      <!-- FIXME: explain options ? -->
472
498
 
473
499
      <para>
474
 
        You may also want to enable GTK-Doc for the distcheckmake target. Just
475
 
        add then one-liner show in the next example to you top-level
 
500
        You may also want to enable GTK-Doc for the distcheck make target. Just
 
501
        add the one line shown in the next example to your top-level
476
502
        <filename>Makefile.am</filename>:
477
503
      </para>
478
504
 
511
537
 
512
538
      <para>
513
539
        When running <application>gtkdocize</application> it copies
514
 
        <filename>gtk-doc.make</filename> to you project root (or any directory
 
540
        <filename>gtk-doc.make</filename> to your project root (or any directory
515
541
        specified by the <option>--docdir</option> option).
516
 
        If also check you configure script for the <function>GTK_DOC_CHECK</function>
517
 
        invocation.
 
542
        It also checks you configure script for the <function>GTK_DOC_CHECK</function>
 
543
        invocation. This macro can be used to pass extra parameters to
 
544
        <application>gtkdocize</application>.
518
545
      </para>
519
546
 
520
547
      <para>
521
 
        Historically GTK-Doc was gerating template files where developers entered the docs.
522
 
        this turned out to be not so good. Since a few version GTK-Doc could also get all
523
 
        the information from source comments.
524
 
        Since GTK-Doc 1.9 the templates can be avoided. We encourage people to keep
 
548
        Historically GTK-Doc was generating template files where developers entered the docs.
 
549
        This turned out to be not so good (e.g. the need for having generated
 
550
        files under version control).
 
551
        Since GTK-Doc 1.9 the tools can get all the information from source comments
 
552
        and thus the templates can be avoided. We encourage people to keep
525
553
        documentation in the code. <application>gtkdocize</application> supports now
526
554
        a <option>--flavour no-tmpl</option> option that chooses a makefile that skips
527
555
        tmpl usage totally. Besides adding the option directly to the command
528
 
        invocation, they can be added also to a environment variable called <symbol>GTKDOCIZE_FLAGS</symbol>
 
556
        invocation, they can be added also to an environment variable called <symbol>GTKDOCIZE_FLAGS</symbol>
529
557
        or set as a 2nd parameter in <symbol>GTK_DOC_CHECK</symbol> macro in the configure script.
530
558
        If you have never changed file in tmpl by hand and migrating from older gtkdoc versions,
531
559
        please remove the dir (e.g. from version control system).
587
615
    <para>
588
616
      GTK-Doc uses source code comment with a special syntax for code documentation.
589
617
      Further it retrieves information about your project structure from other
590
 
      sources. During the next section you find all information about the syntax
591
 
      of the comments.
 
618
      sources. During the next section you will find all information about the
 
619
      syntax of the comments.
592
620
    </para>
593
621
 
594
622
    <note>
605
633
        way of documenting code.
606
634
      </para>
607
635
    </note>
 
636
    
 
637
    <para>
 
638
      The scanner can handle the majority of c headers fine. In the case of
 
639
      receiving warnings from the scanner that look like a special case, one can
 
640
      hint GTK-Doc to skip over them.
 
641
      <example><title>GTK-Doc comment block</title>
 
642
        <programlisting>
 
643
<![CDATA[
 
644
#ifndef __GTK_DOC_IGNORE__
 
645
/* unparseable code here */
 
646
#endif
 
647
]]>
 
648
        </programlisting>
 
649
      </example>
 
650
    </para>
608
651
 
609
652
    <!--  -->
610
653
 
689
732
      </para>
690
733
 
691
734
      <tip>
692
 
        <para>
693
 
          If you need to use the special characters '&lt;', '&gt;', '()', '@',
694
 
          '%', or '#' in your documentation without GTK-Doc changing them you
695
 
          can use the XML entities "&amp;lt;", "&amp;gt;", "&amp;lpar;",
696
 
          "&amp;rpar;", "&amp;commat;", "&amp;percnt;" and "&amp;num;"
697
 
          respectively or escape them with a backslash '\'.
698
 
        </para>
 
735
          <para>
 
736
        If you need to use the special characters '&lt;', '&gt;', '()', '@',
 
737
        '%', or '#' in your documentation without GTK-Doc changing them you
 
738
        can use the XML entities "&amp;lt;", "&amp;gt;", "&amp;lpar;",
 
739
        "&amp;rpar;", "&amp;commat;", "&amp;percnt;" and "&amp;num;"
 
740
        respectively or escape them with a backslash '\'.
 
741
          </para>
699
742
      </tip>
700
743
 
701
744
      <para>
702
745
        DocBook can do more that just links. One can also have lists, tables and
703
746
        examples. To enable the usage of SGML/XML tags inside doc-comments you
704
 
        need to have <option>--sgml-mode</option> in the variable
705
 
        <symbol>MKDB_OPTIONS</symbol> inside <filename>Makefile.am</filename>.
 
747
        need to have <option>--xml-mode</option> or <option>--sgml-mode</option>
 
748
        in the variable <symbol>MKDB_OPTIONS</symbol> inside 
 
749
        <filename>Makefile.am</filename>.
706
750
      </para>
707
751
 
708
752
      <tip>
741
785
 * @see_also: #MeepSettings
742
786
 * @stability: Stable
743
787
 * @include: meep/app.h
744
 
 * @Image: application.png
 
788
 * @image: application.png
745
789
 *
746
790
 * The application class handles ...
747
791
 */
785
829
          <listitem>
786
830
            <para>
787
831
              Overrides the use of title as a section identifier. For GObjects
788
 
              the &lt;title&gt; is used as a section_id and for other section it
789
 
              is &lt;MODULE&gt;-&lt;title&gt;.
 
832
              the &lt;title&gt; is used as a section_id and for other sections
 
833
              it is &lt;MODULE&gt;-&lt;title&gt;.
790
834
            </para>
791
835
          </listitem>
792
836
        </varlistentry>
794
838
          <term>@see_also</term>
795
839
          <listitem>
796
840
            <para>
797
 
              A list of symbols that are related to this section..
 
841
              A list of symbols that are related to this section.
798
842
            </para>
799
843
          </listitem>
800
844
        </varlistentry>
890
934
        Each symbol (function, macro, struct, enum, signal and property) is
891
935
        documented in a separate block. The block is best placed close to the
892
936
        definition of the symbols so that it is easy to keep them in sync.
893
 
        Thus function are usually documented in the c-source and macros, struct
894
 
        and enum in the header file.
 
937
        Thus functions are usually documented in the c-source and macros,
 
938
        structs and enums in the header file.
895
939
      </para>
896
940
 
897
941
      <sect2><title>General tags</title>
1106
1150
        <para>
1107
1151
          Use <code>/*&lt; private &gt;*/</code> before the private struct fields
1108
1152
          you want to hide. Use <code>/*&lt; public &gt;*/</code> for the reverse
1109
 
          behavirour.
 
1153
          behaviour.
 
1154
        </para>
 
1155
        
 
1156
        <para>
 
1157
          Struct comment blocks can also be used for GObjects and GObjectClasses.
 
1158
          It is usualy a good idea to add a comment blco for a class, if it has
 
1159
          vmethods (as this is how they can be documented). For the GObject
 
1160
          itself one can use the related section docs, having a separate block
 
1161
          for the instance struct would be useful if the instance has public
 
1162
          fields. One disadvantage here is that this creates two index entries
 
1163
          of the same name (the structure and the section).
1110
1164
        </para>
1111
1165
 
1112
1166
      </sect2>
1136
1190
        <para>
1137
1191
          Use <code>/*&lt; private &gt;*/</code> before the private enum values
1138
1192
          you want to hide. Use <code>/*&lt; public &gt;*/</code> for the reverse
1139
 
          behavirour.
 
1193
          behaviour.
1140
1194
        </para>
1141
1195
 
1142
1196
      </sect2>
1382
1436
        GTK-Doc produces documentation in DocBook SGML/XML. When processing the
1383
1437
        inline source comments, the GTK-Doc tools generate one documentation
1384
1438
        page per class or module as a separate file. The master document
1385
 
        includes them and place them in a order.
 
1439
        includes them and place them in an order.
1386
1440
      </para>
1387
1441
 
1388
1442
      <para>
1480
1534
        If your library contains private types which you don't want to appear in
1481
1535
        the object hierarchy and the list of implemented or required interfaces,
1482
1536
        add them to a Private subsection.
 
1537
        Wheter you would place GObject and GObjectClass like structs in public
 
1538
        or Standard section depends if they have public entries (variables,
 
1539
        vmethods).
1483
1540
      </para>
1484
1541
 
1485
1542
      <para>
1541
1598
    <para>
1542
1599
      One can also look at the files produced by the source code scanner:
1543
1600
      <filename>&lt;package&gt;-decl-list.txt</filename> and
1544
 
      <filename>&lt;package&gt;-decl.txt</filename>. The first and can be
 
1601
      <filename>&lt;package&gt;-decl.txt</filename>. The first one can be
1545
1602
      compared with the section file if that is manualy maintained. The second
1546
1603
      lists all declarations fromt he headers If a symbol is missing one could
1547
1604
      check if this file contains it.
1560
1617
      <command>GTK_DOC_KEEP_INTERMEDIATE=1 make</command>.
1561
1618
    </para>
1562
1619
  </chapter>
 
1620
  
 
1621
  <chapter id="documenting-others">
 
1622
    <title>Documenting other interfaces</title>
 
1623
    
 
1624
    <para>
 
1625
      So far we have been using GTK-Doc to document the API of code. The next
 
1626
      sections contain suggestions how the tools can be used to document other
 
1627
      interfaces too.
 
1628
    </para>
 
1629
    
 
1630
    <sect1 id="commandline-interfaces">
 
1631
      <title>Commandline options and man pages</title>
 
1632
      
 
1633
      <para>
 
1634
        As one can generate man pages for a docbook refentry as well, it sounds
 
1635
        like a good idea to use it for that purpose. This way the interface is
 
1636
        part of the reference and one gets the man-page for free.
 
1637
      </para>
 
1638
 
 
1639
      <sect2 id="commandline-interfaces-file">
 
1640
        <title>Document the tool</title>
 
1641
 
 
1642
        <para>
 
1643
          Create one refentry file per tool. Following 
 
1644
          <link linkend="settingup_docfiles">our example</link> we would call it
 
1645
          <filename>meep/docs/reference/meeper/meep.xml</filename>. For the xml
 
1646
          tags that should be used and can look at generated file in the xml
 
1647
          subdirectory as well as examples e.g. in glib.
 
1648
        </para>
 
1649
      </sect2>
 
1650
 
 
1651
      <sect2 id="commandline-interfaces-configure">
 
1652
        <title>Adding the extra configure check</title>
 
1653
 
 
1654
        <para>
 
1655
          <example><title>Extra configure checks</title>
 
1656
            <programlisting>
 
1657
<![CDATA[
 
1658
AC_ARG_ENABLE(man,
 
1659
              [AC_HELP_STRING([--enable-man],
 
1660
                              [regenerate man pages from Docbook [default=no]])],enable_man=yes,
 
1661
              enable_man=no)
 
1662
 
 
1663
AC_PATH_PROG([XSLTPROC], [xsltproc])
 
1664
AM_CONDITIONAL(ENABLE_MAN, test x$enable_man != xno)
 
1665
]]>
 
1666
            </programlisting>
 
1667
          </example>
 
1668
        </para>
 
1669
      </sect2>
 
1670
      
 
1671
      <sect2 id="commandline-interfaces-make">
 
1672
        <title>Adding the extra makefile rules</title>
 
1673
      
 
1674
        <para>
 
1675
          <example><title>Extra configure checks</title>
 
1676
            <programlisting>
 
1677
<![CDATA[
 
1678
man_MANS = \
 
1679
       meeper.1
 
1680
 
 
1681
if ENABLE_GTK_DOC
 
1682
if ENABLE_MAN
 
1683
 
 
1684
%.1 : %.xml
 
1685
        @XSLTPROC@ -nonet http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl $<
 
1686
 
 
1687
endif
 
1688
endif
 
1689
 
 
1690
BUILT_EXTRA_DIST = $(man_MANS)
 
1691
EXTRA_DIST += meep.xml
 
1692
]]>
 
1693
            </programlisting>
 
1694
          </example>
 
1695
        </para>
 
1696
      </sect2>
 
1697
    </sect1>
 
1698
    
 
1699
    <sect1 id="dbus-interfaces">
 
1700
      <title>DBus interfaces</title>
 
1701
 
 
1702
      <para>
 
1703
        (FIXME: http://hal.freedesktop.org/docs/DeviceKit/DeviceKit.html,
 
1704
http://cgit.freedesktop.org/DeviceKit/DeviceKit/tree/doc/dbus)
 
1705
      </para>
 
1706
    </sect1>
 
1707
 
 
1708
  </chapter>
1563
1709
 
1564
1710
  <chapter id="faq">
1565
 
    <title>Frequently asked question</title>
 
1711
    <title>Frequently asked questions</title>
1566
1712
 
1567
1713
    <segmentedlist>
1568
1714
      <?dbhtml list-presentation="list"?>