manual.mk 5.9 KB

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