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

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

export PYBUILD_NAME=ieplib
export PYBUILD_DESTDIR_python3=debian/python3-$(PYBUILD_NAME)
export PYBUILD_DISABLE=test
IEP_DESTDIR=debian/iep

# To be used until dh_python3 pyremove is backported to all supported
# distributions.
PY3VERS := $(shell py3versions -vr)

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

override_dh_auto_build:
	dh_auto_build
	# Generate application icon
	convert $(CURDIR)/iep/resources/appicons/ieplogo32.png -resize 32 \
		$(CURDIR)/debian/ieplogo.xpm	

override_dh_auto_install:
	dh_auto_install
	# Install common package files
	dh_install --package=iep-common iep/resources usr/share/$(PYBUILD_NAME)
	dh_install --package=iep-common iep/*.txt usr/share/$(PYBUILD_NAME)
	# Install launcher 
	dh_install --sourcedir=$(CURDIR)/$(PYBUILD_DESTDIR_python3) \
		--package=iep usr/bin
	rm -rf $(CURDIR)/$(PYBUILD_DESTDIR_python3)/usr/bin
	# Install desktop file
	mkdir -p $(CURDIR)/$(IEP_DESTDIR)/usr/share/applications
	cp $(CURDIR)/debian/iep.desktop $(CURDIR)/$(IEP_DESTDIR)/usr/share/applications
	# Install icon
	mkdir -p $(CURDIR)/$(IEP_DESTDIR)/usr/share/pixmaps
	cp $(CURDIR)/debian/ieplogo.xpm $(CURDIR)/$(IEP_DESTDIR)/usr/share/pixmaps
	# Remove unwanted files, needed for distributions without dh_python3
	# pyremove
	for v in $(PY3VERS); do \
		rm -rf $(CURDIR)/$(PYBUILD_DESTDIR_python3)/usr/lib/python$$v/dist-packages/iep/resources ;\
		rm -rf $(CURDIR)/$(PYBUILD_DESTDIR_python3)/usr/lib/python$$v/dist-packages/iep/*.txt ;\
	done
