#
# Makefile.mingw
#
# Description: Makefile for win32 (mingw) version of Gaim
#

GAIM_TOP := ..
include $(GAIM_TOP)/libgaim/win32/global.mak

NEEDED_DLLS = $(GTKSPELL_TOP)/gtkspell/libgtkspell.dll

##
## VARIABLE DEFINITIONS
##
EXE_TARGET := gaim
GTKGAIM_TARGET := gtkgaim
EXE_NAME := $(EXE_TARGET).exe

WINAPP := -mwindows
# The Debug version of gaim is a console app, always having a console
CONSOLEAPP := -mconsole

LDFLAGS := $(WINAPP)

##
## INCLUDE PATHS
##
LIBGAIM_INCLUDE_PATHS =	\
			-I$(GAIM_LIB_TOP) \
			-I$(GAIM_LIB_TOP)/win32 \
			-I$(GAIM_TOP) \
			-I$(GTK_TOP)/include \
			-I$(GTK_TOP)/include/glib-2.0 \
			-I$(GTK_TOP)/lib/glib-2.0/include

INCLUDE_PATHS =	\
			$(LIBGAIM_INCLUDE_PATHS) \
			-I$(GAIM_GTK_IDLETRACK_TOP) \
			-I$(GAIM_GTK_TOP) \
			-I$(GAIM_GTK_TOP)/win32 \
			-I$(GTK_TOP)/include/gtk-2.0 \
			-I$(GTK_TOP)/include/pango-1.0 \
			-I$(GTK_TOP)/include/atk-1.0 \
			-I$(GTK_TOP)/lib/gtk-2.0/include \
			-I$(GTKSPELL_TOP) \
			-I$(ASPELL_TOP)/include

LIB_PATHS =		-L$(GTK_TOP)/lib \
			-L$(GAIM_LIB_TOP) \
			-L$(GAIM_GTK_TOP) \
			-L$(GAIM_GTK_IDLETRACK_TOP) \
			-L$(ASPELL_TOP)/lib

##
##  SOURCES, OBJECTS
##
GTKGAIM_C_SRC =	\
			gaimstock.c \
			gtkaccount.c \
			gtkblist.c \
			gtkconn.c \
			gtkconv.c \
			gtkcellrendererprogress.c \
			gtkdebug.c \
			gtkdialogs.c \
			gtkdnd-hints.c \
			gtkeventloop.c \
			gtkexpander.c \
			gtkft.c \
			gtkidle.c \
			gtkimhtml.c \
			gtkimhtmltoolbar.c \
			gtklog.c \
			gtkmain.c \
			gtkmenutray.c \
			gtknotify.c \
			gtkplugin.c \
			gtkpluginpref.c \
			gtkpounce.c \
			gtkprefs.c \
			gtkprivacy.c \
			gtkrequest.c \
			gtkroomlist.c \
			gtksavedstatuses.c \
			gtksound.c \
			gtksourceiter.c \
			gtkstatusbox.c \
			gtkthemes.c \
			gtkutils.c \
			gtkwhiteboard.c \
			win32/gtkwin32dep.c \
			win32/untar.c \
			win32/wspell.c

GTKGAIM_RC_SRC = win32/gtkgaimrc.rc
GTKGAIM_OBJECTS = $(GTKGAIM_C_SRC:%.c=%.o) $(GTKGAIM_RC_SRC:%.rc=%.o)

EXE_RC_SRC = win32/gaimrc.rc
EXE_C_SRC = win32/win_gaim.c
EXE_OBJECTS = $(EXE_C_SRC:%.c=%.o) $(EXE_RC_SRC:%.rc=%.o)

##
## LIBRARIES
##
LIBGAIM_LIBS =	\
		-lgaim \
		-lglib-2.0 \
		-lgthread-2.0 \
		-lgobject-2.0 \
		-lgmodule-2.0 \
		-lintl \
		-lws2_32 \
		-lwinmm \
		-lz \
		-liberty

GTKGAIM_LIBS =	\
		$(LIBGAIM_LIBS) \
		-lidletrack \
		-lgtk-win32-2.0 \
		-latk-1.0 \
		-lpango-1.0 \
		-lgdk-win32-2.0 \
		-lgdk_pixbuf-2.0

