## Process this file with automake to produce Makefile.in

if MAINTAINER_MODE
# Export these so that we run the locally installed autotools when building
# from a bootstrapped git tree.
export ACLOCAL AUTOCONF AUTOHEADER AUTOM4TE AUTOMAKE
endif

# Note: we don't want dist tarballs built with docs missing, so for simplicity
# this Makefile.am blindly assumes the tools are in place when "make dist" is
# being run.  For "make all", "make check", etc we carefully skip any docs
# which we don't have the tools to generate.

RSTDOCS = \
	bm25.rst \
	geospatial.rst \
	index.rst \
	install.rst \
	intro_ir.rst \
	overview.rst \
	queryparser.rst \
	remote.rst \
	stemming.rst \
	termgenerator.rst \
	valueranges.rst

RSTHTML = $(RSTDOCS:.rst=.html)

# Files which should be put in the distribution by automake
EXTRA_DIST = doxygen_api.conf.in doxygen_source.conf.in \
	doxygen_api_header.html_tmpl doxygen_api_footer.html_tmpl \
	doxygen_source_header.html_tmpl doxygen_source_footer.html_tmpl \
	$(RSTDOCS) $(HTMLDOCS) $(RSTHTML)

# Other files which should be distributed
dist-hook: doxygen_api_docs
	$(MKDIR_P) '$(distdir)/apidoc/html'
	for e in png css html js ; do \
	  test "`echo $(srcdir)/apidoc/html/*.$$e`" = "$(srcdir)/apidoc/html/*.$$e" || \
	    cp -p $(srcdir)/apidoc/html/*.$$e $(distdir)/apidoc/html ;\
	  test "`echo apidoc/html/*.$$e`" = "apidoc/html/*.$$e" || \
	    cp -p apidoc/html/*.$$e $(distdir)/apidoc/html ;\
	done

# Disable these rules if configured with --enable-maintainer-mode and
# --disable-documentation so that "make install" works in this case.
if !MAINTAINER_NO_DOCS
doc_DATA = $(HTMLDOCS) $(RSTHTML)

install-data-local: doxygen_api_docs
	$(mkinstalldirs) $(DESTDIR)$(docdir)/apidoc/html
	$(INSTALL_DATA) `test -f apidoc/html/index.html || echo $(srcdir)/`apidoc/html/*.png $(DESTDIR)$(docdir)/apidoc/html
	$(INSTALL_DATA) `test -f apidoc/html/index.html || echo $(srcdir)/`apidoc/html/*.css $(DESTDIR)$(docdir)/apidoc/html
	$(INSTALL_DATA) `test -f apidoc/html/index.html || echo $(srcdir)/`apidoc/html/*.html $(DESTDIR)$(docdir)/apidoc/html
	$(INSTALL_DATA) `test -f apidoc/html/index.html || echo $(srcdir)/`apidoc/html/*.js $(DESTDIR)$(docdir)/apidoc/html
endif

###############################
# How to clean up local files #
###############################

maintainer-clean-local:
	rm -rf apidoc sourcedoc

################################
# How to uninstall local files #
################################
uninstall-local:
	rm -rf $(DESTDIR)$(docdir)/apidoc

MAINTAINERCLEANFILES = doxygen_api.conf doxygen_source.conf \
	apidoc.pdf \
	$(RSTHTML)

.PHONY: doxygen_source_docs doxygen_api_docs doxygen_docs

doxygen_source_docs: sourcedoc/html/index.html
doxygen_api_docs: apidoc/html/index.html
doxygen_docs: doxygen_source_docs doxygen_api_docs

if DOCUMENTATION_RULES
# Build API docs with doxygen
all-local: doxygen_api_docs

# We use $T instead of $(top_srcdir) in APIDOC_SRC and SOURCEDOC_SRC to keep
# their sizes down.
T=$(top_srcdir)

# docsource.mk is generated by preautoreconf, run by bootstrap prior to
# it running autoreconf.
include docsource.mk

APIDOC_DEPS = $(APIDOC_SRC) doxygen_api.conf \
		$(srcdir)/doxygen_api_header.html_tmpl \
		$(srcdir)/doxygen_api_footer.html_tmpl

apidoc/html/index.html: $(APIDOC_DEPS)
	rm -rf apidoc doxygen_api_html.conf.tmp
	## Use a temporary file to work around doxygen 1.8.19 bug which
	## truncates a config file read from stdin to 4096 bytes.
	sed 's/^\(GENERATE_HTML\)\>.*/\1 = YES/;s/^\(GENERATE_LATEX\)\>.*/\1 = NO/' doxygen_api.conf > doxygen_api_html.conf.tmp
	top_srcdir='$(top_srcdir)' top_builddir='$(top_builddir)' $(DOXYGEN) doxygen_api_html.conf.tmp
	rm -f doxygen_api_html.conf.tmp
	## Regression test - 1.0.17 failed to generate docs from error.h in a
	## VPATH build.
	test -f apidoc/html/classXapian_1_1RuntimeError.html || \
	  ( echo "No api docs for Xapian::RuntimeError" ; \
	    rm apidoc/html/index.html ; exit 1 )
	if test "x$(PNGCRUSH)" != x ; then \
	  for png in apidoc/html/*.png ; do \
	    $(PNGCRUSH) -q "$$png" "$${png}T" && mv "$${png}T" "$$png" ; \
	  done \
	fi
	touch apidoc/html/index.html

# Not built by default, but available in case users want to build it for
# themselves.
apidoc.pdf: $(APIDOC_DEPS)
	rm -f doxygen_api_pdf.conf.tmp
	## Use a temporary file to work around doxygen 1.8.19 bug which
	## truncates a config file read from stdin to 4096 bytes.
	sed 's/^\(GENERATE_HTML\)\>.*/\1 = NO/;s/^\(GENERATE_LATEX\)\>.*/\1 = YES/' doxygen_api.conf > doxygen_api_pdf.conf.tmp
	top_srcdir='$(top_srcdir)' top_builddir='$(top_builddir)' $(DOXYGEN) doxygen_api_pdf.conf.tmp
	rm -f doxygen_api_pdf.conf.tmp
	cd apidoc/latex && (pool_size=750000 $(MAKE) refman.pdf||(cat refman.log;exit 1))
	mv apidoc/latex/refman.pdf apidoc.pdf

sourcedoc/html/index.html: $(SOURCEDOC_SRC) $(APIDOC_SRC) \
		doxygen_source.conf \
		$(srcdir)/doxygen_source_header.html_tmpl \
		$(srcdir)/doxygen_source_footer.html_tmpl
	rm -rf sourcedoc
	top_srcdir='$(top_srcdir)' top_builddir='$(top_builddir)' $(DOXYGEN) doxygen_source.conf

.rst.html:
	$(RST2HTML) --math-output=HTML --exit-status=warning $< $@
endif
