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 := wanbook.xml z8530book.xml mcabook.xml videobook.xml \
10	    kernel-hacking.xml kernel-locking.xml deviceiobook.xml \
11	    procfs-guide.xml writing_usb_driver.xml \
12	    kernel-api.xml filesystems.xml lsm.xml usb.xml \
13	    gadget.xml libata.xml mtdnand.xml librs.xml rapidio.xml \
14	    genericirq.xml
15
16###
17# The build process is as follows (targets):
18#              (xmldocs)
19# file.tmpl --> file.xml +--> file.ps   (psdocs)
20#                        +--> file.pdf  (pdfdocs)
21#                        +--> DIR=file  (htmldocs)
22#                        +--> man/      (mandocs)
23
24
25# for PDF and PS output you can choose between xmlto and docbook-utils tools
26PDF_METHOD	= $(prefer-db2x)
27PS_METHOD	= $(prefer-db2x)
28
29
30###
31# The targets that may be used.
32PHONY += xmldocs sgmldocs psdocs pdfdocs htmldocs mandocs installmandocs
33
34BOOKS := $(addprefix $(obj)/,$(DOCBOOKS))
35xmldocs: $(BOOKS)
36sgmldocs: xmldocs
37
38PS := $(patsubst %.xml, %.ps, $(BOOKS))
39psdocs: $(PS)
40
41PDF := $(patsubst %.xml, %.pdf, $(BOOKS))
42pdfdocs: $(PDF)
43
44HTML := $(sort $(patsubst %.xml, %.html, $(BOOKS)))
45htmldocs: $(HTML)
46	$(call build_main_index)
47
48MAN := $(patsubst %.xml, %.9, $(BOOKS))
49mandocs: $(MAN)
50
51installmandocs: mandocs
52	mkdir -p /usr/local/man/man9/
53	install Documentation/DocBook/man/*.9.gz /usr/local/man/man9/
54
55###
56#External programs used
57KERNELDOC = $(srctree)/scripts/kernel-doc
58DOCPROC   = $(objtree)/scripts/basic/docproc
59
60XMLTOFLAGS = -m $(srctree)/Documentation/DocBook/stylesheet.xsl
61#XMLTOFLAGS += --skip-validation
62
63###
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).
70quiet_cmd_docproc = DOCPROC $@
71      cmd_docproc = SRCTREE=$(srctree)/ $(DOCPROC) doc $< >$@
72define rule_docproc
73	set -e;								\
74        $(if $($(quiet)cmd_$(1)),echo '  $($(quiet)cmd_$(1))';) 	\
75        $(cmd_$(1)); 							\
76        ( 								\
77          echo 'cmd_$@ := $(cmd_$(1))'; 				\
78          echo $@: `SRCTREE=$(srctree) $(DOCPROC) depend $<`; 		\
79        ) > $(dir $@).$(notdir $@).cmd
80endef
81
82%.xml: %.tmpl FORCE
83	$(call if_changed_rule,docproc)
84
85###
86#Read in all saved dependency files 
87cmd_files := $(wildcard $(foreach f,$(BOOKS),$(dir $(f)).$(notdir $(f)).cmd))
88
89ifneq ($(cmd_files),)
90  include $(cmd_files)
91endif
92
93###
94# Changes in kernel-doc force a rebuild of all documentation
95$(BOOKS): $(KERNELDOC)
96
97###
98# procfs guide uses a .c file as example code.
99# This requires an explicit dependency
100C-procfs-example = procfs_example.xml
101C-procfs-example2 = $(addprefix $(obj)/,$(C-procfs-example))
102$(obj)/procfs-guide.xml: $(C-procfs-example2)
103
104notfoundtemplate = echo "*** You have to install docbook-utils or xmlto ***"; \
105		   exit 1
106db2xtemplate = db2TYPE -o $(dir $@) $<
107xmltotemplate = xmlto TYPE $(XMLTOFLAGS) -o $(dir $@) $<
108
109# determine which methods are available
110ifeq ($(shell which db2ps >/dev/null 2>&1 && echo found),found)
111	use-db2x = db2x
112	prefer-db2x = db2x
113else
114	use-db2x = notfound
115	prefer-db2x = $(use-xmlto)
116endif
117ifeq ($(shell which xmlto >/dev/null 2>&1 && echo found),found)
118	use-xmlto = xmlto
119	prefer-xmlto = xmlto
120else
121	use-xmlto = notfound
122	prefer-xmlto = $(use-db2x)
123endif
124
125# the commands, generated from the chosen template
126quiet_cmd_db2ps = PS      $@
127      cmd_db2ps = $(subst TYPE,ps, $($(PS_METHOD)template))
128%.ps : %.xml
129	$(call cmd,db2ps)
130
131quiet_cmd_db2pdf = PDF      $@
132      cmd_db2pdf = $(subst TYPE,pdf, $($(PDF_METHOD)template))
133%.pdf : %.xml
134	$(call cmd,db2pdf)
135
136
137main_idx = Documentation/DocBook/index.html
138build_main_index = rm -rf $(main_idx) && \
139		   echo '<h1>Linux Kernel HTML Documentation</h1>' >> $(main_idx) && \
140		   echo '<h2>Kernel Version: $(KERNELVERSION)</h2>' >> $(main_idx) && \
141		   cat $(HTML) >> $(main_idx)
142
143quiet_cmd_db2html = HTML   $@
144      cmd_db2html = xmlto xhtml $(XMLTOFLAGS) -o $(patsubst %.html,%,$@) $< && \
145		echo '<a HREF="$(patsubst %.html,%,$(notdir $@))/index.html"> \
146        $(patsubst %.html,%,$(notdir $@))</a><p>' > $@
147
148%.html:	%.xml
149	@(which xmlto > /dev/null 2>&1) || \
150	 (echo "*** You need to install xmlto ***"; \
151	  exit 1)
152	@rm -rf $@ $(patsubst %.html,%,$@)
153	$(call cmd,db2html)
154	@if [ ! -z "$(PNG-$(basename $(notdir $@)))" ]; then \
155            cp $(PNG-$(basename $(notdir $@))) $(patsubst %.html,%,$@); fi
156
157quiet_cmd_db2man = MAN     $@
158      cmd_db2man = if grep -q refentry $<; then xmlto man $(XMLTOFLAGS) -o $(obj)/man $< ; gzip -f $(obj)/man/*.9; fi
159%.9 : %.xml
160	@(which xmlto > /dev/null 2>&1) || \
161	 (echo "*** You need to install xmlto ***"; \
162	  exit 1)
163	$(Q)mkdir -p $(obj)/man
164	$(call cmd,db2man)
165	@touch $@
166
167###
168# Rules to generate postscripts and PNG imgages from .fig format files
169quiet_cmd_fig2eps = FIG2EPS $@
170      cmd_fig2eps = fig2dev -Leps $< $@
171
172%.eps: %.fig
173	@(which fig2dev > /dev/null 2>&1) || \
174	 (echo "*** You need to install transfig ***"; \
175	  exit 1)
176	$(call cmd,fig2eps)
177
178quiet_cmd_fig2png = FIG2PNG $@
179      cmd_fig2png = fig2dev -Lpng $< $@
180
181%.png: %.fig
182	@(which fig2dev > /dev/null 2>&1) || \
183	 (echo "*** You need to install transfig ***"; \
184	  exit 1)
185	$(call cmd,fig2png)
186
187###
188# Rule to convert a .c file to inline XML documentation
189%.xml: %.c
190	@echo '  GEN     $@'
191	@(                            \
192	   echo "<programlisting>";   \
193	   expand --tabs=8 < $< |     \
194	   sed -e "s/&/\\&amp;/g"     \
195	       -e "s/</\\&lt;/g"      \
196	       -e "s/>/\\&gt;/g";     \
197	   echo "</programlisting>")  > $@
198
199###
200# Help targets as used by the top-level makefile
201dochelp:
202	@echo  ' Linux kernel internal documentation in different formats:'
203	@echo  '  htmldocs        - HTML'
204	@echo  '  installmandocs  - install man pages generated by mandocs'
205	@echo  '  mandocs         - man pages'
206	@echo  '  pdfdocs         - PDF'
207	@echo  '  psdocs          - Postscript'
208	@echo  '  xmldocs         - XML DocBook'
209
210###
211# Temporary files left by various tools
212clean-files := $(DOCBOOKS) \
213	$(patsubst %.xml, %.dvi,  $(DOCBOOKS)) \
214	$(patsubst %.xml, %.aux,  $(DOCBOOKS)) \
215	$(patsubst %.xml, %.tex,  $(DOCBOOKS)) \
216	$(patsubst %.xml, %.log,  $(DOCBOOKS)) \
217	$(patsubst %.xml, %.out,  $(DOCBOOKS)) \
218	$(patsubst %.xml, %.ps,   $(DOCBOOKS)) \
219	$(patsubst %.xml, %.pdf,  $(DOCBOOKS)) \
220	$(patsubst %.xml, %.html, $(DOCBOOKS)) \
221	$(patsubst %.xml, %.9,    $(DOCBOOKS)) \
222	$(C-procfs-example)
223
224clean-dirs := $(patsubst %.xml,%,$(DOCBOOKS)) man
225
226# Declare the contents of the .PHONY variable as phony.  We keep that
227# information in a variable se we can use it in if_changed and friends.
228
229.PHONY: $(PHONY)
230