parse-headers.rst 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. ===========================
  2. Including uAPI header files
  3. ===========================
  4. Sometimes, it is useful to include header files and C example codes in
  5. order to describe the userspace API and to generate cross-references
  6. between the code and the documentation. Adding cross-references for
  7. userspace API files has an additional vantage: Sphinx will generate warnings
  8. if a symbol is not found at the documentation. That helps to keep the
  9. uAPI documentation in sync with the Kernel changes.
  10. The :ref:`parse_headers.pl <parse_headers>` provide a way to generate such
  11. cross-references. It has to be called via Makefile, while building the
  12. documentation. Please see ``Documentation/userspace-api/media/Makefile`` for an example
  13. about how to use it inside the Kernel tree.
  14. .. _parse_headers:
  15. parse_headers.pl
  16. ^^^^^^^^^^^^^^^^
  17. NAME
  18. ****
  19. parse_headers.pl - parse a C file, in order to identify functions, structs,
  20. enums and defines and create cross-references to a Sphinx book.
  21. SYNOPSIS
  22. ********
  23. \ **parse_headers.pl**\ [<options>] <C_FILE> <OUT_FILE> [<EXCEPTIONS_FILE>]
  24. Where <options> can be: --debug, --help or --usage.
  25. OPTIONS
  26. *******
  27. \ **--debug**\
  28. Put the script in verbose mode, useful for debugging.
  29. \ **--usage**\
  30. Prints a brief help message and exits.
  31. \ **--help**\
  32. Prints a more detailed help message and exits.
  33. DESCRIPTION
  34. ***********
  35. Convert a C header or source file (C_FILE), into a ReStructured Text
  36. included via ..parsed-literal block with cross-references for the
  37. documentation files that describe the API. It accepts an optional
  38. EXCEPTIONS_FILE with describes what elements will be either ignored or
  39. be pointed to a non-default reference.
  40. The output is written at the (OUT_FILE).
  41. It is capable of identifying defines, functions, structs, typedefs,
  42. enums and enum symbols and create cross-references for all of them.
  43. It is also capable of distinguish #define used for specifying a Linux
  44. ioctl.
  45. The EXCEPTIONS_FILE contain two types of statements: \ **ignore**\ or \ **replace**\ .
  46. The syntax for the ignore tag is:
  47. ignore \ **type**\ \ **name**\
  48. The \ **ignore**\ means that it won't generate cross references for a
  49. \ **name**\ symbol of type \ **type**\ .
  50. The syntax for the replace tag is:
  51. replace \ **type**\ \ **name**\ \ **new_value**\
  52. The \ **replace**\ means that it will generate cross references for a
  53. \ **name**\ symbol of type \ **type**\ , but, instead of using the default
  54. replacement rule, it will use \ **new_value**\ .
  55. For both statements, \ **type**\ can be either one of the following:
  56. \ **ioctl**\
  57. The ignore or replace statement will apply to ioctl definitions like:
  58. #define VIDIOC_DBG_S_REGISTER _IOW('V', 79, struct v4l2_dbg_register)
  59. \ **define**\
  60. The ignore or replace statement will apply to any other #define found
  61. at C_FILE.
  62. \ **typedef**\
  63. The ignore or replace statement will apply to typedef statements at C_FILE.
  64. \ **struct**\
  65. The ignore or replace statement will apply to the name of struct statements
  66. at C_FILE.
  67. \ **enum**\
  68. The ignore or replace statement will apply to the name of enum statements
  69. at C_FILE.
  70. \ **symbol**\
  71. The ignore or replace statement will apply to the name of enum value
  72. at C_FILE.
  73. For replace statements, \ **new_value**\ will automatically use :c:type:
  74. references for \ **typedef**\ , \ **enum**\ and \ **struct**\ types. It will use :ref:
  75. for \ **ioctl**\ , \ **define**\ and \ **symbol**\ types. The type of reference can
  76. also be explicitly defined at the replace statement.
  77. EXAMPLES
  78. ********
  79. ignore define _VIDEODEV2_H
  80. Ignore a #define _VIDEODEV2_H at the C_FILE.
  81. ignore symbol PRIVATE
  82. On a struct like:
  83. enum foo { BAR1, BAR2, PRIVATE };
  84. It won't generate cross-references for \ **PRIVATE**\ .
  85. replace symbol BAR1 :c:type:\`foo\`
  86. replace symbol BAR2 :c:type:\`foo\`
  87. On a struct like:
  88. enum foo { BAR1, BAR2, PRIVATE };
  89. It will make the BAR1 and BAR2 enum symbols to cross reference the foo
  90. symbol at the C domain.
  91. BUGS
  92. ****
  93. Report bugs to Mauro Carvalho Chehab <[email protected]>
  94. COPYRIGHT
  95. *********
  96. Copyright (c) 2016 by Mauro Carvalho Chehab <[email protected]>.
  97. License GPLv2: GNU GPL version 2 <https://gnu.org/licenses/gpl.html>.
  98. This is free software: you are free to change and redistribute it.
  99. There is NO WARRANTY, to the extent permitted by law.