include $(top_srcdir)/doc/files.am
include $(top_srcdir)/build/makefiles/sphinx-build.am

$(html_files): html-build-stamp
$(html_files_relative_from_locale_dir): html-build-stamp

am__nobase_dist_doc_locale_DATA_DIST =
if DOCUMENT_AVAILABLE
doc_localedir = $(docdir)/$(LOCALE)
nobase_dist_doc_locale_DATA =			\
	$(html_files_relative_from_locale_dir)
am__nobase_dist_doc_locale_DATA_DIST +=	\
	$(nobase_dist_doc_locale_DATA)
endif

document_source_files =				\
	$(absolute_source_files)		\
	$(absolute_theme_files)			\
	$(po_files_relative_from_locale_dir)	\
	$(mo_files_relative_from_locale_dir)

required_build_stamps =				\
	html-build-stamp			\
	mo-build-stamp

if DOCUMENT_BUILDABLE
EXTRA_DIST += $(required_build_stamps)
endif

generated_files =				\
	$(DOCTREES_BASE)			\
	html					\
	html-build-stamp			\
	text					\
	text-build-stamp			\
	markdown				\
	markdown-build-stamp

$(mo_files_relative_from_locale_dir): mo-build-stamp

mo-build-stamp: $(po_files_relative_from_locale_dir)
	cd LC_MESSAGES && $(MAKE) build
	@touch $@

if DOCUMENT_BUILDABLE
clean-local: $(clean_targets) clean-doctrees

clean-doctrees:
	rm -rf $(DOCTREES_BASE)

maintainer-clean-local:
	rm -rf -- $(generated_files)
endif

.PHONY: help
.PHONY: html clean-html
.PHONY: text clean-text
.PHONY: markdown clean-markdown

if DOCUMENT_BUILDABLE
help:
	@echo "Please use \`make <target>' where <target> is one of"
	@echo "  html      to make standalone HTML files"
	@echo "  markdown  to make Markdown files (requires sphinx-markdown-builder)"
	@echo "  text      to make text files"

html: html-recursive html-build-stamp
text: text-recursive text-build-stamp
markdown: markdown-recursive markdown-build-stamp

clean_targets =					\
	clean-html				\
	clean-text				\
	clean-markdown

$(clean_targets):
	target=`echo $@ | sed -e 's/^clean-//'`;	\
	  rm -rf $${target}-build-stamp $${target}

build_stamps =					\
	html-build-stamp			\
	text-build-stamp			\
	markdown-build-stamp

$(build_stamps): $(document_source_files)
	target=`echo $@ | sed -e 's/-build-stamp$$//'`;	\
	  $(SPHINX_BUILD_COMMAND)			\
	    -Dlanguage=$(LOCALE)			\
	    -d $(DOCTREES_BASE)/$${target}		\
	    -b $${target}				\
	    $(ALLSPHINXOPTS)				\
	    $${target}
	@touch $@
endif
