kernel-doc-nano-HOWTO.txt 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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/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: (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). Avoid putting a
  82. spurious blank line after the function name, or else the description will
  83. be repeated!
  84. All descriptive text is further processed, scanning for the following special
  85. patterns, which are highlighted appropriately.
  86. 'funcname()' - function
  87. '$ENVVAR' - environment variable
  88. '&struct_name' - name of a structure (up to two words including 'struct')
  89. '@parameter' - name of a parameter
  90. '%CONST' - name of a constant.
  91. Take a look around the source tree for examples.
  92. kernel-doc for structs, unions, enums, and typedefs
  93. ---------------------------------------------------
  94. Beside functions you can also write documentation for structs, unions,
  95. enums and typedefs. Instead of the function name you must write the name
  96. of the declaration; the struct/union/enum/typedef must always precede
  97. the name. Nesting of declarations is not supported.
  98. Use the argument mechanism to document members or constants.
  99. Inside a struct description, you can use the "private:" and "public:"
  100. comment tags. Structure fields that are inside a "private:" area
  101. are not listed in the generated output documentation.
  102. Example:
  103. /**
  104. * struct my_struct - short description
  105. * @a: first member
  106. * @b: second member
  107. *
  108. * Longer description
  109. */
  110. struct my_struct {
  111. int a;
  112. int b;
  113. /* private: */
  114. int c;
  115. };
  116. How to make new SGML template files
  117. -----------------------------------
  118. SGML template files (*.tmpl) are like normal SGML files, except that
  119. they can contain escape sequences where extracted documentation should
  120. be inserted.
  121. !E<filename> is replaced by the documentation, in <filename>, for
  122. functions that are exported using EXPORT_SYMBOL: the function list is
  123. collected from files listed in Documentation/DocBook/Makefile.
  124. !I<filename> is replaced by the documentation for functions that are
  125. _not_ exported using EXPORT_SYMBOL.
  126. !D<filename> is used to name additional files to search for functions
  127. exported using EXPORT_SYMBOL.
  128. !F<filename> <function [functions...]> is replaced by the
  129. documentation, in <filename>, for the functions listed.
  130. Tim.
  131. */ <twaugh@redhat.com>