#!/usr/bin/make -f
export DH_VERBOSE = 1
export MAKE = ninja -v
export LC_ALL=C.UTF-8
export DEB_BUILD_MAINT_OPTIONS = hardening=+bindnow

%:
	dh $@

override_dh_clean:
	dh_clean
	rm -rf debian/build
ifeq ($(shell dpkg-vendor --derives-from Ubuntu && echo ubuntu),ubuntu)

	@if [ -e ./debian/ubuntu/applied ]; then \
		patch -R -p1 < debian/ubuntu/show_nm-applet_in_tray.patch ; \
		rm ./debian/ubuntu/applied ; \
	fi
endif
	rm -f ./debian/budgie-desktop.gsettings-override

override_dh_auto_configure:
ifeq ($(shell dpkg-vendor --derives-from Ubuntu && echo ubuntu),ubuntu)
	patch -p1 < debian/ubuntu/show_nm-applet_in_tray.patch
	touch ./debian/ubuntu/applied
endif
	mkdir -p debian/build
	cd debian/build && LDFLAGS="-Wl,-z,now -Wl,-z,relro" meson --buildtype plain --prefix=/usr --libdir=/usr/lib --sysconfdir=/etc ../..

override_dh_auto_build:
	cd debian/build && $(MAKE)

override_dh_auto_install:
	dh_auto_install
	cd debian/build && DESTDIR=$(CURDIR)/debian/tmp $(MAKE) install
	# remove unrecognised and non ISO639 locale
	find debian -type d -name "zh-Hant" -print0 | xargs -r0 -- rm -r
	mkdir -p "$(CURDIR)/debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/girepository-1.0"
	mv "$(CURDIR)/debian/tmp/usr/lib/girepository-1.0/Budgie-1.0.typelib" "$(CURDIR)/debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/girepository-1.0"
	rm -rf "$(CURDIR)/debian/tmp/usr/lib/girepository-1.0"

override_dh_installgsettings:
ifeq ($(shell dpkg-vendor --derives-from Ubuntu && echo ubuntu),ubuntu)
	cp ./debian/budgie-desktop.gsettings-override.ubuntu ./debian/budgie-desktop.gsettings-override
else
	cp ./debian/budgie-desktop.gsettings-override.debian ./debian/budgie-desktop.gsettings-override
endif
	# install override but budgie has to take precedence over
	# gnome-shell defaults
	dh_installgsettings --priority=15

override_dh_installchangelogs:
	dh_installchangelogs debian/changelog-announcement.txt
