Makefile 5.8 KB

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