#***********************************************************************************
#
#	Copyright (C) 2007-2008 Ahmet Öztürk (aoz_2@yahoo.com)
#
#   This file is part of Lifeograph.
#
#	Lifeograph 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, either version 3 of the License, or
#   (at your option) any later version.
#
#   Lifeograph 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.
#
#   You should have received a copy of the GNU General Public License
#	along with Lifeograph.  If not, see <http://www.gnu.org/licenses/>.
#
#***********************************************************************************

INSTALL		= install -o root -g root
MKDIR		= mkdir
RM			= rm
CXX			= g++
#CC			= gcc
MSGFMT		= msgfmt
XGETTEXT	= xgettext
MSGMERGE	= msgmerge
PACKAGE		= lifeograph
AUTHORS		= "Ahmet Öztürk"
OBJ			= ../obj/main.o ../obj/lifeograph.o ../obj/lifeodata.o\
			  ../obj/helpers.o ../obj/password.o
LINKOBJ		= ../obj/*.o
LIBS		= `pkg-config gtkmm-2.4 gconfmm-2.6 --cflags --libs` -lgcrypt -lgpg-error
CXXFLAGS	= -Wall `pkg-config gtkmm-2.4 gconfmm-2.6 --cflags`
BIN			= ../bin/lifeograph
ICONS		= ../icons
BACKGROUNDS	= ../backgrounds
OPTFLAGS	= -O2
prefix		= /usr
exec_prefix	= $(prefix)
bindir		= $(exec_prefix)/bin
datadir		= /usr/share
localedir	= $(datadir)/locale
pixmapdir	= $(datadir)/pixmaps
mandir		= $(datadir)/man
POT			= ../po/lifeograph.pot
PO			:= $(wildcard ../po/*.po)
MO			:= $(PO:.po=.mo)
LOCALES		:= $(notdir $(PO:.po=))


.PHONY: all all-before all-after clean clean-custom install uninstall pot msgmerge

all: all-before $(BIN) $(MO) all-after

clean:
	$(RM) -f $(LINKOBJ) $(BIN)
	$(RM) -f $(MO)


# INSTALLATION
install: $(BIN) $(MO)
	$(INSTALL) -m 755 -d $(DESTDIR)$(bindir) $(DESTDIR)$(pixmapdir) \
		$(DESTDIR)$(pixmapdir)/$(PACKAGE) $(DESTDIR)$(pixmapdir)/$(PACKAGE)/backgrounds \
		$(DESTDIR)$(datadir)/applications
	$(INSTALL) -m 755 $(BIN) $(DESTDIR)$(bindir)
	$(INSTALL) -m 644 $(ICONS)/lifeograph.png $(DESTDIR)$(pixmapdir)
	$(INSTALL) -m 644 $(BACKGROUNDS)/* $(DESTDIR)$(pixmapdir)/$(PACKAGE)/backgrounds
	$(INSTALL) -m 644 ../lifeograph.desktop $(DESTDIR)$(datadir)/applications
	for i in $(LOCALES); do \
		$(INSTALL) -m 755 -d $(DESTDIR)$(localedir); \
		$(INSTALL) -m 755 -d $(DESTDIR)$(localedir)/$$i; \
		$(INSTALL) -m 755 -d $(DESTDIR)$(localedir)/$$i/LC_MESSAGES; \
		$(INSTALL) -m 644 ../po/$$i.mo $(DESTDIR)$(localedir)/$$i/LC_MESSAGES/$(PACKAGE).mo; \
		done

uninstall:
	$(RM) $(DESTDIR)$(bindir)/$(BIN)
	$(RM) -R $(DESTDIR)$(pixmapdir)/$(PACKAGE)
	$(RM) $(DESTDIR)$(pixmapdir)/lifeograph.png
	$(RM) $(DESTDIR)$(datadir)/applications/lifeograph.desktop
	for i in $(DESTDIR)$(localedir)/*; do \
		$(RM) -f $$i/LC_MESSAGES/$(PACKAGE).mo; \
		done


# INTERNATIONALIZATION
../po/%.mo: ../po/%.po
	@echo "$(MSGFMT) -c -o $@ $<";\
	$(MSGFMT) -c -v -o $@ $<

msgmerge: $(POT)
	for i in $(PO);\
		do $(MSGMERGE) -U $$i $(POT);\
	done

pot: lifeograph.cpp lifeograph.hpp password.cpp
	$(XGETTEXT) -kN_ -k_\
			--default-domain=$(PACKAGE)\
			--package-name=$(PACKAGE)\
			--copyright-holder=$(AUTHORS)\
			--add-comments=TRANSLATORS:\
			--from-code=UTF-8 -o $(POT) lifeograph.hpp lifeograph.cpp password.cpp


# EXECUTABLE FILE
# maybe some day there will be a windows version:
ifneq (,$(findstring indows,$(OS)))
$(BIN): $(OBJ)
	$(CXX) $(LINKOBJ) $(OPTFLAGS) $(LIBS)\
			-Wl,--enable-runtime-pseudo-reloc -mwindows -o $@
else
$(BIN): $(OBJ)
	$(CXX) $(LINKOBJ) $(OPTFLAGS) $(LIBS) -o $@
endif


# OBJECT FILES
../obj/helpers.o: helpers.cpp helpers.hpp
	$(CXX) -c helpers.cpp $(CXXFLAGS) $(OPTFLAGS) -o $@

../obj/lifeodata.o: lifeodata.cpp lifeodata.hpp helpers.hpp
	$(CXX) -c lifeodata.cpp $(CXXFLAGS) $(OPTFLAGS) -o $@

../obj/password.o: password.cpp password.hpp
	$(CXX) -c password.cpp $(CXXFLAGS) $(OPTFLAGS) -o $@

../obj/lifeograph.o: lifeograph.cpp lifeograph.hpp lifeodata.hpp helpers.hpp password.hpp
	$(CXX) -c lifeograph.cpp $(CXXFLAGS) $(OPTFLAGS) -o $@
	
../obj/main.o: main.cpp
	$(CXX) -c main.cpp $(CXXFLAGS) $(OPTFLAGS) -o $@

