Makefile 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. 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 sh.xml regulator.xml \
  15. alsa-driver-api.xml writing-an-alsa-driver.xml \
  16. tracepoint.xml media.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 media
  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: media $(HTML)
  39. $(call build_main_index)
  40. MAN := $(patsubst %.xml, %.9, $(BOOKS))
  41. mandocs: $(MAN)
  42. media:
  43. mkdir -p $(srctree)/Documentation/DocBook/media/
  44. cp $(srctree)/Documentation/DocBook/dvb/*.png $(srctree)/Documentation/DocBook/v4l/*.gif $(srctree)/Documentation/DocBook/media/
  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/basic/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. ###
  84. # procfs guide uses a .c file as example code.
  85. # This requires an explicit dependency
  86. C-procfs-example = procfs_example.xml
  87. C-procfs-example2 = $(addprefix $(obj)/,$(C-procfs-example))
  88. $(obj)/procfs-guide.xml: $(C-procfs-example2)
  89. # List of programs to build
  90. ##oops, this is a kernel module::hostprogs-y := procfs_example
  91. obj-m += procfs_example.o
  92. # Tell kbuild to always build the programs
  93. always := $(hostprogs-y)
  94. notfoundtemplate = echo "*** You have to install docbook-utils or xmlto ***"; \
  95. exit 1
  96. db2xtemplate = db2TYPE -o $(dir $@) $<
  97. xmltotemplate = xmlto TYPE $(XMLTOFLAGS) -o $(dir $@) $<
  98. # determine which methods are available
  99. ifeq ($(shell which db2ps >/dev/null 2>&1 && echo found),found)
  100. use-db2x = db2x
  101. prefer-db2x = db2x
  102. else
  103. use-db2x = notfound
  104. prefer-db2x = $(use-xmlto)
  105. endif
  106. ifeq ($(shell which xmlto >/dev/null 2>&1 && echo found),found)
  107. use-xmlto = xmlto
  108. prefer-xmlto = xmlto
  109. else
  110. use-xmlto = notfound
  111. prefer-xmlto = $(use-db2x)
  112. endif
  113. # the commands, generated from the chosen template
  114. quiet_cmd_db2ps = PS $@
  115. cmd_db2ps = $(subst TYPE,ps, $($(PS_METHOD)template))
  116. %.ps : %.xml
  117. $(call cmd,db2ps)
  118. quiet_cmd_db2pdf = PDF $@
  119. cmd_db2pdf = $(subst TYPE,pdf, $($(PDF_METHOD)template))
  120. %.pdf : %.xml
  121. $(call cmd,db2pdf)
  122. index = index.html
  123. main_idx = Documentation/DocBook/$(index)
  124. build_main_index = rm -rf $(main_idx) && \
  125. echo '<h1>Linux Kernel HTML Documentation</h1>' >> $(main_idx) && \
  126. echo '<h2>Kernel Version: $(KERNELVERSION)</h2>' >> $(main_idx) && \
  127. cat $(HTML) >> $(main_idx)
  128. quiet_cmd_db2html = HTML $@
  129. cmd_db2html = xmlto xhtml $(XMLTOFLAGS) -o $(patsubst %.html,%,$@) $< && \
  130. echo '<a HREF="$(patsubst %.html,%,$(notdir $@))/index.html"> \
  131. $(patsubst %.html,%,$(notdir $@))</a><p>' > $@
  132. %.html: %.xml
  133. @(which xmlto > /dev/null 2>&1) || \
  134. (echo "*** You need to install xmlto ***"; \
  135. exit 1)
  136. @rm -rf $@ $(patsubst %.html,%,$@)
  137. $(call cmd,db2html)
  138. @if [ ! -z "$(PNG-$(basename $(notdir $@)))" ]; then \
  139. cp $(PNG-$(basename $(notdir $@))) $(patsubst %.html,%,$@); fi
  140. quiet_cmd_db2man = MAN $@
  141. cmd_db2man = if grep -q refentry $<; then xmlto man $(XMLTOFLAGS) -o $(obj)/man $< ; gzip -f $(obj)/man/*.9; fi
  142. %.9 : %.xml
  143. @(which xmlto > /dev/null 2>&1) || \
  144. (echo "*** You need to install xmlto ***"; \
  145. exit 1)
  146. $(Q)mkdir -p $(obj)/man
  147. $(call cmd,db2man)
  148. @touch $@
  149. ###
  150. # Rules to generate postscripts and PNG images from .fig format files
  151. quiet_cmd_fig2eps = FIG2EPS $@
  152. cmd_fig2eps = fig2dev -Leps $< $@
  153. %.eps: %.fig
  154. @(which fig2dev > /dev/null 2>&1) || \
  155. (echo "*** You need to install transfig ***"; \
  156. exit 1)
  157. $(call cmd,fig2eps)
  158. quiet_cmd_fig2png = FIG2PNG $@
  159. cmd_fig2png = fig2dev -Lpng $< $@
  160. %.png: %.fig
  161. @(which fig2dev > /dev/null 2>&1) || \
  162. (echo "*** You need to install transfig ***"; \
  163. exit 1)
  164. $(call cmd,fig2png)
  165. ###
  166. # Rule to convert a .c file to inline XML documentation
  167. gen_xml = :
  168. quiet_gen_xml = echo ' GEN $@'
  169. silent_gen_xml = :
  170. %.xml: %.c
  171. @$($(quiet)gen_xml)
  172. @( \
  173. echo "<programlisting>"; \
  174. expand --tabs=8 < $< | \
  175. sed -e "s/&/\\&amp;/g" \
  176. -e "s/</\\&lt;/g" \
  177. -e "s/>/\\&gt;/g"; \
  178. echo "</programlisting>") > $@
  179. ###
  180. # Help targets as used by the top-level makefile
  181. dochelp:
  182. @echo ' Linux kernel internal documentation in different formats:'
  183. @echo ' htmldocs - HTML'
  184. @echo ' pdfdocs - PDF'
  185. @echo ' psdocs - Postscript'
  186. @echo ' xmldocs - XML DocBook'
  187. @echo ' mandocs - man pages'
  188. @echo ' installmandocs - install man pages generated by mandocs'
  189. @echo ' cleandocs - clean all generated DocBook files'
  190. ###
  191. # Temporary files left by various tools
  192. clean-files := $(DOCBOOKS) \
  193. $(patsubst %.xml, %.dvi, $(DOCBOOKS)) \
  194. $(patsubst %.xml, %.aux, $(DOCBOOKS)) \
  195. $(patsubst %.xml, %.tex, $(DOCBOOKS)) \
  196. $(patsubst %.xml, %.log, $(DOCBOOKS)) \
  197. $(patsubst %.xml, %.out, $(DOCBOOKS)) \
  198. $(patsubst %.xml, %.ps, $(DOCBOOKS)) \
  199. $(patsubst %.xml, %.pdf, $(DOCBOOKS)) \
  200. $(patsubst %.xml, %.html, $(DOCBOOKS)) \
  201. $(patsubst %.xml, %.9, $(DOCBOOKS)) \
  202. $(C-procfs-example) $(index)
  203. clean-dirs := $(patsubst %.xml,%,$(DOCBOOKS)) man
  204. cleandocs:
  205. $(Q)rm -f $(call objectify, $(clean-files))
  206. $(Q)rm -rf $(call objectify, $(clean-dirs))
  207. # Declare the contents of the .PHONY variable as phony. We keep that
  208. # information in a variable se we can use it in if_changed and friends.
  209. .PHONY: $(PHONY)