manual.mk 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. $(BUILD_DIR)/docs/$(pkgname):
  2. $(Q)mkdir -p $@
  3. manual-rsync: $(BUILD_DIR)/docs/$(pkgname)
  4. $(Q)$(call MESSAGE,"Preparing the manual sources...")
  5. $(Q)rsync -a docs/$(pkgname)/ $(BUILD_DIR)/docs/$(pkgname)
  6. # Packages included in BR2_EXTERNAL are not part of buildroot, so they
  7. # should not be included in the manual.
  8. manual-update-lists: manual-check-dependencies-lists $(BUILD_DIR)/docs/$(pkgname)
  9. $(Q)$(call MESSAGE,"Updating the manual lists...")
  10. $(Q)BR2_DEFCONFIG="" TOPDIR=$(TOPDIR) O=$(BUILD_DIR)/docs/$(pkgname) \
  11. BR2_EXTERNAL=$(TOPDIR)/support/dummy-external \
  12. python -B $(TOPDIR)/support/scripts/gen-manual-lists.py
  13. manual-prepare-sources: manual-rsync manual-update-lists
  14. # we can't use suitable-host-package here because that's not available in
  15. # the context of 'make release'
  16. manual-check-dependencies:
  17. $(Q)if [ -z "$(shell support/dependencies/check-host-asciidoc.sh)" ]; then \
  18. echo "You need a sufficiently recent asciidoc on your host" \
  19. "to generate the manual"; \
  20. exit 1; \
  21. fi
  22. $(Q)if [ -z "`which w3m 2>/dev/null`" ]; then \
  23. echo "You need w3m on your host to generate the manual"; \
  24. exit 1; \
  25. fi
  26. manual-check-dependencies-pdf:
  27. $(Q)if [ -z "`which dblatex 2>/dev/null`" ]; then \
  28. echo "You need dblatex on your host to generate the pdf manual"; \
  29. exit 1; \
  30. fi
  31. manual-check-dependencies-lists:
  32. $(Q)if ! python -c "import argparse" >/dev/null 2>&1 ; then \
  33. echo "You need python with argparse on your host to generate" \
  34. "the list of packages in the manual"; \
  35. exit 1; \
  36. fi
  37. ################################################################################
  38. # GENDOC_INNER -- generates the make targets needed to build a specific type of
  39. # asciidoc documentation.
  40. #
  41. # argument 1 is the name of the document and must be a subdirectory of docs/;
  42. # the top-level asciidoc file must have the same name
  43. # argument 2 is the type of document to generate (-f argument of a2x)
  44. # argument 3 is the document type as used in the make target
  45. # argument 4 is the output file extension for the document type
  46. # argument 5 is the human text for the document type
  47. # argument 6 (optional) are extra arguments for a2x
  48. #
  49. # The variable <DOCUMENT_NAME>_SOURCES defines the dependencies.
  50. #
  51. # Since this function will be called from within an $(eval ...)
  52. # all variable references except the arguments must be $$-quoted.
  53. ################################################################################
  54. define GENDOC_INNER
  55. $(1): $(1)-$(3)
  56. .PHONY: $(1)-$(3)
  57. $(1)-$(3): $$(O)/docs/$(1)/$(1).$(4)
  58. manual-check-dependencies-$(3):
  59. MANUAL_$(2)_ASCIIDOC_CONF = docs/$(1)/asciidoc-$(2).conf
  60. ifneq ($$(wildcard $$(MANUAL_$(2)_ASCIIDOC_CONF)),)
  61. MANUAL_$(2)_ASCIIDOC_OPTS += -f $$(MANUAL_$(2)_ASCIIDOC_CONF)
  62. endif
  63. # Handle a2x warning about --destination-dir option only applicable to HTML
  64. # based outputs. So:
  65. # - use the --destination-dir option if possible (html and split-html),
  66. # - otherwise copy the generated manual to the output directory
  67. MANUAL_$(2)_A2X_OPTS =
  68. ifneq ($$(filter $(3),html split-html),)
  69. MANUAL_$(2)_A2X_OPTS += --destination-dir="$$(@D)"
  70. else
  71. define MANUAL_$(2)_INSTALL_CMDS
  72. $$(Q)cp -f $$(BUILD_DIR)/docs/$(1)/$(1).$(4) $$(@D)
  73. endef
  74. endif
  75. $$(O)/docs/$(1)/$(1).$(4): docs/$(1)/$(1).txt \
  76. $$($$(call UPPERCASE,$(1))_SOURCES) \
  77. manual-check-dependencies \
  78. manual-check-dependencies-$(3) \
  79. manual-prepare-sources
  80. $$(Q)$$(call MESSAGE,"Generating $(5) $(1)...")
  81. $$(Q)mkdir -p $$(@D)
  82. $$(Q)a2x $(6) -f $(2) -d book -L -r $$(TOPDIR)/docs/images \
  83. $$(MANUAL_$(2)_A2X_OPTS) \
  84. --asciidoc-opts="$$(MANUAL_$(2)_ASCIIDOC_OPTS)" \
  85. $$(BUILD_DIR)/docs/$(1)/$(1).txt
  86. # install the generated manual
  87. $$(MANUAL_$(2)_INSTALL_CMDS)
  88. endef
  89. ################################################################################
  90. # GENDOC -- generates the make targets needed to build asciidoc documentation.
  91. #
  92. # argument 1 is the name of the document and must be a subdirectory of docs/;
  93. # the top-level asciidoc file must have the same name
  94. #
  95. # The variable <DOCUMENT_NAME>_SOURCES defines the dependencies.
  96. ################################################################################
  97. define GENDOC
  98. $(call GENDOC_INNER,$(pkgname),xhtml,html,html,HTML,\
  99. --xsltproc-opts "--stringparam toc.section.depth 1")
  100. $(call GENDOC_INNER,$(pkgname),chunked,split-html,chunked,split HTML,\
  101. --xsltproc-opts "--stringparam toc.section.depth 1")
  102. $(call GENDOC_INNER,$(pkgname),pdf,pdf,pdf,PDF,\
  103. --dblatex-opts "-P latex.output.revhistory=0")
  104. $(call GENDOC_INNER,$(pkgname),text,text,text,text)
  105. $(call GENDOC_INNER,$(pkgname),epub,epub,epub,ePUB)
  106. clean: $(pkgname)-clean
  107. $(pkgname)-clean:
  108. $$(Q)$$(RM) -rf $$(BUILD_DIR)/docs/$(pkgname)
  109. .PHONY: $(pkgname) $(pkgname)-clean manual-update-lists
  110. endef
  111. MANUAL_SOURCES = $(sort $(wildcard docs/manual/*.txt) $(wildcard docs/images/*))
  112. $(eval $(call GENDOC))