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

prefix=/usr/local

# Beware that the installation list below is also extracted by deploy-n900 script! :)
INSTALLATION_LIST=config mapicons images hivemind translations qt4reactor idavoll

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 '  clean-binaries	     - remove python binaries'
	@echo '  pylint              - run pylint static checker for all code'
	@echo '  pylint-hook         - run pylint static checker from mercurial hook'
	@echo '  unittest            = run all unit tests (can be used as a hook)'
	@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 "'\'\'\''\nHiveMind version information. \n\
	This file is auto-generated. Do not edit!\n'\'\'\''" } \
	/^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: clean-binaries
	rm -f $(patsubst %.ts,%.qm,$(wildcard translations/*.ts))
	rm -rf html
	rm -f hivemind/__version__.py

clean-binaries:
	find . -name '*.py[co]' | xargs -r rm

install: build-translations
	install -d ${DESTDIR}${prefix}/share/hivemind ${DESTDIR}${prefix}/bin
	cp -r ${INSTALLATION_LIST} ${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

pylint:
	find hivemind -name '*.py' -a -not -regex '^hivemind/test.*' | \
	xargs pylint --rcfile=pylint.conf

pylint-hook:
	hg status -am --change ${HG_NODE} -I 'glob:**.py' | cut -d ' ' -f 2 | \
	xargs -r pylint --rcfile=pylint.conf

unittest:
	UNITTEST=1 nosetests hivemind/test/*py hivemind/test/network/*py

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