#!/usr/bin/make -f

ifeq "$(DEB_HOST_ARCH)" "armel"
	EXTRA_CFLAGS="-DZM_STRIP_NEON=1"
endif

# source is missing in web/api/app/Plugin/CakePHP-Enum-Behavior
# and                  web/api/app/Plugin/Crud
# From a git source :
# git submodule update --init --recursive
# and then copy web/api/app/Plugin/* here
# cp -r (zoneminder-git)/dep/RtspServer/* dep/RtspServer/
# cp -r (zoneminder-git)/web/api/app/Plugin/* web/api/app/Plugin/


%:
	dh $@ -Scmake+ninja --with quilt,apache2,linktree,sphinxdoc

override_dh_auto_configure:
	dh_auto_configure -- \
	-D CMAKE_BUILD_TYPE=RelWithDebInfo \
	-D CMAKE_HOST_ARCH=$(DEB_HOST_ARCH) \
	-D ZM_CGIDIR="/usr/lib/cgi-bin" \
	-D ZM_CONFIG_DIR="/etc/zm" \
	-D ZM_CONFIG="/etc/zm/zm.conf" \
	-D ZM_CONTENTDIR="/var/cache/zoneminder" \
	-D ZM_DIR_EVENTS="/var/cache/zoneminder/events" \
	-D ZM_DIR_IMAGES="/var/cache/zoneminder/images" \
	-D ZM_PCRE=OFF \
	-D ZM_ONVIF=ON \
	-D ZM_RUNDIR="/run/zm" \
	-D ZM_SOCKDIR="/run/zm" \
	-D ZM_SYSTEMD=ON \
	-D ZM_TMPDIR="/tmp/zm" \
	$(EXTRA_CFLAGS)

#	exit 1

override_dh_auto_build-arch:
	dh_auto_build

override_dh_auto_build-indep:
	$(MAKE) -C docs html

override_dh_auto_install:
	dh_auto_install

	$(RM) -rf debian/zoneminder/src
	$(RM) -rf debian/zoneminder/tmp

	$(RM) debian/tmp/usr/share/man/man3/WSNotification*
	$(RM) debian/tmp/usr/share/man/man3/ONVIF*
	$(RM) debian/tmp/usr/share/man/man3/WSDiscovery10*

	# remove worthless files:
	$(RM) $(CURDIR)/debian/tmp/usr/share/perl5/*/*/*/.packlist
	$(RM) $(CURDIR)/debian/tmp/usr/share/perl5/*/*.in
	$(RM) $(CURDIR)/debian/tmp/usr/share/zoneminder/www/fonts/license.md

	find debian -name *.js.URL -delete

	# remove empty directories:
	find $(CURDIR)/debian/tmp/usr -type d -empty -delete -printf 'removed %p\n'

	# remove extra file:
	$(RM) $(CURDIR)/debian/zoneminder/usr/share/zoneminder/www/api/lib/Cake/LICENSE.txt
	$(RM) $(CURDIR)/debian/zoneminder/usr/share/zoneminder/www/api/.gitattributes
	$(RM) $(CURDIR)/debian/zoneminder/usr/share/zoneminder/www/api/.gitignore

	# Don't ship core.php as it contains pre-generated/static salts.
	# We keep core.php.default as a template for the postinst.
	rm -f $(CURDIR)/debian/tmp/usr/share/zoneminder/www/api/app/Config/core.php

override_dh_fixperms:
	dh_fixperms

	chmod -c o-r $(CURDIR)/debian/zoneminder/etc/zm/zm.conf

override_dh_clean:
	dh_clean $(MANPAGES1) web/api/app/vendor/composer/installers/.gitignore
	$(RM) -r docs/_build docs/installationguide

override_dh_auto_test:
