Makefile 6.4 KB

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