1 # SPDX-License-Identifier: GPL-2.0
3 # This makefile is used to generate the kernel documentation,
4 # primarily based on in-line comments in various source files.
5 # See Documentation/kernel-doc-nano-HOWTO.txt for instruction in how
6 # 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
10 DOCBOOKS := linker_lists.xml stdio.xml
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]
21 # for PDF and PS output you can choose between xmlto and docbook-utils tools
22 PDF_METHOD = $(prefer-db2x)
23 PS_METHOD = $(prefer-db2x)
27 # The targets that may be used.
28 PHONY += xmldocs sgmldocs psdocs pdfdocs htmldocs mandocs installmandocs cleandocs
30 targets += $(DOCBOOKS)
31 BOOKS := $(addprefix $(obj)/,$(DOCBOOKS))
35 PS := $(patsubst %.xml, %.ps, $(BOOKS))
38 PDF := $(patsubst %.xml, %.pdf, $(BOOKS))
41 HTML := $(sort $(patsubst %.xml, %.html, $(BOOKS)))
43 $(call build_main_index)
45 $(call install_media_images)
47 MAN := $(patsubst %.xml, %.9, $(BOOKS))
49 $(if $(wildcard $(obj)/man/*.9),gzip -f $(obj)/man/*.9)
51 installmandocs: mandocs
52 mkdir -p /usr/local/man/man9/
53 install $(obj)/man/*.9.gz /usr/local/man/man9/
56 #External programs used
57 KERNELDOC = $(srctree)/scripts/kernel-doc
58 DOCPROC = $(objtree)/scripts/docproc
60 XMLTOFLAGS = -m $(srctree)/$(src)/stylesheet.xsl
61 XMLTOFLAGS += --skip-validation
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).
70 quiet_cmd_docproc = DOCPROC $@
71 cmd_docproc = SRCTREE=$(srctree)/ $(DOCPROC) doc $< >$@
74 $(if $($(quiet)cmd_$(1)),echo ' $($(quiet)cmd_$(1))';) \
77 echo 'cmd_$@ := $(cmd_$(1))'; \
78 echo $@: `SRCTREE=$(srctree) $(DOCPROC) depend $<`; \
79 ) > $(dir $@).$(notdir $@).cmd
82 %.xml: %.tmpl $(KERNELDOC) $(DOCPROC) FORCE
83 $(call if_changed_rule,docproc)
85 # Tell kbuild to always build the programs
86 always := $(hostprogs-y)
88 notfoundtemplate = echo "*** You have to install docbook-utils or xmlto ***"; \
90 db2xtemplate = db2TYPE -o $(dir $@) $<
91 xmltotemplate = xmlto TYPE $(XMLTOFLAGS) -o $(dir $@) $<
93 # determine which methods are available
94 ifeq ($(shell which db2ps >/dev/null 2>&1 && echo found),found)
99 prefer-db2x = $(use-xmlto)
101 ifeq ($(shell which xmlto >/dev/null 2>&1 && echo found),found)
106 prefer-xmlto = $(use-db2x)
109 # the commands, generated from the chosen template
110 quiet_cmd_db2ps = PS $@
111 cmd_db2ps = $(subst TYPE,ps, $($(PS_METHOD)template))
115 quiet_cmd_db2pdf = PDF $@
116 cmd_db2pdf = $(subst TYPE,pdf, $($(PDF_METHOD)template))
122 main_idx = $(obj)/$(index)
123 build_main_index = rm -rf $(main_idx); \
124 echo '<h1>U-Boot Bootloader HTML Documentation</h1>' >> $(main_idx) && \
125 echo '<h2>U-Boot Version: $(UBOOTVERSION)</h2>' >> $(main_idx) && \
126 cat $(HTML) >> $(main_idx)
128 quiet_cmd_db2html = HTML $@
129 cmd_db2html = xmlto html $(XMLTOFLAGS) -o $(patsubst %.html,%,$@) $< && \
130 echo '<a HREF="$(patsubst %.html,%,$(notdir $@))/index.html"> \
131 $(patsubst %.html,%,$(notdir $@))</a><p>' > $@
134 @(which xmlto > /dev/null 2>&1) || \
135 (echo "*** You need to install xmlto ***"; \
137 @rm -rf $@ $(patsubst %.html,%,$@)
139 @if [ ! -z "$(PNG-$(basename $(notdir $@)))" ]; then \
140 cp $(PNG-$(basename $(notdir $@))) $(patsubst %.html,%,$@); fi
142 quiet_cmd_db2man = MAN $@
143 cmd_db2man = if grep -q refentry $<; then xmlto man $(XMLTOFLAGS) -o $(obj)/man $< ; fi
145 @(which xmlto > /dev/null 2>&1) || \
146 (echo "*** You need to install xmlto ***"; \
148 $(Q)mkdir -p $(obj)/man
153 # Rules to generate postscripts and PNG images from .fig format files
154 quiet_cmd_fig2eps = FIG2EPS $@
155 cmd_fig2eps = fig2dev -Leps $< $@
158 @(which fig2dev > /dev/null 2>&1) || \
159 (echo "*** You need to install transfig ***"; \
163 quiet_cmd_fig2png = FIG2PNG $@
164 cmd_fig2png = fig2dev -Lpng $< $@
167 @(which fig2dev > /dev/null 2>&1) || \
168 (echo "*** You need to install transfig ***"; \
173 # Rule to convert a .c file to inline XML documentation
175 quiet_gen_xml = echo ' GEN $@'
180 echo "<programlisting>"; \
181 expand --tabs=8 < $< | \
182 sed -e "s/&/\\&/g" \
185 echo "</programlisting>") > $@
188 # Help targets as used by the top-level makefile
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'
200 # Temporary files left by various tools
201 clean-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)) \
213 clean-dirs := $(patsubst %.xml,%,$(DOCBOOKS)) man
216 $(Q)rm -f $(call objectify, $(clean-files))
217 $(Q)rm -rf $(call objectify, $(clean-dirs))
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.