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

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

SOURCE_FORMAT = $(shell dpkg-source --print-format . | tr -d '3.0() ')

# Debian
CONFIGURE_FLAGS = -DENABLE_UBUNTU_ACCOUNTSSERVICE=OFF
CONFIGURE_FLAGS += -DDISTRIBUTOR_LOGO="/usr/share/icons/vendor/scalable/emblems/emblem-vendor.svg"
CONFIGURE_FLAGS += -DDARK_MODE_DISTRIBUTOR_LOGO="/usr/share/icons/vendor/scalable/emblems/emblem-vendor.svg"
FONT_PACKAGE = fonts-noto-core
LOGO_PACKAGE = desktop-base
PRINTING_PACKAGES = "cups, lomiri-printing-app"

ifeq ($(shell dpkg-vendor --query vendor),Ubuntu)
	CONFIGURE_FLAGS = -DENABLE_UBUNTU_ACCOUNTSSERVICE=ON
ifneq ($(SOURCE_FORMAT), quilt)
# Ubuntu Touch
	CONFIGURE_FLAGS += -DDISTRIBUTOR_LOGO="/usr/share/ubuntutouch-artwork/ubuntu_touch_logo_light.svg"
	CONFIGURE_FLAGS += -DDARK_MODE_DISTRIBUTOR_LOGO="/usr/share/ubuntutouch-artwork/ubuntu_touch_logo_dark.svg"
	FONT_PACKAGE = fonts-ubuntu
	LOGO_PACKAGE = "ubuntutouch-artwork"
	PRINTING_PACKAGES = "qml-module-snapd2"
else
# Ubuntu that isn't Ubuntu Touch
	CONFIGURE_FLAGS += -DDISTRIBUTOR_LOGO="/usr/share/pixmaps/ubuntu-logo-text.svg"
	CONFIGURE_FLAGS += -DDARK_MODE_DISTRIBUTOR_LOGO="/usr/share/pixmaps/ubuntu-logo-text-dark.svg"
	FONT_PACKAGE = fonts-noto-core
	LOGO_PACKAGE = "base-files (>= 13ubuntu2)"
	PRINTING_PACKAGES = "cups, lomiri-printing-app"
endif
endif

# Ubuntu 24.04 LTS
DISTRO=$(shell lsb_release -sc)
ifeq ($(DISTRO),noble)
	CONFIGURE_FLAGS += -DDISTRIBUTOR_LOGO="/usr/share/pixmaps/ubuntu-logo-text.png"
	CONFIGURE_FLAGS += -DDARK_MODE_DISTRIBUTOR_LOGO="/usr/share/pixmaps/ubuntu-logo-text-dark.png"
endif

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure -- \
		-DENABLE_LIBDEVICEINFO=ON \
		-DENABLE_TESTS=$(if $(filter nocheck,$(DEB_BUILD_OPTIONS)),OFF,ON) \
		-DLOMIRI_KEYBOARD_PLUGIN_PATH="/usr/lib/$(DEB_HOST_MULTIARCH)/lomiri-keyboard/plugins" \
		$(CONFIGURE_FLAGS)

override_dh_makeshlibs:
	dh_makeshlibs -Xusr/lib/$(DEB_HOST_MULTIARCH)/lomiri-system-settings

# Debian's logo is in base-files, while Ubuntu's is in base-files
override_dh_gencontrol:
ifeq ($(shell dpkg-vendor --derives-from Ubuntu && echo yes),yes)
	dh_gencontrol -- \
		-Vaccountsservice-ubuntu-schemas='accountsservice-ubuntu-schemas (>= 0.0.7)' \
		-Vfont:Depends=$(FONT_PACKAGE) \
		-Vlogo:Depends=$(LOGO_PACKAGE)  \
		-Vprinting:Depends=$(PRINTING_PACKAGES)
else
	dh_gencontrol -- \
		-Vaccountsservice-ubuntu-schemas= \
		-Vfont:Depends=$(FONT_PACKAGE) \
		-Vlogo:Depends=$(LOGO_PACKAGE) \
		-Vprinting:Depends=$(PRINTING_PACKAGES)
endif

get-orig-source:
	uscan --noconf --force-download --rename --download-current-version --destdir=..
