2
1

adding-packages-asciidoc.adoc 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // -*- mode:doc; -*-
  2. // vim: syntax=asciidoc
  3. === Infrastructure for asciidoc documents
  4. [[asciidoc-documents-tutorial]]
  5. The Buildroot manual, which you are currently reading, is entirely written
  6. using the http://asciidoc.org/[AsciiDoc] mark-up syntax. The manual is then
  7. rendered to many formats:
  8. * html
  9. * split-html
  10. * pdf
  11. * epub
  12. * text
  13. Although Buildroot only contains one document written in AsciiDoc, there
  14. is, as for packages, an infrastructure for rendering documents using the
  15. AsciiDoc syntax.
  16. Also as for packages, the AsciiDoc infrastructure is available from a
  17. xref:outside-br-custom[br2-external tree]. This allows documentation for
  18. a br2-external tree to match the Buildroot documentation, as it will be
  19. rendered to the same formats and use the same layout and theme.
  20. ==== +asciidoc-document+ tutorial
  21. Whereas package infrastructures are suffixed with +-package+, the document
  22. infrastructures are suffixed with +-document+. So, the AsciiDoc infrastructure
  23. is named +asciidoc-document+.
  24. Here is an example to render a simple AsciiDoc document.
  25. ----
  26. 01: ################################################################################
  27. 02: #
  28. 03: # foo-document
  29. 04: #
  30. 05: ################################################################################
  31. 06:
  32. 07: FOO_SOURCES = $(sort $(wildcard $(FOO_DOCDIR)/*))
  33. 08: $(eval $(call asciidoc-document))
  34. ----
  35. On line 7, the Makefile declares what the sources of the document are.
  36. Currently, it is expected that the document's sources are only local;
  37. Buildroot will not attempt to download anything to render a document.
  38. Thus, you must indicate where the sources are. Usually, the string
  39. above is sufficient for a document with no sub-directory structure.
  40. On line 8, we call the +asciidoc-document+ function, which generates all
  41. the Makefile code necessary to render the document.
  42. ==== +asciidoc-document+ reference
  43. The list of variables that can be set in a +.mk+ file to give metadata
  44. information is (assuming the document name is +foo+) :
  45. * +FOO_SOURCES+, mandatory, defines the source files for the document.
  46. * +FOO_RESOURCES+, optional, may contain a space-separated list of paths
  47. to one or more directories containing so-called resources (like CSS or
  48. images). By default, empty.
  49. * +FOO_DEPENDENCIES+, optional, the list of packages (most probably,
  50. host-packages) that must be built before building this document.
  51. * +FOO_TOC_DEPTH+, +FOO_TOC_DEPTH_<FMT>+, optionals, the depth of the
  52. table of content for this document, which can be overridden for the
  53. specified format +<FMT>+ (see the list of rendered formats, above,
  54. but in uppercase, and with dash replaced by underscore; see example,
  55. below). By default: +1+.
  56. There are also additional hooks (see xref:hooks[] for general information
  57. on hooks), that a document may set to define extra actions to be done at
  58. various steps:
  59. * +FOO_POST_RSYNC_HOOKS+ to run additional commands after the sources
  60. have been copied by Buildroot. This can for example be used to
  61. generate part of the manual with information extracted from the
  62. tree. As an example, Buildroot uses this hook to generate the tables
  63. in the appendices.
  64. * +FOO_CHECK_DEPENDENCIES_HOOKS+ to run additional tests on required
  65. components to generate the document. In AsciiDoc, it is possible to
  66. call filters, that is, programs that will parse an AsciiDoc block and
  67. render it appropriately (e.g. http://ditaa.sourceforge.net/[ditaa] or
  68. https://pythonhosted.org/aafigure/[aafigure]).
  69. * +FOO_CHECK_DEPENDENCIES_<FMT>_HOOKS+, to run additional tests for
  70. the specified format +<FMT>+ (see the list of rendered formats, above).
  71. Buildroot sets the following variable that can be used in the definitions
  72. above:
  73. * +$(FOO_DOCDIR)+, similar to +$(FOO_PKGDIR)+, contains the path to the
  74. directory containing +foo.mk+. It can be used to refer to the document
  75. sources, and can be used in the hooks, especially the post-rsync hook
  76. if parts of the documentation needs to be generated.
  77. * +$(@D)+, as for traditional packages, contains the path to the directory
  78. where the document will be copied and built.
  79. Here is a complete example that uses all variables and all hooks:
  80. ----
  81. 01: ################################################################################
  82. 02: #
  83. 03: # foo-document
  84. 04: #
  85. 05: ################################################################################
  86. 06:
  87. 07: FOO_SOURCES = $(sort $(wildcard $(FOO_DOCDIR)/*))
  88. 08: FOO_RESOURCES = $(sort $(wildcard $(FOO_DOCDIR)/resources))
  89. 09:
  90. 10: FOO_TOC_DEPTH = 2
  91. 11: FOO_TOC_DEPTH_HTML = 1
  92. 12: FOO_TOC_DEPTH_SPLIT_HTML = 3
  93. 13:
  94. 14: define FOO_GEN_EXTRA_DOC
  95. 15: /path/to/generate-script --outdir=$(@D)
  96. 16: endef
  97. 17: FOO_POST_RSYNC_HOOKS += FOO_GEN_EXTRA_DOC
  98. 18:
  99. 19: define FOO_CHECK_MY_PROG
  100. 20: if ! which my-prog >/dev/null 2>&1; then \
  101. 21: echo "You need my-prog to generate the foo document"; \
  102. 22: exit 1; \
  103. 23: fi
  104. 24: endef
  105. 25: FOO_CHECK_DEPENDENCIES_HOOKS += FOO_CHECK_MY_PROG
  106. 26:
  107. 27: define FOO_CHECK_MY_OTHER_PROG
  108. 28: if ! which my-other-prog >/dev/null 2>&1; then \
  109. 29: echo "You need my-other-prog to generate the foo document as PDF"; \
  110. 30: exit 1; \
  111. 31: fi
  112. 32: endef
  113. 33: FOO_CHECK_DEPENDENCIES_PDF_HOOKS += FOO_CHECK_MY_OTHER_PROG
  114. 34:
  115. 35: $(eval $(call asciidoc-document))
  116. ----