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
9 # SPDX-License-Identifier: GPL-2.0
12 DOCBOOKS := linker_lists.xml stdio.xml
15 # The build process is as follows (targets):
16 # (xmldocs) [by docproc]
17 # file.tmpl --> file.xml +--> file.ps (psdocs) [by db2ps or xmlto]
18 # +--> file.pdf (pdfdocs) [by db2pdf or xmlto]
19 # +--> DIR=file (htmldocs) [by xmlto]
20 # +--> man/ (mandocs) [by xmlto]
23 # for PDF and PS output you can choose between xmlto and docbook-utils tools
24 PDF_METHOD = $(prefer-db2x)
25 PS_METHOD = $(prefer-db2x)
29 # The targets that may be used.
30 PHONY += xmldocs sgmldocs psdocs pdfdocs htmldocs mandocs installmandocs cleandocs
32 targets += $(DOCBOOKS)
33 BOOKS := $(addprefix $(obj)/,$(DOCBOOKS))
37 PS := $(patsubst %.xml, %.ps, $(BOOKS))
40 PDF := $(patsubst %.xml, %.pdf, $(BOOKS))
43 HTML := $(sort $(patsubst %.xml, %.html, $(BOOKS)))
45 $(call build_main_index)
47 $(call install_media_images)
49 MAN := $(patsubst %.xml, %.9, $(BOOKS))
51 $(if $(wildcard $(obj)/man/*.9),gzip -f $(obj)/man/*.9)
53 installmandocs: mandocs
54 mkdir -p /usr/local/man/man9/
55 install $(obj)/man/*.9.gz /usr/local/man/man9/
58 #External programs used
59 KERNELDOC = $(srctree)/scripts/kernel-doc
60 DOCPROC = $(objtree)/scripts/docproc
62 XMLTOFLAGS = -m $(srctree)/$(src)/stylesheet.xsl
63 XMLTOFLAGS += --skip-validation
66 # DOCPROC is used for two purposes:
67 # 1) To generate a dependency list for a .tmpl file
68 # 2) To preprocess a .tmpl file and call kernel-doc with
69 # appropriate parameters.
70 # The following rules are used to generate the .xml documentation
71 # required to generate the final targets. (ps, pdf, html).
72 quiet_cmd_docproc = DOCPROC $@
73 cmd_docproc = SRCTREE=$(srctree)/ $(DOCPROC) doc $< >$@
76 $(if $($(quiet)cmd_$(1)),echo ' $($(quiet)cmd_$(1))';) \
79 echo 'cmd_$@ := $(cmd_$(1))'; \
80 echo $@: `SRCTREE=$(srctree) $(DOCPROC) depend $<`; \
81 ) > $(dir $@).$(notdir $@).cmd
84 %.xml: %.tmpl $(KERNELDOC) $(DOCPROC) FORCE
85 $(call if_changed_rule,docproc)
87 # Tell kbuild to always build the programs
88 always := $(hostprogs-y)
90 notfoundtemplate = echo "*** You have to install docbook-utils or xmlto ***"; \
92 db2xtemplate = db2TYPE -o $(dir $@) $<
93 xmltotemplate = xmlto TYPE $(XMLTOFLAGS) -o $(dir $@) $<
95 # determine which methods are available
96 ifeq ($(shell which db2ps >/dev/null 2>&1 && echo found),found)
101 prefer-db2x = $(use-xmlto)
103 ifeq ($(shell which xmlto >/dev/null 2>&1 && echo found),found)
108 prefer-xmlto = $(use-db2x)
111 # the commands, generated from the chosen template
112 quiet_cmd_db2ps = PS $@
113 cmd_db2ps = $(subst TYPE,ps, $($(PS_METHOD)template))
117 quiet_cmd_db2pdf = PDF $@
118 cmd_db2pdf = $(subst TYPE,pdf, $($(PDF_METHOD)template))
124 main_idx = $(obj)/$(index)
125 build_main_index = rm -rf $(main_idx); \
126 echo '<h1>U-Boot Bootloader HTML Documentation</h1>' >> $(main_idx) && \
127 echo '<h2>U-Boot Version: $(UBOOTVERSION)</h2>' >> $(main_idx) && \
128 cat $(HTML) >> $(main_idx)
130 quiet_cmd_db2html = HTML $@
131 cmd_db2html = xmlto html $(XMLTOFLAGS) -o $(patsubst %.html,%,$@) $< && \
132 echo '<a HREF="$(patsubst %.html,%,$(notdir $@))/index.html"> \
133 $(patsubst %.html,%,$(notdir $@))</a><p>' > $@
136 @(which xmlto > /dev/null 2>&1) || \
137 (echo "*** You need to install xmlto ***"; \
139 @rm -rf $@ $(patsubst %.html,%,$@)
141 @if [ ! -z "$(PNG-$(basename $(notdir $@)))" ]; then \
142 cp $(PNG-$(basename $(notdir $@))) $(patsubst %.html,%,$@); fi
144 quiet_cmd_db2man = MAN $@
145 cmd_db2man = if grep -q refentry $<; then xmlto man $(XMLTOFLAGS) -o $(obj)/man $< ; fi
147 @(which xmlto > /dev/null 2>&1) || \
148 (echo "*** You need to install xmlto ***"; \
150 $(Q)mkdir -p $(obj)/man
155 # Rules to generate postscripts and PNG images from .fig format files
156 quiet_cmd_fig2eps = FIG2EPS $@
157 cmd_fig2eps = fig2dev -Leps $< $@
160 @(which fig2dev > /dev/null 2>&1) || \
161 (echo "*** You need to install transfig ***"; \
165 quiet_cmd_fig2png = FIG2PNG $@
166 cmd_fig2png = fig2dev -Lpng $< $@
169 @(which fig2dev > /dev/null 2>&1) || \
170 (echo "*** You need to install transfig ***"; \
175 # Rule to convert a .c file to inline XML documentation
177 quiet_gen_xml = echo ' GEN $@'
182 echo "<programlisting>"; \
183 expand --tabs=8 < $< | \
184 sed -e "s/&/\\&/g" \
187 echo "</programlisting>") > $@
190 # Help targets as used by the top-level makefile
192 @echo ' U-Boot bootloader internal documentation in different formats:'
193 @echo ' htmldocs - HTML'
194 @echo ' pdfdocs - PDF'
195 @echo ' psdocs - Postscript'
196 @echo ' xmldocs - XML DocBook'
197 @echo ' mandocs - man pages'
198 @echo ' installmandocs - install man pages generated by mandocs'
199 @echo ' cleandocs - clean all generated DocBook files'
202 # Temporary files left by various tools
203 clean-files := $(DOCBOOKS) \
204 $(patsubst %.xml, %.dvi, $(DOCBOOKS)) \
205 $(patsubst %.xml, %.aux, $(DOCBOOKS)) \
206 $(patsubst %.xml, %.tex, $(DOCBOOKS)) \
207 $(patsubst %.xml, %.log, $(DOCBOOKS)) \
208 $(patsubst %.xml, %.out, $(DOCBOOKS)) \
209 $(patsubst %.xml, %.ps, $(DOCBOOKS)) \
210 $(patsubst %.xml, %.pdf, $(DOCBOOKS)) \
211 $(patsubst %.xml, %.html, $(DOCBOOKS)) \
212 $(patsubst %.xml, %.9, $(DOCBOOKS)) \
215 clean-dirs := $(patsubst %.xml,%,$(DOCBOOKS)) man
218 $(Q)rm -f $(call objectify, $(clean-files))
219 $(Q)rm -rf $(call objectify, $(clean-dirs))
221 # Declare the contents of the .PHONY variable as phony. We keep that
222 # information in a variable se we can use it in if_changed and friends.