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

override_dh_auto_configure:
	./configure \
--prefix=/usr \
--unitdir=/lib/systemd/system \
--confdir=/etc \
--statedir=/var/spool/cron/crontabs \
--runparts="/bin/run-parts --report" \
--libdir=/lib \
--enable-boot=no \
--enable-persistent=yes

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:
	dh_systemd_start --no-start
	# Re-run dh_systemd_start for cron.target, otherwise systemd-cron
	# will not do anything after installation.
	dh_systemd_start cron.target

override_dh_clean:
	rm -f Makefile
	dh_clean

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

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
