xref: /rk3399_rockchip-uboot/doc/DocBook/Makefile (revision c25a1784d022b8b8b82ec7e1bc28716c213ce80c)
1###
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
7# list of DOCBOOKS.
8
9DOCBOOKS := linker_lists.xml stdio.xml
10
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.
27PHONY += xmldocs sgmldocs psdocs pdfdocs htmldocs mandocs installmandocs cleandocs
28
29targets += $(DOCBOOKS)
30BOOKS := $(addprefix $(obj)/,$(DOCBOOKS))
31xmldocs: $(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)
48	$(if $(wildcard $(obj)/man/*.9),gzip -f $(obj)/man/*.9)
49
50installmandocs: mandocs
51	mkdir -p /usr/local/man/man9/
52	install $(obj)/man/*.9.gz /usr/local/man/man9/
53
54###
55#External programs used
56KERNELDOC = $(srctree)/scripts/kernel-doc
57DOCPROC   = $(objtree)/scripts/docproc
58
59XMLTOFLAGS = -m $(srctree)/$(src)/stylesheet.xsl
60XMLTOFLAGS += --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).
69quiet_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
80
81%.xml: %.tmpl $(KERNELDOC) $(DOCPROC) FORCE
82	$(call if_changed_rule,docproc)
83
84# Tell kbuild to always build the programs
85always := $(hostprogs-y)
86
87notfoundtemplate = 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
112	$(call cmd,db2ps)
113
114quiet_cmd_db2pdf = PDF     $@
115      cmd_db2pdf = $(subst TYPE,pdf, $($(PDF_METHOD)template))
116%.pdf : %.xml
117	$(call cmd,db2pdf)
118
119
120index = index.html
121main_idx = $(obj)/$(index)
122build_main_index = rm -rf $(main_idx); \
123		   echo '<h1>U-Boot Bootloader HTML Documentation</h1>' >> $(main_idx) && \
124		   echo '<h2>U-Boot Version: $(UBOOTVERSION)</h2>' >> $(main_idx) && \
125		   cat $(HTML) >> $(main_idx)
126
127quiet_cmd_db2html = HTML    $@
128      cmd_db2html = xmlto html $(XMLTOFLAGS) -o $(patsubst %.html,%,$@) $< && \
129		echo '<a HREF="$(patsubst %.html,%,$(notdir $@))/index.html"> \
130		$(patsubst %.html,%,$(notdir $@))</a><p>' > $@
131
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,%,$@)
137	$(call cmd,db2html)
138	@if [ ! -z "$(PNG-$(basename $(notdir $@)))" ]; then \
139            cp $(PNG-$(basename $(notdir $@))) $(patsubst %.html,%,$@); fi
140
141quiet_cmd_db2man = MAN     $@
142      cmd_db2man = if grep -q refentry $<; then xmlto man $(XMLTOFLAGS) -o $(obj)/man $< ; fi
143%.9 : %.xml
144	@(which xmlto > /dev/null 2>&1) || \
145	 (echo "*** You need to install xmlto ***"; \
146	  exit 1)
147	$(Q)mkdir -p $(obj)/man
148	$(call cmd,db2man)
149	@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)
160	$(call cmd,fig2eps)
161
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)
169	$(call cmd,fig2png)
170
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:
215	$(Q)rm -f $(call objectify, $(clean-files))
216	$(Q)rm -rf $(call objectify, $(clean-dirs))
217
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)
222