#!/usr/bin/make -f

UPSTREAM := $(shell dpkg-parsechangelog -S version | sed 's/-.?*//')

%:
	dh $@ --with phpcomposer

override_dh_auto_build:
	dh_auto_build
	phpab \
		--output lib/PhpParser/autoload.php \
		--template debian/autoload.php.tpl \
		--exclude lib/PhpParser/BuilderFactory.php \
		lib/PhpParser
	mkdir --parents vendor
	phpab \
		--output vendor/autoload.php \
		--template debian/autoload.tests.php.tpl \
		test/PhpParser

override_dh_auto_test:
ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
	phpunit --include-path lib
else
	@echo "** tests disabled"
endif

override_dh_installman:
	mkdir --parents $(CURDIR)/debian/tmp
	cd $(CURDIR)/debian/php-parser/usr/share/php && \
		help2man --version-string=$(UPSTREAM) --no-info --no-discard-stderr \
		--name='command line interface for PHP Parser' \
		'php $(CURDIR)/debian/php-parser/usr/bin/php-parse' \
		> $(CURDIR)/debian/tmp/php-parse.1
	dh_installman
