PREFIX ?= /usr
TARGET = happytimer
OBJECT = happytimer.o timecheck.o interface.o callback.o eggtrayicon.o
SRC = happytimer.c timecheck.c interface.c callback.c
PO_SRC_DIR = po
PO_DEST_DIR = /usr/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 ph

$(TARGET) : $(OBJECT)
	$(CC) -o $(TARGET) $(OBJECT) $(PACKAGE_LIBS) -lsexy
	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
	$(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)

eggtrayicon.o : lib/eggtrayicon/eggtrayicon.h lib/eggtrayicon/eggtrayicon.c
	$(CC) $(CFLAGS) -c lib/eggtrayicon/eggtrayicon.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
