Makefile 6.9 KB

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