#!/usr/bin/make -f
# -*- Makefile -*-

# Use debhelper V. 4
# export DH_COMPAT := 4

# Make sure perl is defined (allow overriding from the command line
PERL ?= /usr/bin/perl

# Set our build directory
b := $(shell pwd)/debian/libwww-perl

arrange: arrange-stamp
arrange-stamp: install
	dh_testdir
	dh_installdirs
	touch arrange-stamp

binary: binary-stamp
binary-stamp: binary-indep binary-arch
	dh_testdir
	touch binary-stamp

binary-arch: binary-arch-stamp
binary-arch-stamp: arrange
	dh_testdir
	touch binary-arch-stamp

binary-indep: binary-indep-stamp
binary-indep-stamp: arrange
	dh_testdir
	dh_testroot
	dh_installexamples
	dh_installdocs
	dh_installchangelogs Changes
	dh_link
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_perl
	dh_gencontrol
	dh_md5sums
	dh_builddeb
	touch binary-indep-stamp

build: build-stamp
build-stamp:
	dh_testdir
	echo "y" | $(PERL) Makefile.PL INSTALLDIRS=vendor
	if [ -f t/live/ENABLED ]; then rm t/live/ENABLED; fi # Turn off the live checks
	if [ -f t/live/ZLIB_OK ]; then rm t/live/ZLIB_OK; fi # Turn off the live checks
	$(MAKE)
	$(MAKE) test
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	if [ -e Makefile ]; then $(MAKE) -i distclean; fi
	dh_clean arrange-stamp binary-stamp binary-arch-stamp binary-indep-stamp build-stamp install-stamp

install: install-stamp
install-stamp: build
	dh_testdir
	$(MAKE) install PREFIX=$(b)/usr

	rm -f $(b)/usr/bin/GET \
		$(b)/usr/bin/POST \
		$(b)/usr/bin/HEAD

	rm -f $(b)/usr/share/man/man1/GET.1p \
	    $(b)/usr/share/man/man1/HEAD.1p \
	    $(b)/usr/share/man/man1/POST.1p
	-find $(CURDIR)/debian -type d | xargs rmdir -p --ignore-fail-on-non-empty
	touch install-stamp

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