# This file should be included by the Makefile
# of each language directory

XML_LANG ?= $(subst _,-,$(patsubst -%,%,$(DOCSUFFIX)))

local-all: local-html comments

# We do not want to recurse in parent dir for the "clean" rule
local-clean: local-html-clean local-pdf-clean local-epub-clean local-cheatsheet-clean
	rm -f images # work around https://trac.osgeo.org/postgis/ticket/5422
	rm -f $(XML_INPUTS)
	rm -f postgis-out.xml.in postgis-nospecial.xml.in
	rm -rf xsl

# We do not want to recurse in parent dir here
local-distclean:
	rm -f Makefile

local-%: xsl
	$(MAKE) $(patsubst local-%,%,$@) DOCSUFFIX=$(DOCSUFFIX)

xsl:
	ln -sf $(srcdir)/../../xsl .

# for XML_SOURCES
include ../../Makefile

# XML gettext tools
PO2XML=po2xml

$(XML_SOURCES): %.xml: postgis-manual.po $(abs_srcdir)/%.xml
	$(PO2XML) $(abs_srcdir)/$@ $< > $@.tmp
	if test "$@" = "postgis.xml"; then \
		$(PERL) -0pi -e 's/(<book\b)(?![^>]*\bxml:lang=)/$$1 xml:lang="$(XML_LANG)"/' $@.tmp; \
	fi
	mv $@.tmp $@

