doc-asciidoc.mk 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. # we can't use suitable-host-package here because that's not available in
  2. # the context of 'make release'
  3. .PHONY: asciidoc-check-dependencies
  4. asciidoc-check-dependencies:
  5. $(Q)if [ -z "$(shell support/dependencies/check-host-asciidoc.sh)" ]; then \
  6. echo "You need a sufficiently recent asciidoc on your host" \
  7. "to generate documents"; \
  8. exit 1; \
  9. fi
  10. $(Q)if [ -z "`which w3m 2>/dev/null`" ]; then \
  11. echo "You need w3m on your host to generate documents"; \
  12. exit 1; \
  13. fi
  14. asciidoc-check-dependencies-pdf:
  15. $(Q)if [ -z "`which dblatex 2>/dev/null`" ]; then \
  16. echo "You need dblatex on your host to generate PDF documents"; \
  17. exit 1; \
  18. fi
  19. # PDF generation is broken because of a bug in xsltproc program provided
  20. # by libxslt <=1.1.28, which does not honor an option we need to set.
  21. # Fortunately, this bug is already fixed upstream:
  22. # https://gitorious.org/libxslt/libxslt/commit/5af7ad745323004984287e48b42712e7305de35c
  23. #
  24. # So, bail out when trying to build a PDF using a buggy version of the
  25. # xsltproc program.
  26. #
  27. # So, to overcome this issue and being able to build a PDF, you can
  28. # build xsltproc from its source repository, then run:
  29. # $ PATH=/path/to/custom-xsltproc/bin:${PATH} make manual
  30. GENDOC_XSLTPROC_IS_BROKEN = \
  31. $(shell xsltproc --maxvars 0 >/dev/null 2>/dev/null || echo y)
  32. # Apply this configuration to all documents
  33. BR_ASCIIDOC_CONF = docs/conf/asciidoc.conf
  34. ################################################################################
  35. # ASCIIDOC_INNER -- generates the make targets needed to build a specific type of
  36. # asciidoc documentation.
  37. #
  38. # argument 1 is the name of the document and the top-level asciidoc file must
  39. # have the same name
  40. # argument 2 is the uppercase name of the document
  41. # argument 3 is the directory containing the document
  42. # argument 4 is the type of document to generate (-f argument of a2x)
  43. # argument 5 is the document type as used in the make target
  44. # argument 6 is the output file extension for the document type
  45. # argument 7 is the human text for the document type
  46. # argument 8 (optional) are extra arguments for a2x
  47. #
  48. # The variable <DOCUMENT_NAME>_SOURCES defines the dependencies.
  49. #
  50. # Since this function will be called from within an $(eval ...)
  51. # all variable references except the arguments must be $$-quoted.
  52. ################################################################################
  53. define ASCIIDOC_INNER
  54. $(1): $(1)-$(5)
  55. .PHONY: $(1)-$(5)
  56. $(1)-$(5): $$(O)/docs/$(1)/$(1).$(6)
  57. asciidoc-check-dependencies-$(5):
  58. .PHONY: $(1)-check-dependencies-$(5)
  59. # Single line, because splitting a foreach is not easy...
  60. $(1)-check-dependencies-$(5): asciidoc-check-dependencies-$(5)
  61. $$(Q)$$(foreach hook,$$($(2)_CHECK_DEPENDENCIES_$$(call UPPERCASE,$(5))_HOOKS),$$(call $$(hook))$$(sep))
  62. # Include Buildroot's AsciiDoc configuration first:
  63. # - generic configuration,
  64. # - then output-specific configuration
  65. ifneq ($$(wildcard $$(BR_ASCIIDOC_CONF)),)
  66. $(2)_$(4)_ASCIIDOC_OPTS += -f $$(BR_ASCIIDOC_CONF)
  67. endif
  68. BR_$(4)_ASCIIDOC_CONF = docs/conf/asciidoc-$(4).conf
  69. ifneq ($$(wildcard $$(BR_$(4)_ASCIIDOC_CONF)),)
  70. $(2)_$(4)_ASCIIDOC_OPTS += -f $$(BR_$(4)_ASCIIDOC_CONF)
  71. endif
  72. # Then include the document's AsciiDoc configuration:
  73. # - generic configuration,
  74. # - then output-specific configuration
  75. ifneq ($$(wildcard $$($(2)_ASCIIDOC_CONF)),)
  76. $(2)_$(4)_ASCIIDOC_OPTS += -f $$($(2)_ASCIIDOC_CONF)
  77. endif
  78. $(2)_$(4)_ASCIIDOC_CONF = $(3)/asciidoc-$(4).conf
  79. ifneq ($$(wildcard $$($(2)_$(4)_ASCIIDOC_CONF)),)
  80. $(2)_$(4)_ASCIIDOC_OPTS += -f $$($(2)_$(4)_ASCIIDOC_CONF)
  81. endif
  82. # Handle a2x warning about --destination-dir option only applicable to HTML
  83. # based outputs. So:
  84. # - use the --destination-dir option if possible (html and split-html),
  85. # - otherwise copy the generated document to the output directory
  86. $(2)_$(4)_A2X_OPTS =
  87. ifneq ($$(filter $(5),html split-html),)
  88. $(2)_$(4)_A2X_OPTS += --destination-dir="$$(@D)"
  89. else
  90. define $(2)_$(4)_INSTALL_CMDS
  91. $$(Q)cp -f $$(BUILD_DIR)/docs/$(1)/$(1).$(6) $$(@D)
  92. endef
  93. endif
  94. $$(O)/docs/$(1)/$(1).$(6): export TZ=UTC
  95. ifeq ($(6)-$$(GENDOC_XSLTPROC_IS_BROKEN),pdf-y)
  96. $$(O)/docs/$(1)/$(1).$(6):
  97. $$(warning PDF generation is disabled because of a bug in \
  98. xsltproc. To be able to generate a PDF, you should \
  99. build xsltproc from the libxslt sources >=1.1.29 and pass it \
  100. to make through the command line: \
  101. 'PATH=/path/to/custom-xsltproc/bin:$$$${PATH} make $(1)-pdf')
  102. else
  103. # -r $(@D) is there for documents that use external filters; those filters
  104. # generate code at the same location it finds the document's source files.
  105. $$(O)/docs/$(1)/$(1).$(6): $$($(2)_SOURCES) \
  106. $(1)-check-dependencies \
  107. $(1)-check-dependencies-$(5) \
  108. $(1)-prepare-sources
  109. $$(Q)$$(call MESSAGE,"Generating $(7) $(1)...")
  110. $$(Q)mkdir -p $$(@D)
  111. $$(Q)a2x $(8) -f $(4) -d book -L \
  112. $$(foreach r,$$($(2)_RESOURCES) $$(@D), \
  113. --resource="$$(abspath $$(r))") \
  114. $$($(2)_$(4)_A2X_OPTS) \
  115. --asciidoc-opts="$$($(2)_$(4)_ASCIIDOC_OPTS)" \
  116. $$(BUILD_DIR)/docs/$(1)/$(1).txt
  117. # install the generated document
  118. $$($(2)_$(4)_INSTALL_CMDS)
  119. endif
  120. endef
  121. ################################################################################
  122. # ASCIIDOC -- generates the make targets needed to build asciidoc documentation.
  123. #
  124. # argument 1 is the lowercase name of the document; the document's main file
  125. # must have the same name, with the .txt extension
  126. # argument 2 is the uppercase name of the document
  127. # argument 3 is the directory containing the document's sources
  128. #
  129. # The variable <DOCUMENT_NAME>_SOURCES defines the dependencies.
  130. # The variable <DOCUMENT_NAME>_RESOURCES defines where the document's
  131. # resources, such as images, are located; must be an absolute path.
  132. ################################################################################
  133. define ASCIIDOC
  134. # Single line, because splitting a foreach is not easy...
  135. .PHONY: $(1)-check-dependencies
  136. $(1)-check-dependencies: asciidoc-check-dependencies $$($(2)_DEPENDENCIES)
  137. $$(Q)$$(foreach hook,$$($(2)_CHECK_DEPENDENCIES_HOOKS),$$(call $$(hook))$$(sep))
  138. # Single line, because splitting a foreach is not easy...
  139. # Do not touch the stamp file, so we get to rsync again every time we build
  140. # the document.
  141. $$(BUILD_DIR)/docs/$(1)/.stamp_doc_rsynced:
  142. $$(Q)$$(call MESSAGE,"Preparing the $(1) sources...")
  143. $$(Q)mkdir -p $$(@D)
  144. $$(Q)rsync -a $(3) $$(@D)
  145. $$(Q)$$(foreach hook,$$($(2)_POST_RSYNC_HOOKS),$$(call $$(hook))$$(sep))
  146. .PHONY: $(1)-prepare-sources
  147. $(1)-prepare-sources: $$(BUILD_DIR)/docs/$(1)/.stamp_doc_rsynced
  148. $(2)_ASCIIDOC_CONF = $(3)/asciidoc.conf
  149. $(call ASCIIDOC_INNER,$(1),$(2),$(3),xhtml,html,html,HTML,\
  150. --xsltproc-opts "--stringparam toc.section.depth 1")
  151. $(call ASCIIDOC_INNER,$(1),$(2),$(3),chunked,split-html,chunked,split HTML,\
  152. --xsltproc-opts "--stringparam toc.section.depth 1")
  153. # dblatex needs to pass the '--maxvars ...' option to xsltproc to prevent it
  154. # from reaching the template recursion limit when processing the (long) target
  155. # package table and bailing out.
  156. $(call ASCIIDOC_INNER,$(1),$(2),$(3),pdf,pdf,pdf,PDF,\
  157. --dblatex-opts "-P latex.output.revhistory=0 -x '--maxvars 100000'")
  158. $(call ASCIIDOC_INNER,$(1),$(2),$(3),text,text,text,text)
  159. $(call ASCIIDOC_INNER,$(1),$(2),$(3),epub,epub,epub,ePUB)
  160. clean: $(1)-clean
  161. $(1)-clean:
  162. $$(Q)$$(RM) -rf $$(BUILD_DIR)/docs/$(1)
  163. .PHONY: $(1) $(1)-clean
  164. endef
  165. ################################################################################
  166. # asciidoc-document -- the target generator macro for asciidoc documents
  167. ################################################################################
  168. asciidoc-document = $(call ASCIIDOC,$(pkgname),$(call UPPERCASE,$(pkgname)),$(pkgdir))