#!/usr/bin/make -f

#export DH_VERBOSE=1

DEB_HOST_ARCH = $(shell dpkg-architecture -qDEB_HOST_ARCH)

# disable unity builds for arches with low memory
ifneq ($(findstring $(DEB_HOST_ARCH), armhf),)
	UNITY_BUILD = -DICINGA2_UNITY_BUILD=Off
endif

ifneq ($(findstring $(DEB_HOST_ARCH), mips),)
	UNITY_BUILD = -DICINGA2_UNITY_BUILD=Off
endif

ifneq ($(findstring $(DEB_HOST_ARCH), mipsel),)
	UNITY_BUILD = -DICINGA2_UNITY_BUILD=Off
endif



%:
	dh $@ --with bash_completion,systemd

override_dh_systemd_enable:
	dh_systemd_enable --name=icinga2
override_dh_auto_build:
	dh_auto_build --parallel

override_dh_auto_clean:
	dh_auto_clean
	test ! -f third-party/cmake/GNUInstallDirs.cmake.disabled || \
		mv third-party/cmake/GNUInstallDirs.cmake.disabled third-party/cmake/GNUInstallDirs.cmake

override_dh_auto_configure:
	test -f third-party/cmake/GNUInstallDirs.cmake.disabled || \
		mv third-party/cmake/GNUInstallDirs.cmake third-party/cmake/GNUInstallDirs.cmake.disabled
	dh_auto_configure \
		-- \
		-DCMAKE_INSTALL_LOCALSTATEDIR=/var \
		-DCMAKE_INSTALL_SYSCONFDIR=/etc \
		-DICINGA2_RUNDIR=/run \
		-DICINGA2_USER=nagios \
		-DICINGA2_GROUP=nagios \
		-DICINGA2_COMMAND_GROUP=www-data \
		-DICINGA2_GIT_VERSION_INFO=false \
		-DICINGA2_PLUGINDIR=/usr/lib/nagios/plugins \
		-DICINGA2_WITH_STUDIO=true \
		$(UNITY_BUILD)

override_dh_auto_install:
	dh_auto_install
	# remove features-enabled - these will be activated by postinst later
	rm -r debian/tmp/etc/icinga2/features-enabled/*

override_dh_install-indep:
	dh_install -i
	chmod +x debian/icinga2-common/usr/lib/icinga2/prepare-dirs
	rm debian/icinga2-common/etc/icinga2/features-available/ido-*

override_dh_install-arch:
	dh_install -a
	rm debian/libicinga2/usr/lib/*/icinga2/libdb_ido_*
	for dbms in mysql pgsql; do \
		mkdir -p debian/icinga2-ido-$$dbms/usr/share/dbconfig-common/data/icinga2-ido-$$dbms/install ; \
		mkdir -p debian/icinga2-ido-$$dbms/usr/share/dbconfig-common/data/icinga2-ido-$$dbms/upgrade/$$dbms; \
		cp lib/db_ido_$$dbms/schema/$$dbms.sql debian/icinga2-ido-$$dbms/usr/share/dbconfig-common/data/icinga2-ido-$$dbms/install/$$dbms ; \
		for file in lib/db_ido_$$dbms/schema/upgrade/* ; do \
			cp $$file debian/icinga2-ido-$$dbms/usr/share/dbconfig-common/data/icinga2-ido-$$dbms/upgrade/$$dbms/`basename $$file .sql`; \
		done; \
	done

override_dh_installinit:
	dh_installinit --name=icinga2

.PHONY: override_dh_strip
override_dh_strip:
	dh_strip --dbg-package=icinga2-dbg

# vi: noexpandtab ts=4 sw=4 :
