#!/usr/bin/make -f

# export DH_VERBOSE := 1

POLICY_TARGETS := binary binary-arch binary-indep build build-arch \
 build-indep clean
.PHONY: $(POLICY_TARGETS)
$(POLICY_TARGETS):
	dh $@ --with python2

# Tell each dh_auto_* tool which buildsystem is needed.
override_dh_auto_clean:: override_%:
	$* --buildsystem=makefile -- reallyclean
override_dh_auto_build: override_%:
	$* --buildsystem=makefile -- prepare
	$* --buildsystem=python_distutils
override_dh_auto_install:: override_%:
	$* --buildsystem=python_distutils

override_dh_auto_test:
	rm -fr tests_tmp
	ADTTMP=. sh debian/tests/unittests
override_dh_auto_clean::
	rm -rf tests_tmp

# Translate upstream changelog to text for dh_installchangelogs.
# Upstream "make clean" will remove it.
CHANGES.txt:
	python changes.in/make.py text > $@
override_dh_auto_build: CHANGES.txt

# Files extracted from thirdparty tarballs by "make prepare" should be
# deleted with "make nuke", but upstream implementation uses the local
# subversion repository so we have to do an ugly explicit list.
# Information about thirdparty is centralized in debian/copyright.
override_dh_auto_clean::
	rm -f    taskcoachlib/thirdparty/customtreectrl.py
	rm -f -r taskcoachlib/thirdparty/desktop
	rm -f -r taskcoachlib/thirdparty/gntp
	rm -f    taskcoachlib/thirdparty/hypertreelist.py
	rm -f    taskcoachlib/thirdparty/lockfile.py
	rm -f -r taskcoachlib/thirdparty/ntlm
	rm -f -r taskcoachlib/thirdparty/pubsub
	rm -f    taskcoachlib/thirdparty/pybonjour.py
	rm -f    taskcoachlib/thirdparty/wmi.py
	rm -f -r taskcoachlib/thirdparty/wxScheduler

# Generated file, removed by dfsg_cleaner. See there for details.
override_dh_auto_clean::
	rm -f i18n.in/messages.pot

# Provide an icon for the menu file.
XPM_ICON := icons.in/taskcoach.xpm
$(XPM_ICON): %.xpm: %.png
	gm convert $< $@
override_dh_auto_build: $(XPM_ICON)
override_dh_auto_install::
	dh_install $(XPM_ICON) usr/share/pixmaps
override_dh_auto_clean::
	rm -f $(XPM_ICON)

# Upstream provides the main executable with a .py suffix.
EXE_DIR := debian/taskcoach/usr/bin
DESKTOP := debian/taskcoach/usr/share/applications/taskcoach.desktop
override_dh_auto_install::
	cd $(EXE_DIR) && mv taskcoach.py taskcoach
	sed --in-place s/Exec=taskcoach.py/Exec=taskcoach/ $(DESKTOP)

# Upstream provided XPM is too large for Debian standards (48x48).
MENU_ICON := debian/taskcoach/usr/share/pixmaps/taskcoach.xpm
override_dh_auto_install::
	gm convert -resize 32x32 $(MENU_ICON) $(MENU_ICON).tmp
	mv -f $(MENU_ICON).tmp $(MENU_ICON)

# Avoid compressing the TODO list, provided in the taskcoach format.
override_dh_compress:
	dh_compress -Xusr/share/doc/taskcoach/TODO.tsk
