#!/usr/bin/make -f

# See debhelper(7) (uncomment to enable).
# Output every command that modifies files on the build system.
export DH_VERBOSE = 1

include /usr/share/dpkg/pkg-info.mk

%:
	dh $@

override_dh_auto_test:
	# Run the upstream suite through build/audit_tests.pl so failures and
	# uninitialised-value warnings are still gated.  Two tests need
	# resources that a source package build does not provide:
	#   challenge_m1_adversarial.t needs a real mysqladmin binary;
	#   stress_ci_doc_lint_adversarial.t needs a git work tree and rewrites
	#   documentation/QUALITY_AND_TESTING.md with identical content on every
	#   run, so an upstream file changes its mtime and rebuilds differ.
	perl build/audit_tests.pl "prove -j4 $(shell ls tests/*.t | grep -vE '(challenge_m1_adversarial|stress_ci_doc_lint_adversarial)\.t$$' | tr '\n' ' ')"

override_dh_auto_build:
	# Use CR (Courier Roman) rather than the Pod::Man default CW; groff no
	# longer accepts CW and lintian then reports groff-message warnings.
	# Pod::Man otherwise stamps the man page with the build time; pin the
	# date to SOURCE_DATE_EPOCH from dpkg/pkg-info.mk.
	pod2man --fixed=CR --date="$$(date -u -d "@$(SOURCE_DATE_EPOCH)" +%Y-%m-%d)" \
		mysqltuner.pl > mysqltuner.1

override_dh_auto_install:
	dh_auto_install
	cp mysqltuner.pl debian/mysqltuner/usr/bin/mysqltuner
	sed -i '1s|^#!/usr/bin/env perl|#!/usr/bin/perl|' debian/mysqltuner/usr/bin/mysqltuner

override_dh_auto_clean:
	dh_auto_clean
	rm -f mysqltuner.1
