1 <section xmlns="http://docbook.org/ns/docbook" version="5.0"
2 xml:id="appendix.porting.doc" xreflabel="Documentation Hacking">
3 <?dbhtml filename="documentation_hacking.html"?>
5 <info><title>Writing and Generating Documentation</title>
7 <keyword>ISO C++</keyword>
8 <keyword>documentation</keyword>
9 <keyword>style</keyword>
10 <keyword>docbook</keyword>
11 <keyword>doxygen</keyword>
15 <section xml:id="doc.intro">
17 <title>Introduction</title>
20 Documentation for the GNU C++ Library is created from three
21 independent sources: a manual, a FAQ, and an API reference.
24 The sub-directory <filename class="directory">doc</filename>
25 within the main source directory contains
26 <filename>Makefile.am</filename> and
27 <filename>Makefile.in</filename>, which provide rules for
28 generating documentation, described in excruciating detail
29 below. The <filename class="directory">doc</filename>
30 sub-directory also contains three directories: <filename
31 class="directory">doxygen</filename>, which contains scripts and
32 fragments for <command>doxygen</command>, <filename
33 class="directory">html</filename>, which contains an html
34 version of the manual, and <filename
35 class="directory">xml</filename>, which contains an xml version
39 Diverging from established documentation conventions in the rest
40 of the GCC project, libstdc++ does not use Texinfo as a markup
41 language. Instead, Docbook is used to create the manual and the
42 FAQ, and Doxygen is used to construct the API
43 reference. Although divergent, this conforms to the GNU Project
44 recommendations as long as the output is of sufficient quality,
46 <link xmlns:xlink="http://www.w3.org/1999/xlink"
47 xlink:href="http://www.gnu.org/prep/standards/standards.html#Documentation">
52 <section xml:id="doc.generation">
54 <title>Generating Documentation</title>
58 Certain Makefile rules are required by the GNU Coding
59 Standards. These standard rules generate HTML, PDF, XML, or man
60 files. For each of the generative rules, there is an additional
61 install rule that is used to install any generated documentation
62 files into the prescribed installation directory. Files are
63 installed into <filename class="directory">share/doc</filename>
64 or <filename class="directory">share/man</filename> directories.
68 The standard Makefile rules are conditionally supported, based
69 on the results of examining the host environment for
70 prerequisites at configuration time. If requirements are not
71 found, the rule is aliased to a dummy rule that does nothing,
72 and produces no documentation. If the requirements are found,
73 the rule forwards to a private rule that produces the requested
78 For more details on what prerequisites were found and where,
79 please consult the file <filename>config.log</filename> in the
80 libstdc++ build directory. Compare this log to what is expected
81 for the relevant Makefile conditionals:
82 <literal>BUILD_INFO</literal>, <literal>BUILD_XML</literal>,
83 <literal>BUILD_HTML</literal>, <literal>BUILD_MAN</literal>,
84 <literal>BUILD_PDF</literal>, and <literal>BUILD_EPUB</literal>.
88 Supported Makefile rules:
94 <emphasis>make html</emphasis>
97 <emphasis>make install-html</emphasis>
101 Generates multi-page HTML documentation, and installs it
102 in the following directories:
105 <filename class="directory">
106 doc/libstdc++/libstdc++-api.html
110 <filename class="directory">
111 doc/libstdc++/libstdc++-manual.html
119 <emphasis>make pdf</emphasis>
122 <emphasis>make install-pdf</emphasis>
126 Generates indexed PDF documentation, and installs it as
130 <filename>doc/libstdc++/libstdc++-api.pdf</filename>
133 <filename>doc/libstdc++/libstdc++-manual.pdf</filename>
140 <emphasis>make man</emphasis>
143 <emphasis>make install-man</emphasis>
147 Generates man pages, and installs it in the following directory:
150 <filename class="directory">man/man3/</filename>
153 The generated man pages are namespace-qualified, so to look at
154 the man page for <classname>vector</classname>, one would use
155 <command>man std::vector</command>.
162 <emphasis>make epub</emphasis>
165 <emphasis>make install-epub</emphasis>
169 Generates documentation in the ebook/portable electronic
170 reader format called Epub, and installs it as the
174 <filename>doc/libstdc++/libstdc++-manual.epub</filename>
181 <emphasis>make xml</emphasis>
184 <emphasis>make install-xml</emphasis>
188 Generates single-file XML documentation, and installs it
189 as the following files:
192 <filename>doc/libstdc++/libstdc++-api-single.xml</filename>
195 <filename>doc/libstdc++/libstdc++-manual-single.xml</filename>
202 Makefile rules for several other formats are explicitly not
203 supported, and are always aliased to dummy rules. These
204 unsupported formats are: <emphasis>info</emphasis>,
205 <emphasis>ps</emphasis>, and <emphasis>dvi</emphasis>.
209 <section xml:id="doc.doxygen"><info><title>Doxygen</title></info>
211 <section xml:id="doxygen.prereq"><info><title>Prerequisites</title></info>
214 <title>Doxygen Prerequisites</title>
216 <tgroup cols="3" align="center" colsep="1" rowsep="1">
217 <colspec colname="c1"/>
218 <colspec colname="c2"/>
219 <colspec colname="c3"/>
224 <entry>Version</entry>
225 <entry>Required By</entry>
232 <entry>coreutils</entry>
244 <entry>doxygen</entry>
250 <entry>graphviz</entry>
252 <entry>graphical hierarchies</entry>
256 <entry>pdflatex</entry>
257 <entry>2007-59</entry>
258 <entry>pdf output</entry>
267 Prerequisite tools are Bash 2.0 or later,
268 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.doxygen.org/">Doxygen</link>, and
269 the <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.gnu.org/software/coreutils/">GNU
270 coreutils</link>. (GNU versions of find, xargs, and possibly
271 sed and grep are used, just because the GNU versions make
276 To generate the pretty pictures and hierarchy
278 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.graphviz.org">Graphviz</link> package
279 will need to be installed. For PDF
280 output, <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.tug.org/applications/pdftex/">
281 pdflatex</link> is required.
285 <section xml:id="doxygen.rules"><info><title>Generating the Doxygen Files</title></info>
288 The following Makefile rules run Doxygen to generate HTML
289 docs, XML docs, XML docs as a single file, PDF docs, and the
290 man pages. These rules are not conditional! If the required
291 tools are not found, or are the wrong versions, the rule may
296 <screen><userinput>make doc-html-doxygen</userinput></screen>
300 <screen><userinput>make doc-xml-doxygen</userinput></screen>
304 <screen><userinput>make doc-xml-single-doxygen</userinput></screen>
308 <screen><userinput>make doc-pdf-doxygen</userinput></screen>
312 <screen><userinput>make doc-man-doxygen</userinput></screen>
316 Generated files are output into separate sub directories of
317 <filename class="directory">doc/doxygen/</filename> in the
318 build directory, based on the output format. For instance, the
319 HTML docs will be in <filename class="directory">doc/doxygen/html</filename>.
323 Careful observers will see that the Makefile rules simply call
324 a script from the source tree, <filename>run_doxygen</filename>, which
325 does the actual work of running Doxygen and then (most
326 importantly) massaging the output files. If for some reason
327 you prefer to not go through the Makefile, you can call this
328 script directly. (Start by passing <literal>--help</literal>.)
332 If you wish to tweak the Doxygen settings, do so by editing
333 <filename>doc/doxygen/user.cfg.in</filename>. Notes to fellow
334 library hackers are written in triple-# comments.
339 <section xml:id="doxygen.markup"><info><title>Markup</title></info>
343 In general, libstdc++ files should be formatted according to
344 the rules found in the
345 <link linkend="contrib.coding_style">Coding Standard</link>. Before
346 any doxygen-specific formatting tweaks are made, please try to
347 make sure that the initial formatting is sound.
351 Adding Doxygen markup to a file (informally called
352 <quote>doxygenating</quote>) is very simple. The Doxygen manual can be
354 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.stack.nl/~dimitri/doxygen/download.html#latestman">here</link>.
355 We try to use a very-recent version of Doxygen.
360 <classname>deque</classname>/<classname>vector</classname>/<classname>list</classname>
361 and <classname>std::pair</classname> as examples. For
362 functions, see their member functions, and the free functions
363 in <filename>stl_algobase.h</filename>. Member functions of
364 other container-like types should read similarly to these
369 Some commentary to accompany
370 the first list in the <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.stack.nl/~dimitri/doxygen/docblocks.html">Special
371 Documentation Blocks</link> section of
375 <orderedlist inheritnum="ignore" continuation="restarts">
377 <para>For longer comments, use the Javadoc style...</para>
382 ...not the Qt style. The intermediate *'s are preferred.
388 Use the triple-slash style only for one-line comments (the
389 <quote>brief</quote> mode).
395 This is disgusting. Don't do this.
401 Some specific guidelines:
405 Use the @-style of commands, not the !-style. Please be
406 careful about whitespace in your markup comments. Most of the
407 time it doesn't matter; doxygen absorbs most whitespace, and
408 both HTML and *roff are agnostic about whitespace. However,
409 in <pre> blocks and @code/@endcode sections, spacing can
410 have <quote>interesting</quote> effects.
414 Use either kind of grouping, as
415 appropriate. <filename>doxygroups.cc</filename> exists for this
416 purpose. See <filename>stl_iterator.h</filename> for a good example
417 of the <quote>other</quote> kind of grouping.
421 Please use markup tags like @p and @a when referring to things
422 such as the names of function parameters. Use @e for emphasis
423 when necessary. Use @c to refer to other standard names.
424 (Examples of all these abound in the present code.)
428 Complicated math functions should use the multi-line
429 format. An example from <filename>random.h</filename>:
433 <literallayout class="normal">
435 * @brief A model of a linear congruential random number generator.
438 * x_{i+1}\leftarrow(ax_{i} + c) \bmod m
445 One area of note is the markup required for
446 <literal>@file</literal> markup in header files. Two details
447 are important: for filenames that have the same name in
448 multiple directories, include part of the installed path to
449 disambiguate. For example:
453 <literallayout class="normal">
454 /** @file debug/vector
455 * This file is a GNU debug extension to the Standard C++ Library.
461 The other relevant detail for header files is the use of a
462 libstdc++-specific doxygen alias that helps distinguish
463 between public header files (like <filename>random</filename>)
464 from implementation or private header files (like
465 <filename>bits/c++config.h</filename>.) This alias is spelled
466 <literal>@headername</literal> and can take one or two
467 arguments that detail the public header file or files that
468 should be included to use the contents of the file. All header
469 files that are not intended for direct inclusion must use
470 <literal>headername</literal> in the <literal>file</literal>
475 <literallayout class="normal">
476 /** @file bits/basic_string.h
477 * This is an internal header file, included by other library headers.
478 * Do not attempt to use it directly. @headername{string}
484 Be careful about using certain, special characters when
485 writing Doxygen comments. Single and double quotes, and
486 separators in filenames are two common trouble spots. When in
487 doubt, consult the following table.
491 <title>HTML to Doxygen Markup Comparison</title>
493 <tgroup cols="2" align="left" colsep="1" rowsep="1">
494 <colspec colname="c1"/>
495 <colspec colname="c2"/>
500 <entry>Doxygen</entry>
521 <entry><i></entry>
522 <entry>@a word</entry>
526 <entry><b></entry>
527 <entry>@b word</entry>
531 <entry><code></entry>
532 <entry>@c word</entry>
536 <entry><em></entry>
537 <entry>@a word</entry>
541 <entry><em></entry>
542 <entry><em>two words or more</em></entry>
554 <section xml:id="doc.docbook"><info><title>Docbook</title></info>
557 <section xml:id="docbook.prereq"><info><title>Prerequisites</title></info>
561 <title>Docbook Prerequisites</title>
563 <tgroup cols="3" align="center" colsep="1" rowsep="1">
564 <colspec colname="c1"/>
565 <colspec colname="c2"/>
566 <colspec colname="c3"/>
571 <entry>Version</entry>
572 <entry>Required By</entry>
579 <entry>docbook5-style-xsl</entry>
580 <entry>1.76.1</entry>
585 <entry>xsltproc</entry>
586 <entry>1.1.26</entry>
591 <entry>xmllint</entry>
593 <entry>validation</entry>
597 <entry>dblatex</entry>
599 <entry>pdf output</entry>
603 <entry>pdflatex</entry>
604 <entry>2007-59</entry>
605 <entry>pdf output</entry>
609 <entry>docbook2X</entry>
611 <entry>info output</entry>
619 Editing the DocBook sources requires an XML editor. Many
620 exist: some notable options
621 include <command>emacs</command>, <application>Kate</application>,
622 or <application>Conglomerate</application>.
626 Some editors support special <quote>XML Validation</quote>
627 modes that can validate the file as it is
628 produced. Recommended is the <command>nXML Mode</command>
629 for <command>emacs</command>.
633 Besides an editor, additional DocBook files and XML tools are
638 Access to the DocBook 5.0 stylesheets and schema is required. The
639 stylesheets are usually packaged by vendor, in something
640 like <filename>docbook5-style-xsl</filename>. To exactly match
641 generated output, please use a version of the stylesheets
643 to <filename>docbook5-style-xsl-1.75.2-3</filename>. The
644 installation directory for this package corresponds to
645 the <literal>XSL_STYLE_DIR</literal>
646 in <filename>doc/Makefile.am</filename> and defaults
647 to <filename class="directory">/usr/share/sgml/docbook/xsl-ns-stylesheets</filename>.
651 For processing XML, an XML processor and some style
652 sheets are necessary. Defaults are <command>xsltproc</command>
653 provided by <filename>libxslt</filename>.
657 For validating the XML document, you'll need
658 something like <command>xmllint</command> and access to the
659 relevant DocBook schema. These are provided
660 by a vendor package like <filename>libxml2</filename> and <filename>docbook5-schemas-5.0-4</filename>
664 For PDF output, something that transforms valid Docbook XML to PDF is
665 required. Possible solutions include <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://dblatex.sourceforge.net">dblatex</link>,
666 <command>xmlto</command>, or <command>prince</command>. Of
667 these, <command>dblatex</command> is the default. Other
668 options are listed on the DocBook web <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://wiki.docbook.org/topic/DocBookPublishingTools">pages</link>. Please
669 consult the <email>libstdc++@gcc.gnu.org</email> list when
670 preparing printed manuals for current best practice and
675 For Texinfo output, something that transforms valid Docbook
676 XML to Texinfo is required. The default choice is <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://docbook2x.sourceforge.net/">docbook2X</link>.
680 <section xml:id="docbook.rules"><info><title>Generating the DocBook Files</title></info>
684 The following Makefile rules generate (in order): an HTML
685 version of all the DocBook documentation, a PDF version of the
686 same, and a single XML document. These rules are not
687 conditional! If the required tools are not found, or are the
688 wrong versions, the rule may end in an error.
692 <screen><userinput>make doc-html-docbook</userinput></screen>
696 <screen><userinput>make doc-pdf-docbook</userinput></screen>
700 <screen><userinput>make doc-xml-single-docbook</userinput></screen>
704 Generated files are output into separate sub directores of
705 <filename class="directory">doc/docbook/</filename> in the
706 build directory, based on the output format. For instance, the
707 HTML docs will be in <filename
708 class="directory">doc/docbook/html</filename>.
712 If the Docbook stylesheets are installed in a custom location,
713 one can use the variable <literal>XSL_STYLE_DIR</literal> to
714 over-ride the Makefile defaults. As so:
719 make <literal>XSL_STYLE_DIR="/usr/share/xml/docbook/stylesheet/nwalsh"</literal> doc-html-docbook
725 <section xml:id="docbook.validation"><info><title>Editing and Validation</title></info>
728 After editing the xml sources, please make sure that the XML
729 documentation and markup is still valid. This can be
730 done easily, with the following validation rule:
734 <userinput>make doc-xml-validate-docbook</userinput>
738 This is equivalent to doing:
743 xmllint --noout --valid <filename>xml/index.xml</filename>
748 Please note that individual sections and chapters of the
749 manual can be validated by substituting the file desired for
750 <filename>xml/index.xml</filename> in the command
751 above. Reducing scope in this manner can be helpful when
752 validation on the entire manual fails.
756 All Docbook xml sources should always validate. No excuses!
761 <section xml:id="docbook.examples"><info><title>File Organization and Basics</title></info>
764 <literallayout class="normal">
765 <emphasis>Which files are important</emphasis>
767 All Docbook files are in the directory
770 Inside this directory, the files of importance:
771 spine.xml - index to documentation set
772 manual/spine.xml - index to manual
773 manual/*.xml - individual chapters and sections of the manual
774 faq.xml - index to FAQ
775 api.xml - index to source level / API
777 All *.txml files are template xml files, i.e., otherwise empty files with
778 the correct structure, suitable for filling in with new information.
780 <emphasis>Canonical Writing Style</emphasis>
784 member function template
785 (via C++ Templates, Vandevoorde)
787 class in namespace std: allocator, not std::allocator
789 header file: iostream, not <iostream>
792 <emphasis>General structure</emphasis>
827 <section xml:id="docbook.markup"><info><title>Markup By Example</title></info>
831 Complete details on Docbook markup can be found in the DocBook
833 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.docbook.org/tdg/en/html/part2.html">online</link>.
834 An incomplete reference for HTML to Docbook conversion is
835 detailed in the table below.
839 <title>HTML to Docbook XML Markup Comparison</title>
841 <tgroup cols="2" align="left" colsep="1" rowsep="1">
842 <colspec colname="c1"/>
843 <colspec colname="c2"/>
848 <entry>Docbook</entry>
854 <entry><p></entry>
855 <entry><para></entry>
858 <entry><pre></entry>
859 <entry><computeroutput>, <programlisting>,
860 <literallayout></entry>
863 <entry><ul></entry>
864 <entry><itemizedlist></entry>
867 <entry><ol></entry>
868 <entry><orderedlist></entry>
871 <entry><il></entry>
872 <entry><listitem></entry>
875 <entry><dl></entry>
876 <entry><variablelist></entry>
879 <entry><dt></entry>
880 <entry><term></entry>
883 <entry><dd></entry>
884 <entry><listitem></entry>
888 <entry><a href=""></entry>
889 <entry><ulink url=""></entry>
892 <entry><code></entry>
893 <entry><literal>, <programlisting></entry>
896 <entry><strong></entry>
897 <entry><emphasis></entry>
900 <entry><em></entry>
901 <entry><emphasis></entry>
905 <entry><quote></entry>
912 And examples of detailed markup for which there are no real HTML
913 equivalents are listed in the table below.
917 <title>Docbook XML Element Use</title>
919 <tgroup cols="2" align="left" colsep="1" rowsep="1">
920 <colspec colname="c1"/>
921 <colspec colname="c2"/>
925 <entry>Element</entry>
932 <entry><structname></entry>
933 <entry><structname>char_traits</structname></entry>
936 <entry><classname></entry>
937 <entry><classname>string</classname></entry>
940 <entry><function></entry>
942 <para><function>clear()</function></para>
943 <para><function>fs.clear()</function></para>
947 <entry><type></entry>
948 <entry><type>long long</type></entry>
951 <entry><varname></entry>
952 <entry><varname>fs</varname></entry>
955 <entry><literal></entry>
957 <para><literal>-Weffc++</literal></para>
958 <para><literal>rel_ops</literal></para>
962 <entry><constant></entry>
964 <para><constant>_GNU_SOURCE</constant></para>
965 <para><constant>3.0</constant></para>
969 <entry><command></entry>
970 <entry><command>g++</command></entry>
973 <entry><errortext></entry>
974 <entry><errortext>In instantiation of</errortext></entry>
977 <entry><filename></entry>
979 <para><filename class="headerfile">ctype.h</filename></para>
980 <para><filename class="directory">/home/gcc/build</filename></para>
981 <para><filename class="libraryfile">libstdc++.so</filename></para>