Makefile 7.5 KB

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