Makefile 7.3 KB

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