Makefile 6.5 KB

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