#!/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 -f debian/rules
	touch $@

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

refresh:
	cd doc && $(MAKE)

binary: binary-indep binary-arch

binary-arch:

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

	install -m 755 -d $(tmp)/DEBIAN \
          $(tmp)/usr/share/doc-base $(tmp)/usr/share/doc/doc-debian $(docdir)
# 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

	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) ..

# The extra-package files:
	cp $(docdir)/constitution.1.2.txt ../constitution.txt
	cp $(docdir)/social-contract.1.1.txt ../social-contract.txt

	dpkg-distaddfile constitution.txt byhand -
	dpkg-distaddfile social-contract.txt byhand -
# Code disabled: There already is a mechanism (which one?)
# synching files over to f.d.o/debian/doc although not exactly the
# same (it retains page footers, which this one doesn't)
#
#      cp $(docdir)/debian-manifesto ../
#      dpkg-distaddfile debian-manifesto byhand -
#      ( cd $(docdir) && ls *.txt) |  \
#          grep -v constitution | \
#          grep -v social-contract | \
#          while read txtfile; do \
#             cp $(docdir)/$$txtfile ../ ; \
#             dpkg-distaddfile $$txtfile byhand - ; \
#            done


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