#!/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,php5,sphinxdoc --fail-missing

override_dh_auto_clean-arch:
	dh_auto_clean -O--sourcedirectory=ext/twig
	cd ext/twig && \
		phpize --clean

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

override_dh_auto_configure-arch:
	cd ext/twig && \
		phpize
	 dh_auto_configure -O--sourcedirectory=ext/twig

override_dh_auto_build-arch:
	dh_auto_build -O--sourcedirectory=ext/twig

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-arch:
	dh_auto_test -O--sourcedirectory=ext/twig

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

override_dh_auto_install-arch:
	dh_auto_install \
		-O--sourcedirectory=ext/twig \
		-- INSTALL_ROOT=$(CURDIR)/debian/php5-twig
