#####################
# PSIP - A lightweight GTK GUI for pjsip
# (C) James Budiono 2011
# License: GNU GPL Version 3 or later, please see attached gpl-3.0.txt 
# or http://www.gnu.org/copyleft/gpl.html
# 
# The build recipe for psip.
#####################

GTK_CFLAGS=$(shell pkg-config --cflags gtk+-2.0 gmodule-2.0 gthread-2.0)
GTK_LDFLAGS=$(shell pkg-config --libs gtk+-2.0 gmodule-2.0 gthread-2.0)
PJPROJECT_LDFLAGS=$(shell pkg-config --libs libpjproject)
OSXCART_CFLAGS=$(shell pkg-config --cflags osxcart)
OSXCART_LDFLAGS=$(shell pkg-config --libs osxcart)

CFLAGS  := -g -O0 -Wall -Werror=implicit-function-declaration -Werror=implicit-int $(GTK_CFLAGS) $(OSXCART_CFLAGS) $(CFLAGS)
LDFLAGS := -Wl,--export-dynamic $(LDFLAGS)
LDLIBS  := $(GTK_LDFLAGS) $(PJPROJECT_LDFLAGS) $(OSXCART_LDFLAGS)

all: psip psip-no-recorder

psip.o: psip.c psip.h psip_icon.h Makefile

cJSON.o: cJSON.c cJSON.h Makefile

config.o: config.c psip.h Makefile

backend.o: backend.c psip.h Makefile

# convert app icon to include
psip_icon.h: psip_icon.png
	gdk-pixbuf-csource --raw --name=psip_icon psip_icon.png > psip_icon.h

psip: psip.o config.o cJSON.o backend.o 

clean:
	-rm *.o
	-rm psip
	-rm psip-no-recorder
	-rm psip.glade.h
	-rm psip_icon.h

rebuild_psip.o:
	-rm psip.o

release: CFLAGS:=$(CFLAGS) -DRELEASE -O2
release: rebuild_psip.o psip.glade.h all

# convert glade files into release include
psip.glade.h: psip.glade psip_im.glade
	#
	# gzip the main ui file before including - it's huge (140k+).
	#
	echo "unsigned char MAIN_GUI_GLADE[] = { " > psip.glade.h
	#./xml2c.sh psip.glade >> psip.glade.h
	#gzip -c psip.glade | xxd -i >> psip.glade.h  ## xxd doesn't exist in wary
	xmllint --noblanks psip.glade | gzip -9 | hexdump -v -e '" " 16/1 "  0x%02x, " "\n"' | sed -e '$ s/0x  ,//g' >> psip.glade.h
	echo "};" >> psip.glade.h
	echo "#define MAIN_GUI_GLADE_ORIGINAL_SIZE $(shell xmllint --noblanks psip.glade | wc -c)" >> psip.glade.h
	#
	# use standard xml2c conversion for im_window - it's small (less than 10k).
	#
	echo "gchar *IM_GUI_GLADE = " >> psip.glade.h
	#./xml2c.sh psip_im.glade >> psip.glade.h
	xmllint --noblanks psip_im.glade | ./xml2c.sh >> psip.glade.h
	echo ";" >> psip.glade.h


# the "no-recorder" version
psip-no-recorder: psip-no-recorder.o config.o cJSON.o backend.o 

psip-no-recorder.o: psip.c psip.h psip_icon.h Makefile
	$(CC) $(CFLAGS) -DDISABLE_RECORDER -c -o psip-no-recorder.o psip.c


.PHONY: all clean release rebuild_psip.o
