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