# Other Makefile.am files should set:
# VALA_SOURCE_FILES, VALA_SOURCE_FILES_WITH_PATHS, 
# RYGEL_DOCBUILD_VALADOC_FLAGS, RYGEL_DOCBUILD_MODULE
# and RYGEL_DOCBUILD_EXTRA_GTKDOC_OPTIONS
# and the include this .am file.

if ENABLE_VALADOC

VALADOC_FLAGS = --force \
		--vapidir $(top_srcdir)/src/lib$(RYGEL_DOCBUILD_MODULE) \
		$(RYGEL_DOCBUILD_VALADOC_FLAGS) \
		--target-glib=2.32 \
		--vapidir=$(rygeldir) \
		--pkg rygel-build-config \
		-b $(top_srcdir)/src/lib$(RYGEL_DOCBUILD_MODULE) \
		--package-name lib$(RYGEL_DOCBUILD_MODULE) \
		--package-version 2.0 \
		$(VALA_SOURCE_FILES_WITH_PATHS)


valadoc-gen: $(VALA_SOURCE_FILES_WITH_PATHS)
	$(AM_V_GEN)$(VALADOC) \
		-o valadoc \
		$(VALADOC_FLAGS)

# Avoid regeneration of the html if none of its dependencies have changed:
gtkdoc/html/index.html: gtkdoc-gen

RYGEL_GTKDOC_DOCS_XML = \
	$(top_srcdir)/doc/reference/lib$(RYGEL_DOCBUILD_MODULE)/gtkdoc/lib$(RYGEL_DOCBUILD_MODULE)-docs.xml \
	$(top_srcdir)/doc/reference/lib$(RYGEL_DOCBUILD_MODULE)/gtkdoc/overview.xml $(RYGEL_GTKDOC_DOCS_XML_EXTRA)

gtkdoc-gen: $(VALA_SOURCE_FILES_WITH_PATHS) $(RYGEL_GTKDOC_DOCS_XML)
	@rm -rf gtkdoc/html
	$(AM_V_GEN)$(VALADOC) \
		-X $(top_srcdir)/src/lib$(RYGEL_DOCBUILD_MODULE)/$(RYGEL_DOCBUILD_MODULE).h \
		$(RYGEL_DOCBUILD_EXTRA_GTKDOC_OPTIONS) \
		-X -l -X $(top_builddir)/src/lib$(RYGEL_DOCBUILD_MODULE)/.libs/lib$(RYGEL_DOCBUILD_MODULE)-2.0.so \
		-o gtkdoc \
		--doclet gtkdoc \
		$(VALADOC_FLAGS)
		
clean-local:
	rm -rf valadoc gtkdoc/html
	rm -f gtkdoc/html.stamp
	rm -f gtkdoc/sgml.stamp
	rm -rf gtkdoc/ccomments
	rm -rf gtkdoc/xml
	rm -rf gtkdoc/cscan
	rm -f gtkdoc/lib$(RYGEL_DOCBUILD_MODULE).args
	rm -f gtkdoc/lib$(RYGEL_DOCBUILD_MODULE).interfaces
	rm -f gtkdoc/lib$(RYGEL_DOCBUILD_MODULE).hierarchy
	rm -f gtkdoc/lib$(RYGEL_DOCBUILD_MODULE).signals
	rm -f gtkdoc/lib$(RYGEL_DOCBUILD_MODULE).types
	rm -f gtkdoc/lib$(RYGEL_DOCBUILD_MODULE)*.txt
	rm -f gtkdoc/lib$(RYGEL_DOCBUILD_MODULE).prerequisites

RYGEL_GTKDOC_INSTALL_DIR = $(DESTDIR)$(datadir)/gtk-doc/html/lib$(RYGEL_DOCBUILD_MODULE)

uninstall-hook:
	rm -rf $(INSTALL_DIR)

all: valadoc-gen gtkdoc-gen

endif

# The chmod corrects the directory permissions so that distcheck can remove the installed files.
install-data-hook: gtkdoc/html/index.html
	$(MKDIR_P) $(RYGEL_GTKDOC_INSTALL_DIR)
	cp -d -R $(srcdir)/gtkdoc/html $(RYGEL_GTKDOC_INSTALL_DIR)
	chmod -R u+w $(RYGEL_GTKDOC_INSTALL_DIR)


EXTRA_DIST = $(RYGEL_GTKDOC_DOCS_XML) gtkdoc/html valadoc

