blob: 52576135138cc9539f7a92d40807bf6601b92048 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001# SPDX-License-Identifier: GPL-2.0
Marek Vasut1f747c12012-10-06 14:04:58 +00002###
3# This makefile is used to generate the kernel documentation,
4# primarily based on in-line comments in various source files.
Masahiro Yamada5bfd11b2014-02-05 10:52:50 +09005# See Documentation/kernel-doc-nano-HOWTO.txt for instruction in how
Marek Vasut1f747c12012-10-06 14:04:58 +00006# to document the SRC - and how to read it.
7# To add a new book the only step required is to add the book to the
8# list of DOCBOOKS.
9
Heinrich Schuchardt59999172018-05-11 18:15:41 +020010DOCBOOKS := efi.xml linker_lists.xml stdio.xml
Marek Vasut1f747c12012-10-06 14:04:58 +000011
12###
13# The build process is as follows (targets):
14# (xmldocs) [by docproc]
15# file.tmpl --> file.xml +--> file.ps (psdocs) [by db2ps or xmlto]
16# +--> file.pdf (pdfdocs) [by db2pdf or xmlto]
17# +--> DIR=file (htmldocs) [by xmlto]
18# +--> man/ (mandocs) [by xmlto]
19
20
21# for PDF and PS output you can choose between xmlto and docbook-utils tools
22PDF_METHOD = $(prefer-db2x)
23PS_METHOD = $(prefer-db2x)
24
25
26###
27# The targets that may be used.
Masahiro Yamada0d68fb12014-02-04 17:24:28 +090028PHONY += xmldocs sgmldocs psdocs pdfdocs htmldocs mandocs installmandocs cleandocs
Marek Vasut1f747c12012-10-06 14:04:58 +000029
Masahiro Yamada9d9ef812014-04-15 13:30:51 +090030targets += $(DOCBOOKS)
Masahiro Yamada0d68fb12014-02-04 17:24:28 +090031BOOKS := $(addprefix $(obj)/,$(DOCBOOKS))
Marek Vasut1f747c12012-10-06 14:04:58 +000032xmldocs: $(BOOKS)
33sgmldocs: xmldocs
34
35PS := $(patsubst %.xml, %.ps, $(BOOKS))
36psdocs: $(PS)
37
38PDF := $(patsubst %.xml, %.pdf, $(BOOKS))
39pdfdocs: $(PDF)
40
41HTML := $(sort $(patsubst %.xml, %.html, $(BOOKS)))
42htmldocs: $(HTML)
43 $(call build_main_index)
44 $(call build_images)
45 $(call install_media_images)
46
47MAN := $(patsubst %.xml, %.9, $(BOOKS))
48mandocs: $(MAN)
Masahiro Yamada9d9ef812014-04-15 13:30:51 +090049 $(if $(wildcard $(obj)/man/*.9),gzip -f $(obj)/man/*.9)
Marek Vasut1f747c12012-10-06 14:04:58 +000050
51installmandocs: mandocs
52 mkdir -p /usr/local/man/man9/
Masahiro Yamada9d9ef812014-04-15 13:30:51 +090053 install $(obj)/man/*.9.gz /usr/local/man/man9/
Marek Vasut1f747c12012-10-06 14:04:58 +000054
55###
56#External programs used
Masahiro Yamada5bfd11b2014-02-05 10:52:50 +090057KERNELDOC = $(srctree)/scripts/kernel-doc
58DOCPROC = $(objtree)/scripts/docproc
Marek Vasut1f747c12012-10-06 14:04:58 +000059
Masahiro Yamada9d9ef812014-04-15 13:30:51 +090060XMLTOFLAGS = -m $(srctree)/$(src)/stylesheet.xsl
Marek Vasut1f747c12012-10-06 14:04:58 +000061XMLTOFLAGS += --skip-validation
62
63###
64# DOCPROC is used for two purposes:
65# 1) To generate a dependency list for a .tmpl file
66# 2) To preprocess a .tmpl file and call kernel-doc with
67# appropriate parameters.
68# The following rules are used to generate the .xml documentation
69# required to generate the final targets. (ps, pdf, html).
Masahiro Yamada0d68fb12014-02-04 17:24:28 +090070quiet_cmd_docproc = DOCPROC $@
71 cmd_docproc = SRCTREE=$(srctree)/ $(DOCPROC) doc $< >$@
72define rule_docproc
73 set -e; \
74 $(if $($(quiet)cmd_$(1)),echo ' $($(quiet)cmd_$(1))';) \
75 $(cmd_$(1)); \
76 ( \
77 echo 'cmd_$@ := $(cmd_$(1))'; \
78 echo $@: `SRCTREE=$(srctree) $(DOCPROC) depend $<`; \
79 ) > $(dir $@).$(notdir $@).cmd
80endef
Marek Vasut1f747c12012-10-06 14:04:58 +000081
Masahiro Yamada9d9ef812014-04-15 13:30:51 +090082%.xml: %.tmpl $(KERNELDOC) $(DOCPROC) FORCE
Masahiro Yamada0d68fb12014-02-04 17:24:28 +090083 $(call if_changed_rule,docproc)
84
Masahiro Yamada0d68fb12014-02-04 17:24:28 +090085# Tell kbuild to always build the programs
86always := $(hostprogs-y)
87
Marek Vasut1f747c12012-10-06 14:04:58 +000088notfoundtemplate = echo "*** You have to install docbook-utils or xmlto ***"; \
89 exit 1
90db2xtemplate = db2TYPE -o $(dir $@) $<
91xmltotemplate = xmlto TYPE $(XMLTOFLAGS) -o $(dir $@) $<
92
93# determine which methods are available
94ifeq ($(shell which db2ps >/dev/null 2>&1 && echo found),found)
95 use-db2x = db2x
96 prefer-db2x = db2x
97else
98 use-db2x = notfound
99 prefer-db2x = $(use-xmlto)
100endif
101ifeq ($(shell which xmlto >/dev/null 2>&1 && echo found),found)
102 use-xmlto = xmlto
103 prefer-xmlto = xmlto
104else
105 use-xmlto = notfound
106 prefer-xmlto = $(use-db2x)
107endif
108
109# the commands, generated from the chosen template
110quiet_cmd_db2ps = PS $@
111 cmd_db2ps = $(subst TYPE,ps, $($(PS_METHOD)template))
112%.ps : %.xml
Masahiro Yamada0d68fb12014-02-04 17:24:28 +0900113 $(call cmd,db2ps)
Marek Vasut1f747c12012-10-06 14:04:58 +0000114
115quiet_cmd_db2pdf = PDF $@
116 cmd_db2pdf = $(subst TYPE,pdf, $($(PDF_METHOD)template))
117%.pdf : %.xml
Masahiro Yamada0d68fb12014-02-04 17:24:28 +0900118 $(call cmd,db2pdf)
Marek Vasut1f747c12012-10-06 14:04:58 +0000119
120
121index = index.html
Masahiro Yamada9d9ef812014-04-15 13:30:51 +0900122main_idx = $(obj)/$(index)
Marek Vasut1f747c12012-10-06 14:04:58 +0000123build_main_index = rm -rf $(main_idx); \
124 echo '<h1>U-Boot Bootloader HTML Documentation</h1>' >> $(main_idx) && \
Masahiro Yamadab91674a2014-02-24 11:12:09 +0900125 echo '<h2>U-Boot Version: $(UBOOTVERSION)</h2>' >> $(main_idx) && \
Marek Vasut1f747c12012-10-06 14:04:58 +0000126 cat $(HTML) >> $(main_idx)
127
Marek Vasut1f747c12012-10-06 14:04:58 +0000128quiet_cmd_db2html = HTML $@
Masahiro Yamada9d9ef812014-04-15 13:30:51 +0900129 cmd_db2html = xmlto html $(XMLTOFLAGS) -o $(patsubst %.html,%,$@) $< && \
Marek Vasut1f747c12012-10-06 14:04:58 +0000130 echo '<a HREF="$(patsubst %.html,%,$(notdir $@))/index.html"> \
Masahiro Yamada9d9ef812014-04-15 13:30:51 +0900131 $(patsubst %.html,%,$(notdir $@))</a><p>' > $@
Marek Vasut1f747c12012-10-06 14:04:58 +0000132
133%.html: %.xml
134 @(which xmlto > /dev/null 2>&1) || \
135 (echo "*** You need to install xmlto ***"; \
136 exit 1)
137 @rm -rf $@ $(patsubst %.html,%,$@)
Masahiro Yamada0d68fb12014-02-04 17:24:28 +0900138 $(call cmd,db2html)
Marek Vasut1f747c12012-10-06 14:04:58 +0000139 @if [ ! -z "$(PNG-$(basename $(notdir $@)))" ]; then \
Masahiro Yamada0d68fb12014-02-04 17:24:28 +0900140 cp $(PNG-$(basename $(notdir $@))) $(patsubst %.html,%,$@); fi
Marek Vasut1f747c12012-10-06 14:04:58 +0000141
142quiet_cmd_db2man = MAN $@
Masahiro Yamada9d9ef812014-04-15 13:30:51 +0900143 cmd_db2man = if grep -q refentry $<; then xmlto man $(XMLTOFLAGS) -o $(obj)/man $< ; fi
Marek Vasut1f747c12012-10-06 14:04:58 +0000144%.9 : %.xml
145 @(which xmlto > /dev/null 2>&1) || \
146 (echo "*** You need to install xmlto ***"; \
147 exit 1)
Masahiro Yamada59f15f22014-02-04 17:24:24 +0900148 $(Q)mkdir -p $(obj)/man
Masahiro Yamada0d68fb12014-02-04 17:24:28 +0900149 $(call cmd,db2man)
Marek Vasut1f747c12012-10-06 14:04:58 +0000150 @touch $@
151
152###
153# Rules to generate postscripts and PNG images from .fig format files
154quiet_cmd_fig2eps = FIG2EPS $@
155 cmd_fig2eps = fig2dev -Leps $< $@
156
157%.eps: %.fig
158 @(which fig2dev > /dev/null 2>&1) || \
159 (echo "*** You need to install transfig ***"; \
160 exit 1)
Masahiro Yamada0d68fb12014-02-04 17:24:28 +0900161 $(call cmd,fig2eps)
Marek Vasut1f747c12012-10-06 14:04:58 +0000162
163quiet_cmd_fig2png = FIG2PNG $@
164 cmd_fig2png = fig2dev -Lpng $< $@
165
166%.png: %.fig
167 @(which fig2dev > /dev/null 2>&1) || \
168 (echo "*** You need to install transfig ***"; \
169 exit 1)
Masahiro Yamada0d68fb12014-02-04 17:24:28 +0900170 $(call cmd,fig2png)
Marek Vasut1f747c12012-10-06 14:04:58 +0000171
172###
173# Rule to convert a .c file to inline XML documentation
174 gen_xml = :
175 quiet_gen_xml = echo ' GEN $@'
176silent_gen_xml = :
177%.xml: %.c
178 @$($(quiet)gen_xml)
179 @( \
180 echo "<programlisting>"; \
181 expand --tabs=8 < $< | \
182 sed -e "s/&/\\&amp;/g" \
183 -e "s/</\\&lt;/g" \
184 -e "s/>/\\&gt;/g"; \
185 echo "</programlisting>") > $@
186
187###
188# Help targets as used by the top-level makefile
189dochelp:
190 @echo ' U-Boot bootloader internal documentation in different formats:'
191 @echo ' htmldocs - HTML'
192 @echo ' pdfdocs - PDF'
193 @echo ' psdocs - Postscript'
194 @echo ' xmldocs - XML DocBook'
195 @echo ' mandocs - man pages'
196 @echo ' installmandocs - install man pages generated by mandocs'
197 @echo ' cleandocs - clean all generated DocBook files'
198
199###
200# Temporary files left by various tools
201clean-files := $(DOCBOOKS) \
202 $(patsubst %.xml, %.dvi, $(DOCBOOKS)) \
203 $(patsubst %.xml, %.aux, $(DOCBOOKS)) \
204 $(patsubst %.xml, %.tex, $(DOCBOOKS)) \
205 $(patsubst %.xml, %.log, $(DOCBOOKS)) \
206 $(patsubst %.xml, %.out, $(DOCBOOKS)) \
207 $(patsubst %.xml, %.ps, $(DOCBOOKS)) \
208 $(patsubst %.xml, %.pdf, $(DOCBOOKS)) \
209 $(patsubst %.xml, %.html, $(DOCBOOKS)) \
210 $(patsubst %.xml, %.9, $(DOCBOOKS)) \
211 $(index)
212
213clean-dirs := $(patsubst %.xml,%,$(DOCBOOKS)) man
214
215cleandocs:
Masahiro Yamada5bfd11b2014-02-05 10:52:50 +0900216 $(Q)rm -f $(call objectify, $(clean-files))
217 $(Q)rm -rf $(call objectify, $(clean-dirs))
Marek Vasut1f747c12012-10-06 14:04:58 +0000218
219# Declare the contents of the .PHONY variable as phony. We keep that
220# information in a variable se we can use it in if_changed and friends.
221
222.PHONY: $(PHONY)