Makefile 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. ###
  2. # This makefile is used to generate the kernel documentation,
  3. # primarily based on in-line comments in various source files.
  4. # See Documentation/kernel-doc-nano-HOWTO.txt for instruction in how
  5. # to document the SRC - and how to read it.
  6. # To add a new book the only step required is to add the book to the
  7. # list of DOCBOOKS.
  8. #
  9. # SPDX-License-Identifier: GPL-2.0
  10. #
  11. DOCBOOKS := linker_lists.xml stdio.xml
  12. ###
  13. # The build process is as follows (targets):
  14. # (xmldocs) [by docproc]
  15. # file.tmpl --> file.xml +--> file.ps (psdocs) [by db2ps or xmlto]
  16. # +--> file.pdf (pdfdocs) [by db2pdf or xmlto]
  17. # +--> DIR=file (htmldocs) [by xmlto]
  18. # +--> man/ (mandocs) [by xmlto]
  19. # for PDF and PS output you can choose between xmlto and docbook-utils tools
  20. PDF_METHOD = $(prefer-db2x)
  21. PS_METHOD = $(prefer-db2x)
  22. ###
  23. # The targets that may be used.
  24. PHONY += xmldocs sgmldocs psdocs pdfdocs htmldocs mandocs installmandocs cleandocs
  25. targets += $(DOCBOOKS)
  26. BOOKS := $(addprefix $(obj)/,$(DOCBOOKS))
  27. xmldocs: $(BOOKS)
  28. sgmldocs: xmldocs
  29. PS := $(patsubst %.xml, %.ps, $(BOOKS))
  30. psdocs: $(PS)
  31. PDF := $(patsubst %.xml, %.pdf, $(BOOKS))
  32. pdfdocs: $(PDF)
  33. HTML := $(sort $(patsubst %.xml, %.html, $(BOOKS)))
  34. htmldocs: $(HTML)
  35. $(call build_main_index)
  36. $(call build_images)
  37. $(call install_media_images)
  38. MAN := $(patsubst %.xml, %.9, $(BOOKS))
  39. mandocs: $(MAN)
  40. $(if $(wildcard $(obj)/man/*.9),gzip -f $(obj)/man/*.9)
  41. installmandocs: mandocs
  42. mkdir -p /usr/local/man/man9/
  43. install $(obj)/man/*.9.gz /usr/local/man/man9/
  44. ###
  45. #External programs used
  46. KERNELDOC = $(srctree)/scripts/kernel-doc
  47. DOCPROC = $(objtree)/scripts/docproc
  48. XMLTOFLAGS = -m $(srctree)/$(src)/stylesheet.xsl
  49. XMLTOFLAGS += --skip-validation
  50. ###
  51. # DOCPROC is used for two purposes:
  52. # 1) To generate a dependency list for a .tmpl file
  53. # 2) To preprocess a .tmpl file and call kernel-doc with
  54. # appropriate parameters.
  55. # The following rules are used to generate the .xml documentation
  56. # required to generate the final targets. (ps, pdf, html).
  57. quiet_cmd_docproc = DOCPROC $@
  58. cmd_docproc = SRCTREE=$(srctree)/ $(DOCPROC) doc $< >$@
  59. define rule_docproc
  60. set -e; \
  61. $(if $($(quiet)cmd_$(1)),echo ' $($(quiet)cmd_$(1))';) \
  62. $(cmd_$(1)); \
  63. ( \
  64. echo 'cmd_$@ := $(cmd_$(1))'; \
  65. echo $@: `SRCTREE=$(srctree) $(DOCPROC) depend $<`; \
  66. ) > $(dir $@).$(notdir $@).cmd
  67. endef
  68. %.xml: %.tmpl $(KERNELDOC) $(DOCPROC) FORCE
  69. $(call if_changed_rule,docproc)
  70. # Tell kbuild to always build the programs
  71. always := $(hostprogs-y)
  72. notfoundtemplate = echo "*** You have to install docbook-utils or xmlto ***"; \
  73. exit 1
  74. db2xtemplate = db2TYPE -o $(dir $@) $<
  75. xmltotemplate = xmlto TYPE $(XMLTOFLAGS) -o $(dir $@) $<
  76. # determine which methods are available
  77. ifeq ($(shell which db2ps >/dev/null 2>&1 && echo found),found)
  78. use-db2x = db2x
  79. prefer-db2x = db2x
  80. else
  81. use-db2x = notfound
  82. prefer-db2x = $(use-xmlto)
  83. endif
  84. ifeq ($(shell which xmlto >/dev/null 2>&1 && echo found),found)
  85. use-xmlto = xmlto
  86. prefer-xmlto = xmlto
  87. else
  88. use-xmlto = notfound
  89. prefer-xmlto = $(use-db2x)
  90. endif
  91. # the commands, generated from the chosen template
  92. quiet_cmd_db2ps = PS $@
  93. cmd_db2ps = $(subst TYPE,ps, $($(PS_METHOD)template))
  94. %.ps : %.xml
  95. $(call cmd,db2ps)
  96. quiet_cmd_db2pdf = PDF $@
  97. cmd_db2pdf = $(subst TYPE,pdf, $($(PDF_METHOD)template))
  98. %.pdf : %.xml
  99. $(call cmd,db2pdf)
  100. index = index.html
  101. main_idx = $(obj)/$(index)
  102. build_main_index = rm -rf $(main_idx); \
  103. echo '<h1>U-Boot Bootloader HTML Documentation</h1>' >> $(main_idx) && \
  104. echo '<h2>U-Boot Version: $(UBOOTVERSION)</h2>' >> $(main_idx) && \
  105. cat $(HTML) >> $(main_idx)
  106. quiet_cmd_db2html = HTML $@
  107. cmd_db2html = xmlto html $(XMLTOFLAGS) -o $(patsubst %.html,%,$@) $< && \
  108. echo '<a HREF="$(patsubst %.html,%,$(notdir $@))/index.html"> \
  109. $(patsubst %.html,%,$(notdir $@))</a><p>' > $@
  110. %.html: %.xml
  111. @(which xmlto > /dev/null 2>&1) || \
  112. (echo "*** You need to install xmlto ***"; \
  113. exit 1)
  114. @rm -rf $@ $(patsubst %.html,%,$@)
  115. $(call cmd,db2html)
  116. @if [ ! -z "$(PNG-$(basename $(notdir $@)))" ]; then \
  117. cp $(PNG-$(basename $(notdir $@))) $(patsubst %.html,%,$@); fi
  118. quiet_cmd_db2man = MAN $@
  119. cmd_db2man = if grep -q refentry $<; then xmlto man $(XMLTOFLAGS) -o $(obj)/man $< ; fi
  120. %.9 : %.xml
  121. @(which xmlto > /dev/null 2>&1) || \
  122. (echo "*** You need to install xmlto ***"; \
  123. exit 1)
  124. $(Q)mkdir -p $(obj)/man
  125. $(call cmd,db2man)
  126. @touch $@
  127. ###
  128. # Rules to generate postscripts and PNG images from .fig format files
  129. quiet_cmd_fig2eps = FIG2EPS $@
  130. cmd_fig2eps = fig2dev -Leps $< $@
  131. %.eps: %.fig
  132. @(which fig2dev > /dev/null 2>&1) || \
  133. (echo "*** You need to install transfig ***"; \
  134. exit 1)
  135. $(call cmd,fig2eps)
  136. quiet_cmd_fig2png = FIG2PNG $@
  137. cmd_fig2png = fig2dev -Lpng $< $@
  138. %.png: %.fig
  139. @(which fig2dev > /dev/null 2>&1) || \
  140. (echo "*** You need to install transfig ***"; \
  141. exit 1)
  142. $(call cmd,fig2png)
  143. ###
  144. # Rule to convert a .c file to inline XML documentation
  145. gen_xml = :
  146. quiet_gen_xml = echo ' GEN $@'
  147. silent_gen_xml = :
  148. %.xml: %.c
  149. @$($(quiet)gen_xml)
  150. @( \
  151. echo "<programlisting>"; \
  152. expand --tabs=8 < $< | \
  153. sed -e "s/&/\\&amp;/g" \
  154. -e "s/</\\&lt;/g" \
  155. -e "s/>/\\&gt;/g"; \
  156. echo "</programlisting>") > $@
  157. ###
  158. # Help targets as used by the top-level makefile
  159. dochelp:
  160. @echo ' U-Boot bootloader internal documentation in different formats:'
  161. @echo ' htmldocs - HTML'
  162. @echo ' pdfdocs - PDF'
  163. @echo ' psdocs - Postscript'
  164. @echo ' xmldocs - XML DocBook'
  165. @echo ' mandocs - man pages'
  166. @echo ' installmandocs - install man pages generated by mandocs'
  167. @echo ' cleandocs - clean all generated DocBook files'
  168. ###
  169. # Temporary files left by various tools
  170. clean-files := $(DOCBOOKS) \
  171. $(patsubst %.xml, %.dvi, $(DOCBOOKS)) \
  172. $(patsubst %.xml, %.aux, $(DOCBOOKS)) \
  173. $(patsubst %.xml, %.tex, $(DOCBOOKS)) \
  174. $(patsubst %.xml, %.log, $(DOCBOOKS)) \
  175. $(patsubst %.xml, %.out, $(DOCBOOKS)) \
  176. $(patsubst %.xml, %.ps, $(DOCBOOKS)) \
  177. $(patsubst %.xml, %.pdf, $(DOCBOOKS)) \
  178. $(patsubst %.xml, %.html, $(DOCBOOKS)) \
  179. $(patsubst %.xml, %.9, $(DOCBOOKS)) \
  180. $(index)
  181. clean-dirs := $(patsubst %.xml,%,$(DOCBOOKS)) man
  182. cleandocs:
  183. $(Q)rm -f $(call objectify, $(clean-files))
  184. $(Q)rm -rf $(call objectify, $(clean-dirs))
  185. # Declare the contents of the .PHONY variable as phony. We keep that
  186. # information in a variable se we can use it in if_changed and friends.
  187. .PHONY: $(PHONY)