blob: 5fd8f5effd0c59b06d0dccec9bade44c8d6395a2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001###
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
Adrian Bunk58ef2c42006-04-01 01:04:59 +02005# to document the SRC - and how to read it.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006# To add a new book the only step required is to add the book to the
7# list of DOCBOOKS.
8
Jonathan Corbet47cb3982016-08-20 13:02:50 -06009DOCBOOKS := z8530book.xml \
Jeff Garzikac9296f2005-05-01 08:59:27 -070010 kernel-hacking.xml kernel-locking.xml deviceiobook.xml \
Alexey Dobriyan82c1e492009-12-15 16:46:59 -080011 writing_usb_driver.xml networking.xml \
Oliver Neukumdd0b38d2016-11-14 15:52:43 +010012 kernel-api.xml filesystems.xml lsm.xml kgdb.xml \
Thomas Gleixner11c869e2006-06-29 02:24:47 -070013 gadget.xml libata.xml mtdnand.xml librs.xml rapidio.xml \
Alexander Dahlcadf81062017-01-28 10:45:32 +010014 genericirq.xml s390-drivers.xml scsi.xml \
John Brooks66115332016-12-23 00:53:10 +000015 sh.xml regulator.xml w1.xml \
Stephan Muellerc441a472016-10-21 04:57:00 +020016 writing_musb_glue_layer.xml iio.xml
Mauro Carvalho Chehab42661292011-05-31 16:27:44 -030017
Jani Nikulabdf107d2016-08-04 11:48:26 +030018ifeq ($(DOCBOOKS),)
19
20# Skip DocBook build if the user explicitly requested no DOCBOOKS.
21.DEFAULT:
22 @echo " SKIP DocBook $@ target (DOCBOOKS=\"\" specified)."
Jani Nikulabdf107d2016-08-04 11:48:26 +030023else
Markus Heiser606b9ac2016-08-13 16:12:42 +020024ifneq ($(SPHINXDIRS),)
25
26# Skip DocBook build if the user explicitly requested a sphinx dir
27.DEFAULT:
28 @echo " SKIP DocBook $@ target (SPHINXDIRS specified)."
29else
30
Jani Nikulabdf107d2016-08-04 11:48:26 +030031
Linus Torvalds1da177e2005-04-16 15:20:36 -070032###
33# The build process is as follows (targets):
Randy Dunlap2ac534b2007-07-19 01:48:23 -070034# (xmldocs) [by docproc]
35# file.tmpl --> file.xml +--> file.ps (psdocs) [by db2ps or xmlto]
36# +--> file.pdf (pdfdocs) [by db2pdf or xmlto]
37# +--> DIR=file (htmldocs) [by xmlto]
38# +--> man/ (mandocs) [by xmlto]
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Martin Waitz71f95cf2005-11-13 16:08:15 -080040
41# for PDF and PS output you can choose between xmlto and docbook-utils tools
42PDF_METHOD = $(prefer-db2x)
43PS_METHOD = $(prefer-db2x)
44
45
Masahiro Yamada6f89b9c2014-01-20 14:10:10 +090046targets += $(DOCBOOKS)
Linus Torvalds1da177e2005-04-16 15:20:36 -070047BOOKS := $(addprefix $(obj)/,$(DOCBOOKS))
Ben Hutchingsa4356002010-08-10 18:02:51 -070048xmldocs: $(BOOKS)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049sgmldocs: xmldocs
50
51PS := $(patsubst %.xml, %.ps, $(BOOKS))
52psdocs: $(PS)
53
54PDF := $(patsubst %.xml, %.pdf, $(BOOKS))
55pdfdocs: $(PDF)
56
Randy Dunlapf15a3cc2007-04-11 08:44:12 -070057HTML := $(sort $(patsubst %.xml, %.html, $(BOOKS)))
Mauro Carvalho Chehab04893042011-05-25 12:24:48 -030058htmldocs: $(HTML)
Mauro Carvalho Chehabe237b652015-11-19 12:38:46 -020059 $(call cmd,build_main_index)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61MAN := $(patsubst %.xml, %.9, $(BOOKS))
62mandocs: $(MAN)
Ben Hutchings32c17352015-07-08 20:06:44 +010063 find $(obj)/man -name '*.9' | xargs gzip -nf
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65installmandocs: mandocs
Martin Waitz8b0c2d92005-05-01 08:59:27 -070066 mkdir -p /usr/local/man/man9/
Ben Hutchings9ed71e72015-08-06 23:36:52 +010067 find $(obj)/man -name '*.9.gz' -printf '%h %f\n' | \
68 sort -k 2 -k 1 | uniq -f 1 | sed -e 's: :/:' | \
69 xargs install -m 644 -t /usr/local/man/man9/
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Jani Nikula22cba312016-05-19 15:14:05 +030071# no-op for the DocBook toolchain
72epubdocs:
Mauro Carvalho Chehabd5651272016-08-18 11:53:39 -030073latexdocs:
Jani Nikula22cba312016-05-19 15:14:05 +030074
Linus Torvalds1da177e2005-04-16 15:20:36 -070075###
76#External programs used
Danilo Cesar Lemes de Paula5699f872015-07-28 16:45:15 -030077KERNELDOCXMLREF = $(srctree)/scripts/kernel-doc-xml-ref
78KERNELDOC = $(srctree)/scripts/kernel-doc
79DOCPROC = $(objtree)/scripts/docproc
Ben Hutchingsb479bfd2015-09-28 01:09:52 +010080CHECK_LC_CTYPE = $(objtree)/scripts/check-lc_ctype
81
82# Use a fixed encoding - UTF-8 if the C library has support built-in
83# or ASCII if not
84LC_CTYPE := $(call try-run, LC_CTYPE=C.UTF-8 $(CHECK_LC_CTYPE),C.UTF-8,C)
85export LC_CTYPE
Martin Waitz8b0c2d92005-05-01 08:59:27 -070086
Masahiro Yamadaec3fadd2014-03-18 15:47:13 +090087XMLTOFLAGS = -m $(srctree)/$(src)/stylesheet.xsl
Alexey Dobriyan82c1e492009-12-15 16:46:59 -080088XMLTOFLAGS += --skip-validation
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
90###
91# DOCPROC is used for two purposes:
92# 1) To generate a dependency list for a .tmpl file
93# 2) To preprocess a .tmpl file and call kernel-doc with
94# appropriate parameters.
95# The following rules are used to generate the .xml documentation
96# required to generate the final targets. (ps, pdf, html).
97quiet_cmd_docproc = DOCPROC $@
98 cmd_docproc = SRCTREE=$(srctree)/ $(DOCPROC) doc $< >$@
99define rule_docproc
100 set -e; \
101 $(if $($(quiet)cmd_$(1)),echo ' $($(quiet)cmd_$(1))';) \
102 $(cmd_$(1)); \
103 ( \
104 echo 'cmd_$@ := $(cmd_$(1))'; \
105 echo $@: `SRCTREE=$(srctree) $(DOCPROC) depend $<`; \
106 ) > $(dir $@).$(notdir $@).cmd
107endef
108
Danilo Cesar Lemes de Paula5699f872015-07-28 16:45:15 -0300109%.xml: %.tmpl $(KERNELDOC) $(DOCPROC) $(KERNELDOCXMLREF) FORCE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 $(call if_changed_rule,docproc)
111
Randy Dunlap3794f3e2008-08-12 15:09:06 -0700112# Tell kbuild to always build the programs
113always := $(hostprogs-y)
114
Martin Waitz71f95cf2005-11-13 16:08:15 -0800115notfoundtemplate = echo "*** You have to install docbook-utils or xmlto ***"; \
116 exit 1
117db2xtemplate = db2TYPE -o $(dir $@) $<
118xmltotemplate = xmlto TYPE $(XMLTOFLAGS) -o $(dir $@) $<
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Martin Waitz71f95cf2005-11-13 16:08:15 -0800120# determine which methods are available
121ifeq ($(shell which db2ps >/dev/null 2>&1 && echo found),found)
122 use-db2x = db2x
123 prefer-db2x = db2x
124else
125 use-db2x = notfound
126 prefer-db2x = $(use-xmlto)
127endif
128ifeq ($(shell which xmlto >/dev/null 2>&1 && echo found),found)
129 use-xmlto = xmlto
130 prefer-xmlto = xmlto
131else
132 use-xmlto = notfound
133 prefer-xmlto = $(use-db2x)
134endif
135
136# the commands, generated from the chosen template
137quiet_cmd_db2ps = PS $@
138 cmd_db2ps = $(subst TYPE,ps, $($(PS_METHOD)template))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139%.ps : %.xml
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 $(call cmd,db2ps)
141
Hans Ulrich Niedermanna34645f2008-10-29 14:00:57 -0700142quiet_cmd_db2pdf = PDF $@
Martin Waitz71f95cf2005-11-13 16:08:15 -0800143 cmd_db2pdf = $(subst TYPE,pdf, $($(PDF_METHOD)template))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144%.pdf : %.xml
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 $(call cmd,db2pdf)
146
Borislav Petkoveb81d932007-05-08 00:29:36 -0700147
Randy Dunlap64e3da12009-04-17 18:28:55 -0700148index = index.html
Masahiro Yamadaec3fadd2014-03-18 15:47:13 +0900149main_idx = $(obj)/$(index)
Mauro Carvalho Chehabe237b652015-11-19 12:38:46 -0200150quiet_cmd_build_main_index = HTML $(main_idx)
151 cmd_build_main_index = rm -rf $(main_idx); \
Borislav Petkoveb81d932007-05-08 00:29:36 -0700152 echo '<h1>Linux Kernel HTML Documentation</h1>' >> $(main_idx) && \
153 echo '<h2>Kernel Version: $(KERNELVERSION)</h2>' >> $(main_idx) && \
154 cat $(HTML) >> $(main_idx)
155
Hans Ulrich Niedermanna34645f2008-10-29 14:00:57 -0700156quiet_cmd_db2html = HTML $@
Robert P. J. Dayc4d79a42013-11-06 13:18:27 -0800157 cmd_db2html = xmlto html $(XMLTOFLAGS) -o $(patsubst %.html,%,$@) $< && \
Martin Waitz4fa35162005-05-01 08:59:28 -0700158 echo '<a HREF="$(patsubst %.html,%,$(notdir $@))/index.html"> \
Masahiro Yamadaec3fadd2014-03-18 15:47:13 +0900159 $(patsubst %.html,%,$(notdir $@))</a><p>' > $@
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
Danilo Cesar Lemes de Paula5699f872015-07-28 16:45:15 -0300161###
162# Rules to create an aux XML and .db, and use them to re-process the DocBook XML
163# to fill internal hyperlinks
164 gen_aux_xml = :
165 quiet_gen_aux_xml = echo ' XMLREF $@'
166silent_gen_aux_xml = :
167%.aux.xml: %.xml
168 @$($(quiet)gen_aux_xml)
169 @rm -rf $@
170 @(cat $< | egrep "^<refentry id" | egrep -o "\".*\"" | cut -f 2 -d \" > $<.db)
171 @$(KERNELDOCXMLREF) -db $<.db $< > $@
172.PRECIOUS: %.aux.xml
173
174%.html: %.aux.xml
Martin Waitz8b0c2d92005-05-01 08:59:27 -0700175 @(which xmlto > /dev/null 2>&1) || \
Sam Ravnborgfd4a3242005-05-01 08:59:28 -0700176 (echo "*** You need to install xmlto ***"; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 exit 1)
178 @rm -rf $@ $(patsubst %.html,%,$@)
179 $(call cmd,db2html)
180 @if [ ! -z "$(PNG-$(basename $(notdir $@)))" ]; then \
181 cp $(PNG-$(basename $(notdir $@))) $(patsubst %.html,%,$@); fi
182
Martin Waitz71f95cf2005-11-13 16:08:15 -0800183quiet_cmd_db2man = MAN $@
Ben Hutchings9ed71e72015-08-06 23:36:52 +0100184 cmd_db2man = if grep -q refentry $<; then xmlto man $(XMLTOFLAGS) -o $(obj)/man/$(*F) $< ; fi
Martin Waitz8b0c2d92005-05-01 08:59:27 -0700185%.9 : %.xml
186 @(which xmlto > /dev/null 2>&1) || \
Sam Ravnborgfd4a3242005-05-01 08:59:28 -0700187 (echo "*** You need to install xmlto ***"; \
Martin Waitz8b0c2d92005-05-01 08:59:27 -0700188 exit 1)
Ben Hutchings9ed71e72015-08-06 23:36:52 +0100189 $(Q)mkdir -p $(obj)/man/$(*F)
Martin Waitz8b0c2d92005-05-01 08:59:27 -0700190 $(call cmd,db2man)
191 @touch $@
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
193###
Simon Arlott0f035b82007-10-20 01:30:25 +0200194# Rules to generate postscripts and PNG images from .fig format files
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195quiet_cmd_fig2eps = FIG2EPS $@
196 cmd_fig2eps = fig2dev -Leps $< $@
197
198%.eps: %.fig
199 @(which fig2dev > /dev/null 2>&1) || \
200 (echo "*** You need to install transfig ***"; \
201 exit 1)
202 $(call cmd,fig2eps)
203
204quiet_cmd_fig2png = FIG2PNG $@
205 cmd_fig2png = fig2dev -Lpng $< $@
206
207%.png: %.fig
208 @(which fig2dev > /dev/null 2>&1) || \
209 (echo "*** You need to install transfig ***"; \
210 exit 1)
211 $(call cmd,fig2png)
212
213###
214# Rule to convert a .c file to inline XML documentation
Mike Frysinger759cd602008-03-28 14:30:58 -0700215 gen_xml = :
216 quiet_gen_xml = echo ' GEN $@'
217silent_gen_xml = :
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218%.xml: %.c
Mike Frysinger759cd602008-03-28 14:30:58 -0700219 @$($(quiet)gen_xml)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 @( \
221 echo "<programlisting>"; \
222 expand --tabs=8 < $< | \
223 sed -e "s/&/\\&amp;/g" \
224 -e "s/</\\&lt;/g" \
225 -e "s/>/\\&gt;/g"; \
226 echo "</programlisting>") > $@
227
Jani Nikulabdf107d2016-08-04 11:48:26 +0300228endif # DOCBOOKS=""
Markus Heiser606b9ac2016-08-13 16:12:42 +0200229endif # SPHINDIR=...
Mauro Carvalho Chehab54721882016-07-09 13:12:45 -0300230
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231###
232# Help targets as used by the top-level makefile
233dochelp:
Jani Nikulaebc88ef2016-06-22 15:41:48 +0300234 @echo ' Linux kernel internal documentation in different formats (DocBook):'
Jesper Juhl6fc52f82006-12-07 00:16:26 +0100235 @echo ' htmldocs - HTML'
Jesper Juhl6fc52f82006-12-07 00:16:26 +0100236 @echo ' pdfdocs - PDF'
237 @echo ' psdocs - Postscript'
238 @echo ' xmldocs - XML DocBook'
Randy Dunlap2810ae82009-04-10 14:20:54 -0700239 @echo ' mandocs - man pages'
240 @echo ' installmandocs - install man pages generated by mandocs'
241 @echo ' cleandocs - clean all generated DocBook files'
Mauro Carvalho Chehabe57f0792015-11-19 12:38:44 -0200242 @echo
Jani Nikulaebc88ef2016-06-22 15:41:48 +0300243 @echo ' make DOCBOOKS="s1.xml s2.xml" [target] Generate only docs s1.xml s2.xml'
Mauro Carvalho Chehabe57f0792015-11-19 12:38:44 -0200244 @echo ' valid values for DOCBOOKS are: $(DOCBOOKS)'
Mauro Carvalho Chehab54721882016-07-09 13:12:45 -0300245 @echo
Jani Nikulabdf107d2016-08-04 11:48:26 +0300246 @echo " make DOCBOOKS=\"\" [target] Don't generate docs from Docbook"
Mauro Carvalho Chehab54721882016-07-09 13:12:45 -0300247 @echo ' This is useful to generate only the ReST docs (Sphinx)'
Mauro Carvalho Chehabe57f0792015-11-19 12:38:44 -0200248
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
250###
251# Temporary files left by various tools
252clean-files := $(DOCBOOKS) \
Danilo Cesar Lemes de Paula5699f872015-07-28 16:45:15 -0300253 $(patsubst %.xml, %.dvi, $(DOCBOOKS)) \
254 $(patsubst %.xml, %.aux, $(DOCBOOKS)) \
255 $(patsubst %.xml, %.tex, $(DOCBOOKS)) \
256 $(patsubst %.xml, %.log, $(DOCBOOKS)) \
257 $(patsubst %.xml, %.out, $(DOCBOOKS)) \
258 $(patsubst %.xml, %.ps, $(DOCBOOKS)) \
259 $(patsubst %.xml, %.pdf, $(DOCBOOKS)) \
260 $(patsubst %.xml, %.html, $(DOCBOOKS)) \
261 $(patsubst %.xml, %.9, $(DOCBOOKS)) \
262 $(patsubst %.xml, %.aux.xml, $(DOCBOOKS)) \
263 $(patsubst %.xml, %.xml.db, $(DOCBOOKS)) \
264 $(patsubst %.xml, %.xml, $(DOCBOOKS)) \
Markus Heiser05d5f952016-11-01 15:36:02 +0100265 $(patsubst %.xml, .%.xml.cmd, $(DOCBOOKS)) \
Alexey Dobriyan82c1e492009-12-15 16:46:59 -0800266 $(index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
Mauro Carvalho Chehab42661292011-05-31 16:27:44 -0300268clean-dirs := $(patsubst %.xml,%,$(DOCBOOKS)) man
Paul Smith4f193362006-03-05 17:14:10 -0500269
Mauro Carvalho Chehab43f71d92016-07-27 06:32:31 -0300270cleandocs:
Randy Dunlap2810ae82009-04-10 14:20:54 -0700271 $(Q)rm -f $(call objectify, $(clean-files))
272 $(Q)rm -rf $(call objectify, $(clean-dirs))
273
Paul Smith4f193362006-03-05 17:14:10 -0500274# Declare the contents of the .PHONY variable as phony. We keep that
275# information in a variable se we can use it in if_changed and friends.
276
277.PHONY: $(PHONY)