#!/usr/bin/make -f
# SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
# SPDX-FileCopyrightText: 2016 Jonathan Riddell <jr@jriddell.org>
# SPDX-FileCopyrightText: 2018-2021 Harald Sitter <sitter@kde.org>

export DH_VERBOSE=1

%:
	dh $@

override_dh_auto_build:
	rake test
	dh_auto_build

override_dh_usrlocal:
	true

override_dh_installsystemd:
	# Random safe guard. dh_installsystemd doesn't handle /usr/lib/systemd same as /lib/systemd 🙄
	if find debian/neon-settings-*/lib/systemd/ -type f -not \( -name '*.service' -or -name '*.timer' -or -name '*.slice' \) | grep '.'; then \
		echo "   !!! Only put unit files in /lib/systemd, everything else in /usr/lib/systemd!"; \
		exit 1; \
	fi

	# Perferrably use lib/systemd/system/ instead of placing units in debian/ since the naming is much clearer there.
	# Also mind https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=987989
	# Also mind that dh_installsystemd acts as an append-only system. So when we call
	# it first without arguments it will enable and start everything installed. If we want to control what a service
	# does we need to -X exclude it and add a manual call
	dh_installsystemd -Xneon-offline-skip.service

	# Manual control of excluded services:
	## mustn't auto-start it is only meant to start as part of the system-update target. It's not hardened against
	## starting in other scenarios.
	dh_installsystemd -pneon-settings-2 --no-start --name=neon-offline-skip

	# "Legacy" services in debian/ rather than lib/
	dh_installsystemd --name=neon-apt-clean.timer
	dh_installsystemd --no-start --name=neon-flathub
	dh_installsystemd --no-start --name=neon-packagekit-offline-update-policy
	dh_installsystemd --no-start --name=neon-packagekit-online-update-policy

