Makefile 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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 := wanbook.xml z8530book.xml mcabook.xml videobook.xml \
  9. kernel-hacking.xml kernel-locking.xml deviceiobook.xml \
  10. procfs-guide.xml writing_usb_driver.xml \
  11. kernel-api.xml filesystems.xml lsm.xml usb.xml \
  12. gadget.xml libata.xml mtdnand.xml librs.xml rapidio.xml \
  13. genericirq.xml s390-drivers.xml
  14. ###
  15. # The build process is as follows (targets):
  16. # (xmldocs) [by docproc]
  17. # file.tmpl --> file.xml +--> file.ps (psdocs) [by db2ps or xmlto]
  18. # +--> file.pdf (pdfdocs) [by db2pdf or xmlto]
  19. # +--> DIR=file (htmldocs) [by xmlto]
  20. # +--> man/ (mandocs) [by xmlto]
  21. # for PDF and PS output you can choose between xmlto and docbook-utils tools
  22. PDF_METHOD = $(prefer-db2x)
  23. PS_METHOD = $(prefer-db2x)
  24. ###
  25. # The targets that may be used.
  26. PHONY += xmldocs sgmldocs psdocs pdfdocs htmldocs mandocs installmandocs
  27. BOOKS := $(addprefix $(obj)/,$(DOCBOOKS))
  28. xmldocs: $(BOOKS)
  29. sgmldocs: xmldocs
  30. PS := $(patsubst %.xml, %.ps, $(BOOKS))
  31. psdocs: $(PS)
  32. PDF := $(patsubst %.xml, %.pdf, $(BOOKS))
  33. pdfdocs: $(PDF)
  34. HTML := $(sort $(patsubst %.xml, %.html, $(BOOKS)))
  35. htmldocs: $(HTML)
  36. $(call build_main_index)
  37. MAN := $(patsubst %.xml, %.9, $(BOOKS))
  38. mandocs: $(MAN)
  39. installmandocs: mandocs
  40. mkdir -p /usr/local/man/man9/
  41. install Documentation/DocBook/man/*.9.gz /usr/local/man/man9/
  42. ###
  43. #External programs used
  44. KERNELDOC = $(srctree)/scripts/kernel-doc
  45. DOCPROC = $(objtree)/scripts/basic/docproc
  46. XMLTOFLAGS = -m $(srctree)/Documentation/DocBook/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 FORCE
  67. $(call if_changed_rule,docproc)
  68. ###
  69. #Read in all saved dependency files
  70. cmd_files := $(wildcard $(foreach f,$(BOOKS),$(dir $(f)).$(notdir $(f)).cmd))
  71. ifneq ($(cmd_files),)
  72. include $(cmd_files)
  73. endif
  74. ###
  75. # Changes in kernel-doc force a rebuild of all documentation
  76. $(BOOKS): $(KERNELDOC)
  77. ###
  78. # procfs guide uses a .c file as example code.
  79. # This requires an explicit dependency
  80. C-procfs-example = procfs_example.xml
  81. C-procfs-example2 = $(addprefix $(obj)/,$(C-procfs-example))
  82. $(obj)/procfs-guide.xml: $(C-procfs-example2)
  83. notfoundtemplate = echo "*** You have to install docbook-utils or xmlto ***"; \
  84. exit 1
  85. db2xtemplate = db2TYPE -o $(dir $@) $<
  86. xmltotemplate = xmlto TYPE $(XMLTOFLAGS) -o $(dir $@) $<
  87. # determine which methods are available
  88. ifeq ($(shell which db2ps >/dev/null 2>&1 && echo found),found)
  89. use-db2x = db2x
  90. prefer-db2x = db2x
  91. else
  92. use-db2x = notfound
  93. prefer-db2x = $(use-xmlto)
  94. endif
  95. ifeq ($(shell which xmlto >/dev/null 2>&1 && echo found),found)
  96. use-xmlto = xmlto
  97. prefer-xmlto = xmlto
  98. else
  99. use-xmlto = notfound
  100. prefer-xmlto = $(use-db2x)
  101. endif
  102. # the commands, generated from the chosen template
  103. quiet_cmd_db2ps = PS $@
  104. cmd_db2ps = $(subst TYPE,ps, $($(PS_METHOD)template))
  105. %.ps : %.xml
  106. $(call cmd,db2ps)
  107. quiet_cmd_db2pdf = PDF $@
  108. cmd_db2pdf = $(subst TYPE,pdf, $($(PDF_METHOD)template))
  109. %.pdf : %.xml
  110. $(call cmd,db2pdf)
  111. main_idx = Documentation/DocBook/index.html
  112. build_main_index = rm -rf $(main_idx) && \
  113. echo '<h1>Linux Kernel HTML Documentation</h1>' >> $(main_idx) && \
  114. echo '<h2>Kernel Version: $(KERNELVERSION)</h2>' >> $(main_idx) && \
  115. cat $(HTML) >> $(main_idx)
  116. quiet_cmd_db2html = HTML $@
  117. cmd_db2html = xmlto xhtml $(XMLTOFLAGS) -o $(patsubst %.html,%,$@) $< && \
  118. echo '<a HREF="$(patsubst %.html,%,$(notdir $@))/index.html"> \
  119. $(patsubst %.html,%,$(notdir $@))</a><p>' > $@
  120. %.html: %.xml
  121. @(which xmlto > /dev/null 2>&1) || \
  122. (echo "*** You need to install xmlto ***"; \
  123. exit 1)
  124. @rm -rf $@ $(patsubst %.html,%,$@)
  125. $(call cmd,db2html)
  126. @if [ ! -z "$(PNG-$(basename $(notdir $@)))" ]; then \
  127. cp $(PNG-$(basename $(notdir $@))) $(patsubst %.html,%,$@); fi
  128. quiet_cmd_db2man = MAN $@
  129. cmd_db2man = if grep -q refentry $<; then xmlto man $(XMLTOFLAGS) -o $(obj)/man $< ; gzip -f $(obj)/man/*.9; fi
  130. %.9 : %.xml
  131. @(which xmlto > /dev/null 2>&1) || \
  132. (echo "*** You need to install xmlto ***"; \
  133. exit 1)
  134. $(Q)mkdir -p $(obj)/man
  135. $(call cmd,db2man)
  136. @touch $@
  137. ###
  138. # Rules to generate postscripts and PNG imgages from .fig format files
  139. quiet_cmd_fig2eps = FIG2EPS $@
  140. cmd_fig2eps = fig2dev -Leps $< $@
  141. %.eps: %.fig
  142. @(which fig2dev > /dev/null 2>&1) || \
  143. (echo "*** You need to install transfig ***"; \
  144. exit 1)
  145. $(call cmd,fig2eps)
  146. quiet_cmd_fig2png = FIG2PNG $@
  147. cmd_fig2png = fig2dev -Lpng $< $@
  148. %.png: %.fig
  149. @(which fig2dev > /dev/null 2>&1) || \
  150. (echo "*** You need to install transfig ***"; \
  151. exit 1)
  152. $(call cmd,fig2png)
  153. ###
  154. # Rule to convert a .c file to inline XML documentation
  155. %.xml: %.c
  156. @echo ' GEN $@'
  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 ' Linux kernel internal documentation in different formats:'
  168. @echo ' htmldocs - HTML'
  169. @echo ' installmandocs - install man pages generated by mandocs'
  170. @echo ' mandocs - man pages'
  171. @echo ' pdfdocs - PDF'
  172. @echo ' psdocs - Postscript'
  173. @echo ' xmldocs - XML DocBook'
  174. ###
  175. # Temporary files left by various tools
  176. clean-files := $(DOCBOOKS) \
  177. $(patsubst %.xml, %.dvi, $(DOCBOOKS)) \
  178. $(patsubst %.xml, %.aux, $(DOCBOOKS)) \
  179. $(patsubst %.xml, %.tex, $(DOCBOOKS)) \
  180. $(patsubst %.xml, %.log, $(DOCBOOKS)) \
  181. $(patsubst %.xml, %.out, $(DOCBOOKS)) \
  182. $(patsubst %.xml, %.ps, $(DOCBOOKS)) \
  183. $(patsubst %.xml, %.pdf, $(DOCBOOKS)) \
  184. $(patsubst %.xml, %.html, $(DOCBOOKS)) \
  185. $(patsubst %.xml, %.9, $(DOCBOOKS)) \
  186. $(C-procfs-example)
  187. clean-dirs := $(patsubst %.xml,%,$(DOCBOOKS)) man
  188. # Declare the contents of the .PHONY variable as phony. We keep that
  189. # information in a variable se we can use it in if_changed and friends.
  190. .PHONY: $(PHONY)