# HiveMind - Distributed mind map editor for Maemo 5 platform
# Makefile
# Copyright (C) 2010 Ilya Paramonov

prefix=/usr/local

all: build-translations

help:
	@echo 'Targets:'
	@echo '  update-translations - update all .ts-files'
	@echo '  build-translations  - build all .ts-files'
	@echo '  version             - generate __version__.py from hg log'
	@echo '  documentation       - create documentation using epydoc'
	@echo '  clean               - remove files created by other targets'
	@echo '  install             - install previously built application'
	@echo '  uninstall           - uninstall application'
	@echo	
	@echo 'Default location for install/uninstall is /usr/local. Use -e prefix=<directory> to override'

update-translations:
	pyside-lupdate `find . -name '*.py'` -ts `find translations -name '*.ts'` -noobsolete

build-translations: $(patsubst %.ts,%.qm,$(wildcard translations/*.ts))

%.qm: %.ts
	lrelease $<

version:
	hg log -r . | awk ' \
	BEGIN{ print "# This file is auto-generated. Do not edit!" } \
	/^changeset:/{ VERSION = "r" substr($$2, 0, index($$2, ":") - 1) "+dev"; } \
	/^tag: *v/{ VERSION = substr($$2, 2); } \
	/^summary: *Added tag v/{ VERSION = substr($$4, 2); } \
	END{ print "VERSION = \"" VERSION "\"" } \
	' > hivemind/__version__.py

documentation:
	find hivemind -name '*.py' -a ! -wholename 'hivemind/test/*' | \
		xargs epydoc -v --name HiveMind --graph all $(EPYPARAMS)

clean:
	rm -f $(patsubst %.ts,%.qm,$(wildcard translations/*.ts))
	rm -rf html
	rm -f hivemind/__version__.py
	find . -name '*.pyc' -delete

install: build-translations
	install -d ${DESTDIR}${prefix}/share/hivemind ${DESTDIR}${prefix}/bin
	cp -r config icons images hivemind translations qt4reactor ${DESTDIR}${prefix}/share/hivemind/
	cp hivemind.py ${DESTDIR}${prefix}/bin/hivemind
	cd ${DESTDIR}${prefix}/share/hivemind

uninstall:
	rm -rf ${DESTDIR}${prefix}/share/hivemind
	rm -f ${DESTDIR}${prefix}/bin/hivemind

.PHONY: help all update-translations build-translations version documentation clean install
