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