#!/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

build: stamp-build
stamp-build:
	test -d FAQ -a -f debian/rules
	cd FAQ && $(MAKE) html text ps pdf
	cd FAQ && gzip -9 debian-faq.en.txt debian-faq.en.ps debian-faq.en.pdf
	touch $@

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

refresh:
	cd doc && $(MAKE)

binary: binary-indep binary-arch

binary-arch:

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

	install -m 755 -d $(tmp)/DEBIAN $(docdir)/FAQ \
          $(tmp)/usr/share/doc-base $(tmp)/usr/share/doc/doc-debian
# Copy all the contents of doc/
	cp -p doc/* $(docdir)
# Save for the files that are used to auto-generate them
	rm -f $(docdir)/*wml
	rm -f $(docdir)/Makefile
	cd FAQ && install -m 644 debian-faq.en.txt.gz debian-faq.en.ps.gz \
                    debian-faq.en.pdf.gz debian-faq.en.html/* $(docdir)/FAQ
	cd $(docdir)/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 $(docdir)/FAQ/debian-faq.txt.gz
	ln -sf debian-faq.en.ps.gz $(docdir)/FAQ/debian-faq.ps.gz
	ln -sf debian-faq.en.pdf.gz $(docdir)/FAQ/debian-faq.pdf.gz
	ln -sf debian-faq.en.pdf.gz $(docdir)/FAQ/debian-faq.pdf.gz

	install -m 755 debian/prerm debian/postinst $(tmp)/DEBIAN
	install -m 644 doc-base/* $(tmp)/usr/share/doc-base
	install -m 644 debian/copyright $(tmp)/usr/share/doc/doc-debian
	gzip -c9 debian/changelog > $(tmp)/usr/share/doc/doc-debian/changelog.gz
	chown -R root.root $(tmp) && chmod -R go=rX $(tmp)
	dpkg-gencontrol -isp
	dpkg --build $(tmp) ..

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