doc-asciidoc.mk 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 type of document to generate (-f argument of a2x)
  42. # argument 4 is the document type as used in the make target
  43. # argument 5 is the output file extension for the document type
  44. # argument 6 is the human text for the document type
  45. # argument 7 (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)-$(4)
  54. .PHONY: $(1)-$(4)
  55. $(1)-$(4): $$(O)/docs/$(1)/$(1).$(5)
  56. asciidoc-check-dependencies-$(4):
  57. .PHONY: $(1)-check-dependencies-$(4)
  58. # Single line, because splitting a foreach is not easy...
  59. $(1)-check-dependencies-$(4): asciidoc-check-dependencies-$(4)
  60. $$(Q)$$(foreach hook,$$($(2)_CHECK_DEPENDENCIES_$$(call UPPERCASE,$(4))_HOOKS),$$(call $$(hook))$$(sep))
  61. # Include Buildroot's AsciiDoc configuration first:
  62. # - generic configuration,
  63. # - then output-specific configuration
  64. ifneq ($$(wildcard $$(BR_ASCIIDOC_CONF)),)
  65. $(2)_$(3)_ASCIIDOC_OPTS += -f $$(BR_ASCIIDOC_CONF)
  66. endif
  67. BR_$(3)_ASCIIDOC_CONF = docs/conf/asciidoc-$(3).conf
  68. ifneq ($$(wildcard $$(BR_$(3)_ASCIIDOC_CONF)),)
  69. $(2)_$(3)_ASCIIDOC_OPTS += -f $$(BR_$(3)_ASCIIDOC_CONF)
  70. endif
  71. # Then include the document's AsciiDoc configuration:
  72. # - generic configuration,
  73. # - then output-specific configuration
  74. ifneq ($$(wildcard $$($(2)_ASCIIDOC_CONF)),)
  75. $(2)_$(3)_ASCIIDOC_OPTS += -f $$($(2)_ASCIIDOC_CONF)
  76. endif
  77. $(2)_$(3)_ASCIIDOC_CONF = $$($(2)_DOCDIR)/asciidoc-$(3).conf
  78. ifneq ($$(wildcard $$($(2)_$(3)_ASCIIDOC_CONF)),)
  79. $(2)_$(3)_ASCIIDOC_OPTS += -f $$($(2)_$(3)_ASCIIDOC_CONF)
  80. endif
  81. $(2)_$(3)_A2X_OPTS = \
  82. --xsltproc-opts "--stringparam toc.section.depth $$(or $$($(2)_TOC_DEPTH_$$(call UPPERCASE,$(4))),$$($(2)_TOC_DEPTH))"
  83. # Handle a2x warning about --destination-dir option only applicable to HTML
  84. # based outputs. So:
  85. # - use the --destination-dir option if possible (html and split-html),
  86. # - otherwise copy the generated document to the output directory
  87. ifneq ($$(filter $(4),html split-html),)
  88. $(2)_$(3)_A2X_OPTS += --destination-dir="$$(@D)"
  89. else
  90. define $(2)_$(3)_INSTALL_CMDS
  91. $$(Q)cp -f $$(BUILD_DIR)/docs/$(1)/$(1).$(5) $$(@D)
  92. endef
  93. endif
  94. $$(O)/docs/$(1)/$(1).$(5): export TZ=UTC
  95. ifeq ($(5)-$$(GENDOC_XSLTPROC_IS_BROKEN),pdf-y)
  96. $$(O)/docs/$(1)/$(1).$(5):
  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).$(5): $$($(2)_SOURCES) \
  106. $(1)-check-dependencies \
  107. $(1)-check-dependencies-$(4) \
  108. $(1)-prepare-sources
  109. $$(Q)$$(call MESSAGE,"Generating $(6) $(1)...")
  110. $$(Q)mkdir -p $$(@D)
  111. $$(Q)a2x $(7) -f $(3) -d book -L \
  112. $$(foreach r,$$($(2)_RESOURCES) $$(@D), \
  113. --resource="$$(abspath $$(r))") \
  114. $$($(2)_$(3)_A2X_OPTS) \
  115. --asciidoc-opts="$$($(2)_$(3)_ASCIIDOC_OPTS)" \
  116. $$(BUILD_DIR)/docs/$(1)/$(1).adoc
  117. # install the generated document
  118. $$($(2)_$(3)_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. #
  128. # The variable <DOCUMENT_NAME>_SOURCES defines the dependencies.
  129. # The variable <DOCUMENT_NAME>_RESOURCES defines where the document's
  130. # resources, such as images, are located; must be an absolute path.
  131. ################################################################################
  132. define ASCIIDOC
  133. $(2)_DOCDIR = $(pkgdir)
  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 $$($(2)_DOCDIR) $$(@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)_TOC_DEPTH ?= 1
  149. $(2)_ASCIIDOC_CONF = $$($(2)_DOCDIR)/asciidoc.conf
  150. $(call ASCIIDOC_INNER,$(1),$(2),xhtml,html,html,HTML)
  151. $(call ASCIIDOC_INNER,$(1),$(2),chunked,split-html,chunked,split HTML)
  152. # dblatex needs to pass the '--maxvars ...' option to xsltproc to prevent it
  153. # from reaching the template recursion limit when processing the (long) target
  154. # package table and bailing out.
  155. $(call ASCIIDOC_INNER,$(1),$(2),pdf,pdf,pdf,PDF,\
  156. --dblatex-opts "-P latex.output.revhistory=0 -x '--maxvars 100000'")
  157. $(call ASCIIDOC_INNER,$(1),$(2),text,text,text,text)
  158. $(call ASCIIDOC_INNER,$(1),$(2),epub,epub,epub,ePUB)
  159. clean: $(1)-clean
  160. $(1)-clean:
  161. $$(Q)$$(RM) -rf $$(BUILD_DIR)/docs/$(1)
  162. .PHONY: $(1) $(1)-clean
  163. endef
  164. ################################################################################
  165. # asciidoc-document -- the target generator macro for asciidoc documents
  166. ################################################################################
  167. asciidoc-document = $(call ASCIIDOC,$(pkgname),$(call UPPERCASE,$(pkgname)))