#!/usr/bin/make -f

EMACS_VERSION=21

build: build-arch build-indep
build-arch:
build-indep:


binary: binary-arch binary-indep
binary-arch:
binary-indep:
	[ -f debian/control ]
	[ `id -u` -eq 0 ]

	pkgs=`sed -n -e "/^Package:/s/^Package: *//p" debian/control`; \
	for pkg in $$pkgs; do ( \
		set -e -x; \
		install -d debian/$$pkg; \
		\
		install -o root -g root -m755 -d \
			debian/$$pkg/usr/share/doc/$$pkg; \
		install -o root -g root -m644 debian/copyright \
			debian/$$pkg/usr/share/doc/$$pkg/copyright; \
		install -o root -g root -m644 debian/changelog \
			debian/$$pkg/usr/share/doc/$$pkg/changelog; \
		gzip -f -9 debian/$$pkg/usr/share/doc/$$pkg/changelog; \
		\
		install -d debian/$$pkg/DEBIAN; \
		dpkg-gencontrol -Vemacs-version=$(EMACS_VERSION) \
			-p$$pkg -Pdebian/$$pkg; \
		chown root:root debian/$$pkg/DEBIAN/control; \
		chmod 644 debian/$$pkg/DEBIAN/control; \
		\
		dpkg-deb --build debian/$$pkg ..; \
	); done


clean:
	[ -f debian/control ]

	rm -f debian/files debian/*~

	pkgs=`sed -n -e "/^Package:/s/^Package: *//p" debian/control`; \
	for pkg in $$pkgs; do ( \
		set -e -x; \
		rm -rf debian/$$pkg; \
	); done


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