#!/usr/bin/make -f

# output every command that modifies files on the build system.
#export DH_VERBOSE = 1

# see FEATURE AREAS in dpkg-buildflags(1)
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# see ENVIRONMENT in dpkg-buildflags(1)
# package maintainers to append CFLAGS
export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
export deb_systemdsleepdir = $(shell pkg-config --variable=systemdsleepdir systemd)

DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

%:
	dh $@

override_dh_auto_clean:
	dh_auto_clean
	rm -f debian/atop.service debian/atop.default debian/atop.atopacct.service debian/atop.init debian/atopacct.init debian/atop.atop-rotate.timer debian/atop.atop-rotate.service
	rm -f atop atopsar

override_dh_installinit:
	dh_installinit --name=atopacct
	dh_installinit --name=atop

override_dh_auto_install:
	dh_auto_install -- PMPATHD=${deb_systemdsleepdir}
	make sysvinstall DESTDIR=$(shell pwd)/debian/atop
	make install DESTDIR=$(shell pwd)/debian/atop PMPATHD=${deb_systemdsleepdir}
	mv debian/atop/lib/systemd/system/atop-rotate.timer debian/atop.atop-rotate.timer
	mv debian/atop/lib/systemd/system/atop-rotate.service debian/atop.atop-rotate.service
	rmdir --parents --ignore-fail-on-non-empty debian/atop/lib/systemd/system
	cp atop.default debian/atop.default
	cp atop.service debian/atop.service
	cp atop.default debian/atop.default
	cp atopacct.service debian/atop.atopacct.service
	cp atop.init debian/atop.init
	cp atopacct.init debian/atopacct.init

override_dh_installsystemd:
	dh_installsystemd --name atop-rotate atop-rotate.timer
	dh_installsystemd --name atop-rotate --no-enable --no-start atop-rotate.service
	dh_installsystemd --name atopacct
	dh_installsystemd atop.service
