blob: 593237f04ae2dea836cdd4fff3d64fe9cddb782c [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.
8
Masahiro Yamadababb4442014-02-05 10:52:52 +09009DOCBOOKS := linker_lists.xml stdio.xml
Marek Vasut30ff8912012-10-06 14:04:58 +000010
11###
12# The build process is as follows (targets):
13# (xmldocs) [by docproc]
14# file.tmpl --> file.xml +--> file.ps (psdocs) [by db2ps or xmlto]
15# +--> file.pdf (pdfdocs) [by db2pdf or xmlto]
16# +--> DIR=file (htmldocs) [by xmlto]
17# +--> man/ (mandocs) [by xmlto]
18
19
20# for PDF and PS output you can choose between xmlto and docbook-utils tools
21PDF_METHOD = $(prefer-db2x)
22PS_METHOD = $(prefer-db2x)
23
24
25###
26# The targets that may be used.
Masahiro Yamada6825a952014-02-04 17:24:28 +090027PHONY += xmldocs sgmldocs psdocs pdfdocs htmldocs mandocs installmandocs cleandocs
Marek Vasut30ff8912012-10-06 14:04:58 +000028
Masahiro Yamada71ba2452014-04-15 13:30:51 +090029targets += $(DOCBOOKS)
Masahiro Yamada6825a952014-02-04 17:24:28 +090030BOOKS := $(addprefix $(obj)/,$(DOCBOOKS))
Marek Vasut30ff8912012-10-06 14:04:58 +000031xmldocs: $(BOOKS)
32sgmldocs: xmldocs
33
34PS := $(patsubst %.xml, %.ps, $(BOOKS))
35psdocs: $(PS)
36
37PDF := $(patsubst %.xml, %.pdf, $(BOOKS))
38pdfdocs: $(PDF)
39
40HTML := $(sort $(patsubst %.xml, %.html, $(BOOKS)))
41htmldocs: $(HTML)
42 $(call build_main_index)
43 $(call build_images)
44 $(call install_media_images)
45
46MAN := $(patsubst %.xml, %.9, $(BOOKS))
47mandocs: $(MAN)
Masahiro Yamada71ba2452014-04-15 13:30:51 +090048 $(if $(wildcard $(obj)/man/*.9),gzip -f $(obj)/man/*.9)
Marek Vasut30ff8912012-10-06 14:04:58 +000049
50installmandocs: mandocs
51 mkdir -p /usr/local/man/man9/
Masahiro Yamada71ba2452014-04-15 13:30:51 +090052 install $(obj)/man/*.9.gz /usr/local/man/man9/
Marek Vasut30ff8912012-10-06 14:04:58 +000053
54###
55#External programs used
Masahiro Yamada8fac9c72014-02-05 10:52:50 +090056KERNELDOC = $(srctree)/scripts/kernel-doc
57DOCPROC = $(objtree)/scripts/docproc
Marek Vasut30ff8912012-10-06 14:04:58 +000058
Masahiro Yamada71ba2452014-04-15 13:30:51 +090059XMLTOFLAGS = -m $(srctree)/$(src)/stylesheet.xsl
Marek Vasut30ff8912012-10-06 14:04:58 +000060XMLTOFLAGS += --skip-validation
61
62###
63# DOCPROC is used for two purposes:
64# 1) To generate a dependency list for a .tmpl file
65# 2) To preprocess a .tmpl file and call kernel-doc with
66# appropriate parameters.
67# The following rules are used to generate the .xml documentation
68# required to generate the final targets. (ps, pdf, html).
Masahiro Yamada6825a952014-02-04 17:24:28 +090069quiet_cmd_docproc = DOCPROC $@
70 cmd_docproc = SRCTREE=$(srctree)/ $(DOCPROC) doc $< >$@
71define rule_docproc
72 set -e; \
73 $(if $($(quiet)cmd_$(1)),echo ' $($(quiet)cmd_$(1))';) \
74 $(cmd_$(1)); \
75 ( \
76 echo 'cmd_$@ := $(cmd_$(1))'; \
77 echo $@: `SRCTREE=$(srctree) $(DOCPROC) depend $<`; \
78 ) > $(dir $@).$(notdir $@).cmd
79endef
Marek Vasut30ff8912012-10-06 14:04:58 +000080
Masahiro Yamada71ba2452014-04-15 13:30:51 +090081%.xml: %.tmpl $(KERNELDOC) $(DOCPROC) FORCE
Masahiro Yamada6825a952014-02-04 17:24:28 +090082 $(call if_changed_rule,docproc)
83
Masahiro Yamada6825a952014-02-04 17:24:28 +090084# Tell kbuild to always build the programs
85always := $(hostprogs-y)
86
Marek Vasut30ff8912012-10-06 14:04:58 +000087notfoundtemplate = echo "*** You have to install docbook-utils or xmlto ***"; \
88 exit 1
89db2xtemplate = db2TYPE -o $(dir $@) $<
90xmltotemplate = xmlto TYPE $(XMLTOFLAGS) -o $(dir $@) $<
91
92# determine which methods are available
93ifeq ($(shell which db2ps >/dev/null 2>&1 && echo found),found)
94 use-db2x = db2x
95 prefer-db2x = db2x
96else
97 use-db2x = notfound
98 prefer-db2x = $(use-xmlto)
99endif
100ifeq ($(shell which xmlto >/dev/null 2>&1 && echo found),found)
101 use-xmlto = xmlto
102 prefer-xmlto = xmlto
103else
104 use-xmlto = notfound
105 prefer-xmlto = $(use-db2x)
106endif
107
108# the commands, generated from the chosen template
109quiet_cmd_db2ps = PS $@
110 cmd_db2ps = $(subst TYPE,ps, $($(PS_METHOD)template))
111%.ps : %.xml
Masahiro Yamada6825a952014-02-04 17:24:28 +0900112 $(call cmd,db2ps)
Marek Vasut30ff8912012-10-06 14:04:58 +0000113
114quiet_cmd_db2pdf = PDF $@
115 cmd_db2pdf = $(subst TYPE,pdf, $($(PDF_METHOD)template))
116%.pdf : %.xml
Masahiro Yamada6825a952014-02-04 17:24:28 +0900117 $(call cmd,db2pdf)
Marek Vasut30ff8912012-10-06 14:04:58 +0000118
119
120index = index.html
Masahiro Yamada71ba2452014-04-15 13:30:51 +0900121main_idx = $(obj)/$(index)
Marek Vasut30ff8912012-10-06 14:04:58 +0000122build_main_index = rm -rf $(main_idx); \
123 echo '<h1>U-Boot Bootloader HTML Documentation</h1>' >> $(main_idx) && \
Masahiro Yamada74241452014-02-24 11:12:09 +0900124 echo '<h2>U-Boot Version: $(UBOOTVERSION)</h2>' >> $(main_idx) && \
Marek Vasut30ff8912012-10-06 14:04:58 +0000125 cat $(HTML) >> $(main_idx)
126
Marek Vasut30ff8912012-10-06 14:04:58 +0000127quiet_cmd_db2html = HTML $@
Masahiro Yamada71ba2452014-04-15 13:30:51 +0900128 cmd_db2html = xmlto html $(XMLTOFLAGS) -o $(patsubst %.html,%,$@) $< && \
Marek Vasut30ff8912012-10-06 14:04:58 +0000129 echo '<a HREF="$(patsubst %.html,%,$(notdir $@))/index.html"> \
Masahiro Yamada71ba2452014-04-15 13:30:51 +0900130 $(patsubst %.html,%,$(notdir $@))</a><p>' > $@
Marek Vasut30ff8912012-10-06 14:04:58 +0000131
132%.html: %.xml
133 @(which xmlto > /dev/null 2>&1) || \
134 (echo "*** You need to install xmlto ***"; \
135 exit 1)
136 @rm -rf $@ $(patsubst %.html,%,$@)
Masahiro Yamada6825a952014-02-04 17:24:28 +0900137 $(call cmd,db2html)
Marek Vasut30ff8912012-10-06 14:04:58 +0000138 @if [ ! -z "$(PNG-$(basename $(notdir $@)))" ]; then \
Masahiro Yamada6825a952014-02-04 17:24:28 +0900139 cp $(PNG-$(basename $(notdir $@))) $(patsubst %.html,%,$@); fi
Marek Vasut30ff8912012-10-06 14:04:58 +0000140
141quiet_cmd_db2man = MAN $@
Masahiro Yamada71ba2452014-04-15 13:30:51 +0900142 cmd_db2man = if grep -q refentry $<; then xmlto man $(XMLTOFLAGS) -o $(obj)/man $< ; fi
Marek Vasut30ff8912012-10-06 14:04:58 +0000143%.9 : %.xml
144 @(which xmlto > /dev/null 2>&1) || \
145 (echo "*** You need to install xmlto ***"; \
146 exit 1)
Masahiro Yamada9e414032014-02-04 17:24:24 +0900147 $(Q)mkdir -p $(obj)/man
Masahiro Yamada6825a952014-02-04 17:24:28 +0900148 $(call cmd,db2man)
Marek Vasut30ff8912012-10-06 14:04:58 +0000149 @touch $@
150
151###
152# Rules to generate postscripts and PNG images from .fig format files
153quiet_cmd_fig2eps = FIG2EPS $@
154 cmd_fig2eps = fig2dev -Leps $< $@
155
156%.eps: %.fig
157 @(which fig2dev > /dev/null 2>&1) || \
158 (echo "*** You need to install transfig ***"; \
159 exit 1)
Masahiro Yamada6825a952014-02-04 17:24:28 +0900160 $(call cmd,fig2eps)
Marek Vasut30ff8912012-10-06 14:04:58 +0000161
162quiet_cmd_fig2png = FIG2PNG $@
163 cmd_fig2png = fig2dev -Lpng $< $@
164
165%.png: %.fig
166 @(which fig2dev > /dev/null 2>&1) || \
167 (echo "*** You need to install transfig ***"; \
168 exit 1)
Masahiro Yamada6825a952014-02-04 17:24:28 +0900169 $(call cmd,fig2png)
Marek Vasut30ff8912012-10-06 14:04:58 +0000170
171###
172# Rule to convert a .c file to inline XML documentation
173 gen_xml = :
174 quiet_gen_xml = echo ' GEN $@'
175silent_gen_xml = :
176%.xml: %.c
177 @$($(quiet)gen_xml)
178 @( \
179 echo "<programlisting>"; \
180 expand --tabs=8 < $< | \
181 sed -e "s/&/\\&amp;/g" \
182 -e "s/</\\&lt;/g" \
183 -e "s/>/\\&gt;/g"; \
184 echo "</programlisting>") > $@
185
186###
187# Help targets as used by the top-level makefile
188dochelp:
189 @echo ' U-Boot bootloader internal documentation in different formats:'
190 @echo ' htmldocs - HTML'
191 @echo ' pdfdocs - PDF'
192 @echo ' psdocs - Postscript'
193 @echo ' xmldocs - XML DocBook'
194 @echo ' mandocs - man pages'
195 @echo ' installmandocs - install man pages generated by mandocs'
196 @echo ' cleandocs - clean all generated DocBook files'
197
198###
199# Temporary files left by various tools
200clean-files := $(DOCBOOKS) \
201 $(patsubst %.xml, %.dvi, $(DOCBOOKS)) \
202 $(patsubst %.xml, %.aux, $(DOCBOOKS)) \
203 $(patsubst %.xml, %.tex, $(DOCBOOKS)) \
204 $(patsubst %.xml, %.log, $(DOCBOOKS)) \
205 $(patsubst %.xml, %.out, $(DOCBOOKS)) \
206 $(patsubst %.xml, %.ps, $(DOCBOOKS)) \
207 $(patsubst %.xml, %.pdf, $(DOCBOOKS)) \
208 $(patsubst %.xml, %.html, $(DOCBOOKS)) \
209 $(patsubst %.xml, %.9, $(DOCBOOKS)) \
210 $(index)
211
212clean-dirs := $(patsubst %.xml,%,$(DOCBOOKS)) man
213
214cleandocs:
Masahiro Yamada8fac9c72014-02-05 10:52:50 +0900215 $(Q)rm -f $(call objectify, $(clean-files))
216 $(Q)rm -rf $(call objectify, $(clean-dirs))
Marek Vasut30ff8912012-10-06 14:04:58 +0000217
218# Declare the contents of the .PHONY variable as phony. We keep that
219# information in a variable se we can use it in if_changed and friends.
220
221.PHONY: $(PHONY)