#!/usr/bin/make -f

%:
	dh $@

# Check files to be installed: find . -type f -maxdepth 1 -print | grep -v -P "(\.md|\.eslintrc.js|\.eslintignore|\.editorconfig|\.browserslistrc|\.lfsconfig|(vue|babel|jest)\.config\.js|(tsconfig|tsconfig\.spec).json|composer\.(lock|json)|(package|package-lock)\.json|phpcs\.xml|LEGALNOTICE|LICENSE)$" | sort
# Check dirs to be installed: find . -type d -maxdepth 1 -print | grep -v -P "(debian|\.git|tmp)$"

override_dh_auto_build:
	phpab --output autoload.php \
		--template debian/autoload.package.php.tpl \
		composer.json

override_dh_install:
	dh_install -X libs/jqplot/build_minified_script.sh -X misc/cron/archive.sh -X libs/Authenticator/LICENSE.md -X libs/Zend/LICENSE.txt -X libs/jqplot/gpl-2.0.txt -X js/LICENSE.txt
	chmod a+w debian/matomo/usr/share/matomo/config

override_dh_auto_test:
	# Back the autoload file
	cp -v ./autoload.php ./autoload.php.bak
	sed -i "s,'/usr/share/matomo,__DIR__ . '," ./autoload.php
	# Check all dependencies resolve
	php -f ./autoload.php
	# Check that the console lists all commands
	php -f ./console
	# Check that the console lists all plugins
	php -f ./console plugin:list
	# Restore the autoload file
	mv -v ./autoload.php.bak ./autoload.php

override_dh_link:
	dh_link
	# dh_link makes a mistake to link the file -- it links one directory up (../).
	# manually link it until this is debugged and fixed via d/links.
	mkdir -p debian/matomo/usr/share/matomo/public/plugins/UserCountryMap/javascripts/vendor
	ln -f -s ../../../../../javascript/raphael/raphael.min.js	debian/matomo/usr/share/matomo/public/plugins/UserCountryMap/javascripts/vendor/raphael.min.js
