[media] DocBook/audio.xml: match section ID's with the reference links
[pandora-kernel.git] / Documentation / DocBook / media / Makefile
1 ###
2 # Media build rules - Auto-generates media contents/indexes and *.h xml's
3 #
4
5 SHELL=/bin/bash
6
7 MEDIA_OBJ_DIR=$(objtree)/Documentation/DocBook/
8 MEDIA_SRC_DIR=$(srctree)/Documentation/DocBook/media
9
10 MEDIA_TEMP =  media-entities.tmpl \
11               media-indices.tmpl \
12               videodev2.h.xml \
13               v4l2.xml \
14               audio.h.xml \
15               ca.h.xml \
16               dmx.h.xml \
17               frontend.h.xml \
18               net.h.xml \
19               osd.h.xml \
20               video.h.xml \
21
22 IMGFILES := $(addprefix $(MEDIA_OBJ_DIR)/media/, $(notdir $(shell ls $(MEDIA_SRC_DIR)/*/*.gif $(MEDIA_SRC_DIR)/*/*.png)))
23 GENFILES := $(addprefix $(MEDIA_OBJ_DIR)/, $(MEDIA_TEMP))
24
25 PHONY += cleanmediadocs mediaindexdocs
26
27 cleanmediadocs:
28         -@rm `find $(MEDIA_OBJ_DIR) -type l` $(GENFILES) $(IMGFILES)
29
30 $(obj)/media_api.xml: $(GENFILES) FORCE
31
32 #$(MEDIA_OBJ_DIR)/media_api.html: $(MEDIA_OBJ_DIR)/media_api.xml
33 #$(MEDIA_OBJ_DIR)/media_api.pdf: $(MEDIA_OBJ_DIR)/media_api.xml
34 #$(MEDIA_OBJ_DIR)/media_api.ps: $(MEDIA_OBJ_DIR)/media_api.xml
35
36 V4L_SGMLS = \
37         $(shell ls $(MEDIA_SRC_DIR)/v4l/*.xml|perl -ne 'print "$$1 " if (m,.*/(.*)\n,)') \
38         capture.c.xml \
39         keytable.c.xml \
40         v4l2grab.c.xml
41
42 DVB_SGMLS = \
43         $(shell ls $(MEDIA_SRC_DIR)/dvb/*.xml|perl -ne 'print "$$1 " if (m,.*/(.*)\n,)')
44
45 MEDIA_SGMLS =  $(addprefix ./,$(V4L_SGMLS)) $(addprefix ./,$(DVB_SGMLS)) $(addprefix ./,$(MEDIA_TEMP))
46
47 FUNCS = \
48         close \
49         ioctl \
50         mmap \
51         munmap \
52         open \
53         poll \
54         read \
55         select \
56         write \
57
58 IOCTLS = \
59         $(shell perl -ne 'print "$$1 " if /\#define\s+([^\s]+)\s+_IO/' $(srctree)/include/linux/videodev2.h) \
60         $(shell perl -ne 'print "$$1 " if /\#define\s+([^\s]+)\s+_IO/' $(srctree)/include/linux/dvb/audio.h) \
61         $(shell perl -ne 'print "$$1 " if /\#define\s+([^\s]+)\s+_IO/' $(srctree)/include/linux/dvb/ca.h) \
62         $(shell perl -ne 'print "$$1 " if /\#define\s+([^\s]+)\s+_IO/' $(srctree)/include/linux/dvb/dmx.h) \
63         $(shell perl -ne 'print "$$1 " if /\#define\s+([^\s]+)\s+_IO/' $(srctree)/include/linux/dvb/frontend.h) \
64         $(shell perl -ne 'print "$$1 " if /\#define\s+([A-Z][^\s]+)\s+_IO/' $(srctree)/include/linux/dvb/net.h) \
65         $(shell perl -ne 'print "$$1 " if /\#define\s+([^\s]+)\s+_IO/' $(srctree)/include/linux/dvb/osd.h) \
66         $(shell perl -ne 'print "$$1 " if /\#define\s+([^\s]+)\s+_IO/' $(srctree)/include/linux/dvb/video.h) \
67         $(shell perl -ne 'print "$$1 " if /\#define\s+([^\s]+)\s+_IO/' $(srctree)/include/linux/media.h) \
68         $(shell perl -ne 'print "$$1 " if /\#define\s+([^\s]+)\s+_IO/' $(srctree)/include/linux/v4l2-subdev.h) \
69         VIDIOC_SUBDEV_G_FRAME_INTERVAL \
70         VIDIOC_SUBDEV_S_FRAME_INTERVAL \
71         VIDIOC_SUBDEV_ENUM_MBUS_CODE \
72         VIDIOC_SUBDEV_ENUM_FRAME_SIZE \
73         VIDIOC_SUBDEV_ENUM_FRAME_INTERVAL \
74
75 TYPES = \
76         $(shell perl -ne 'print "$$1 " if /^typedef\s+[^\s]+\s+([^\s]+)\;/' $(srctree)/include/linux/videodev2.h) \
77         $(shell perl -ne 'print "$$1 " if /^}\s+([a-z0-9_]+_t)/' $(srctree)/include/linux/dvb/frontend.h)
78
79 ENUMS = \
80         $(shell perl -ne 'print "$$1 " if /^enum\s+([^\s]+)\s+/' $(srctree)/include/linux/videodev2.h) \
81         $(shell perl -ne 'print "$$1 " if /^enum\s+([^\s]+)\s+/' $(srctree)/include/linux/dvb/audio.h) \
82         $(shell perl -ne 'print "$$1 " if /^enum\s+([^\s]+)\s+/' $(srctree)/include/linux/dvb/ca.h) \
83         $(shell perl -ne 'print "$$1 " if /^enum\s+([^\s]+)\s+/' $(srctree)/include/linux/dvb/dmx.h) \
84         $(shell perl -ne 'print "$$1 " if /^enum\s+([^\s]+)\s+/' $(srctree)/include/linux/dvb/frontend.h) \
85         $(shell perl -ne 'print "$$1 " if /^enum\s+([^\s]+)\s+/' $(srctree)/include/linux/dvb/net.h) \
86         $(shell perl -ne 'print "$$1 " if /^enum\s+([^\s]+)\s+/' $(srctree)/include/linux/dvb/osd.h) \
87         $(shell perl -ne 'print "$$1 " if /^enum\s+([^\s]+)\s+/' $(srctree)/include/linux/dvb/video.h) \
88         $(shell perl -ne 'print "$$1 " if /^enum\s+([^\s]+)\s+/' $(srctree)/include/linux/media.h) \
89         $(shell perl -ne 'print "$$1 " if /^enum\s+([^\s]+)\s+/' $(srctree)/include/linux/v4l2-mediabus.h) \
90         $(shell perl -ne 'print "$$1 " if /^enum\s+([^\s]+)\s+/' $(srctree)/include/linux/v4l2-subdev.h)
91
92 STRUCTS = \
93         $(shell perl -ne 'print "$$1 " if /^struct\s+([^\s]+)\s+/' $(srctree)/include/linux/videodev2.h) \
94         $(shell perl -ne 'print "$$1 " if (/^struct\s+([^\s\{]+)\s*/)' $(srctree)/include/linux/dvb/audio.h) \
95         $(shell perl -ne 'print "$$1 " if (/^struct\s+([^\s]+)\s+/)' $(srctree)/include/linux/dvb/ca.h) \
96         $(shell perl -ne 'print "$$1 " if (/^struct\s+([^\s]+)\s+/)' $(srctree)/include/linux/dvb/dmx.h) \
97         $(shell perl -ne 'print "$$1 " if (!/dtv\_cmds\_h/ && /^struct\s+([^\s]+)\s+/)' $(srctree)/include/linux/dvb/frontend.h) \
98         $(shell perl -ne 'print "$$1 " if (/^struct\s+([A-Z][^\s]+)\s+/)' $(srctree)/include/linux/dvb/net.h) \
99         $(shell perl -ne 'print "$$1 " if (/^struct\s+([^\s]+)\s+/)' $(srctree)/include/linux/dvb/osd.h) \
100         $(shell perl -ne 'print "$$1 " if (/^struct\s+([^\s]+)\s+/)' $(srctree)/include/linux/dvb/video.h) \
101         $(shell perl -ne 'print "$$1 " if /^struct\s+([^\s]+)\s+/' $(srctree)/include/linux/media.h) \
102         $(shell perl -ne 'print "$$1 " if /^struct\s+([^\s]+)\s+/' $(srctree)/include/linux/v4l2-subdev.h) \
103         $(shell perl -ne 'print "$$1 " if /^struct\s+([^\s]+)\s+/' $(srctree)/include/linux/v4l2-mediabus.h)
104
105 ERRORS = \
106         EACCES \
107         EAGAIN \
108         EBADF \
109         EBUSY \
110         EFAULT \
111         EIO \
112         EINTR \
113         EINVAL \
114         ENFILE \
115         ENOMEM \
116         ENOSPC \
117         ENOTTY \
118         ENXIO \
119         EMFILE \
120         EPERM \
121         ERANGE \
122         EPIPE \
123
124 ESCAPE = \
125         -e "s/&/\\&/g" \
126         -e "s/</\\&lt;/g" \
127         -e "s/>/\\&gt;/g"
128
129 FILENAME = \
130         -e s,"^[^\/]*/",, \
131         -e s/"\\.xml"// \
132         -e s/"\\.tmpl"// \
133         -e s/\\\./-/g \
134         -e s/"^func-"// \
135         -e s/"^pixfmt-"// \
136         -e s/"^vidioc-"//
137
138 # Generate references to these structs in videodev2.h.xml.
139 DOCUMENTED = \
140         -e "s/\(enum *\)v4l2_mpeg_cx2341x_video_\([a-z]*_spatial_filter_type\)/\1<link linkend=\"\2\">v4l2_mpeg_cx2341x_video_\2<\/link>/g" \
141         -e "s/\(\(enum\|struct\) *\)\(v4l2_[a-zA-Z0-9_]*\)/\1<link linkend=\"\3\">\3<\/link>/g" \
142         -e "s/\(V4L2_PIX_FMT_[A-Z0-9_]\+\) /<link linkend=\"\1\">\1<\/link> /g" \
143         -e ":a;s/\(linkend=\".*\)_\(.*\">\)/\1-\2/;ta" \
144         -e "s/v4l2\-mpeg\-vbi\-ITV0/v4l2-mpeg-vbi-itv0-1/g"
145
146 DVB_DOCUMENTED = \
147         -e "s/\(linkend\=\"\)FE_SET_PROPERTY/\1FE_GET_PROPERTY/g" \
148         -e "s,\(struct\s\+\)\([a-z0-9_]\+\)\(\s\+{\),\1\<link linkend=\"\2\">\2\<\/link\>\3,g" \
149         -e "s,\(}\s\+\)\([a-z0-9_]\+_t\+\),\1\<link linkend=\"\2\">\2\<\/link\>,g" \
150         -e "s,\(define\s\+\)\(DTV_[A-Z0-9_]\+\)\(\s\+[0-9]\+\),\1\<link linkend=\"\2\">\2\<\/link\>\3,g" \
151         -e "s,<link linkend=\".*\">\(DTV_IOCTL_MAX_MSGS\|dtv_cmds_h\)<\/link>,\1,g" \
152         -e ":a;s/\(linkend=\".*\)_\(.*\">\)/\1-\2/;ta" \
153         -e "s,\(audio-mixer\|audio-karaoke\|audio-status\)-t,\1,g" \
154         -e "s,DTV-ISDBT-LAYER[A-C],DTV-ISDBT-LAYER,g" \
155         -e "s,\(define\s\+\)\([A-Z0-9_]\+\)\(\s\+_IO\),\1\<link linkend=\"\2\">\2\<\/link\>\3,g" \
156
157 #
158 # Media targets and dependencies
159 #
160
161 $(MEDIA_OBJ_DIR)/v4l2.xml:
162         @$($(quiet)gen_xml)
163         @(mkdir -p $(MEDIA_OBJ_DIR)/media)
164         @(cp $(MEDIA_SRC_DIR)/dvb/*.png $(MEDIA_SRC_DIR)/v4l/*.gif $(MEDIA_OBJ_DIR)/media/)
165         @(ln -sf $(MEDIA_SRC_DIR)/v4l/*xml $(MEDIA_OBJ_DIR)/)
166         @(ln -sf $(MEDIA_SRC_DIR)/dvb/*xml $(MEDIA_OBJ_DIR)/)
167
168 $(MEDIA_OBJ_DIR)/videodev2.h.xml: $(srctree)/include/linux/videodev2.h $(MEDIA_OBJ_DIR)/v4l2.xml
169         @$($(quiet)gen_xml)
170         @(                                      \
171         echo "<programlisting>") > $@
172         @(                                      \
173         expand --tabs=8 < $< |                  \
174           sed $(ESCAPE) $(DOCUMENTED) |         \
175           sed 's/i\.e\./&ie;/') >> $@
176         @(                                      \
177         echo "</programlisting>") >> $@
178
179 $(MEDIA_OBJ_DIR)/audio.h.xml: $(srctree)/include/linux/dvb/audio.h $(MEDIA_OBJ_DIR)/v4l2.xml
180         @$($(quiet)gen_xml)
181         @(                                      \
182         echo "<programlisting>") > $@
183         @(                                      \
184         expand --tabs=8 < $< |                  \
185           sed $(ESCAPE) $(DVB_DOCUMENTED) |     \
186           sed 's/i\.e\./&ie;/') >> $@
187         @(                                      \
188         echo "</programlisting>") >> $@
189
190 $(MEDIA_OBJ_DIR)/ca.h.xml: $(srctree)/include/linux/dvb/ca.h $(MEDIA_OBJ_DIR)/v4l2.xml
191         @$($(quiet)gen_xml)
192         @(                                      \
193         echo "<programlisting>") > $@
194         @(                                      \
195         expand --tabs=8 < $< |                  \
196           sed $(ESCAPE) $(DVB_DOCUMENTED) |     \
197           sed 's/i\.e\./&ie;/') >> $@
198         @(                                      \
199         echo "</programlisting>") >> $@
200
201 $(MEDIA_OBJ_DIR)/dmx.h.xml: $(srctree)/include/linux/dvb/dmx.h $(MEDIA_OBJ_DIR)/v4l2.xml
202         @$($(quiet)gen_xml)
203         @(                                      \
204         echo "<programlisting>") > $@
205         @(                                      \
206         expand --tabs=8 < $< |                  \
207           sed $(ESCAPE) $(DVB_DOCUMENTED) |     \
208           sed 's/i\.e\./&ie;/') >> $@
209         @(                                      \
210         echo "</programlisting>") >> $@
211
212 $(MEDIA_OBJ_DIR)/frontend.h.xml: $(srctree)/include/linux/dvb/frontend.h $(MEDIA_OBJ_DIR)/v4l2.xml
213         @$($(quiet)gen_xml)
214         @(                                      \
215         echo "<programlisting>") > $@
216         @(                                      \
217         expand --tabs=8 < $< |                  \
218           sed $(ESCAPE) $(DVB_DOCUMENTED) |     \
219           sed 's/i\.e\./&ie;/') >> $@
220         @(                                      \
221         echo "</programlisting>") >> $@
222
223 $(MEDIA_OBJ_DIR)/net.h.xml: $(srctree)/include/linux/dvb/net.h $(MEDIA_OBJ_DIR)/v4l2.xml
224         @$($(quiet)gen_xml)
225         @(                                      \
226         echo "<programlisting>") > $@
227         @(                                      \
228         expand --tabs=8 < $< |                  \
229           sed $(ESCAPE) $(DVB_DOCUMENTED) |     \
230           sed 's/i\.e\./&ie;/') >> $@
231         @(                                      \
232         echo "</programlisting>") >> $@
233
234 $(MEDIA_OBJ_DIR)/osd.h.xml: $(srctree)/include/linux/dvb/osd.h $(MEDIA_OBJ_DIR)/v4l2.xml
235         @$($(quiet)gen_xml)
236         @(                                      \
237         echo "<programlisting>") > $@
238         @(                                      \
239         expand --tabs=8 < $< |                  \
240           sed $(ESCAPE) $(DVB_DOCUMENTED) |     \
241           sed 's/i\.e\./&ie;/') >> $@
242         @(                                      \
243         echo "</programlisting>") >> $@
244
245 $(MEDIA_OBJ_DIR)/video.h.xml: $(srctree)/include/linux/dvb/video.h $(MEDIA_OBJ_DIR)/v4l2.xml
246         @$($(quiet)gen_xml)
247         @(                                      \
248         echo "<programlisting>") > $@
249         @(                                      \
250         expand --tabs=8 < $< |                  \
251           sed $(ESCAPE) $(DVB_DOCUMENTED) |     \
252           sed 's/i\.e\./&ie;/') >> $@
253         @(                                      \
254         echo "</programlisting>") >> $@
255
256 $(MEDIA_OBJ_DIR)/media-entities.tmpl: $(MEDIA_OBJ_DIR)/v4l2.xml
257         @$($(quiet)gen_xml)
258         @(                                                              \
259         echo "<!-- Generated file! Do not edit. -->") >$@
260         @(                                                              \
261         echo -e "\n<!-- Functions -->") >>$@
262         @(                                                              \
263         for ident in $(FUNCS) ; do                                      \
264           entity=`echo $$ident | tr _ -` ;                              \
265           echo "<!ENTITY func-$$entity \"<link"                         \
266             "linkend='func-$$entity'><function>$$ident()</function></link>\">" \
267           >>$@ ;                                                        \
268         done)
269         @(                                                              \
270         echo -e "\n<!-- Ioctls -->") >>$@
271         @(                                                              \
272         for ident in $(IOCTLS) ; do                                     \
273           entity=`echo $$ident | tr _ -` ;                              \
274           id=`grep "<refname>$$ident" $(MEDIA_OBJ_DIR)/vidioc-*.xml | sed -r s,"^.*/(.*).xml.*","\1",` ; \
275           echo "<!ENTITY $$entity \"<link"                              \
276             "linkend='$$id'><constant>$$ident</constant></link>\">"     \
277           >>$@ ;                                                        \
278         done)
279         @(                                                              \
280         echo -e "\n<!-- Types -->") >>$@
281         @(                                                              \
282         for ident in $(TYPES) ; do                                      \
283           entity=`echo $$ident | tr _ -` ;                              \
284           echo "<!ENTITY $$entity \"<link"                              \
285             "linkend='$$entity'>$$ident</link>\">" >>$@ ;               \
286         done)
287         @(                                                              \
288         echo -e "\n<!-- Enums -->") >>$@
289         @(                                                              \
290         for ident in $(ENUMS) ; do                                      \
291           entity=`echo $$ident | sed -e "s/v4l2_mpeg_cx2341x_video_\([a-z]*_spatial_filter_type\)/\1/" | tr _ -` ; \
292           echo "<!ENTITY $$entity \"enum&nbsp;<link"                    \
293             "linkend='$$entity'>$$ident</link>\">" >>$@ ;               \
294         done)
295         @(                                                              \
296         echo -e "\n<!-- Structures -->") >>$@
297         @(                                                              \
298         for ident in $(STRUCTS) ; do                                    \
299           entity=`echo $$ident | tr _ - | sed s/v4l2-mpeg-vbi-ITV0/v4l2-mpeg-vbi-itv0-1/g` ; \
300           echo "<!ENTITY $$entity \"struct&nbsp;<link"                  \
301             "linkend='$$entity'>$$ident</link>\">" >>$@ ;               \
302         done)
303         @(                                                              \
304         echo -e "\n<!-- Error Codes -->") >>$@
305         @(                                                              \
306         for ident in $(ERRORS) ; do                                     \
307           echo "<!ENTITY $$ident \"<errorcode>$$ident</errorcode>"      \
308             "error code\">" >>$@ ;                                      \
309         done)
310         @(                                                              \
311         echo -e "\n<!-- Subsections -->") >>$@
312         @(                                                              \
313         for file in $(MEDIA_SGMLS) ; do                                 \
314           entity=`echo "$$file" | sed $(FILENAME) -e s/"^([^-]*)"/sub\1/` ; \
315           if ! echo "$$file" |                                          \
316             grep -q -E -e '^(func|vidioc|pixfmt)-' ; then               \
317             echo "<!ENTITY sub-$$entity SYSTEM \"$$file\">" >>$@ ;      \
318           fi ;                                                          \
319         done)
320         @(                                                              \
321         echo -e "\n<!-- Function Reference -->") >>$@
322         @(                                                              \
323         for file in $(MEDIA_SGMLS) ; do                                 \
324           if echo "$$file" |                                            \
325             grep -q -E -e '(func|vidioc|pixfmt)-' ; then                \
326             entity=`echo "$$file" |sed $(FILENAME)` ;                   \
327             echo "<!ENTITY $$entity SYSTEM \"$$file\">" >>$@ ;  \
328           fi ;                                                          \
329         done)
330
331 # Jade can auto-generate a list-of-tables, which includes all structs,
332 # but we only want data types, all types, and sorted please.
333 $(MEDIA_OBJ_DIR)/media-indices.tmpl: $(MEDIA_OBJ_DIR)/v4l2.xml
334         @$($(quiet)gen_xml)
335         @(                                                              \
336         echo "<!-- Generated file! Do not edit. -->") >$@
337         @(                                                              \
338         echo -e "\n<index><title>List of Types</title>") >>$@
339         @(                                                              \
340         for ident in $(TYPES) ; do                                      \
341           id=`echo $$ident | tr _ -` ;                                  \
342           echo "<indexentry><primaryie><link"                           \
343             "linkend='$$id'>$$ident</link></primaryie></indexentry>" >>$@ ; \
344         done)
345         @(                                                              \
346         for ident in $(ENUMS) ; do                                      \
347           id=`echo $$ident | sed -e "s/v4l2_mpeg_cx2341x_video_\([a-z]*_spatial_filter_type\)/\1/" | tr _ -`; \
348           echo "<indexentry><primaryie>enum&nbsp;<link"                 \
349             "linkend='$$id'>$$ident</link></primaryie></indexentry>" >>$@ ; \
350         done)
351         @(                                                              \
352         for ident in $(STRUCTS) ; do                                    \
353           id=`echo $$ident | tr _ - | sed s/v4l2-mpeg-vbi-ITV0/v4l2-mpeg-vbi-itv0-1/g` ; \
354           echo "<indexentry><primaryie>struct&nbsp;<link"               \
355             "linkend='$$id'>$$ident</link></primaryie></indexentry>" >>$@ ; \
356         done)
357         @(                                                              \
358         echo "</index>") >>$@
359