###########################################################################
#
#
#  Makefile for the Pedro mini-XMPP client
# 
#  Authors:
#    Bob Jamison
# 
#  Copyright (C) 2005-2007 Bob Jamison
# 
#   This library is free software; you can redistribute it and/or
#   modify it under the terms of the GNU Lesser General Public
#   License as published by the Free Software Foundation; either
#   version 2.1 of the License, or (at your option) any later version.
# 
#   This library 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
#   Lesser General Public License for more details.
# 
#   You should have received a copy of the GNU Lesser General Public
#   License along with this library; if not, write to the Free Software
#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#
#
##########################################################################
# FILE SEPARATORS
# $(S) will be set to one of these
##########################################################################
BSLASH := \\#
FSLASH := /

##########################################################################
# SENSE ARCHITECTURE
##########################################################################
ifdef ComSpec
ARCH=win32
else
ARCH=xlib
endif

##########################################################################
# WIN32  SETTINGS
##########################################################################
ifeq ($(ARCH),win32)

#######  Where is your GTK directory?
GTK=c:/gtk210

####### Same thing, DOS style
GTKDOS=c:\gtk210

#SSL=openssl-0.9.8a
SSL=$(GTK)



CFLAGS = -g -Wall -DHAVE_SSL \
-DRELAYTOOL_SSL="static const int libssl_is_present=1; static int __attribute__((unused)) libssl_symbol_is_present(char *s){ return 1; }"

INC  = -I. -I$(GTK)/include -I$(SSL)/include


LIBSC = -mconsole -L$(GTK)/lib -L$(SSL) -lssl -lcrypto -lgdi32 -lws2_32
LIBS  = -mwindows -L$(GTK)/lib -L$(SSL) -lssl -lcrypto -lgdi32 -lws2_32

RM = del
CP = copy
S = $(BSLASH)


all: test.exe pedro.exe

GTKINC = -DGLIBMM_DLL \
-I$(GTK)/include/glibmm-2.4  -I$(GTK)/lib/glibmm-2.4/include \
-I$(GTK)/include/gtkmm-2.4   -I$(GTK)/lib/gtkmm-2.4/include \
-I$(GTK)/include/gdkmm-2.4   -I$(GTK)/lib/gdkmm-2.4/include \
-I$(GTK)/include/pangomm-1.4 -I$(GTK)/include/pangomm-1.4 \
-I$(GTK)/include/atkmm-1.6   -I$(GTK)/include/cairomm-1.0  \
-I$(GTK)/include/sigc++-2.0  -I$(GTK)/lib/sigc++-2.0/include \
-I$(GTK)/include/gtk-2.0     -I$(GTK)/lib/gtk-2.0/include \
-I$(GTK)/include/atk-1.0     -I$(GTK)/include/pango-1.0 \
-I$(GTK)/include/glib-2.0    -I$(GTK)/lib/glib-2.0/include \
-I$(GTK)/include/cairo

####### Our Gtk libs
GTKLIBS = -L$(GTK)/lib \
-lgtkmm-2.4 -lgdkmm-2.4 -lglibmm-2.4 \
-latkmm-1.6 -lpangomm-1.4 -lsigc-2.0 \
-lgtk-win32-2.0 -lgdk-win32-2.0 -latk-1.0 \
-lgdk_pixbuf-2.0 -lm -lpangoft2-1.0 -lpangowin32-1.0 -lpango-1.0 \
-lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lglib-2.0

endif


##########################################################################
# XLIB  SETTINGS
##########################################################################
ifeq ($(ARCH),xlib)

CFLAGS = -g -Wall -DHAVE_SSL -DHAVE_PTHREAD_H
XINC = -I/usr/X11R6/include
XLIB = -L/usr/X11R6/lib -lXrender -lX11
INC  = -I. -I.. $(XINC)
LIBS = $(XLIB) -lpthread -lssl
RM = rm -rf
CP = cp
S = $(FSLASH)
all: test pedro

GTKINC  += `pkg-config gtkmm-2.4 --cflags`
GTKLIBS += `pkg-config gtkmm-2.4 --libs`

endif



OBJ =         \
pedrodom.o    \
pedroxmpp.o   \
pedroconfig.o \
pedroutil.o


GUIOBJ = \
pedrogui.o \
geckoembed.o \
pedromain.o


TESTOBJ = \
work/test.o     \
work/filesend.o \
work/filerec.o  \
work/groupchat.o

test.exe: libpedro.a work/test.o
	$(CXX) -o $@ work/test.o libpedro.a $(LIBSC)
test: libpedro.a work/test.o
	$(CXX) -o $@ work/test.o libpedro.a $(LIBSC)
        
filesend.exe: libpedro.a work/filesend.o
	$(CXX) -o $@ work/filesend.o libpedro.a $(LIBSC)
filesend: libpedro.a work/filesend.o
	$(CXX) -o $@ work/filesend.o libpedro.a $(LIBSC)

filerec.exe: libpedro.a work/filerec.o
	$(CXX) -o $@ work/filerec.o libpedro.a $(LIBSC)
filerec: libpedro.a work/filerec.o
	$(CXX) -o $@ work/filerec.o libpedro.a $(LIBSC)

groupchat.exe: libpedro.a work/groupchat.o
	$(CXX) -o $@ work/groupchat.o libpedro.a $(LIBSC)
groupchat: libpedro.a work/groupchat.o
	$(CXX) -o $@ work/groupchat.o libpedro.a $(LIBSC)

pedro.exe: libpedro.a $(GUIOBJ)
	$(CXX) -o $@ pedromain.o pedrogui.o libpedro.a $(GTKLIBS) $(LIBS)
pedro: libpedro.a pedromain.o pedrogui.o
	$(CXX) -o $@ pedromain.o pedrogui.o libpedro.a $(GTKLIBS) $(LIBS)


libpedro.a: $(OBJ)
	ar crv libpedro.a $(OBJ)

pedromain.o: pedromain.cpp
	$(CXX) $(CFLAGS) $(INC) $(GTKINC) -c -o $@ $<
        
pedrogui.o: pedrogui.cpp pedrogui.h
	$(CXX) $(CFLAGS) $(INC) $(GTKINC) -c -o $@ $<

geckoembed.o: geckoembed.cpp geckoembed.h
	$(CXX) $(CFLAGS) $(INC) $(GTKINC) -c -o $@ $<

.cpp.o:
	$(CXX) $(CFLAGS) $(INC) -c -o $@ $<

clean:
	$(foreach a, $(OBJ), $(shell $(RM) $(subst /,$(S), $(a))))
	$(foreach a, $(GUIOBJ), $(shell $(RM) $(subst /,$(S), $(a))))
	$(foreach a, $(TESTOBJ), $(shell $(RM) $(subst /,$(S), $(a))))
	-$(RM) *.a
	-$(RM) test
	-$(RM) test.exe
	-$(RM) filesend
	-$(RM) filesend.exe
	-$(RM) filerec
	-$(RM) filerec.exe
	-$(RM) groupchat
	-$(RM) groupchat.exe
	-$(RM) pedro
	-$(RM) pedro.exe
	-$(RM) core.*

###########################################################################
# E N D    O F    F I L E
###########################################################################

