#!/usr/bin/make -f

# export DH_VERBOSE := 1

build build-arch build-indep binary binary-arch binary-indep clean:
	dh $@ --with python2 --with linktree

# 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

# 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.
# Note that thirdparty libraries may also affect
# debian/control:Build-Depends, debian/taskcoach.linktrees and
# debian/copyright.
override_dh_auto_clean::
	rm -f    taskcoachlib/persistence/xml/templates.py
	rm -f -r taskcoachlib/thirdparty/apscheduler
	rm -f -r taskcoachlib/thirdparty/aui
	rm -f -r taskcoachlib/thirdparty/chardet
	rm -f    taskcoachlib/thirdparty/customtreectrl.py
	rm -f -r taskcoachlib/thirdparty/dateutil
	rm -f -r taskcoachlib/thirdparty/desktop
	rm -f -r taskcoachlib/thirdparty/gntp
	rm -f    taskcoachlib/thirdparty/hypertreelist.py
	rm -f -r taskcoachlib/thirdparty/keyring
	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/pyparsing.py
	rm -f -r taskcoachlib/thirdparty/squaremap
	rm -f    taskcoachlib/thirdparty/wmi.py
	rm -f -r taskcoachlib/thirdparty/wxScheduler
	rm -f -r taskcoachlib/thirdparty/xdg

# 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
