#!/usr/bin/make -f
%:
	dh $@ --with systemd,python3

override_dh_auto_configure:
	./configure \
--prefix=/usr \
--unitdir=/lib/systemd/system \
--confdir=/etc \
--statedir=/var/spool/cron/crontabs \
--runparts="/bin/run-parts --report" \
--bindir=/bin \
--libdir=/lib \
--enable-boot=no \
--enable-persistent=yes \
--stale-stamps=/etc/cron.weekly/systemd-cron
	sed -i 's|$$(DESTDIR)$$(bindir)|$$(DESTDIR)/usr/bin|' Makefile

override_dh_systemd_enable:
	# Only enable cron.target, it pulls in all the others via .timer files.
	dh_systemd_enable cron.target

override_dh_systemd_start:
	# Only start cron.target, it pulls in all the others via .timer files.
	dh_systemd_start cron.target

override_dh_clean:
	rm -f Makefile
	dh_clean

override_dh_auto_test:
	# tests disabled for now to avoid this bug on pbuilder:
	# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=555331#40
	# they duplicate lintian check "manpage-has-errors-from-man" anyway

override_dh_install:
	dh_install
	sed -i 's|/usr/bin/vim|/usr/bin/editor|' debian/systemd-cron/usr/bin/crontab
	sed -i '/Persistent=true/d' debian/systemd-cron/lib/systemd/system/cron-hourly.timer
	echo 'ExecStartPre=/lib/systemd-cron/boot_delay 5' >> debian/systemd-cron/lib/systemd/system/cron-daily.service
	echo 'ExecStartPre=/lib/systemd-cron/boot_delay 10' >> debian/systemd-cron/lib/systemd/system/cron-weekly.service
	echo 'ExecStartPre=/lib/systemd-cron/boot_delay 15' >> debian/systemd-cron/lib/systemd/system/cron-monthly.service

override_dh_builddeb:
	# set all timestamps to last time in debian/changelog
	find debian/systemd-cron -exec touch -t $(shell date --date="$(shell dpkg-parsechangelog | sed -nr 's/^Date: (.*)/\1/p')" +%Y%m%d%H%M.%S) {} \;
	dh_builddeb
