doc-asciidoc.mk 7.3 KB

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