#!/usr/bin/make -f

cflags = $(shell dpkg-buildflags --get CFLAGS)
cppflags = $(shell dpkg-buildflags --get CPPFLAGS)
ldflags = $(shell dpkg-buildflags --get LDFLAGS)

manpage_sources = $(wildcard debian/manpages/*.pod)
manpages = $(manpage_sources:.pod=.1)

.PHONY: build build-arch build-indep
build build-arch: build-stamp
build-stamp: Makefile debian/control $(manpages)
	ln -s delta singledelta
	rm -f topformflat.c
	$(MAKE) all CFLAGS="$(cflags) $(cppflags) $(ldflags)"
ifeq "$(filter nocheck,$(DEB_BUILD_OPTIONS))" ""
	$(MAKE) check
endif
	rm singledelta
	touch "$@"

%.1: %.pod
	pod2man -c '' -r 'Delta 2006.08.03' $(<) > $(@)

.PHONY: clean
clean: Makefile debian/control
	$(MAKE) clean
	dh_clean $(manpages)

.PHONY: binary binary-arch binary-indep
binary binary-arch: build-stamp
	dh_testroot
	dh_prep
	mkdir -p debian/delta/usr/bin/
	cp multidelta delta topformflat debian/delta/usr/bin/
	mv debian/delta/usr/bin/delta debian/delta/usr/bin/singledelta
	dh_installchangelogs
	dh_installdocs
	dh_installman
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_makeshlibs
	dh_installdeb
	dh_perl
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# vim:ts=4 sw=4 noet
