#!/usr/bin/make -f

DEB_DESTDIR=$(CURDIR)/debian/tmp

# Python definitions
PYVER=2.5
PYTHON=python$(PYVER)

# Directories used by this plugin
CNL_SHARE_DIR=/usr/share/canola
CNL_PLUGINS_DIR=$(CNL_SHARE_DIR)/plugins
FEED_HDL_DBUS=usr/share/dbus-1/services
FEED_HDL_APP=usr/share/applications/hildon
FEED_HDL_BIN=/usr/bin

# Other plugin definitions:
CNL_COLLECTION_NAME=canola-tuning

build: build-stamp
build-stamp:
	dh_testdir
	#
	# Compile sources
	#
	$(PYTHON) -OO -m compileall -d $(CNL_COLLECTION_NAME) $(CURDIR)/$(CNL_COLLECTION_NAME)
	#
	# Build plugin package
	#
	cd $(CURDIR) && \
		zip -q -0 $(CNL_COLLECTION_NAME).zip $(CNL_COLLECTION_NAME)/plugins.info `find $(CNL_COLLECTION_NAME) -name "*.py"`
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	#
	# Remove built sources
	#
	find $(CURDIR)/$(CNL_COLLECTION_NAME) -name "*.pyc" | xargs rm -f
	find $(CURDIR)/$(CNL_COLLECTION_NAME) -name "*.pyo" | xargs rm -f
	#
	# Remove plugin package
	#
	rm -f $(CURDIR)/$(CNL_COLLECTION_NAME).zip
	rm -f build-stamp
	rm -rf $(DEB_DESTDIR)
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_installdirs
	#
	# Install plugin package
	#
	install -D -m 644 $(CURDIR)/$(CNL_COLLECTION_NAME).zip $(DEB_DESTDIR)/$(CNL_PLUGINS_DIR)/$(CNL_COLLECTION_NAME).zip
	install -D -m 655 $(CURDIR)/feedhandler/bin/feedhandler.py $(DEB_DESTDIR)/$(FEED_HDL_BIN)/feedhandler.py
	install -D -m 644 $(CURDIR)/feedhandler/dbus/org.maemo.garage.feedhandler.service $(DEB_DESTDIR)/$(FEED_HDL_DBUS)/org.maemo.garage.feedhandler.service
	dh_install --sourcedir=$(DEB_DESTDIR) --fail-missing

binary: build install
	dh_testdir
	dh_testroot
	dh_installdocs
	dh_installdebconf
	dh_installchangelogs
	dh_strip
	dh_compress
	dh_fixperms
	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

.PHONY: build clean install binary
