#!/usr/bin/make -f

# If set to a true value then MakeMaker's prompt function will
# always return the default without waiting for user input.
export PERL_MM_USE_DEFAULT=1

PACKAGE=$(shell dh_listpackages)

ifndef PERL
PERL = /usr/bin/perl
endif

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

# Allow disabling build optimation by setting noopt in
# $DEB_BUILD_OPTIONS
CFLAGS = -Wall -g
ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
        CFLAGS += -O0
else
        CFLAGS += -O2
endif

build: build-stamp
build-stamp:
	dh_testdir
	$(PERL) Makefile.PL INSTALLDIRS=vendor
	$(MAKE) OPTIMIZE="$(CFLAGS)" LD_RUN_PATH=""
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	-$(MAKE) distclean
	dh_clean build-stamp install-stamp

install: build install-stamp
install-stamp:
	dh_testdir
	dh_testroot
	dh_clean -k
	-(TEST_POD=1 $(MAKE) test)
	$(MAKE) install DESTDIR=$(TMP) PREFIX=/usr
	mv $(TMP)/usr/share/man/man1/parl.1 $(TMP)/usr/share/man/man1/parl.1p
	mv $(TMP)/usr/share/man/man1/par.pl.1 $(TMP)/usr/share/man/man1/par.pl.1p
	mv $(TMP)/usr/share/man/man1/pp.1 $(TMP)/usr/share/man/man1/pp.1p
	mv $(TMP)/usr/share/man/man1/tkpp.1 $(TMP)/usr/share/man/man1/tkpp.1p
	rmdir --ignore-fail-on-non-empty --parents $(TMP)/usr/share/perl5
	touch install-stamp

binary-indep:
# We have nothing to do by default.

binary-arch: build install
	dh_testdir
	dh_testroot
#	dh_installexamples
	dh_installdocs README
	dh_installchangelogs ChangeLog
	dh_perl
	dh_link usr/share/man/man1/parl.1p.gz usr/share/man/man1/parldyn.1p.gz
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_makeshlibs
	dh_shlibdeps	
	dh_gencontrol
	dh_md5sums
	dh_builddeb

source diff:                                                                  
	@echo >&2 'source and diff are obsolete - use dpkg-source -b'; false

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