Makefile 5.8 KB

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