#!/usr/bin/make -f

# Hardcoded Debian paths (avoid Build-Depends on systemd-dev / systemd.pc).
deb_systemdsystemunitdir = /usr/lib/systemd/system
deb_systemdutildir = /usr/lib/systemd

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

# for upstream build system
export VERBOSE=1

%:
	dh $@ --with autoreconf,runit,openrc

# there is a bug in dh_auto_configure, see #887390
# so it can not be run under DH_COMPAT>=11
# do NOT use ${prefix} for --bindir and --sbindir, it does not work with platforms/etc/*.in
#		--bindir=\$${prefix}/bin \
#		--sbindir=\$${prefix}/sbin \
#
override_dh_auto_configure:
	DH_COMPAT=10 dh_auto_configure -- \
		--with-libwrap \
		--enable-cgi \
		--enable-modbus-usb \
		--enable-usb \
		--enable-net \
		--enable-snmp \
		--enable-test \
		--sysconfdir=/etc/apcupsd \
		--bindir=/usr/bin \
		--sbindir=/usr/sbin \
		--with-cgi-bin=\$${prefix}/lib/cgi-bin/apcupsd \
		--with-pid-dir=/var/run \
		--with-log-dir=/var/log \
		--with-lock-dir=/var/lock \
		--with-pwrfail-dir=/etc/apcupsd \
		--disable-install-distdir \
		--with-nis-port=3551 \
		--with-nisip=127.0.0.1 \
		--with-upstype=usb \
		--with-upscable=usb \
		SHUTDOWN=/sbin/shutdown \
		SCRIPTSHELL=/bin/sh
# as gconf shall disappear, do not enable gapcom
#		--enable-gapcmon

override_dh_auto_build:
	dh_auto_build
	make -C doc/manual manual.pdf

override_dh_install:
	dh_install
	dh_install -papcupsd debian/local/apcupsd_shutdown $(deb_systemdutildir)/system-shutdown/

override_dh_link:
	dh_link
	# Mask ups-monitor.service on systemd hosts (Conflicts/Provides ups-monitor).
	dh_link -papcupsd /dev/null $(deb_systemdsystemunitdir)/ups-monitor.service

override_dh_installinit:
	dh_installinit --no-scripts --no-start

override_dh_installsystemd:
	:

override_dh_installchangelogs:
	dh_installchangelogs ChangeLog

override_dh_compress:
	dh_compress -Xusr/share/doc/apcupsd/doc

override_dh_fixperms-arch:
	dh_fixperms
	chmod 0755 debian/apcupsd/etc/apcupsd/killpower
	chmod 0755 debian/apcupsd/etc/apcupsd/ups-monitor
	chmod 0755 debian/apcupsd/usr/lib/apcupsd/prestart
	chmod 0755 debian/apcupsd/$(deb_systemdutildir)/system-shutdown/apcupsd_shutdown
