# This is part of the Zrythm Manual.
# Copyright (C) 2019 Alexandros Theodotou <alex at zrythm dot org>
# See the file index.rst for copying conditions.
#
# ----------------------------------------------------------------------
#
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line.
SPHINXOPTS    =
SPHINXBUILD   = sphinx-build
SOURCEDIR     = .
BUILDDIR      = _build
RENDERDIR     = _rendered

# Put it first so that "make" without argument is like "make help".
help:
	@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: bundle

LANGUAGES = en de fr it es ja pt pt_BR ru zh nb_NO

# Skip chinese latexpdf because it doesn't support Chinese yet
# bundle: html epub
bundle: html latexpdf epub
	for lang in $(LANGUAGES) ; do \
		mkdir -p $(RENDERDIR)/$$lang && \
		cp -R $(BUILDDIR)/$$lang/html/* $(RENDERDIR)/$$lang/ ; \
		if [[ "x$$lang" == "xzh" ]] ; then \
			echo "skipping $$lang pdf" ; \
		else \
			cp $(BUILDDIR)/$$lang/latex/Zrythm.pdf $(RENDERDIR)/$$lang/ ; \
		fi ; \
		cp $(BUILDDIR)/$$lang/epub/Zrythm.epub $(RENDERDIR)/$$lang/ && \
		zip -r $(RENDERDIR)/$$lang/Zrythm-html.zip $(BUILDDIR)/$$lang/html/* ; \
	done


.PHONY: help Makefile

.PHONY: gettext
gettext:
	$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
	for lang in $(LANGUAGES) ; do \
		sphinx-intl update -p $(BUILDDIR)/gettext -l $$lang ; \
	done
	./remove_gfdl_from_po.py

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option.  $(O) is meant as a shortcut for $(SPHINXOPTS).
# Skip chinese latexpdf because it doesn't support Chinese yet
%: Makefile
	for lang in $(LANGUAGES) ; do \
		if [[ "x$@" == "xlatexpdf" ]] && [[ "x$$lang" == "xzh" ]] ; then \
			echo "skipping $@ $$lang" ; \
		else \
			echo "$@ $$lang" ; \
			SPHINXOPTS="-D language=$$lang" && \
			$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)/$$lang" $(SPHINXOPTS) $$SPHINXOPTS $(O) ; \
		fi \
	done
