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

tmp = $(shell pwd)/debian/tmp
docdir = $(tmp)/usr/share/doc/junior-doc
examplesdir = $(docdir)/examples
scriptsdir = $(examplesdir)/scripts

build: stamp-build
stamp-build:
	test -d quickguide -a -f debian/rules
	cd quickguide && $(MAKE) html txt ps
	cd quickguide && gzip -9 junior-quickguide.txt junior-quickguide.ps
	touch $@

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

binary: binary-indep binary-arch

binary-arch:

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

	install -m 755 -d $(tmp)/DEBIAN $(docdir) $(docdir)/quickguide \
          $(examplesdir) $(scriptsdir) $(tmp)/usr/share/doc-base
	cd quickguide && install -m 644 junior-quickguide.txt.gz \
		    junior-quickguide.ps.gz \
                    junior-quickguide.html/* $(docdir)/quickguide

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

# If we were including the quickguide in ftp/doc, we would do the
# following, similar to doc-debian.  But while the project is still
# immature, we will not upload these materials.  Instead, we will
# just distribute them from the Debian Jr. website.  If this is ever
# enabled, it needs to be OK'd by ftpmaster@d.o
#
# The extra-package files:
#	cd quickguide/junior-quickguide.html && GZIP=-9 tar czf ../../../junior-quickguide.html.tar.gz *
#	cp quickguide/junior-quickguide.txt.gz quickguide/junior-quickguide.ps.gz ../
#	dpkg-distaddfile junior-quickguide.html.tar.gz byhand -
#	dpkg-distaddfile junior-quickguide.txt.gz byhand -
#	dpkg-distaddfile junior-quickguide.ps.gz byhand -

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