#!/usr/bin/make -f
#
# Debian rules for building a Debian package
# Version 1.5
#
# These rules have been specifically designed NOT to require root to
# run them. At any time root privileges are required, the command to be
# executed will be made obvious and root's password will be prompted for.
# Of course, root may still run this and no password will be required.
#
# Robert Leslie <rob@mars.org>

PKG =	zsh
VER =	3.0.2
DEB =	1
BLD =	debian/.build
TMP =	debian/.tmp
ARC =	$(shell dpkg --print-architecture)
HST =	$(ARC)-debian-linux

build :: $(BLD)

binary :: $(BLD)
	su -c 'exec ./debian/binary $(PKG) $(VER)-$(DEB) $(ARC) $(TMP)'
	dpkg --build $(TMP) && dpkg-name -o -s .. $(TMP).deb

$(BLD):
	CFLAGS="-g -Wall -fwritable-strings -O2" ./configure  \
		--host="$(HST)"  \
		--prefix="/usr"  \
		--enable-zsh-mem
	make
	touch $(BLD)

clean ::
	test ! -d $(TMP) || su -c 'rm -rf $(TMP)'
	rm -f $(BLD)
	test ! -f Makefile || make distclean
	rm -f Doc/zsh.info*

source ::
	test ! -f $(BLD) || make -f debian/rules clean
	cd .. && tar cf - $(PKG)-$(VER) |  \
	    gzip -9f > $(PKG)_$(VER)-$(DEB).tar.gz

diff ::
	test ! -f $(BLD) || make -f debian/rules clean
	test -d ../$(PKG)-$(VER).orig
	cd .. && diff -cNr $(PKG)-$(VER).orig $(PKG)-$(VER) |  \
	    gzip -9f > $(PKG)_$(VER)-$(DEB).diff.gz
