Makefile 8.6 KB

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