Makefile 7.1 KB

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