Makefile 7.5 KB

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