#!/usr/bin/make -f

USRDIR   := $(CURDIR)/debian/phpunit/usr
UPSTREAM := $(shell head -1 debian/changelog | sed 's/.*(//;s/-.?*).*//')

%:
	dh $@ --with phpcomposer

override_dh_auto_build:
	phpab --output src/Autoload.php \
		--template debian/Autoload.php.tpl src

override_dh_auto_test:
ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
	ant
else
	@echo "** tests disabled"
endif

override_dh_installman:
	mkdir --parent $(CURDIR)/debian/tmp
	cd $(USRDIR)/share/php && help2man \
		--help-option=\  \
		--version-string=$(UPSTREAM) \
		--no-info \
		--include=$(CURDIR)/debian/phpunit.1.in \
		"$(USRDIR)/bin/phpunit|tail -n+3|sed 's/^       phpunit/   or: phpunit/'" \
		| sed 's/|tail\( -n+3\)\?//gi' \
		> $(CURDIR)/debian/tmp/phpunit.1
	dh_installman
