#!/usr/bin/make -f

%:
	dh $@ --with python3 --buildsystem=pybuild

override_dh_auto_build:
	# Build translations before building package
	./build-translations.sh
	dh_auto_build

override_dh_auto_install:
	dh_auto_install
	# Install PolicyKit policy file
	install -D -m 644 debian/org.guideos.guideos-updater.policy \
		$(CURDIR)/debian/guideos-updater/usr/share/polkit-1/actions/org.guideos.guideos-updater.policy
	
	# Install desktop file
	install -D -m 644 debian/guideos-updater.desktop \
		$(CURDIR)/debian/guideos-updater/usr/share/applications/guideos-updater.desktop
	
	# Install main executable
	install -D -m 755 guideos-updater \
		$(CURDIR)/debian/guideos-updater/usr/bin/guideos-updater
	
	# Install Python modules
	mkdir -p $(CURDIR)/debian/guideos-updater/usr/lib/guideos-updater
	cp -r core gui utils *.py \
		$(CURDIR)/debian/guideos-updater/usr/lib/guideos-updater/
	
	# Install locale files
	if [ -d locale ]; then \
		for mo_file in locale/*/LC_MESSAGES/*.mo; do \
			if [ -f "$$mo_file" ]; then \
				lang=$$(echo "$$mo_file" | cut -d'/' -f2); \
				install -D -m 644 "$$mo_file" \
					"$(CURDIR)/debian/guideos-updater/usr/share/locale/$$lang/LC_MESSAGES/guideos-updater.mo"; \
			fi; \
		done; \
	fi

override_dh_python3:
	dh_python3 --skip-private

override_dh_clean:
	dh_clean
	# Remove any leftover build artifacts
	rm -rf debian/gup-update-manager
	rm -f debian/gup-update-manager.*