docs: more out-of-srcdir plugin build fixing
[platform/upstream/gst-common.git] / gtk-doc-plugins.mak
1 # This is an include file specifically tuned for building documentation
2 # for GStreamer plug-ins
3
4 help:
5         @echo
6         @echo "If you are a doc maintainer, run 'make update' to update"
7         @echo "the documentation files maintained in git"
8         @echo
9         @echo Other useful make targets:
10         @echo
11         @echo  check-inspected-versions: make sure the inspected plugin info
12         @echo                            is up to date before a release
13         @echo
14
15 # update the stuff maintained by doc maintainers
16 update:
17         $(MAKE) scanobj-update
18         $(MAKE) check-outdated-docs
19
20 # We set GPATH here; this gives us semantics for GNU make
21 # which are more like other make's VPATH, when it comes to
22 # whether a source that is a target of one rule is then
23 # searched for in VPATH/GPATH.
24 #
25 GPATH = $(srcdir)
26
27 # thomas: make docs parallel installable
28 TARGET_DIR=$(HTML_DIR)/$(DOC_MODULE)-@GST_MAJORMINOR@
29
30 MAINTAINER_DOC_STAMPS =                 \
31         scanobj-build.stamp
32
33 EXTRA_DIST =                            \
34         $(MAINTAINER_DOC_STAMPS)                \
35         $(srcdir)/inspect/*.xml         \
36         $(SCANOBJ_FILES)                \
37         $(content_files)                \
38         $(extra_files)                  \
39         $(HTML_IMAGES)                  \
40         $(DOC_MAIN_SGML_FILE)   \
41         $(DOC_OVERRIDES)                \
42         $(DOC_MODULE)-sections.txt
43
44 # we don't add scanobj-build.stamp here since they are built manually by docs
45 # maintainers and result is commited to git
46 DOC_STAMPS =                            \
47         scan-build.stamp                \
48         tmpl-build.stamp                \
49         sgml-build.stamp                \
50         html-build.stamp                \
51         scan.stamp                      \
52         tmpl.stamp                      \
53         sgml.stamp                      \
54         html.stamp
55
56 # files generated/updated by gtkdoc-scangobj
57 SCANOBJ_FILES =                         \
58         $(DOC_MODULE).args              \
59         $(DOC_MODULE).hierarchy         \
60         $(DOC_MODULE).interfaces        \
61         $(DOC_MODULE).prerequisites     \
62         $(DOC_MODULE).signals           \
63         $(DOC_MODULE).types
64
65 SCANOBJ_FILES_O =                       \
66         .libs/$(DOC_MODULE)-scan.o
67
68 # files generated/updated by gtkdoc-scan
69 SCAN_FILES =                            \
70         $(DOC_MODULE)-sections.txt      \
71         $(DOC_MODULE)-overrides.txt     \
72         $(DOC_MODULE)-decl.txt          \
73         $(DOC_MODULE)-decl-list.txt
74
75
76 REPORT_FILES = \
77         $(DOC_MODULE)-undocumented.txt \
78         $(DOC_MODULE)-undeclared.txt \
79         $(DOC_MODULE)-unused.txt
80
81 CLEANFILES = \
82         $(SCANOBJ_FILES_O) \
83         $(REPORT_FILES) \
84         $(DOC_STAMPS) \
85         inspect-registry.xml
86
87 INSPECT_DIR = inspect
88
89 if ENABLE_GTK_DOC
90 all-local: html-build.stamp
91
92 ### inspect GStreamer plug-ins; done by documentation maintainer ###
93
94 # only look at the plugins in this module when building inspect .xml stuff
95 INSPECT_REGISTRY=$(top_builddir)/docs/plugins/inspect-registry.xml
96 INSPECT_ENVIRONMENT=\
97         LC_ALL=C \
98         GST_PLUGIN_SYSTEM_PATH= \
99         GST_PLUGIN_PATH=$(top_builddir)/gst:$(top_builddir)/sys:$(top_builddir)/ext:$(top_builddir)/plugins:$(top_builddir)/src:$(top_builddir)/gnl \
100         GST_REGISTRY=$(INSPECT_REGISTRY) \
101         PKG_CONFIG_PATH="$(GST_PKG_CONFIG_PATH)" \
102         $(INSPECT_EXTRA_ENVIRONMENT)
103
104 #### scan gobjects; done by documentation maintainer ####
105 scanobj-update:
106         -rm scanobj-build.stamp
107         $(MAKE) scanobj-build.stamp
108
109 # gstdoc-scanobj produces 5 output files (.new)
110 # scangobj-merge.py merges them into the file which we commit later
111 # TODO: also merge the hierarchy
112 scanobj-build.stamp: $(SCANOBJ_DEPS) $(basefiles)
113         @echo "  DOC   Introspecting gobjects"
114         @if test x"$(srcdir)" != x. ; then                              \
115             for f in $(SCANOBJ_FILES) $(SCAN_FILES);                    \
116             do                                                          \
117                 if test -e $(srcdir)/$$f; then cp -u $(srcdir)/$$f . ; fi;      \
118             done;                                                       \
119         fi;                                                             \
120         mkdir -p $(INSPECT_DIR); \
121         scanobj_options=""; \
122         if test "x$(V)" = "x1"; then \
123             scanobj_options="--verbose"; \
124         fi; \
125         $(INSPECT_ENVIRONMENT)                                  \
126         CC="$(GTKDOC_CC)" LD="$(GTKDOC_LD)"                             \
127         CFLAGS="$(GTKDOC_CFLAGS) $(CFLAGS) $(WARNING_CFLAGS)"   \
128         LDFLAGS="$(GTKDOC_LIBS) $(LDFLAGS)"                             \
129         $(GST_DOC_SCANOBJ) $$scanobj_options --type-init-func="gst_init(NULL,NULL)"     \
130             --module=$(DOC_MODULE) --source=$(PACKAGE) --inspect-dir=$(INSPECT_DIR) &&          \
131             echo "  DOC   Merging introspection data" && \
132             $(PYTHON)                                           \
133             $(top_srcdir)/common/scangobj-merge.py $(DOC_MODULE);       \
134         if test x"$(srcdir)" != x. ; then                               \
135             for f in $(SCANOBJ_FILES);                                  \
136             do                                                          \
137                 cmp -s ./$$f $(srcdir)/$$f || cp ./$$f $(srcdir)/ ;             \
138             done;                                                       \
139         fi;                                                             \
140         touch scanobj-build.stamp
141
142 $(DOC_MODULE)-decl.txt $(SCANOBJ_FILES) $(SCANOBJ_FILES_O): scan-build.stamp
143         @true
144
145 ### scan headers; done on every build ###
146 scan-build.stamp: $(HFILE_GLOB) $(EXTRA_HFILES) $(basefiles) scanobj-build.stamp
147         @echo '  DOC   Scanning header files'
148         @if test x"$(srcdir)" != x. ; then                              \
149             for f in $(SCANOBJ_FILES) $(SCAN_FILES);                    \
150             do                                                          \
151                 if test -e $(srcdir)/$$f; then cp -u $(srcdir)/$$f . ; fi;      \
152             done;                                                       \
153         fi
154         @gtkdoc-scan                                                    \
155             $(SCAN_OPTIONS) $(EXTRA_HFILES)                             \
156             --module=$(DOC_MODULE)                                      \
157             --source-dir=$(DOC_SOURCE_DIR)                              \
158             --ignore-headers="$(IGNORE_HFILES)";                        \
159         touch scan-build.stamp
160
161 #### update templates; done on every build ####
162
163 # in a non-srcdir build, we need to copy files from the previous step
164 # and the files from previous runs of this step
165 tmpl-build.stamp: $(DOC_MODULE)-decl.txt $(SCANOBJ_FILES) $(DOC_MODULE)-sections.txt $(DOC_OVERRIDES)
166         @echo '  DOC   Rebuilding template files'
167         @if test x"$(srcdir)" != x. ; then                              \
168             for f in $(SCANOBJ_FILES) $(SCAN_FILES);                    \
169             do                                                          \
170                 if test -e $(srcdir)/$$f; then cp -u $(srcdir)/$$f . ; fi;      \
171             done;                                                       \
172         fi
173         @gtkdoc-mktmpl --module=$(DOC_MODULE)
174         @$(PYTHON) \
175                 $(top_srcdir)/common/mangle-tmpl.py $(srcdir)/$(INSPECT_DIR) tmpl
176         @touch tmpl-build.stamp
177
178 tmpl.stamp: tmpl-build.stamp
179         @true
180
181 #### xml ####
182
183 sgml-build.stamp: tmpl.stamp scan-build.stamp $(CFILE_GLOB) $(top_srcdir)/common/plugins.xsl $(expand_content_files)
184         @echo '  DOC   Building XML'
185         @-mkdir -p xml
186         @for a in $(srcdir)/$(INSPECT_DIR)/*.xml; do \
187             xsltproc --stringparam module $(MODULE) \
188                 $(top_srcdir)/common/plugins.xsl $$a > xml/`basename $$a`; done
189         @for f in $(EXAMPLE_CFILES); do \
190                 $(PYTHON) $(top_srcdir)/common/c-to-xml.py $$f > xml/element-`basename $$f .c`.xml; done
191         @gtkdoc-mkdb \
192                 --module=$(DOC_MODULE) \
193                 --source-dir=$(DOC_SOURCE_DIR) \
194                  --expand-content-files="$(expand_content_files)" \
195                 --main-sgml-file=$(srcdir)/$(DOC_MAIN_SGML_FILE) \
196                 --output-format=xml \
197                 --ignore-files="$(IGNORE_HFILES) $(IGNORE_CFILES)" \
198                 $(MKDB_OPTIONS)
199         @cp ../version.entities xml
200         @touch sgml-build.stamp
201
202 sgml.stamp: sgml-build.stamp
203         @true
204
205 #### html ####
206
207 html-build.stamp: sgml.stamp $(DOC_MAIN_SGML_FILE) $(content_files)
208         @echo '  DOC   Building HTML'
209         @rm -rf html
210         @mkdir html
211         @cp $(srcdir)/$(DOC_MAIN_SGML_FILE) html
212         @for f in $(content_files); do cp $(srcdir)/$$f html; done
213         @cp -pr xml html
214         @cp ../version.entities html
215         @mkhtml_options=""; \
216         gtkdoc-mkhtml 2>&1 --help | grep  >/dev/null "\-\-verbose"; \
217         if test "$(?)" = "0"; then \
218           if test "x$(V)" = "x1"; then \
219             mkhtml_options="$$mkhtml_options --verbose"; \
220           fi; \
221         fi; \
222         cd html && gtkdoc-mkhtml $$mkhtml_options $(DOC_MODULE) $(DOC_MAIN_SGML_FILE)
223         @mv html/index.sgml html/index.sgml.bak
224         @$(SED) "s/ href=\"$(DOC_MODULE)\// href=\"$(DOC_MODULE)-@GST_MAJORMINOR@\//g" html/index.sgml.bak >html/index.sgml
225         @rm -f html/index.sgml.bak
226         @rm -f html/$(DOC_MAIN_SGML_FILE)
227         @rm -rf html/xml
228         @rm -f html/version.entities
229         @test "x$(HTML_IMAGES)" = "x" || for i in "" $(HTML_IMAGES) ; do \
230             if test "$$i" != ""; then cp $(srcdir)/$$i html ; fi; done
231         @echo '  DOC   Fixing cross-references'
232         @gtkdoc-fixxref --module=$(DOC_MODULE) --module-dir=html --html-dir=$(HTML_DIR) $(FIXXREF_OPTIONS)
233         @touch html-build.stamp
234
235 clean-local-gtkdoc:
236         @rm -rf xml tmpl html
237 # clean files copied for nonsrcdir templates build
238         @if test x"$(srcdir)" != x. ; then \
239             rm -rf $(SCANOBJ_FILES) $(SCAN_FILES) $(REPORT_FILES) \
240                 $(MAINTAINER_DOC_STAMPS); \
241         fi
242 else
243 all-local:
244 clean-local-gtkdoc:
245 endif
246
247 clean-local: clean-local-gtkdoc
248         @rm -f *~ *.bak
249         @rm -rf .libs
250
251 distclean-local:
252         @rm -f $(REPORT_FILES) \
253                 $(DOC_MODULE)-decl-list.txt $(DOC_MODULE)-decl.txt
254         @rm -rf tmpl/*.sgml.bak
255         @rm -f $(DOC_MODULE).hierarchy
256         @rm -f *.stamp || true
257         @if test "$(abs_srcdir)" != "$(abs_builddir)" ; then \
258             rm -f $(DOC_MODULE)-docs.sgml ; \
259             rm -f $(DOC_MODULE).types ; \
260             rm -f $(DOC_MODULE).interfaces ; \
261             rm -f $(DOC_MODULE)-overrides.txt ; \
262             rm -f $(DOC_MODULE).prerequisites ; \
263             rm -f $(DOC_MODULE)-sections.txt ; \
264             rm -rf tmpl/*.sgml ; \
265             rm -rf $(INSPECT_DIR); \
266         fi
267         @rm -rf *.o
268
269 MAINTAINERCLEANFILES = $(MAINTAINER_DOC_STAMPS)
270
271 # thomas: make docs parallel installable; devhelp requires majorminor too
272 install-data-local:
273         (installfiles=`echo $(builddir)/html/*.sgml $(builddir)/html/*.html $(builddir)/html/*.png $(builddir)/html/*.css`; \
274         if test "$$installfiles" = '$(builddir)/html/*.sgml $(builddir)/html/*.html $(builddir)/html/*.png $(builddir)/html/*.css'; \
275         then echo '-- Nothing to install' ; \
276         else \
277           $(mkinstalldirs) $(DESTDIR)$(TARGET_DIR); \
278           for i in $$installfiles; do \
279             echo '-- Installing '$$i ; \
280             $(INSTALL_DATA) $$i $(DESTDIR)$(TARGET_DIR); \
281           done; \
282           pngfiles=`echo ./html/*.png`; \
283           if test "$$pngfiles" != './html/*.png'; then \
284             for i in $$pngfiles; do \
285               echo '-- Installing '$$i ; \
286               $(INSTALL_DATA) $$i $(DESTDIR)$(TARGET_DIR); \
287             done; \
288           fi; \
289           echo '-- Installing $(builddir)/html/$(DOC_MODULE).devhelp2' ; \
290           if test -e $(builddir)/html/$(DOC_MODULE).devhelp2; then \
291                     $(INSTALL_DATA) $(builddir)/html/$(DOC_MODULE).devhelp2 \
292                     $(DESTDIR)$(TARGET_DIR)/$(DOC_MODULE)-@GST_MAJORMINOR@.devhelp2; \
293           fi; \
294           (which gtkdoc-rebase >/dev/null && \
295             gtkdoc-rebase --relative --dest-dir=$(DESTDIR) --html-dir=$(DESTDIR)$(TARGET_DIR)) || true ; \
296         fi)
297 uninstall-local:
298         if test -d $(DESTDIR)$(TARGET_DIR); then \
299           rm -rf $(DESTDIR)$(TARGET_DIR)/*; \
300           rmdir -p $(DESTDIR)$(TARGET_DIR) 2>/dev/null || true; \
301         else \
302           echo '-- Nothing to uninstall' ; \
303         fi;
304
305 #
306 # Checks
307 #
308 if ENABLE_GTK_DOC
309 check-hierarchy: $(DOC_MODULE).hierarchy
310         @if grep '      ' $(DOC_MODULE).hierarchy; then \
311             echo "$(DOC_MODULE).hierarchy contains tabs, please fix"; \
312             /bin/false; \
313         fi
314
315 check: check-hierarchy
316 endif
317
318 # wildcard is apparently not portable to other makes, hence the use of find
319 inspect_files = $(shell find $(srcdir)/$(INSPECT_DIR) -name '*.xml')
320
321 check-inspected-versions:
322         @echo Checking plugin versions of inspected plugin data ...; \
323         fail=0 ; \
324         for each in $(inspect_files) ; do \
325           if (grep -H '<version>' $$each | grep -v '<version>$(VERSION)'); then \
326             echo $$each should be fixed to say version $(VERSION) or be removed ; \
327             echo "sed -i -e 's/<version.*version>/<version>$(VERSION)<\/version>/'" $$each; \
328             echo ; \
329             fail=1; \
330           fi ; \
331         done ; \
332         exit $$fail
333
334 check-outdated-docs:
335         $(AM_V_GEN)echo Checking for outdated plugin inspect data ...; \
336         fail=0 ; \
337         if [ -d $(top_srcdir)/.git/ ]; then \
338           files=`find $(srcdir)/inspect/ -name '*xml'`; \
339           for f in $$files; do \
340             ver=`grep '<version>$(PACKAGE_VERSION)</version>' $$f`; \
341             if test "x$$ver" = "x"; then \
342               plugin=`echo $$f | sed -e 's/^.*plugin-//' -e 's/.xml//'`; \
343               # echo "Checking $$plugin $$f"; \
344               pushd "$(top_srcdir)" >/dev/null; \
345               pinit=`git grep -A3 GST_PLUGIN_DEFINE -- ext/ gst/ sys/ | grep "\"$$plugin\""`; \
346               popd >/dev/null; \
347               # echo "[$$pinit]"; \
348               if test "x$$pinit" = "x"; then \
349                 printf " **** outdated docs for plugin %-15s: %s\n" $$plugin $$f; \
350                 fail=1; \
351               fi; \
352             fi; \
353           done; \
354         fi ; \
355         exit $$fail
356
357 #
358 # Require gtk-doc when making dist
359 #
360 if ENABLE_GTK_DOC
361 dist-check-gtkdoc:
362 else
363 dist-check-gtkdoc:
364         @echo "*** gtk-doc must be installed and enabled in order to make dist"
365         @false
366 endif
367
368 # FIXME: decide whether we want to dist generated html or not
369 # also this only works, if the project has been build before
370 # we could dist html only if its there, but that might lead to missing html in
371 # tarballs
372 dist-hook: dist-check-gtkdoc dist-hook-local
373         mkdir $(distdir)/html
374         cp html/* $(distdir)/html
375         -cp $(srcdir)/$(DOC_MODULE).types $(distdir)/
376         -cp $(srcdir)/$(DOC_MODULE)-sections.txt $(distdir)/
377         cd $(distdir) && rm -f $(DISTCLEANFILES)
378         -gtkdoc-rebase --online --relative --html-dir=$(distdir)/html
379
380 .PHONY : dist-hook-local docs check-outdated-docs inspect
381
382 # avoid spurious build errors when distchecking with -jN
383 .NOTPARALLEL: