#!/usr/bin/make -f

include /usr/share/dpkg/architecture.mk
include /usr/share/dpkg/pkg-info.mk

BUILDDIR := obj-$(DEB_HOST_GNU_TYPE)
APPID := cn.labelnova.app
APP_VERSION := $(shell cat VERSION)
APPROOT := $(CURDIR)/debian/labelnova/opt/apps/$(APPID)
APPFILES := $(APPROOT)/files
APPENTRIES := $(APPROOT)/entries

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export QTWEBENGINE_DISABLE_SANDBOX = 1

%:
	dh $@ --buildsystem=cmake

override_dh_auto_configure:
	dh_auto_configure --sourcedirectory=qt-shell --builddirectory=$(BUILDDIR) -- \
		-DCMAKE_BUILD_TYPE=RelWithDebInfo

override_dh_auto_build:
	dh_auto_build --builddirectory=$(BUILDDIR)

override_dh_auto_test:
	node tests/debian-store-layout.test.js
	node tests/label-templates.test.js
	node tests/object-placement.test.js
	node tests/desktop-runtime.test.js

# This override is the authoritative deepin/UOS /opt/apps package staging path.
override_dh_auto_install:
	rm -rf $(APPROOT)
	install -d $(APPFILES)/bin
	install -d $(APPFILES)/frontend
	install -d $(APPENTRIES)/applications
	install -d $(APPENTRIES)/icons/hicolor/scalable/apps
	install -m 0755 $(BUILDDIR)/labelnova $(APPFILES)/bin/labelnova
	cp -a index.html $(APPFILES)/frontend/
	cp -a static $(APPFILES)/frontend/
	cp -a icons $(APPFILES)/frontend/
	install -m 0644 debian/$(APPID).desktop $(APPENTRIES)/applications/$(APPID).desktop
	install -m 0644 qt-shell/packaging/labelnova.svg $(APPENTRIES)/icons/hicolor/scalable/apps/$(APPID).svg
	sed -e 's/@VERSION@/$(APP_VERSION)/g' \
		-e 's/@ARCH@/$(DEB_HOST_ARCH)/g' \
		debian/$(APPID).info.in > $(APPROOT)/info
	desktop-file-validate $(APPENTRIES)/applications/$(APPID).desktop

override_dh_auto_clean:
	dh_auto_clean --sourcedirectory=qt-shell --builddirectory=$(BUILDDIR) || true
	rm -rf qt-shell/build $(BUILDDIR) debian/labelnova/opt
