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