Makefile 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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 \
  9. kernel-hacking.xml kernel-locking.xml deviceiobook.xml \
  10. writing_usb_driver.xml networking.xml \
  11. kernel-api.xml filesystems.xml lsm.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. 80211.xml sh.xml regulator.xml w1.xml \
  15. writing_musb_glue_layer.xml iio.xml
  16. ifeq ($(DOCBOOKS),)
  17. # Skip DocBook build if the user explicitly requested no DOCBOOKS.
  18. .DEFAULT:
  19. @echo " SKIP DocBook $@ target (DOCBOOKS=\"\" specified)."
  20. else
  21. ifneq ($(SPHINXDIRS),)
  22. # Skip DocBook build if the user explicitly requested a sphinx dir
  23. .DEFAULT:
  24. @echo " SKIP DocBook $@ target (SPHINXDIRS specified)."
  25. else
  26. ###
  27. # The build process is as follows (targets):
  28. # (xmldocs) [by docproc]
  29. # file.tmpl --> file.xml +--> file.ps (psdocs) [by db2ps or xmlto]
  30. # +--> file.pdf (pdfdocs) [by db2pdf or xmlto]
  31. # +--> DIR=file (htmldocs) [by xmlto]
  32. # +--> man/ (mandocs) [by xmlto]
  33. # for PDF and PS output you can choose between xmlto and docbook-utils tools
  34. PDF_METHOD = $(prefer-db2x)
  35. PS_METHOD = $(prefer-db2x)
  36. targets += $(DOCBOOKS)
  37. BOOKS := $(addprefix $(obj)/,$(DOCBOOKS))
  38. xmldocs: $(BOOKS)
  39. sgmldocs: xmldocs
  40. PS := $(patsubst %.xml, %.ps, $(BOOKS))
  41. psdocs: $(PS)
  42. PDF := $(patsubst %.xml, %.pdf, $(BOOKS))
  43. pdfdocs: $(PDF)
  44. HTML := $(sort $(patsubst %.xml, %.html, $(BOOKS)))
  45. htmldocs: $(HTML)
  46. $(call cmd,build_main_index)
  47. MAN := $(patsubst %.xml, %.9, $(BOOKS))
  48. mandocs: $(MAN)
  49. find $(obj)/man -name '*.9' | xargs gzip -nf
  50. installmandocs: mandocs
  51. mkdir -p /usr/local/man/man9/
  52. find $(obj)/man -name '*.9.gz' -printf '%h %f\n' | \
  53. sort -k 2 -k 1 | uniq -f 1 | sed -e 's: :/:' | \
  54. xargs install -m 644 -t /usr/local/man/man9/
  55. # no-op for the DocBook toolchain
  56. epubdocs:
  57. latexdocs:
  58. ###
  59. #External programs used
  60. KERNELDOCXMLREF = $(srctree)/scripts/kernel-doc-xml-ref
  61. KERNELDOC = $(srctree)/scripts/kernel-doc
  62. DOCPROC = $(objtree)/scripts/docproc
  63. CHECK_LC_CTYPE = $(objtree)/scripts/check-lc_ctype
  64. # Use a fixed encoding - UTF-8 if the C library has support built-in
  65. # or ASCII if not
  66. LC_CTYPE := $(call try-run, LC_CTYPE=C.UTF-8 $(CHECK_LC_CTYPE),C.UTF-8,C)
  67. export LC_CTYPE
  68. XMLTOFLAGS = -m $(srctree)/$(src)/stylesheet.xsl
  69. XMLTOFLAGS += --skip-validation
  70. ###
  71. # DOCPROC is used for two purposes:
  72. # 1) To generate a dependency list for a .tmpl file
  73. # 2) To preprocess a .tmpl file and call kernel-doc with
  74. # appropriate parameters.
  75. # The following rules are used to generate the .xml documentation
  76. # required to generate the final targets. (ps, pdf, html).
  77. quiet_cmd_docproc = DOCPROC $@
  78. cmd_docproc = SRCTREE=$(srctree)/ $(DOCPROC) doc $< >$@
  79. define rule_docproc
  80. set -e; \
  81. $(if $($(quiet)cmd_$(1)),echo ' $($(quiet)cmd_$(1))';) \
  82. $(cmd_$(1)); \
  83. ( \
  84. echo 'cmd_$@ := $(cmd_$(1))'; \
  85. echo $@: `SRCTREE=$(srctree) $(DOCPROC) depend $<`; \
  86. ) > $(dir $@).$(notdir $@).cmd
  87. endef
  88. %.xml: %.tmpl $(KERNELDOC) $(DOCPROC) $(KERNELDOCXMLREF) FORCE
  89. $(call if_changed_rule,docproc)
  90. # Tell kbuild to always build the programs
  91. always := $(hostprogs-y)
  92. notfoundtemplate = echo "*** You have to install docbook-utils or xmlto ***"; \
  93. exit 1
  94. db2xtemplate = db2TYPE -o $(dir $@) $<
  95. xmltotemplate = xmlto TYPE $(XMLTOFLAGS) -o $(dir $@) $<
  96. # determine which methods are available
  97. ifeq ($(shell which db2ps >/dev/null 2>&1 && echo found),found)
  98. use-db2x = db2x
  99. prefer-db2x = db2x
  100. else
  101. use-db2x = notfound
  102. prefer-db2x = $(use-xmlto)
  103. endif
  104. ifeq ($(shell which xmlto >/dev/null 2>&1 && echo found),found)
  105. use-xmlto = xmlto
  106. prefer-xmlto = xmlto
  107. else
  108. use-xmlto = notfound
  109. prefer-xmlto = $(use-db2x)
  110. endif
  111. # the commands, generated from the chosen template
  112. quiet_cmd_db2ps = PS $@
  113. cmd_db2ps = $(subst TYPE,ps, $($(PS_METHOD)template))
  114. %.ps : %.xml
  115. $(call cmd,db2ps)
  116. quiet_cmd_db2pdf = PDF $@
  117. cmd_db2pdf = $(subst TYPE,pdf, $($(PDF_METHOD)template))
  118. %.pdf : %.xml
  119. $(call cmd,db2pdf)
  120. index = index.html
  121. main_idx = $(obj)/$(index)
  122. quiet_cmd_build_main_index = HTML $(main_idx)
  123. cmd_build_main_index = rm -rf $(main_idx); \
  124. echo '<h1>Linux Kernel HTML Documentation</h1>' >> $(main_idx) && \
  125. echo '<h2>Kernel Version: $(KERNELVERSION)</h2>' >> $(main_idx) && \
  126. cat $(HTML) >> $(main_idx)
  127. quiet_cmd_db2html = HTML $@
  128. cmd_db2html = xmlto html $(XMLTOFLAGS) -o $(patsubst %.html,%,$@) $< && \
  129. echo '<a HREF="$(patsubst %.html,%,$(notdir $@))/index.html"> \
  130. $(patsubst %.html,%,$(notdir $@))</a><p>' > $@
  131. ###
  132. # Rules to create an aux XML and .db, and use them to re-process the DocBook XML
  133. # to fill internal hyperlinks
  134. gen_aux_xml = :
  135. quiet_gen_aux_xml = echo ' XMLREF $@'
  136. silent_gen_aux_xml = :
  137. %.aux.xml: %.xml
  138. @$($(quiet)gen_aux_xml)
  139. @rm -rf $@
  140. @(cat $< | egrep "^<refentry id" | egrep -o "\".*\"" | cut -f 2 -d \" > $<.db)
  141. @$(KERNELDOCXMLREF) -db $<.db $< > $@
  142. .PRECIOUS: %.aux.xml
  143. %.html: %.aux.xml
  144. @(which xmlto > /dev/null 2>&1) || \
  145. (echo "*** You need to install xmlto ***"; \
  146. exit 1)
  147. @rm -rf $@ $(patsubst %.html,%,$@)
  148. $(call cmd,db2html)
  149. @if [ ! -z "$(PNG-$(basename $(notdir $@)))" ]; then \
  150. cp $(PNG-$(basename $(notdir $@))) $(patsubst %.html,%,$@); fi
  151. quiet_cmd_db2man = MAN $@
  152. cmd_db2man = if grep -q refentry $<; then xmlto man $(XMLTOFLAGS) -o $(obj)/man/$(*F) $< ; fi
  153. %.9 : %.xml
  154. @(which xmlto > /dev/null 2>&1) || \
  155. (echo "*** You need to install xmlto ***"; \
  156. exit 1)
  157. $(Q)mkdir -p $(obj)/man/$(*F)
  158. $(call cmd,db2man)
  159. @touch $@
  160. ###
  161. # Rules to generate postscripts and PNG images from .fig format files
  162. quiet_cmd_fig2eps = FIG2EPS $@
  163. cmd_fig2eps = fig2dev -Leps $< $@
  164. %.eps: %.fig
  165. @(which fig2dev > /dev/null 2>&1) || \
  166. (echo "*** You need to install transfig ***"; \
  167. exit 1)
  168. $(call cmd,fig2eps)
  169. quiet_cmd_fig2png = FIG2PNG $@
  170. cmd_fig2png = fig2dev -Lpng $< $@
  171. %.png: %.fig
  172. @(which fig2dev > /dev/null 2>&1) || \
  173. (echo "*** You need to install transfig ***"; \
  174. exit 1)
  175. $(call cmd,fig2png)
  176. ###
  177. # Rule to convert a .c file to inline XML documentation
  178. gen_xml = :
  179. quiet_gen_xml = echo ' GEN $@'
  180. silent_gen_xml = :
  181. %.xml: %.c
  182. @$($(quiet)gen_xml)
  183. @( \
  184. echo "<programlisting>"; \
  185. expand --tabs=8 < $< | \
  186. sed -e "s/&/\\&amp;/g" \
  187. -e "s/</\\&lt;/g" \
  188. -e "s/>/\\&gt;/g"; \
  189. echo "</programlisting>") > $@
  190. endif # DOCBOOKS=""
  191. endif # SPHINDIR=...
  192. ###
  193. # Help targets as used by the top-level makefile
  194. dochelp:
  195. @echo ' Linux kernel internal documentation in different formats (DocBook):'
  196. @echo ' htmldocs - HTML'
  197. @echo ' pdfdocs - PDF'
  198. @echo ' psdocs - Postscript'
  199. @echo ' xmldocs - XML DocBook'
  200. @echo ' mandocs - man pages'
  201. @echo ' installmandocs - install man pages generated by mandocs'
  202. @echo ' cleandocs - clean all generated DocBook files'
  203. @echo
  204. @echo ' make DOCBOOKS="s1.xml s2.xml" [target] Generate only docs s1.xml s2.xml'
  205. @echo ' valid values for DOCBOOKS are: $(DOCBOOKS)'
  206. @echo
  207. @echo " make DOCBOOKS=\"\" [target] Don't generate docs from Docbook"
  208. @echo ' This is useful to generate only the ReST docs (Sphinx)'
  209. ###
  210. # Temporary files left by various tools
  211. clean-files := $(DOCBOOKS) \
  212. $(patsubst %.xml, %.dvi, $(DOCBOOKS)) \
  213. $(patsubst %.xml, %.aux, $(DOCBOOKS)) \
  214. $(patsubst %.xml, %.tex, $(DOCBOOKS)) \
  215. $(patsubst %.xml, %.log, $(DOCBOOKS)) \
  216. $(patsubst %.xml, %.out, $(DOCBOOKS)) \
  217. $(patsubst %.xml, %.ps, $(DOCBOOKS)) \
  218. $(patsubst %.xml, %.pdf, $(DOCBOOKS)) \
  219. $(patsubst %.xml, %.html, $(DOCBOOKS)) \
  220. $(patsubst %.xml, %.9, $(DOCBOOKS)) \
  221. $(patsubst %.xml, %.aux.xml, $(DOCBOOKS)) \
  222. $(patsubst %.xml, %.xml.db, $(DOCBOOKS)) \
  223. $(patsubst %.xml, %.xml, $(DOCBOOKS)) \
  224. $(patsubst %.xml, .%.xml.cmd, $(DOCBOOKS)) \
  225. $(index)
  226. clean-dirs := $(patsubst %.xml,%,$(DOCBOOKS)) man
  227. cleandocs:
  228. $(Q)rm -f $(call objectify, $(clean-files))
  229. $(Q)rm -rf $(call objectify, $(clean-dirs))
  230. # Declare the contents of the .PHONY variable as phony. We keep that
  231. # information in a variable se we can use it in if_changed and friends.
  232. .PHONY: $(PHONY)