blob: 9caa5126085c8cedad1b4e6703a447a78a0e838b [file] [log] [blame]
Marek Vasut30ff8912012-10-06 14:04:58 +00001###
2# This makefile is used to generate the kernel documentation,
3# primarily based on in-line comments in various source files.
Masahiro Yamada8fac9c72014-02-05 10:52:50 +09004# See Documentation/kernel-doc-nano-HOWTO.txt for instruction in how
Marek Vasut30ff8912012-10-06 14:04:58 +00005# 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.
Tom Rinida58dec2015-11-10 01:06:16 +00008#
9# SPDX-License-Identifier: GPL-2.0
10#
Marek Vasut30ff8912012-10-06 14:04:58 +000011
Masahiro Yamadababb4442014-02-05 10:52:52 +090012DOCBOOKS := linker_lists.xml stdio.xml
Marek Vasut30ff8912012-10-06 14:04:58 +000013
14###
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]
21
22
23# for PDF and PS output you can choose between xmlto and docbook-utils tools
24PDF_METHOD = $(prefer-db2x)
25PS_METHOD = $(prefer-db2x)
26
27
28###
29# The targets that may be used.
Masahiro Yamada6825a952014-02-04 17:24:28 +090030PHONY += xmldocs sgmldocs psdocs pdfdocs htmldocs mandocs installmandocs cleandocs
Marek Vasut30ff8912012-10-06 14:04:58 +000031
Masahiro Yamada71ba2452014-04-15 13:30:51 +090032targets += $(DOCBOOKS)
Masahiro Yamada6825a952014-02-04 17:24:28 +090033BOOKS := $(addprefix $(obj)/,$(DOCBOOKS))
Marek Vasut30ff8912012-10-06 14:04:58 +000034xmldocs: $(BOOKS)
35sgmldocs: xmldocs
36
37PS := $(patsubst %.xml, %.ps, $(BOOKS))
38psdocs: $(PS)
39
40PDF := $(patsubst %.xml, %.pdf, $(BOOKS))
41pdfdocs: $(PDF)
42
43HTML := $(sort $(patsubst %.xml, %.html, $(BOOKS)))
44htmldocs: $(HTML)
45 $(call build_main_index)
46 $(call build_images)
47 $(call install_media_images)
48
49MAN := $(patsubst %.xml, %.9, $(BOOKS))
50mandocs: $(MAN)
Masahiro Yamada71ba2452014-04-15 13:30:51 +090051 $(if $(wildcard $(obj)/man/*.9),gzip -f $(obj)/man/*.9)
Marek Vasut30ff8912012-10-06 14:04:58 +000052
53installmandocs: mandocs
54 mkdir -p /usr/local/man/man9/
Masahiro Yamada71ba2452014-04-15 13:30:51 +090055 install $(obj)/man/*.9.gz /usr/local/man/man9/
Marek Vasut30ff8912012-10-06 14:04:58 +000056
57###
58#External programs used
Masahiro Yamada8fac9c72014-02-05 10:52:50 +090059KERNELDOC = $(srctree)/scripts/kernel-doc
60DOCPROC = $(objtree)/scripts/docproc
Marek Vasut30ff8912012-10-06 14:04:58 +000061
Masahiro Yamada71ba2452014-04-15 13:30:51 +090062XMLTOFLAGS = -m $(srctree)/$(src)/stylesheet.xsl
Marek Vasut30ff8912012-10-06 14:04:58 +000063XMLTOFLAGS += --skip-validation
64
65###
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).
Masahiro Yamada6825a952014-02-04 17:24:28 +090072quiet_cmd_docproc = DOCPROC $@
73 cmd_docproc = SRCTREE=$(srctree)/ $(DOCPROC) doc $< >$@
74define rule_docproc
75 set -e; \
76 $(if $($(quiet)cmd_$(1)),echo ' $($(quiet)cmd_$(1))';) \
77 $(cmd_$(1)); \
78 ( \
79 echo 'cmd_$@ := $(cmd_$(1))'; \
80 echo $@: `SRCTREE=$(srctree) $(DOCPROC) depend $<`; \
81 ) > $(dir $@).$(notdir $@).cmd
82endef
Marek Vasut30ff8912012-10-06 14:04:58 +000083
Masahiro Yamada71ba2452014-04-15 13:30:51 +090084%.xml: %.tmpl $(KERNELDOC) $(DOCPROC) FORCE
Masahiro Yamada6825a952014-02-04 17:24:28 +090085 $(call if_changed_rule,docproc)
86
Masahiro Yamada6825a952014-02-04 17:24:28 +090087# Tell kbuild to always build the programs
88always := $(hostprogs-y)
89
Marek Vasut30ff8912012-10-06 14:04:58 +000090notfoundtemplate = echo "*** You have to install docbook-utils or xmlto ***"; \
91 exit 1
92db2xtemplate = db2TYPE -o $(dir $@) $<
93xmltotemplate = xmlto TYPE $(XMLTOFLAGS) -o $(dir $@) $<
94
95# determine which methods are available
96ifeq ($(shell which db2ps >/dev/null 2>&1 && echo found),found)
97 use-db2x = db2x
98 prefer-db2x = db2x
99else
100 use-db2x = notfound
101 prefer-db2x = $(use-xmlto)
102endif
103ifeq ($(shell which xmlto >/dev/null 2>&1 && echo found),found)
104 use-xmlto = xmlto
105 prefer-xmlto = xmlto
106else
107 use-xmlto = notfound
108 prefer-xmlto = $(use-db2x)
109endif
110
111# the commands, generated from the chosen template
112quiet_cmd_db2ps = PS $@
113 cmd_db2ps = $(subst TYPE,ps, $($(PS_METHOD)template))
114%.ps : %.xml
Masahiro Yamada6825a952014-02-04 17:24:28 +0900115 $(call cmd,db2ps)
Marek Vasut30ff8912012-10-06 14:04:58 +0000116
117quiet_cmd_db2pdf = PDF $@
118 cmd_db2pdf = $(subst TYPE,pdf, $($(PDF_METHOD)template))
119%.pdf : %.xml
Masahiro Yamada6825a952014-02-04 17:24:28 +0900120 $(call cmd,db2pdf)
Marek Vasut30ff8912012-10-06 14:04:58 +0000121
122
123index = index.html
Masahiro Yamada71ba2452014-04-15 13:30:51 +0900124main_idx = $(obj)/$(index)
Marek Vasut30ff8912012-10-06 14:04:58 +0000125build_main_index = rm -rf $(main_idx); \
126 echo '<h1>U-Boot Bootloader HTML Documentation</h1>' >> $(main_idx) && \
Masahiro Yamada74241452014-02-24 11:12:09 +0900127 echo '<h2>U-Boot Version: $(UBOOTVERSION)</h2>' >> $(main_idx) && \
Marek Vasut30ff8912012-10-06 14:04:58 +0000128 cat $(HTML) >> $(main_idx)
129
Marek Vasut30ff8912012-10-06 14:04:58 +0000130quiet_cmd_db2html = HTML $@
Masahiro Yamada71ba2452014-04-15 13:30:51 +0900131 cmd_db2html = xmlto html $(XMLTOFLAGS) -o $(patsubst %.html,%,$@) $< && \
Marek Vasut30ff8912012-10-06 14:04:58 +0000132 echo '<a HREF="$(patsubst %.html,%,$(notdir $@))/index.html"> \
Masahiro Yamada71ba2452014-04-15 13:30:51 +0900133 $(patsubst %.html,%,$(notdir $@))</a><p>' > $@
Marek Vasut30ff8912012-10-06 14:04:58 +0000134
135%.html: %.xml
136 @(which xmlto > /dev/null 2>&1) || \
137 (echo "*** You need to install xmlto ***"; \
138 exit 1)
139 @rm -rf $@ $(patsubst %.html,%,$@)
Masahiro Yamada6825a952014-02-04 17:24:28 +0900140 $(call cmd,db2html)
Marek Vasut30ff8912012-10-06 14:04:58 +0000141 @if [ ! -z "$(PNG-$(basename $(notdir $@)))" ]; then \
Masahiro Yamada6825a952014-02-04 17:24:28 +0900142 cp $(PNG-$(basename $(notdir $@))) $(patsubst %.html,%,$@); fi
Marek Vasut30ff8912012-10-06 14:04:58 +0000143
144quiet_cmd_db2man = MAN $@
Masahiro Yamada71ba2452014-04-15 13:30:51 +0900145 cmd_db2man = if grep -q refentry $<; then xmlto man $(XMLTOFLAGS) -o $(obj)/man $< ; fi
Marek Vasut30ff8912012-10-06 14:04:58 +0000146%.9 : %.xml
147 @(which xmlto > /dev/null 2>&1) || \
148 (echo "*** You need to install xmlto ***"; \
149 exit 1)
Masahiro Yamada9e414032014-02-04 17:24:24 +0900150 $(Q)mkdir -p $(obj)/man
Masahiro Yamada6825a952014-02-04 17:24:28 +0900151 $(call cmd,db2man)
Marek Vasut30ff8912012-10-06 14:04:58 +0000152 @touch $@
153
154###
155# Rules to generate postscripts and PNG images from .fig format files
156quiet_cmd_fig2eps = FIG2EPS $@
157 cmd_fig2eps = fig2dev -Leps $< $@
158
159%.eps: %.fig
160 @(which fig2dev > /dev/null 2>&1) || \
161 (echo "*** You need to install transfig ***"; \
162 exit 1)
Masahiro Yamada6825a952014-02-04 17:24:28 +0900163 $(call cmd,fig2eps)
Marek Vasut30ff8912012-10-06 14:04:58 +0000164
165quiet_cmd_fig2png = FIG2PNG $@
166 cmd_fig2png = fig2dev -Lpng $< $@
167
168%.png: %.fig
169 @(which fig2dev > /dev/null 2>&1) || \
170 (echo "*** You need to install transfig ***"; \
171 exit 1)
Masahiro Yamada6825a952014-02-04 17:24:28 +0900172 $(call cmd,fig2png)
Marek Vasut30ff8912012-10-06 14:04:58 +0000173
174###
175# Rule to convert a .c file to inline XML documentation
176 gen_xml = :
177 quiet_gen_xml = echo ' GEN $@'
178silent_gen_xml = :
179%.xml: %.c
180 @$($(quiet)gen_xml)
181 @( \
182 echo "<programlisting>"; \
183 expand --tabs=8 < $< | \
184 sed -e "s/&/\\&amp;/g" \
185 -e "s/</\\&lt;/g" \
186 -e "s/>/\\&gt;/g"; \
187 echo "</programlisting>") > $@
188
189###
190# Help targets as used by the top-level makefile
191dochelp:
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'
200
201###
202# Temporary files left by various tools
203clean-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)) \
213 $(index)
214
215clean-dirs := $(patsubst %.xml,%,$(DOCBOOKS)) man
216
217cleandocs:
Masahiro Yamada8fac9c72014-02-05 10:52:50 +0900218 $(Q)rm -f $(call objectify, $(clean-files))
219 $(Q)rm -rf $(call objectify, $(clean-dirs))
Marek Vasut30ff8912012-10-06 14:04:58 +0000220
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.
223
224.PHONY: $(PHONY)