#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

VERSION = $(shell dpkg-parsechangelog | grep ^Version: | sed "s/.* //" | sed "s/-[^-]*$$//")
DATE = $(shell date -d "$$(dpkg-parsechangelog | grep ^Date: | sed -n '/^Date: /s///p')" "+%d %b %Y")

%: %.in
	sed -e 's/\$$Revision: [0-9.]* \$$/$(VERSION)/g' \
	    -e 's/@VERSION@/$(VERSION)/g' \
	    -e 's/@DATE@/$(DATE)/g' <$< >$@

INSTALL=/usr/bin/install
DESTDIR=$(CURDIR)/debian/sbuild

debian/build/config.status: configure
	dh_testdir

	mkdir debian/build; \
	cd debian/build; \
	CFLAGS="$(CFLAGS)" ../../configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr --sysconfdir=/etc --libexecdir=/usr/share --localstatedir=/var --mandir=\$${prefix}/share/man

build: debian/build/config.status debian/build-stamp
debian/build-stamp:  debian/build/config.status
	dh_testdir

	cd debian/build; \
	$(MAKE) all

	touch debian/build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -rf debian/build
	rm -rf debian/install
	rm -f debian/build-stamp

ifneq "$(wildcard /usr/share/misc/config.sub)" ""
	cp -f /usr/share/misc/config.sub scripts/config.sub
endif
ifneq "$(wildcard /usr/share/misc/config.guess)" ""
	cp -f /usr/share/misc/config.guess scripts/config.guess
endif

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	cd debian/build; \
	$(MAKE) install DESTDIR=$(CURDIR)/debian/install
	dh_install


# Build architecture-independent files here.
binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installdocs debian/cvslogs.old
	dh_installman
	dh_installchangelogs
	dh_link
	dh_compress
# -Xbuildd.chroot -XREADME-buildd.chroot
	dh_fixperms
	dh_installdeb
	dh_perl
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Build architecture-dependent files here.
binary-arch: build
# We have nothing to do by default.

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