#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_LDFLAGS_MAINT_APPEND += -Wl,--as-needed

%:
	dh $@ --parallel --buildsystem=cmake --builddirectory=dbuild --with systemd

override_dh_auto_configure:
	dh_auto_configure --               \
            -DCMAKE_VERBOSE_MAKEFILE=ON    \
            -DCMAKE_BUILD_TYPE=Release     \
            -DZM_CONFIG_DIR="/etc/zm"      \
            -DZM_RUNDIR="/var/run/zm"      \
            -DZM_CGIDIR="/usr/lib/zoneminder/cgi-bin"

override_dh_clean:
	dh_clean $(MANPAGES1)
	# arch-dep-package-has-big-usr-share: removing Cake tests to save ~5 MB.
	$(RM) -rv web/api/lib/Cake/Test

MANPAGES1 = dbuild/scripts/zmupdate.pl.1
$(MANPAGES1):
	# generate man page(s):
	pod2man -s1 --stderr --utf8 $(patsubst %.1, %, $@) $@

override_dh_installman: $(MANPAGES1)
	dh_installman --language=C $(MANPAGES1)

override_dh_auto_install:
	dh_auto_install --destdir=$(CURDIR)/debian/tmp
	# remove zoneminder-shipped mootools, as it is now patched to use mootools
	# shipped from the libjs-mootools package. http://bugs.debian.org/585590
	$(RM) -v $(CURDIR)/debian/tmp/usr/share/zoneminder/www/tools/mootools/*
	# remove worthless file:
	$(RM) -v $(CURDIR)/debian/tmp/usr/share/perl5/*/*/*/.packlist
	# remove empty directories:
	find $(CURDIR)/debian/tmp/usr -type d -empty -delete -printf 'removed %p\n'
	# remove extra-license-file:
	$(RM) -v $(CURDIR)/debian/tmp/usr/share/zoneminder/www/api/lib/Cake/LICENSE.txt

override_dh_fixperms:
	dh_fixperms
	## 637685
	chmod -c o-r $(CURDIR)/debian/zoneminder/etc/zm/zm.conf

override_dh_installinit:
	dh_installinit --no-start

override_dh_systemd_start:
	dh_systemd_start --no-start

override_dh_systemd_enable:
	dh_systemd_enable --no-enable

override_dh_strip:
	[ -d "$(CURDIR)/debian/zoneminder-dbg" ] \
        && dh_strip --dbg-package=zoneminder-dbg \
        || dh_strip

#%:
#	dh $@ --parallel --buildsystem=autoconf --with autoreconf
#
#override_dh_auto_configure:
#	dh_auto_configure -- \
#            --sysconfdir=/etc/zm \
#            --with-mysql=/usr \
#            --with-webdir=/usr/share/zoneminder \
#            --with-ffmpeg=/usr \
#            --with-cgidir=/usr/lib/cgi-bin \
#            --with-webuser=www-data \
#            --with-webgroup=www-data \
#            --enable-mmap=yes
