#!/usr/bin/make -f

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

# for upstream build system
export VERBOSE=1

%:
	# don't use --with autotools_dev with dh10 anymore: dh $@ --with autoreconf,autotools_dev,systemd
	dh $@ --with autoreconf

# there is a bug in dh_auto_configure, see #887390
# so it can not be run under DH_COMPAT>=11
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 \
		--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
# 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_installinit:
	dh_installinit --no-restart-on-upgrade --init-script=apcupsd

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/lib/apcupsd/prestart
	chmod 0755 debian/apcupsd/lib/systemd/system-shutdown/apcupsd_shutdown
