Makefile 6.6 KB

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