# -*- coding: utf-8 -*-
# :Project:   SoL -- Manual related targets
# :Created:   mer 5 mar 2014 09:35:31 CET
# :Author:    Lele Gaifax <lele@metapensiero.it>
# :License:   GNU General Public License version 3 or later
# :Copyright: © 2014, 2016, 2021 Lele Gaifax
#

LANGS = it en
MANUALDIR := $(SOLSRC)/static/manual

.PHONY: manual
manual: $(foreach lang,$(LANGS),manual-$(lang))
	@rm -rf $(MANUALDIR) && ( \
	  cp -a docs/_build/html $(MANUALDIR); \
	  for lang in $(LANGS); do \
	    cp -a docs/_build/$$lang/html $(MANUALDIR)/$$lang; \
	    [ -f $(MANUALDIR)/$$lang/_static/translations.js ] && \
	      mv $(MANUALDIR)/$$lang/_static/translations.js \
		 $(MANUALDIR)/_static/translations-$$lang.js; \
	    rm -rf $(MANUALDIR)/$$lang/_static; \
	    for html in $(MANUALDIR)/$$lang/*.html; do \
	      sed -i "s,_static/translations\.js,_static/translations-$$lang.js,g" $$html; \
	      sed -i 's,"_static/,"../_static/,g' $$html; \
	    done; \
	  done; \
	)

manual-%: manual-dev
	$(MAKE) -C docs/$(@:manual-%=%) -f ../Makefile html LANGDIR=/$(@:manual-%=%)

.PHONY: manual-dev
manual-dev:
	$(MAKE) -C docs html
