#
#  @Copyright (C) 2007 Kim Jin Chul (shriekout@gmail.com).
#
#  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; either version 2 of the License, or
#  (at your option) any later version.
#
#  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 Library General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#

PREFIX ?= /usr
TARGET = happytimer
OBJECT = happytimer.o timecheck.o interface.o callback.o eggtrayicon.o sexy-tooltip.o
SRC = happytimer.c timecheck.c interface.c callback.c lib/eggtrayicon/eggtrayicon.c lib/libsexy/sexy-tooltip.c
PO_SRC_DIR = po
PO_DEST_DIR = $(PREFIX)/share/locale

CC ?= gcc
PACKAGE_CFLAGS = `pkg-config --cflags gtk+-2.0 gstreamer-0.10 libxml-2.0`
PACKAGE_LIBS = `pkg-config --libs gtk+-2.0 gstreamer-0.10 libxml-2.0`
CFLAGS ?= -Wall

ICON_LIST = 16x16 22x22 24x24 32x32 48x48
PO_LIST = ko tgl

$(TARGET) : $(OBJECT)
	$(CC) -o $(TARGET) $(OBJECT) $(PACKAGE_LIBS)
	for po in $(PO_LIST); do\
		msgfmt -o $(PO_SRC_DIR)/$$po.mo $(PO_SRC_DIR)/$$po.po;\
	done

happytimer.o : happytimer.c happytimer.h interface.h callback.h timecheck.h lib/eggtrayicon/eggtrayicon.h lib/libsexy/sexy-tooltip.h config.h
	$(CC) $(CFLAGS) -c happytimer.c $(PACKAGE_CFLAGS)

timecheck.o : timecheck.c happytimer.h callback.h timecheck.h interface.h
	$(CC) $(CFLAGS) -c timecheck.c $(PACKAGE_CFLAGS)

interface.o : interface.c interface.h callback.h happytimer.h timecheck.h config.h
	$(CC) $(CFLAGS) -c interface.c $(PACKAGE_CFLAGS)

callback.o : callback.c callback.h interface.h happytimer.h timecheck.h lib/libsexy/sexy-tooltip.h
	$(CC) $(CFLAGS) -c callback.c $(PACKAGE_CFLAGS)

eggtrayicon.o : lib/eggtrayicon/eggtrayicon.h lib/eggtrayicon/eggtrayicon.c
	$(CC) $(CFLAGS) -c lib/eggtrayicon/eggtrayicon.c $(PACKAGE_CFLAGS)

sexy-tooltip.o : lib/libsexy/sexy-tooltip.h lib/libsexy/sexy-tooltip.c
	$(CC) $(CFLAGS) -c lib/libsexy/sexy-tooltip.c $(PACKAGE_CFLAGS)

install :
	if [ ! -d $(PREFIX)/share/happytimer ]; then\
		mkdir -p $(PREFIX)/share/happytimer/sound;\
	fi
	if [ ! -d $(PREFIX)/bin ]; then\
		mkdir -p $(PREFIX)/bin;\
	fi
	if [ ! -d $(PREFIX)/share/pixmaps ]; then\
		mkdir -p $(PREFIX)/share/pixmaps;\
	fi
	cp $(TARGET) $(PREFIX)/bin/
	cp sound/* $(PREFIX)/share/happytimer/sound/
	cp image/happytimer.png $(PREFIX)/share/pixmaps/
	cp image/happytimer_start.png $(PREFIX)/share/pixmaps/
	if [ ! -d $(PREFIX)/share/icons/gnome/scalable/apps ]; then\
		mkdir -p $(PREFIX)/share/icons/gnome/scalable/apps;\
	fi
	cp image/happytimer.svg $(PREFIX)/share/icons/gnome/scalable/apps/
	for i in $(ICON_LIST); do\
		if [ ! -d $(PREFIX)/$$i ]; then\
			mkdir -p $(PREFIX)/share/icons/gnome/$$i/apps;\
			cp image/happytimer_$$i.png $(PREFIX)/share/icons/gnome/$$i/apps/happytimer.png;\
		fi;\
	done
	if [ ! -d $(PREFIX)/share/applications ]; then\
		mkdir -p $(PREFIX)/share/applications;\
	fi
	cp happytimer.desktop $(PREFIX)/share/applications/
	for po in $(PO_LIST); do\
		if [ ! -d $(PO_DEST_DIR)/$$po/LC_MESSAGES ]; then\
			mkdir -p $(PO_DEST_DIR)/$$po/LC_MESSAGES;\
		fi;\
		cp $(PO_SRC_DIR)/$$po.mo $(PO_DEST_DIR)/$$po/LC_MESSAGES/happytimer.mo;\
	done

clean :
	rm $(TARGET)
	rm *.o
	for po in $(PO_LIST); do\
		rm $(PO_SRC_DIR)/$$po.mo;\
	done

po-update:
	xgettext -k_ $(SRC) -o $(PO_SRC_DIR)/messages.po
