Makefile 8.0 KB

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