#!/usr/bin/make -f
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

REVISION := $(shell head -1 debian/changelog | sed 's/.*(//;s/).*//;s/.*-//')

%:
	dh $@ --with sphinxdoc,phpcomposer

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	# keep in sync with debian/tests/phpunit
	find test/ -type f -print0 | xargs -0 sed -i 's/function setUpBeforeClass()/function setUpBeforeClass(): void/g'
	find test/ -type f -print0 | xargs -0 sed -i 's/function setUp()/function setUp(): void/g'
	find test/ -type f -print0 | xargs -0 sed -i 's/function tearDown()/function tearDown(): void/g'
	LC_ALL=en_US.UTF-8 phpunit --config phpunit.xml.nocoverage --exclude-group selenium,network,git-revision,environment,extension-iconv
	find test/ -type f -print0 | xargs -0 sed -i 's/function setUpBeforeClass(): void/function setUpBeforeClass()/g'
	find test/ -type f -print0 | xargs -0 sed -i 's/function setUp(): void/function setUp()/g'
	find test/ -type f -print0 | xargs -0 sed -i 's/function tearDown(): void/function tearDown()/g'
endif

override_dh_auto_clean:
	# keep this target. dh_auto_clean detects ant as build-environment because of the build.xml

override_dh_auto_build:
	make -C doc/ html
	# remove this line after resolving #35
	rm -rf test/selenium
	# generate outoload-files. keep in sync with debian/tests/phpunit
	phpab --template debian/autoload.php.tpl \
		--output autoload.php \
		libraries/classes \
		setup/lib
	phpab --template debian/autoload-test.php.tpl \
		--output test/autoload.php \
		test

override_dh_missing:
	dh_missing --fail-missing

override_dh_install:
	dh_install
	# spurious licence files, this is in debian/copyright
	rm \
		debian/phpmyadmin/usr/share/phpmyadmin/js/vendor/codemirror/LICENSE \
		debian/phpmyadmin/usr/share/phpmyadmin/js/vendor/jquery/MIT-LICENSE.txt
	# include Debian marker in version string
	sed -ri "/set..PMA_VERSION/ s/'([-0-9a-z.]+)'/'\\1deb$(REVISION)'/" \
	    debian/phpmyadmin/usr/share/phpmyadmin/libraries/classes/Config.php
