#!/usr/bin/make -f

include /usr/share/dpkg/default.mk
UPSTREAM := $(DEB_VERSION_UPSTREAM)

%:
	dh $@

override_dh_auto_build:
	# Build static classloader for shipping
	phpabtpl \
		--basedir src \
		composer.json > \
		debian/autoload.php.tpl
	phpab --output src/Autoload.php \
		--template debian/autoload.php.tpl src
	# Build classloader for tests
	mkdir --parents vendor data
	phpabtpl \
		--require-file ../PHPUnit/Autoload.php \
		--require-file ../tests/_files/CoverageNamespacedFunctionTest.php \
		--require-file ../tests/_files/CoveredFunction.php \
		--require-file ../tests/_files/NamespaceCoveredFunction.php \
		> debian/autoload.tests.php.tpl
	phpab \
		--output vendor/autoload.php \
		--template debian/autoload.tests.php.tpl \
		--exclude tests/end-to-end/migration/_files/possibility-to-migrate-from-92-is-detected/src/Greeter.php \
		--exclude tests/end-to-end/migration/_files/possibility-to-migrate-from-92-is-detected/tests/GreeterTest.php \
		--exclude tests/end-to-end/regression/2448/Test.php \
		--exclude tests/end-to-end/regression/4376/tests/Test.php \
		tests
	# Workaround to ensure the local class takes precedence during tests.
	ln -s src PHPUnit
	# Mimic phpunit.xsd path
	ln -s .. data/PHPUnit

override_dh_auto_clean:

override_dh_auto_test:
	./phpunit

execute_before_dh_installman:
	mkdir --parent $(CURDIR)/debian/tmp
	help2man \
		--help-option=\  \
		--version-string=$(UPSTREAM) \
		--source="phpunit $(UPSTREAM)" \
		--no-info \
		--include=$(CURDIR)/debian/phpunit.1.in \
		"echo -n Usage: && ./phpunit --help|tail -n+4|sed 's/^  phpunit \[options\] <directory>/  or: phpunit [options] <directory>/'" \
		> $(CURDIR)/debian/tmp/phpunit.1

execute_before_dh_installchangelogs:
	for i in $$(ls ChangeLog-*.md -r); do cat $$i >> CHANGELOG; done
