#!/usr/bin/make -f

TWIG_RELEASE_VERSION := $(shell dpkg-parsechangelog | grep -E -e '^Version:' | sed -r 's/^[^:]+: (.*)-[^-]+$$/\1/')
TWIG_VERSION := $(shell echo $(TWIG_RELEASE_VERSION) | sed -r 's/^([0-9]+\.[0-9]+).*/\1/')

%:
	dh $@ --with phpcomposer,sphinxdoc --fail-missing

override_dh_auto_clean-indep:
	rm -rf vendor
	rm -rf debian/build-tmp/php-twig-doc
	rmdir debian/build-tmp || true

override_dh_auto_build-indep:
	sphinx-build -C \
	 -b html \
	 -D source_suffix='.rst' \
	 -D master_doc='index' \
	 -D project='php-twig-doc' \
	 -D copyright='by the Twig Team' \
	 -D version='${TWIG_VERSION}' \
	 -D release='${TWIG_RELEASE_VERSION}' \
	 -D pygments_style='sphinx' \
	 -D html_theme='default' \
	 doc debian/build-tmp/php-twig-doc
	phpab --output lib/Twig/autoload.php lib/Twig

override_dh_auto_test-indep:
ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
	phpunit --bootstrap lib/Twig/autoload.php
	php -f $$(which phpunit) -- --bootstrap lib/Twig/autoload.php
endif
