manual.mk 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. # we can't use suitable-host-package here because that's not available in
  2. # the context of 'make release'
  3. manual-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. manual-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. ################################################################################
  32. # GENDOC_INNER -- generates the make targets needed to build a specific type of
  33. # asciidoc documentation.
  34. #
  35. # argument 1 is the name of the document and the top-level asciidoc file must
  36. # have the same name
  37. # argument 2 is the uppercase name of the document
  38. # argument 3 is the directory containing the document
  39. # argument 4 is the type of document to generate (-f argument of a2x)
  40. # argument 5 is the document type as used in the make target
  41. # argument 6 is the output file extension for the document type
  42. # argument 7 is the human text for the document type
  43. # argument 8 (optional) are extra arguments for a2x
  44. #
  45. # The variable <DOCUMENT_NAME>_SOURCES defines the dependencies.
  46. #
  47. # Since this function will be called from within an $(eval ...)
  48. # all variable references except the arguments must be $$-quoted.
  49. ################################################################################
  50. define GENDOC_INNER
  51. $(1): $(1)-$(5)
  52. .PHONY: $(1)-$(5)
  53. $(1)-$(5): $$(O)/docs/$(1)/$(1).$(6)
  54. $(1)-check-dependencies-$(5):
  55. $(2)_$(4)_ASCIIDOC_CONF = $(3)/asciidoc-$(4).conf
  56. ifneq ($$(wildcard $$($(2)_$(4)_ASCIIDOC_CONF)),)
  57. $(2)_$(4)_ASCIIDOC_OPTS += -f $$($(2)_$(4)_ASCIIDOC_CONF)
  58. endif
  59. # Handle a2x warning about --destination-dir option only applicable to HTML
  60. # based outputs. So:
  61. # - use the --destination-dir option if possible (html and split-html),
  62. # - otherwise copy the generated document to the output directory
  63. $(2)_$(4)_A2X_OPTS =
  64. ifneq ($$(filter $(5),html split-html),)
  65. $(2)_$(4)_A2X_OPTS += --destination-dir="$$(@D)"
  66. else
  67. define $(2)_$(4)_INSTALL_CMDS
  68. $$(Q)cp -f $$(BUILD_DIR)/docs/$(1)/$(1).$(6) $$(@D)
  69. endef
  70. endif
  71. ifeq ($(6)-$$(GENDOC_XSLTPROC_IS_BROKEN),pdf-y)
  72. $$(O)/docs/$(1)/$(1).$(6):
  73. $$(warning PDF generation is disabled because of a bug in \
  74. xsltproc. To be able to generate a PDF, you should \
  75. build xsltproc from the libxslt sources >=1.1.29 and pass it \
  76. to make through the command line: \
  77. 'PATH=/path/to/custom-xsltproc/bin:$$$${PATH} make $(1)-pdf')
  78. else
  79. $$(O)/docs/$(1)/$(1).$(6): $$($(2)_SOURCES) \
  80. $(1)-check-dependencies \
  81. $(1)-check-dependencies-$(5) \
  82. $(1)-prepare-sources
  83. $$(Q)$$(call MESSAGE,"Generating $(7) $(1)...")
  84. $$(Q)mkdir -p $$(@D)
  85. $$(Q)a2x $(8) -f $(4) -d book -L \
  86. $$(foreach r,$$($(2)_RESOURCES),-r $$(r)) \
  87. $$($(2)_$(4)_A2X_OPTS) \
  88. --asciidoc-opts="$$($(2)_$(4)_ASCIIDOC_OPTS)" \
  89. $$(BUILD_DIR)/docs/$(1)/$(1).txt
  90. # install the generated document
  91. $$($(2)_$(4)_INSTALL_CMDS)
  92. endif
  93. endef
  94. ################################################################################
  95. # GENDOC -- generates the make targets needed to build asciidoc documentation.
  96. #
  97. # The variable <DOCUMENT_NAME>_SOURCES defines the dependencies.
  98. # The variable <DOCUMENT_NAME>_RESOURCES defines where the document's
  99. # resources, such as images, are located; must be an absolute path.
  100. ################################################################################
  101. define GENDOC
  102. $$(BUILD_DIR)/docs/$(pkgname):
  103. $$(Q)mkdir -p $$@
  104. $(pkgname)-rsync: $$(BUILD_DIR)/docs/$(pkgname)
  105. $$(Q)$$(call MESSAGE,"Preparing the $(pkgname) sources...")
  106. $$(Q)rsync -a $(pkgdir) $$^
  107. $(pkgname)-prepare-sources: $(pkgname)-rsync
  108. $(call GENDOC_INNER,$(pkgname),$$(call UPPERCASE,$(pkgname)),$(pkgdir),xhtml,html,html,HTML,\
  109. --xsltproc-opts "--stringparam toc.section.depth 1")
  110. $(call GENDOC_INNER,$(pkgname),$$(call UPPERCASE,$(pkgname)),$(pkgdir),chunked,split-html,chunked,split HTML,\
  111. --xsltproc-opts "--stringparam toc.section.depth 1")
  112. # dblatex needs to pass the '--maxvars ...' option to xsltproc to prevent it
  113. # from reaching the template recursion limit when processing the (long) target
  114. # package table and bailing out.
  115. $(call GENDOC_INNER,$(pkgname),$$(call UPPERCASE,$(pkgname)),$(pkgdir),pdf,pdf,pdf,PDF,\
  116. --dblatex-opts "-P latex.output.revhistory=0 -x '--maxvars 100000'")
  117. $(call GENDOC_INNER,$(pkgname),$$(call UPPERCASE,$(pkgname)),$(pkgdir),text,text,text,text)
  118. $(call GENDOC_INNER,$(pkgname),$$(call UPPERCASE,$(pkgname)),$(pkgdir),epub,epub,epub,ePUB)
  119. clean: $(pkgname)-clean
  120. $(pkgname)-clean:
  121. $$(Q)$$(RM) -rf $$(BUILD_DIR)/docs/$(pkgname)
  122. .PHONY: $(pkgname) $(pkgname)-clean
  123. endef
  124. ################################################################################
  125. # The Buildroot manual
  126. ################################################################################
  127. # Our manual needs to generate lists
  128. manual-prepare-sources: manual-update-lists
  129. # Packages included in BR2_EXTERNAL are not part of buildroot, so they
  130. # should not be included in the manual.
  131. .PHONY: manual-update-lists
  132. manual-update-lists: manual-check-dependencies-lists $(BUILD_DIR)/docs/$(pkgname)
  133. $(Q)$(call MESSAGE,"Updating the manual lists...")
  134. $(Q)BR2_DEFCONFIG="" TOPDIR=$(TOPDIR) O=$(BUILD_DIR)/docs/$(pkgname) \
  135. BR2_EXTERNAL=$(TOPDIR)/support/dummy-external \
  136. python -B $(TOPDIR)/support/scripts/gen-manual-lists.py
  137. manual-check-dependencies-lists:
  138. $(Q)if ! python -c "import argparse" >/dev/null 2>&1 ; then \
  139. echo "You need python with argparse on your host to generate" \
  140. "the list of packages in the manual"; \
  141. exit 1; \
  142. fi
  143. MANUAL_SOURCES = $(sort $(wildcard docs/manual/*.txt) $(wildcard docs/images/*))
  144. MANUAL_RESOURCES = $(TOPDIR)/docs/images
  145. $(eval $(call GENDOC))