#!/usr/bin/make -f

DOCDIR=debian/debian-handbook/usr/share/doc/debian-handbook/html
VERSION=$(shell sed -n -e 's|.*<productnumber>\(.*\)</productnumber>.*|\1|p' en-US/Book_Info.xml)
LANGS=$(shell echo [a-z][a-z]-[A-Z][A-Z])

%:
	dh $@ 

# Build multiple languages in parallel
override_dh_auto_build: $(foreach lang,$(LANGS),build-html-$(lang))
build-html-%:
	./bin/build-html --lang=$*

override_dh_auto_install:
	mkdir -p $(DOCDIR)
	for lang in $(LANGS); do \
		mv publish/$$lang/Debian/$(VERSION)/html/debian-handbook $(DOCDIR)/$$lang; \
	done
	# Drop some useless files
	rm -f $(DOCDIR)/*/images/chap-*.png # Chapter pictures only used in PDF
	rm -f $(DOCDIR)/*/images/cover.png  # Cover picture (only used in PDF/ePub)
	rm -f $(DOCDIR)/*/images/*.dia      # Sources of diagrams
	# Deduplicate the remaining files
	rdfind -makehardlinks true -makeresultsfile false $(DOCDIR)/en-US $(DOCDIR)

override_dh_auto_clean:
	publican clean