#!/usr/bin/make -f
# derived from sample debian/rules file for GNU hello by Ian Jackson.

tmp = $(CURDIR)/debian/tmp
docdir = $(tmp)/usr/share/doc/debian
basedir = $(CURDIR)/debian/debian-faq
installdir = $(basedir)/usr/share/doc/debian

langs = de fr it zh_CN

build: stamp-build
stamp-build:
	test -f Makefile -a -f debian/rules
	$(MAKE) html text ps pdf langs="$(langs)"
	gzip -9 debian-faq.en.txt debian-faq.en.ps debian-faq.en.pdf
	for l in $(langs); do \
          gzip -9 $$l/debian-faq.$$l.txt $$l/debian-faq.$$l.ps \
           $$l/debian-faq.$$l.pdf; \
        done
	touch $@

clean:
	test -f Makefile -a -f debian/rules
	test "`id -u`" -eq 0
	$(MAKE) clean
	rm -rf $(tmp)
	rm -f *.gz stamp-build debian/files `find . -name "*~"`
	dh_clean

binary: binary-indep binary-arch

binary-arch:

binary-indep: build
	test -f Makefile -a -f debian/rules
	test "`id -u`" -eq 0
	rm -rf $(tmp)

	dh_clean -k

	install -m 755 -d $(tmp)/DEBIAN $(docdir)/FAQ \
          $(tmp)/usr/share/doc-base $(tmp)/usr/share/doc/debian-faq \
          $(installdir)/FAQ $(basedir)/usr/share/doc-base \
          $(basedir)/usr/share/doc/debian-faq
	install -m 644 debian-faq.en.txt.gz debian-faq.en.ps.gz \
                    debian-faq.en.pdf.gz debian-faq.en.html/* $(installdir)/FAQ

	for l in $(langs); do \
          install -m 755 -d $(docdir)/FAQ/$$l; \
          install -m 644 $$l/debian-faq.$$l.txt.gz $$l/debian-faq.$$l.ps.gz \
           $$l/debian-faq.$$l.pdf.gz $(docdir)/FAQ; \
          install -m 644 $$l/debian-faq.$$l.html/* $(docdir)/FAQ/$$l/; \
        done

	cd $(installdir)/FAQ && for file in *.en.html; do \
          ln -s $$file $${file%$${file#$${file%.en.html}}}.html; \
        done
# Make links for the byhands
	ln -sf debian-faq.en.txt.gz $(installdir)/FAQ/debian-faq.txt.gz
	ln -sf debian-faq.en.ps.gz $(installdir)/FAQ/debian-faq.ps.gz
	ln -sf debian-faq.en.pdf.gz $(installdir)/FAQ/debian-faq.pdf.gz
	ln -sf debian-faq.en.pdf.gz $(installdir)/FAQ/debian-faq.pdf.gz

	dh_installdocs
	dh_installchangelogs
	dh_installdirs --all
	dh_install --sourcedir=$(tmp)
	dh_compress --all
	dh_fixperms
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# The extra-package files:
	mv $(installdir)/FAQ/debian-faq.*txt.gz \
           $(installdir)/FAQ/debian-faq.*ps.gz \
           $(installdir)/FAQ/debian-faq.*pdf.gz \
             ../
	cd $(installdir)/FAQ/ && GZIP=-9 tar czf $(CURDIR)/../debian-faq.en.html.tar.gz *

# list them in the .changes file, so that they'll get uploaded properly:
	dpkg-distaddfile debian-faq.en.html.tar.gz byhand -
	dpkg-distaddfile debian-faq.en.txt.gz byhand -
	dpkg-distaddfile debian-faq.en.ps.gz byhand -
	dpkg-distaddfile debian-faq.en.pdf.gz byhand -

.PHONY: build clean binary binary-arch binary-indep
