#!/usr/bin/make -f

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

%:
	dh $@

override_dh_auto_build:
	mkdir -p build/src/main/php/data/PDepend build/vendor
	cp -a build.properties phpunit.xml.dist src build
	cp -a src/main/resources build/src/main/php/data/PDepend
	phpab \
		--output build/src/main/php/PDepend/autoload.php \
		--template debian/autoload.php.tpl \
		build/src/main/php/PDepend
	sed -i s,@php_bin@,workaround,	build/src/bin/pdepend
	sed -i s,@package_version@,$(UPSTREAM),	\
		build/src/main/php/PDepend/Report/*/Xml.php \
		build/src/test/php/PDepend/Report/*/_expected/*.xml \
		build/src/main/php/PDepend/TextUI/Command.php
	phpab   --output build/vendor/autoload.php \
		--template debian/autoload.tests.php.tpl \
		build/src/test/php/PDepend
	ln -s src/main/php/PDepend /usr/share/php/Symfony \
		/usr/share/php/Psr /usr/share/php/ProxyManager \
		/usr/share/php/Laminas build/

override_dh_auto_clean:

override_dh_auto_test:
	cd build && phpunit

execute_before_dh_installman:
	mkdir -p $(CURDIR)/debian/tmp
	cd $(CURDIR)/debian/pdepend/usr/share/php && \
		help2man --no-info \
		--include=$(CURDIR)/debian/pdepend.1.in \
		$(CURDIR)/debian/pdepend/usr/bin/pdepend \
		> $(CURDIR)/debian/tmp/pdepend.1
