manual.mk 6.6 KB

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