#!/usr/bin/make -f

VERSION = $(shell dpkg-parsechangelog | sed -n '/^Version:/ {s/.*: //; s/+.*//; p;}')
ORIGDIR = rush-$(VERSION)
TARBALL = $(ORIGDIR).tar
TARLOC  = ftp://download.gnu.org.ua/pub/release/rush/$(TARBALL).gz

TARNAME = rush_$(VERSION)+dfsg.orig.tar

CPPFLAGS := $(shell dpkg-buildflags --get CPPFLAGS)
CFLAGS   := $(shell dpkg-buildflags --get CFLAGS)
LDFLAGS  := $(shell dpkg-buildflags --get LDFLAGS)
export CPPFLAGS CFLAGS LDFLAGS

%:
	dh $@ --with autoreconf

override_dh_auto_configure:
	./configure CFLAGS="-Wall ${CFLAGS}" LDFLAGS="${LDFLAGS}" \
			--disable-silent-rules \
			--prefix=/usr \
			--sysconfdir=/etc \
			--localstatedir=/var/lib

override_dh_auto_install:
	dh_auto_install
	# Assign 'setuid' flag; see README.Debian
	chmod 04755 debian/rush/usr/sbin/rush

override_dh_fixperms:
	# Do not reset the manually set 'setuid' flag!
	dh_fixperms --exclude usr/sbin/rush

get-orig-source:
	# Fetch released archive from upstream's location.
	rm -rf   $(ORIGDIR)
	wget -N  $(TARLOC)
	tar -xzf $(TARBALL).gz
	touch -r $(ORIGDIR) stamp
	# Remove the GFDL licensed part.
	rm -rf   $(ORIGDIR)/doc/
	touch -r stamp $(ORIGDIR)
	# Repackage at best compression.  Compress reproducibly.
	tar -H ustar -chf  $(TARNAME) $(ORIGDIR)
	rm -f      $(TARNAME).gz
	gzip -n -9 $(TARNAME)
	rm -rf     stamp $(ORIGDIR)
