#!/usr/bin/make -f

#export DH_VERBOSE=1

PERL ?= /usr/bin/perl

PACKAGE = $(shell dh_listpackages)
TMP     = $(CURDIR)/debian/$(PACKAGE)

configure: configure-stamp
configure-stamp:
	dh_testdir

	perl Makefile.PL verbose INSTALLDIRS=vendor

	touch configure-stamp

build-indep:

build-arch: build-stamp

build-stamp: configure-stamp
	dh_testdir

	$(MAKE) OPTIMIZE="-O2 -g -Wall"
	$(MAKE) test

	touch build-stamp

build: build-arch build-indep

clean:
	dh_testdir
	dh_testroot

	[ ! -e Makefile ] || $(MAKE) distclean

	dh_clean configure-stamp build-stamp

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs

	$(MAKE) install PREFIX=$(TMP)/usr

	# Remove any empty directories
	find $(TMP)/usr -type d -empty -print0 | xargs --no-run-if-empty --null rmdir -p --ignore-fail-on-non-empty

binary-arch:

binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installdocs
	dh_installman
	dh_installchangelogs
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_perl
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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