#!/usr/bin/make -f
#

build:
	$(checkdir)
	$(MAKE) CFLAGS="-O2 -I."
	touch build

clean:
	$(checkdir)
	-rm -rf build debian/files debian/tmp debian/*~
	-rm -f .depend .emacs.desktop
	-$(MAKE) clean

binary: checkroot build
	$(checkdir)
	-rm -rf debian/tmp
# Make the directory tree.
	install -d debian/tmp debian/tmp/DEBIAN
	install -d debian/tmp/lib
	install -d debian/tmp/etc
	install -d debian/tmp/usr/doc/termcap-compat
# Copy copyright file and executables to their proper places.
	install -m 644 debian/copyright debian/tmp/usr/doc/termcap-compat
	install -s -m 755 libtermcap.so.2.0.8 debian/tmp/lib
	install -m 644 termcap.src debian/tmp/etc/termcap
	install -m 644 ChangeLog debian/tmp/usr/doc/termcap-compat
	install -m 644 debian/changelog \
		debian/tmp/usr/doc/termcap-compat/changelog.Debian
# Compress documentation...
	test -f debian/tmp/usr/doc/termcap-compat/changelog.Debian.gz || \
		gzip -9 debian/tmp/usr/doc/termcap-compat/changelog.Debian
# Make the debian control area
	install -m 755 debian/{preinst,postinst,postrm} debian/tmp/DEBIAN
	install -m 644 debian/conffiles debian/tmp/DEBIAN
# Fix permissions...
	chmod -R u=rwX,go=rX debian/tmp
	chown -R root.root debian/tmp
# And finally, build the Debian package!
	dpkg-gencontrol
	dpkg --build debian/tmp ..


define checkdir
	test -f tparam.c -a -f debian/rules
endef

source diff:
	@echo >&2 'source and diff are obsolete - use dpkg-source -b'; false

checkroot:
	$(checkdir)
	test "`whoami`" = root

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