##      Makefile
##
##
## Copyright (C) 2009 Max V. Stotsky <ms@pereslavl.ru>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published
## by the Free Software Foundation; version 3 or later.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##

name = gnetworktester

etcdir = /etc
bindir = /usr/bin
datadir = /usr/share

from_pixmaps=data/pixmaps
from_glade=data/glade

RM = rm -f

all: build

# to create the binary files from the sources
build: pycompile
	msgfmt --strict --check po/ru.po -o $(name).ru.mo

# to compile python sources
pycompile:
	cd src &&\
	python -c "import compileall, re; compileall.compile_dir('./', rx=re.compile('/[.]svn'), force=True)"

# to create the documentation files
builddoc: cleandoc
	cd doc &&\
	rubber --warn all -d userguide.ru.tex

# to install gnetworktester to a $(PREFIX).
# to / by default
install: build 
	install -d -m 0755 $(PREFIX)$(bindir)
	install -d -m 0755 $(PREFIX)$(datadir)/$(name)/data/glade
	install -d -m 0755 $(PREFIX)$(datadir)/$(name)/data/pixmaps
	install -d -m 0755 $(PREFIX)$(datadir)/$(name)/data/pixmaps/flags
	install -d -m 0755 $(PREFIX)$(datadir)/$(name)/src
	install -d -m 0755 $(PREFIX)$(datadir)/applications
	install -d -m 0755 $(PREFIX)$(datadir)/locale/ru/LC_MESSAGES
	install -d -m 0755 $(PREFIX)$(datadir)/pixmaps
	install -d -m 0755 $(PREFIX)$(etcdir)
	install -m 0755 $(name)                             $(PREFIX)$(bindir)/
	install -m 0644 src/*.py                            $(PREFIX)$(datadir)/$(name)/src/
	install -m 0644 $(from_glade)/*.glade               $(PREFIX)$(datadir)/$(name)/data/glade/
	install -m 0644 $(from_pixmaps)/*.svg               $(PREFIX)$(datadir)/$(name)/data/pixmaps/
	install -m 0644 $(from_pixmaps)/*.png               $(PREFIX)$(datadir)/$(name)/data/pixmaps/
	install -m 0644 $(from_pixmaps)/flags/*.png         $(PREFIX)$(datadir)/$(name)/data/pixmaps/flags/
	install -m 0644 $(from_pixmaps)/flags/FLAGS_LICENCE $(PREFIX)$(datadir)/$(name)/data/pixmaps/flags/
	install -m 0644 $(name)$(nid).cfg                   $(PREFIX)$(etcdir)/$(name).cfg
	install -m 0644 $(name).ru.mo                       $(PREFIX)$(datadir)/locale/ru/LC_MESSAGES/$(name).mo
	install -m 0644 $(name).svg                         $(PREFIX)$(datadir)/$(name)/data/pixmaps/
	install -m 0644 $(name)_icon.svg                    $(PREFIX)$(datadir)/pixmaps/$(name).svg
	install -m 0644 $(name).xpm                         $(PREFIX)$(datadir)/pixmaps
	install -m 0644 $(name).desktop                     $(PREFIX)$(datadir)/applications

# to create the deb package
deb:
	dpkg-buildpackage -rfakeroot -tc -I.svn

# to create supported rpm packages
rpms: rpm_fc rpm_mdv rpm_suse rpm_alt

# to create the rpm package for specified distributive
rpm_%:
	./make_spec.sh $(name) $*
	rpmbuild -ba $(name).spec

# to remove files which was created 
clean: cleandoc
	$(RM) src/*.pyc
	$(RM) src/*.pyo
	$(RM) $(name).ru.mo
	$(RM) $(name).spec

# to remove documentation files which was created
cleandoc:
	cd doc &&\
	((which rubber && rubber -d --clean userguide.ru.tex) || true) &&\
	$(RM) userguide.ru.html

