#!/usr/bin/make -f

include /usr/share/dpkg/default.mk
UPSTREAM := $(DEB_VERSION_UPSTREAM)
INSTALL := $(CURDIR)/debian/php-doctrine-dbal/usr/share/php/Doctrine/DBAL

%:
	dh $@ -XREADME.markdown

override_dh_auto_build:
	phpabtpl composer.json > debian/autoload.php.tpl
	phpab --tolerant \
		--output src/autoload.php \
		--template debian/autoload.php.tpl \
		src
	mkdir --parents vendor Doctrine
	phpabtpl \
		--require doctrine/dbal \
		--require symfony/cache \
		> debian/autoload.tests.php.tpl
	phpab \
		--output vendor/autoload.php \
		--template debian/autoload.tests.php.tpl \
		tests
	ln -s ../src Doctrine/DBAL

override_dh_auto_clean:

override_dh_auto_test:
	phpunit --bootstrap vendor/autoload.php

execute_before_dh_install:
	mkdir --parents $(CURDIR)/debian/tmp
	cp bin/doctrine-dbal.php debian/tmp/doctrine-dbal

execute_after_dh_install:
	sed -i "s/@VERSION@/$(UPSTREAM)/;s/\+dfsg//" $(INSTALL)/Tools/Console/ConsoleRunner.php

override_dh_installchangelogs:
	dh_installchangelogs debian/upstream/changelog

execute_before_dh_installman:
	mkdir --parents $(CURDIR)/config
	ln -s ../debian/cli-config.php $(CURDIR)/config
	help2man \
		--help-option=\  \
		--version-string=$(UPSTREAM) \
		--source="doctrine-dbal $(UPSTREAM)" \
		--no-info \
		--include=$(CURDIR)/debian/doctrine-dbal.1.in \
		"echo -n Usage: doctrine-dbal && $(CURDIR)/bin/doctrine-dbal --no-ansi|tail -n+6" \
		> $(CURDIR)/debian/tmp/doctrine-dbal.1