Makefile 7.7 KB

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