#!/usr/bin/make -f

PACKAGE = $(shell dh_listpackages)

ifndef PERL
PERL = $(shell which perl)
endif

configure: configure-stamp
configure-stamp:
	dh_testdir
	$(PERL) Makefile.PL INSTALLDIRS=vendor DESTDIR=$(CURDIR)/debian/$(PACKAGE)
	touch configure-stamp

build: build-stamp

build-stamp: configure-stamp 
	dh_testdir
	$(MAKE) OPTIMIZE="-O2 -g -Wall"
	$(MAKE) test
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp
	[ ! -f Makefile ] || $(MAKE) realclean
	dh_clean 

install: build
	dh_testdir
	dh_testroot
	dh_prep 
	$(MAKE) install

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

binary-arch: build install

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