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>
245 <entry>1.7.6.1</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 Be warned the PDF file generated via doxygen is extremely
286 large. At last count, the PDF file is over three thousand
287 pages. Generating this document taxes the underlying TeX
288 formatting system, and will require the expansion of TeX's memory
289 capacity. Specifically, the <literal>pool_size</literal>
290 variable in the configuration file <filename>texmf.cnf</filename> may
291 need to be increased by a minimum factor of two.
295 <section xml:id="doxygen.rules"><info><title>Generating the Doxygen Files</title></info>
298 The following Makefile rules run Doxygen to generate HTML
299 docs, XML docs, XML docs as a single file, PDF docs, and the
300 man pages. These rules are not conditional! If the required
301 tools are not found, or are the wrong versions, the rule may
306 <screen><userinput>make doc-html-doxygen</userinput></screen>
310 <screen><userinput>make doc-xml-doxygen</userinput></screen>
314 <screen><userinput>make doc-xml-single-doxygen</userinput></screen>
318 <screen><userinput>make doc-pdf-doxygen</userinput></screen>
322 <screen><userinput>make doc-man-doxygen</userinput></screen>
326 Generated files are output into separate sub directories of
327 <filename class="directory">doc/doxygen/</filename> in the
328 build directory, based on the output format. For instance, the
329 HTML docs will be in <filename class="directory">doc/doxygen/html</filename>.
333 Careful observers will see that the Makefile rules simply call
334 a script from the source tree, <filename>run_doxygen</filename>, which
335 does the actual work of running Doxygen and then (most
336 importantly) massaging the output files. If for some reason
337 you prefer to not go through the Makefile, you can call this
338 script directly. (Start by passing <literal>--help</literal>.)
342 If you wish to tweak the Doxygen settings, do so by editing
343 <filename>doc/doxygen/user.cfg.in</filename>. Notes to fellow
344 library hackers are written in triple-# comments.
349 <section xml:id="doxygen.markup"><info><title>Markup</title></info>
353 In general, libstdc++ files should be formatted according to
354 the rules found in the
355 <link linkend="contrib.coding_style">Coding Standard</link>. Before
356 any doxygen-specific formatting tweaks are made, please try to
357 make sure that the initial formatting is sound.
361 Adding Doxygen markup to a file (informally called
362 <quote>doxygenating</quote>) is very simple. The Doxygen manual can be
364 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.stack.nl/~dimitri/doxygen/download.html#latestman">here</link>.
365 We try to use a very-recent version of Doxygen.
370 <classname>deque</classname>/<classname>vector</classname>/<classname>list</classname>
371 and <classname>std::pair</classname> as examples. For
372 functions, see their member functions, and the free functions
373 in <filename>stl_algobase.h</filename>. Member functions of
374 other container-like types should read similarly to these
379 Some commentary to accompany
380 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
381 Documentation Blocks</link> section of
385 <orderedlist inheritnum="ignore" continuation="restarts">
387 <para>For longer comments, use the Javadoc style...</para>
392 ...not the Qt style. The intermediate *'s are preferred.
398 Use the triple-slash style only for one-line comments (the
399 <quote>brief</quote> mode).
405 This is disgusting. Don't do this.
411 Some specific guidelines:
415 Use the @-style of commands, not the !-style. Please be
416 careful about whitespace in your markup comments. Most of the
417 time it doesn't matter; doxygen absorbs most whitespace, and
418 both HTML and *roff are agnostic about whitespace. However,
419 in <pre> blocks and @code/@endcode sections, spacing can
420 have <quote>interesting</quote> effects.
424 Use either kind of grouping, as
425 appropriate. <filename>doxygroups.cc</filename> exists for this
426 purpose. See <filename>stl_iterator.h</filename> for a good example
427 of the <quote>other</quote> kind of grouping.
431 Please use markup tags like @p and @a when referring to things
432 such as the names of function parameters. Use @e for emphasis
433 when necessary. Use @c to refer to other standard names.
434 (Examples of all these abound in the present code.)
438 Complicated math functions should use the multi-line
439 format. An example from <filename>random.h</filename>:
443 <literallayout class="normal">
445 * @brief A model of a linear congruential random number generator.
448 * x_{i+1}\leftarrow(ax_{i} + c) \bmod m
455 One area of note is the markup required for
456 <literal>@file</literal> markup in header files. Two details
457 are important: for filenames that have the same name in
458 multiple directories, include part of the installed path to
459 disambiguate. For example:
463 <literallayout class="normal">
464 /** @file debug/vector
465 * This file is a GNU debug extension to the Standard C++ Library.
471 The other relevant detail for header files is the use of a
472 libstdc++-specific doxygen alias that helps distinguish
473 between public header files (like <filename>random</filename>)
474 from implementation or private header files (like
475 <filename>bits/c++config.h</filename>.) This alias is spelled
476 <literal>@headername</literal> and can take one or two
477 arguments that detail the public header file or files that
478 should be included to use the contents of the file. All header
479 files that are not intended for direct inclusion must use
480 <literal>headername</literal> in the <literal>file</literal>
485 <literallayout class="normal">
486 /** @file bits/basic_string.h
487 * This is an internal header file, included by other library headers.
488 * Do not attempt to use it directly. @headername{string}
494 Be careful about using certain, special characters when
495 writing Doxygen comments. Single and double quotes, and
496 separators in filenames are two common trouble spots. When in
497 doubt, consult the following table.
501 <title>HTML to Doxygen Markup Comparison</title>
503 <tgroup cols="2" align="left" colsep="1" rowsep="1">
504 <colspec colname="c1"/>
505 <colspec colname="c2"/>
510 <entry>Doxygen</entry>
531 <entry><i></entry>
532 <entry>@a word</entry>
536 <entry><b></entry>
537 <entry>@b word</entry>
541 <entry><code></entry>
542 <entry>@c word</entry>
546 <entry><em></entry>
547 <entry>@a word</entry>
551 <entry><em></entry>
552 <entry><em>two words or more</em></entry>
564 <section xml:id="doc.docbook"><info><title>Docbook</title></info>
567 <section xml:id="docbook.prereq"><info><title>Prerequisites</title></info>
571 <title>Docbook Prerequisites</title>
573 <tgroup cols="3" align="center" colsep="1" rowsep="1">
574 <colspec colname="c1"/>
575 <colspec colname="c2"/>
576 <colspec colname="c3"/>
581 <entry>Version</entry>
582 <entry>Required By</entry>
589 <entry>docbook5-style-xsl</entry>
590 <entry>1.76.1</entry>
595 <entry>xsltproc</entry>
596 <entry>1.1.26</entry>
601 <entry>xmllint</entry>
603 <entry>validation</entry>
607 <entry>dblatex</entry>
609 <entry>pdf output</entry>
613 <entry>pdflatex</entry>
614 <entry>2007-59</entry>
615 <entry>pdf output</entry>
619 <entry>docbook2X</entry>
621 <entry>info output</entry>
625 <entry>epub3 stylesheets</entry>
627 <entry>epub output</entry>
635 Editing the DocBook sources requires an XML editor. Many
636 exist: some notable options
637 include <command>emacs</command>, <application>Kate</application>,
638 or <application>Conglomerate</application>.
642 Some editors support special <quote>XML Validation</quote>
643 modes that can validate the file as it is
644 produced. Recommended is the <command>nXML Mode</command>
645 for <command>emacs</command>.
649 Besides an editor, additional DocBook files and XML tools are
654 Access to the DocBook 5.0 stylesheets and schema is required. The
655 stylesheets are usually packaged by vendor, in something
656 like <filename>docbook5-style-xsl</filename>. To exactly match
657 generated output, please use a version of the stylesheets
659 to <filename>docbook5-style-xsl-1.75.2-3</filename>. The
660 installation directory for this package corresponds to
661 the <literal>XSL_STYLE_DIR</literal>
662 in <filename>doc/Makefile.am</filename> and defaults
663 to <filename class="directory">/usr/share/sgml/docbook/xsl-ns-stylesheets</filename>.
667 For processing XML, an XSLT processor and some style
668 sheets are necessary. Defaults are <command>xsltproc</command>
669 provided by <filename>libxslt</filename>.
673 For validating the XML document, you'll need
674 something like <command>xmllint</command> and access to the
675 relevant DocBook schema. These are provided
676 by a vendor package like <filename>libxml2</filename> and <filename>docbook5-schemas-5.0-4</filename>
680 For PDF output, something that transforms valid Docbook XML to PDF is
681 required. Possible solutions include <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://dblatex.sourceforge.net">dblatex</link>,
682 <command>xmlto</command>, or <command>prince</command>. Of
683 these, <command>dblatex</command> is the default. Other
684 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
685 consult the <email>libstdc++@gcc.gnu.org</email> list when
686 preparing printed manuals for current best practice and
691 For Texinfo output, something that transforms valid Docbook
692 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>.
696 For epub output, the <link xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:href="http://sourceforge.net/projects/docbook/files/epub3/">stylesheets</link> for EPUB3 are required. These stylesheets are still in development. To validate the created file, <link xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:href="https://code.google.com/p/epubcheck/">epubcheck</link> is necessary.
700 <section xml:id="docbook.rules"><info><title>Generating the DocBook Files</title></info>
704 The following Makefile rules generate (in order): an HTML
705 version of all the DocBook documentation, a PDF version of the
706 same, and a single XML document. These rules are not
707 conditional! If the required tools are not found, or are the
708 wrong versions, the rule may end in an error.
712 <screen><userinput>make doc-html-docbook</userinput></screen>
716 <screen><userinput>make doc-pdf-docbook</userinput></screen>
720 <screen><userinput>make doc-xml-single-docbook</userinput></screen>
724 Generated files are output into separate sub directores of
725 <filename class="directory">doc/docbook/</filename> in the
726 build directory, based on the output format. For instance, the
727 HTML docs will be in <filename
728 class="directory">doc/docbook/html</filename>.
732 If the Docbook stylesheets are installed in a custom location,
733 one can use the variable <literal>XSL_STYLE_DIR</literal> to
734 override the Makefile defaults. For example:
739 make <literal>XSL_STYLE_DIR="/usr/share/xml/docbook/stylesheet/nwalsh"</literal> doc-html-docbook
745 <section xml:id="docbook.validation"><info><title>Editing and Validation</title></info>
748 After editing the xml sources, please make sure that the XML
749 documentation and markup is still valid. This can be
750 done easily, with the following validation rule:
754 <userinput>make doc-xml-validate-docbook</userinput>
758 This is equivalent to doing:
763 xmllint --noout --valid <filename>xml/index.xml</filename>
768 Please note that individual sections and chapters of the
769 manual can be validated by substituting the file desired for
770 <filename>xml/index.xml</filename> in the command
771 above. Reducing scope in this manner can be helpful when
772 validation on the entire manual fails.
776 All Docbook xml sources should always validate. No excuses!
781 <section xml:id="docbook.examples"><info><title>File Organization and Basics</title></info>
784 <literallayout class="normal">
785 <emphasis>Which files are important</emphasis>
787 All Docbook files are in the directory
790 Inside this directory, the files of importance:
791 spine.xml - index to documentation set
792 manual/spine.xml - index to manual
793 manual/*.xml - individual chapters and sections of the manual
794 faq.xml - index to FAQ
795 api.xml - index to source level / API
797 All *.txml files are template xml files, i.e., otherwise empty files with
798 the correct structure, suitable for filling in with new information.
800 <emphasis>Canonical Writing Style</emphasis>
804 member function template
805 (via C++ Templates, Vandevoorde)
807 class in namespace std: allocator, not std::allocator
809 header file: iostream, not <iostream>
812 <emphasis>General structure</emphasis>
847 <section xml:id="docbook.markup"><info><title>Markup By Example</title></info>
851 Complete details on Docbook markup can be found in the DocBook
853 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.docbook.org/tdg/en/html/part2.html">online</link>.
854 An incomplete reference for HTML to Docbook conversion is
855 detailed in the table below.
859 <title>HTML to Docbook XML Markup Comparison</title>
861 <tgroup cols="2" align="left" colsep="1" rowsep="1">
862 <colspec colname="c1"/>
863 <colspec colname="c2"/>
868 <entry>Docbook</entry>
874 <entry><p></entry>
875 <entry><para></entry>
878 <entry><pre></entry>
879 <entry><computeroutput>, <programlisting>,
880 <literallayout></entry>
883 <entry><ul></entry>
884 <entry><itemizedlist></entry>
887 <entry><ol></entry>
888 <entry><orderedlist></entry>
891 <entry><il></entry>
892 <entry><listitem></entry>
895 <entry><dl></entry>
896 <entry><variablelist></entry>
899 <entry><dt></entry>
900 <entry><term></entry>
903 <entry><dd></entry>
904 <entry><listitem></entry>
908 <entry><a href=""></entry>
909 <entry><ulink url=""></entry>
912 <entry><code></entry>
913 <entry><literal>, <programlisting></entry>
916 <entry><strong></entry>
917 <entry><emphasis></entry>
920 <entry><em></entry>
921 <entry><emphasis></entry>
925 <entry><quote></entry>
932 And examples of detailed markup for which there are no real HTML
933 equivalents are listed in the table below.
937 <title>Docbook XML Element Use</title>
939 <tgroup cols="2" align="left" colsep="1" rowsep="1">
940 <colspec colname="c1"/>
941 <colspec colname="c2"/>
945 <entry>Element</entry>
952 <entry><structname></entry>
953 <entry><structname>char_traits</structname></entry>
956 <entry><classname></entry>
957 <entry><classname>string</classname></entry>
960 <entry><function></entry>
962 <para><function>clear()</function></para>
963 <para><function>fs.clear()</function></para>
967 <entry><type></entry>
968 <entry><type>long long</type></entry>
971 <entry><varname></entry>
972 <entry><varname>fs</varname></entry>
975 <entry><literal></entry>
977 <para><literal>-Weffc++</literal></para>
978 <para><literal>rel_ops</literal></para>
982 <entry><constant></entry>
984 <para><constant>_GNU_SOURCE</constant></para>
985 <para><constant>3.0</constant></para>
989 <entry><command></entry>
990 <entry><command>g++</command></entry>
993 <entry><errortext></entry>
994 <entry><errortext>In instantiation of</errortext></entry>
997 <entry><filename></entry>
999 <para><filename class="headerfile">ctype.h</filename></para>
1000 <para><filename class="directory">/home/gcc/build</filename></para>
1001 <para><filename class="libraryfile">libstdc++.so</filename></para>