#
#  @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
SRC = happytimer.c timecheck.c interface.c callback.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 libnotify`
PACKAGE_LIBS = `pkg-config --libs gtk+-2.0 gstreamer-0.10 libxml-2.0 libnotify`
CFLAGS ?= -Wall

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

$(TARGET) : $(OBJECT)  $(PO_LIST)
	$(CC) -o $(TARGET) $(OBJECT) $(PACKAGE_LIBS)

$(PO_LIST) :
	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
	$(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
	$(CC) $(CFLAGS) -c callback.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/
	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)/share/icons/gnome/$$i/apps ]; then\
			mkdir -p $(PREFIX)/share/icons/gnome/$$i/apps;\
		fi;\
		cp image/happytimer_$$i.png $(PREFIX)/share/icons/gnome/$$i/apps/happytimer.png;\
	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 :
	if [ -f $(TARGET) ]; then\
		rm $(TARGET);\
	fi
	for obj in $(OBJECT); do\
		if [ -f $$obj ]; then\
			rm $$obj;\
		fi;\
	done
	for po in $(PO_LIST); do\
		if [ -f $(PO_SRC_DIR)/$$po.mo ]; then\
			rm $(PO_SRC_DIR)/$$po.mo;\
		fi;\
	done
	if [ -f $(PO_SRC_DIR)/messages.po ]; then\
		rm $(PO_SRC_DIR)/messages.po;\
	fi

uninstall :
	if [ -d $(PREFIX)/share/happytimer ]; then\
		rm -fr $(PREFIX)/share/happytimer;\
	fi
	if [ -f $(PREFIX)/bin/$(TARGET) ]; then\
		rm $(PREFIX)/bin/$(TARGET);\
	fi
	if [ -f $(PREFIX)/share/pixmaps/happytimer.png ]; then\
		rm $(PREFIX)/share/pixmaps/happytimer.png;\
	fi
	if [ -f $(PREFIX)/share/icons/gnome/scalable/apps/happytimer.svg ]; then\
		rm $(PREFIX)/share/icons/gnome/scalable/apps/happytimer.svg;\
	fi
	for i in $(ICON_LIST); do\
		if [ -f $(PREFIX)/share/icons/gnome/$$i/apps/happytimer.png ]; then\
			rm $(PREFIX)/share/icons/gnome/$$i/apps/happytimer.png;\
		fi;\
	done
	if [ -f $(PREFIX)/share/applications/happytimer.desktop ]; then\
		rm $(PREFIX)/share/applications/happytimer.desktop;\
	fi
	for po in $(PO_LIST); do\
		if [ -f $(PO_DEST_DIR)/$$po/LC_MESSAGES/happytimer.mo ]; then\
			rm $(PO_DEST_DIR)/$$po/LC_MESSAGES/happytimer.mo;\
		fi;\
	done

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