include $(GAIM_COMMON_RULES)

##
## TARGET DEFINITIONS
##
.PHONY: all clean clean_exe

./win32/gaimrc.rc: ./win32/gaimrc.rc.in $(GAIM_TOP)/VERSION
	sed -e 's/@GAIM_VERSION@/$(GAIM_VERSION)/g' \
	    -e 's/@ORIGINAL_FILENAME@/$(EXE_NAME)/' \
	    $@.in > $@

all: $(EXE_TARGET).exe $(GTKGAIM_TARGET).dll
	$(MAKE) -C $(GAIM_GTK_PLUGINS_TOP) -f $(GAIM_WIN32_MAKEFILE)

install: all $(GAIM_INSTALL_DIR)
	$(MAKE) -C $(GAIM_GTK_PLUGINS_TOP) -f $(GAIM_WIN32_MAKEFILE) install
	$(MAKE) -C $(GAIM_GTK_PIXMAPS_TOP) -f $(GAIM_WIN32_MAKEFILE) install
	$(MAKE) -C $(GAIM_GTK_SOUNDS_TOP) -f $(GAIM_WIN32_MAKEFILE) install
	$(MAKE) -C $(GAIM_GTK_IDLETRACK_TOP) -f $(GAIM_WIN32_MAKEFILE) install
	cp $(EXE_TARGET).exe $(GTKGAIM_TARGET).dll $(GAIM_INSTALL_DIR)
	cp $(NEEDED_DLLS) $(GAIM_INSTALL_DIR)

./win32/gtkgaimrc.rc: ./win32/gtkgaimrc.rc.in $(GAIM_TOP)/VERSION
	sed -e 's/@GAIM_VERSION@/$(GAIM_VERSION)/g' \
	    $@.in > $@

$(EXE_OBJECTS) $(GTKGAIM_OBJECTS): $(GAIM_CONFIG_H)

$(GTKGAIM_TARGET).dll $(GTKGAIM_TARGET).dll.a: $(GAIM_LIBGAIM_DLL).a $(GAIM_IDLETRACK_DLL).a $(GTKGAIM_OBJECTS)
	$(CC) -shared $(GTKGAIM_OBJECTS) $(LIB_PATHS) $(GTKGAIM_LIBS) $(DLL_LD_FLAGS) -Wl,--out-implib,$(GTKGAIM_TARGET).dll.a -o $(GTKGAIM_TARGET).dll

$(EXE_TARGET).exe: $(GAIM_CONFIG_H) $(GAIM_GTKGAIM_DLL).a $(GAIM_IDLETRACK_DLL).a $(EXE_OBJECTS)
	$(CC) $(LDFLAGS) $(EXE_OBJECTS) -o $(EXE_TARGET).exe

$(EXE_TARGET)-portable.exe: DEFINES += -DPORTABLE
$(EXE_TARGET)-portable.exe: EXE_NAME := $(EXE_TARGET)-portable.exe
$(EXE_TARGET)-portable.exe: clean_exe $(GAIM_CONFIG_H) $(GAIM_GTKGAIM_DLL).a $(GAIM_IDLETRACK_DLL).a $(EXE_OBJECTS)
	$(CC) $(LDFLAGS) $(EXE_OBJECTS) -o $(EXE_TARGET)-portable.exe
	$(MAKE) -f $(GAIM_WIN32_MAKEFILE) clean_exe

##
## CLEAN RULES
##
clean:
	$(MAKE) -C $(GAIM_GTK_IDLETRACK_TOP) -f $(GAIM_WIN32_MAKEFILE) clean
	$(MAKE) -C $(GAIM_GTK_PLUGINS_TOP) -f $(GAIM_WIN32_MAKEFILE) clean
	rm -f $(GTKGAIM_OBJECTS) $(GTKGAIM_RC_SRC) $(EXE_OBJECTS) $(EXE_RC_SRC)
	rm -f $(GTKGAIM_TARGET).dll $(GTKGAIM_TARGET).dll.a
	rm -f $(EXE_TARGET).exe $(EXE_TARGET)-portable.exe

clean_exe:
	rm -f $(EXE_OBJECTS) $(EXE_RC_SRC)

include $(GAIM_COMMON_TARGETS)
