manual.mk 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. # Packages included in BR2_EXTERNAL are not part of buildroot, so they
  2. # should not be included in the manual.
  3. manual-update-lists: manual-check-dependencies-lists $(BUILD_DIR)/docs/$(pkgname)
  4. $(Q)$(call MESSAGE,"Updating the manual lists...")
  5. $(Q)BR2_DEFCONFIG="" TOPDIR=$(TOPDIR) O=$(BUILD_DIR)/docs/$(pkgname) \
  6. BR2_EXTERNAL=$(TOPDIR)/support/dummy-external \
  7. python -B $(TOPDIR)/support/scripts/gen-manual-lists.py
  8. manual-prepare-sources: manual-rsync manual-update-lists
  9. # we can't use suitable-host-package here because that's not available in
  10. # the context of 'make release'
  11. manual-check-dependencies:
  12. $(Q)if [ -z "$(shell support/dependencies/check-host-asciidoc.sh)" ]; then \
  13. echo "You need a sufficiently recent asciidoc on your host" \
  14. "to generate the manual"; \
  15. exit 1; \
  16. fi
  17. $(Q)if [ -z "`which w3m 2>/dev/null`" ]; then \
  18. echo "You need w3m on your host to generate the manual"; \
  19. exit 1; \
  20. fi
  21. manual-check-dependencies-pdf:
  22. $(Q)if [ -z "`which dblatex 2>/dev/null`" ]; then \
  23. echo "You need dblatex on your host to generate the pdf manual"; \
  24. exit 1; \
  25. fi
  26. manual-check-dependencies-lists:
  27. $(Q)if ! python -c "import argparse" >/dev/null 2>&1 ; then \
  28. echo "You need python with argparse on your host to generate" \
  29. "the list of packages in the manual"; \
  30. exit 1; \
  31. fi
  32. # PDF manual generation is broken because of a bug in xsltproc program provided
  33. # by libxslt <=1.1.28, which does not honor an option we need to set.
  34. # Fortunately, this bug is already fixed upstream:
  35. # https://gitorious.org/libxslt/libxslt/commit/5af7ad745323004984287e48b42712e7305de35c
  36. #
  37. # So, bail out when trying to build the pdf manual using a buggy version of the
  38. # xsltproc program.
  39. #
  40. # So, to overcome this issue and being able to build the pdf manual, you can
  41. # build xsltproc from it source repository, then run:
  42. # $ PATH=/path/to/custom-xsltproc/bin:${PATH} make manual
  43. MANUAL_XSLTPROC_IS_BROKEN = \
  44. $(shell xsltproc --maxvars 0 >/dev/null 2>/dev/null || echo y)
  45. ################################################################################
  46. # GENDOC_INNER -- generates the make targets needed to build a specific type of
  47. # asciidoc documentation.
  48. #
  49. # argument 1 is the name of the document and must be a subdirectory of docs/;
  50. # the top-level asciidoc file must have the same name
  51. # argument 2 is the type of document to generate (-f argument of a2x)
  52. # argument 3 is the document type as used in the make target
  53. # argument 4 is the output file extension for the document type
  54. # argument 5 is the human text for the document type
  55. # argument 6 (optional) are extra arguments for a2x
  56. #
  57. # The variable <DOCUMENT_NAME>_SOURCES defines the dependencies.
  58. #
  59. # Since this function will be called from within an $(eval ...)
  60. # all variable references except the arguments must be $$-quoted.
  61. ################################################################################
  62. define GENDOC_INNER
  63. $(1): $(1)-$(3)
  64. .PHONY: $(1)-$(3)
  65. $(1)-$(3): $$(O)/docs/$(1)/$(1).$(4)
  66. manual-check-dependencies-$(3):
  67. MANUAL_$(2)_ASCIIDOC_CONF = docs/$(1)/asciidoc-$(2).conf
  68. ifneq ($$(wildcard $$(MANUAL_$(2)_ASCIIDOC_CONF)),)
  69. MANUAL_$(2)_ASCIIDOC_OPTS += -f $$(MANUAL_$(2)_ASCIIDOC_CONF)
  70. endif
  71. # Handle a2x warning about --destination-dir option only applicable to HTML
  72. # based outputs. So:
  73. # - use the --destination-dir option if possible (html and split-html),
  74. # - otherwise copy the generated manual to the output directory
  75. MANUAL_$(2)_A2X_OPTS =
  76. ifneq ($$(filter $(3),html split-html),)
  77. MANUAL_$(2)_A2X_OPTS += --destination-dir="$$(@D)"
  78. else
  79. define MANUAL_$(2)_INSTALL_CMDS
  80. $$(Q)cp -f $$(BUILD_DIR)/docs/$(1)/$(1).$(4) $$(@D)
  81. endef
  82. endif
  83. ifeq ($(4)-$$(MANUAL_XSLTPROC_IS_BROKEN),pdf-y)
  84. $$(O)/docs/$(1)/$(1).$(4):
  85. $$(warning PDF manual generation is disabled because of a bug in \
  86. xsltproc. To be able to generate the PDF manual, you should \
  87. build xsltproc from the libxslt sources >=1.1.29 and pass it \
  88. to make through the command line: \
  89. 'PATH=/path/to/custom-xsltproc/bin:$$$${PATH} make manual-pdf')
  90. else
  91. $$(O)/docs/$(1)/$(1).$(4): docs/$(1)/$(1).txt \
  92. $$($$(call UPPERCASE,$(1))_SOURCES) \
  93. manual-check-dependencies \
  94. manual-check-dependencies-$(3) \
  95. manual-prepare-sources
  96. $$(Q)$$(call MESSAGE,"Generating $(5) $(1)...")
  97. $$(Q)mkdir -p $$(@D)
  98. $$(Q)a2x $(6) -f $(2) -d book -L -r $$(TOPDIR)/docs/images \
  99. $$(MANUAL_$(2)_A2X_OPTS) \
  100. --asciidoc-opts="$$(MANUAL_$(2)_ASCIIDOC_OPTS)" \
  101. $$(BUILD_DIR)/docs/$(1)/$(1).txt
  102. # install the generated manual
  103. $$(MANUAL_$(2)_INSTALL_CMDS)
  104. endif
  105. endef
  106. ################################################################################
  107. # GENDOC -- generates the make targets needed to build asciidoc documentation.
  108. #
  109. # The variable <DOCUMENT_NAME>_SOURCES defines the dependencies.
  110. ################################################################################
  111. define GENDOC
  112. $$(BUILD_DIR)/docs/$(pkgname):
  113. $$(Q)mkdir -p $$@
  114. $(pkgname)-rsync: $$(BUILD_DIR)/docs/$(pkgname)
  115. $$(Q)$$(call MESSAGE,"Preparing the $(pkgname) sources...")
  116. $$(Q)rsync -a docs/$(pkgname)/ $$^
  117. $(call GENDOC_INNER,$(pkgname),xhtml,html,html,HTML,\
  118. --xsltproc-opts "--stringparam toc.section.depth 1")
  119. $(call GENDOC_INNER,$(pkgname),chunked,split-html,chunked,split HTML,\
  120. --xsltproc-opts "--stringparam toc.section.depth 1")
  121. # dblatex needs to pass the '--maxvars ...' option to xsltproc to prevent it
  122. # from reaching the template recursion limit when processing the (long) target
  123. # package table and bailing out.
  124. $(call GENDOC_INNER,$(pkgname),pdf,pdf,pdf,PDF,\
  125. --dblatex-opts "-P latex.output.revhistory=0 -x '--maxvars 100000'")
  126. $(call GENDOC_INNER,$(pkgname),text,text,text,text)
  127. $(call GENDOC_INNER,$(pkgname),epub,epub,epub,ePUB)
  128. clean: $(pkgname)-clean
  129. $(pkgname)-clean:
  130. $$(Q)$$(RM) -rf $$(BUILD_DIR)/docs/$(pkgname)
  131. .PHONY: $(pkgname) $(pkgname)-clean manual-update-lists
  132. endef
  133. MANUAL_SOURCES = $(sort $(wildcard docs/manual/*.txt) $(wildcard docs/images/*))
  134. $(eval $(call GENDOC))