#!/usr/bin/make -f

include /usr/share/quilt/quilt.make
include /usr/share/cli-common/cli.make

LDFLAGS += -Wl,-z,defs -Wl,-O1 -Wl,--as-needed

MAKEFILE = $(firstword $(MAKEFILE_LIST))
DEBIAN_DIR = $(dir $(MAKEFILE))
DEB_SOURCE_NAME = $(shell dpkg-parsechangelog -l$(DEBIAN_DIR)/changelog | grep ^Source | cut -d" " -f2)
DEB_VERSION = $(shell dpkg-parsechangelog -l$(DEBIAN_DIR)/changelog | grep ^Version | cut -d" " -f2)   
VERSION = $(shell echo $(DEB_VERSION) | cut -d"-" -f1 | sed 's/+dfsg.*//')

override_dh_autoreconf:
	cp /usr/share/gnome-doc-utils/gnome-doc-utils.make $(CURDIR)
	dh_autoreconf
	# replace ltmain.sh with our patched one that supports --as-needed
	install --mode=755 $(CURDIR)/debian/ltmain-as-needed.sh $(CURDIR)/ltmain.sh

override_dh_auto_configure:
	dh_auto_configure -- \
		--disable-scrollkeeper \
		--disable-update-mimedb \
		LDFLAGS="$(LDFLAGS)" \
		GMCS=/usr/bin/mono-csc

override_dh_auto_install:
	dh_auto_install -- GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL=1
	convert $(CURDIR)/data/icons/hicolor_apps_16x16_tomboy.png $(CURDIR)/debian/tomboy/usr/share/pixmaps/tomboy-16.xpm
	convert $(CURDIR)/data/icons/hicolor_apps_32x32_tomboy.png $(CURDIR)/debian/tomboy/usr/share/pixmaps/tomboy-32.xpm
	cp debian/PrintNotes.dll.config debian/tomboy/usr/lib/tomboy/addins
	rm -rf debian/tomboy/usr/lib/tomboy/*.la
	# crush it good
	find $(CURDIR)/debian/tomboy/usr/share/gnome/help/tomboy -type f -name "*.png" -exec sh -c 'pngquant 256 < {} > {}.crushed; mv {}.crushed {}' \;
	# create pot file for Ubuntu - doesn't affect built debs for Debian
	cd po; intltool-update --pot
	echo "X-Ubuntu-Gettext-Domain=tomboy" >> debian/tomboy/usr/share/applications/tomboy.desktop
	GETTEXT_DOMAIN="tomboy" perl /usr/lib/cdbs/strip-schema.pl debian/tomboy/etc/gconf/schemas/tomboy.schemas > debian/tomboy/etc/gconf/schemas/tomboy.schemas.new; mv debian/tomboy/etc/gconf/schemas/tomboy.schemas.new debian/tomboy/etc/gconf/schemas/tomboy.schemas


# disable tests
override_dh_auto_test:

get-orig-source:
	uscan \
		--package $(DEB_SOURCE_NAME) \
		--watchfile $(DEBIAN_DIR)/watch \
		--upstream-version $(VERSION) \
		--download-version $(VERSION) \
		--destdir . \
		--force-download \
		--rename

%:
	dh --with=quilt,autoreconf $@

.PHONY: autoreconf get-orig-source
