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