kernel-doc-nano-HOWTO.txt 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. kernel-doc nano-HOWTO
  2. =====================
  3. Many places in the source tree have extractable documentation in the
  4. form of block comments above functions. The components of this system
  5. are:
  6. - scripts/kernel-doc
  7. This is a perl script that hunts for the block comments and can mark
  8. them up directly into DocBook, man, text, and HTML. (No, not
  9. texinfo.)
  10. - Documentation/DocBook/*.tmpl
  11. These are SGML template files, which are normal SGML files with
  12. special place-holders for where the extracted documentation should
  13. go.
  14. - scripts/basic/docproc.c
  15. This is a program for converting SGML template files into SGML
  16. files. When a file is referenced it is searched for symbols
  17. exported (EXPORT_SYMBOL), to be able to distinguish between internal
  18. and external functions.
  19. It invokes kernel-doc, giving it the list of functions that
  20. are to be documented.
  21. Additionally it is used to scan the SGML template files to locate
  22. all the files referenced herein. This is used to generate dependency
  23. information as used by make.
  24. - Makefile
  25. The targets 'sgmldocs', 'psdocs', 'pdfdocs', and 'htmldocs' are used
  26. to build DocBook files, PostScript files, PDF files, and html files
  27. in Documentation/DocBook.
  28. - Documentation/DocBook/Makefile
  29. This is where C files are associated with SGML templates.
  30. How to extract the documentation
  31. --------------------------------
  32. If you just want to read the ready-made books on the various
  33. subsystems (see Documentation/DocBook/*.tmpl), just type 'make
  34. psdocs', or 'make pdfdocs', or 'make htmldocs', depending on your
  35. preference. If you would rather read a different format, you can type
  36. 'make sgmldocs' and then use DocBook tools to convert
  37. Documentation/DocBook/*.sgml to a format of your choice (for example,
  38. 'db2html ...' if 'make htmldocs' was not defined).
  39. If you want to see man pages instead, you can do this:
  40. $ cd linux
  41. $ scripts/kernel-doc -man $(find -name '*.c') | split-man.pl /tmp/man
  42. $ scripts/kernel-doc -man $(find -name '*.h') | split-man.pl /tmp/man
  43. Here is split-man.pl:
  44. -->
  45. #!/usr/bin/perl
  46. if ($#ARGV < 0) {
  47. die "where do I put the results?\n";
  48. }
  49. mkdir $ARGV[0],0777;
  50. $state = 0;
  51. while (<STDIN>) {
  52. if (/^\.TH \"[^\"]*\" 4 \"([^\"]*)\"/) {
  53. if ($state == 1) { close OUT }
  54. $state = 1;
  55. $fn = "$ARGV[0]/$1.4";
  56. print STDERR "Creating $fn\n";
  57. open OUT, ">$fn" or die "can't open $fn: $!\n";
  58. print OUT $_;
  59. } elsif ($state != 0) {
  60. print OUT $_;
  61. }
  62. }
  63. close OUT;
  64. <--
  65. If you just want to view the documentation for one function in one
  66. file, you can do this:
  67. $ scripts/kernel-doc -man -function fn file | nroff -man | less
  68. or this:
  69. $ scripts/kernel-doc -text -function fn file
  70. How to add extractable documentation to your source files
  71. ---------------------------------------------------------
  72. The format of the block comment is like this:
  73. /**
  74. * function_name(:)? (- short description)?
  75. (* @parameterx(space)*: (description of parameter x)?)*
  76. (* a blank line)?
  77. * (Description:)? (Description of function)?
  78. * (section header: (section description)? )*
  79. (*)?*/
  80. The short function description ***cannot be multiline***, but the other
  81. descriptions can be (and they can contain blank lines). If you continue
  82. that initial short description onto a second line, that second line will
  83. appear further down at the beginning of the description section, which is
  84. almost certainly not what you had in mind.
  85. Avoid putting a spurious blank line after the function name, or else the
  86. description will be repeated!
  87. All descriptive text is further processed, scanning for the following special
  88. patterns, which are highlighted appropriately.
  89. 'funcname()' - function
  90. '$ENVVAR' - environment variable
  91. '&struct_name' - name of a structure (up to two words including 'struct')
  92. '@parameter' - name of a parameter
  93. '%CONST' - name of a constant.
  94. NOTE 1: The multi-line descriptive text you provide does *not* recognize
  95. line breaks, so if you try to format some text nicely, as in:
  96. Return codes
  97. 0 - cool
  98. 1 - invalid arg
  99. 2 - out of memory
  100. this will all run together and produce:
  101. Return codes 0 - cool 1 - invalid arg 2 - out of memory
  102. NOTE 2: If the descriptive text you provide has lines that begin with
  103. some phrase followed by a colon, each of those phrases will be taken as
  104. a new section heading, which means you should similarly try to avoid text
  105. like:
  106. Return codes:
  107. 0: cool
  108. 1: invalid arg
  109. 2: out of memory
  110. every line of which would start a new section. Again, probably not
  111. what you were after.
  112. Take a look around the source tree for examples.
  113. kernel-doc for structs, unions, enums, and typedefs
  114. ---------------------------------------------------
  115. Beside functions you can also write documentation for structs, unions,
  116. enums and typedefs. Instead of the function name you must write the name
  117. of the declaration; the struct/union/enum/typedef must always precede
  118. the name. Nesting of declarations is not supported.
  119. Use the argument mechanism to document members or constants.
  120. Inside a struct description, you can use the "private:" and "public:"
  121. comment tags. Structure fields that are inside a "private:" area
  122. are not listed in the generated output documentation.
  123. Example:
  124. /**
  125. * struct my_struct - short description
  126. * @a: first member
  127. * @b: second member
  128. *
  129. * Longer description
  130. */
  131. struct my_struct {
  132. int a;
  133. int b;
  134. /* private: */
  135. int c;
  136. };
  137. How to make new SGML template files
  138. -----------------------------------
  139. SGML template files (*.tmpl) are like normal SGML files, except that
  140. they can contain escape sequences where extracted documentation should
  141. be inserted.
  142. !E<filename> is replaced by the documentation, in <filename>, for
  143. functions that are exported using EXPORT_SYMBOL: the function list is
  144. collected from files listed in Documentation/DocBook/Makefile.
  145. !I<filename> is replaced by the documentation for functions that are
  146. _not_ exported using EXPORT_SYMBOL.
  147. !D<filename> is used to name additional files to search for functions
  148. exported using EXPORT_SYMBOL.
  149. !F<filename> <function [functions...]> is replaced by the
  150. documentation, in <filename>, for the functions listed.
  151. Tim.
  152. */ <twaugh@redhat.com>