#!/usr/bin/make -f

include /usr/share/dpkg/default.mk
UPSTREAM := $(DEB_VERSION_UPSTREAM)

%:
	dh $@ --with phpcomposer

override_dh_auto_build:
	phpab \
		--output src/main/php/PHPMD/autoload.php \
		--template debian/autoload.php.tpl \
		src/main/php/PHPMD
	mkdir --parents vendor
	cp debian/autoload.php vendor

override_dh_auto_clean:

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

override_dh_install:
	dh_install
	sed -i s,@data_dir@,/usr/share/php/data, debian/phpmd/usr/share/php/PHPMD/RuleSetFactory.php
	sed -i s,@package_version@,$(UPSTREAM),	 debian/phpmd/usr/bin/phpmd \
		debian/phpmd/usr/share/php/PHPMD/TextUI/Command.php

override_dh_installman:
	mkdir $(CURDIR)/debian/tmp
	cd debian/phpmd/usr/share/php && \
        help2man --no-info --no-discard-stderr \
        --name='PHPMD command line interface' \
        ../../bin/phpmd \
        > $(CURDIR)/debian/tmp/phpmd.1
	dh_installman
