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

PIDGIN_TREE_TOP := ..
include $(PIDGIN_TREE_TOP)/libpurple/win32/global.mak

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

##
## VARIABLE DEFINITIONS
##
EXE_TARGET := pidgin
PIDGIN_TARGET := pidgin
EXE_NAME := $(EXE_TARGET).exe

WINAPP := -mwindows

LDFLAGS := $(WINAPP)

##
## INCLUDE PATHS
##
PURPLE_INCLUDE_PATHS =	\
			-I$(PURPLE_TOP) \
			-I$(PURPLE_TOP)/win32 \
			-I$(PIDGIN_TREE_TOP) \
			-I$(GTK_TOP)/include \
			-I$(GTK_TOP)/include/glib-2.0 \
			-I$(GTK_TOP)/lib/glib-2.0/include

INCLUDE_PATHS +=	\
			$(PURPLE_INCLUDE_PATHS) \
			-I$(PIDGIN_IDLETRACK_TOP) \
			-I$(PIDGIN_TOP) \
			-I$(PIDGIN_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)/include/cairo \
			-I$(GTK_TOP)/lib/gtk-2.0/include \
			-I$(GTKSPELL_TOP) \
			-I$(ASPELL_TOP)/include

LIB_PATHS +=		-L$(GTK_TOP)/lib \
			-L$(PURPLE_TOP) \
			-L$(PIDGIN_TOP) \
			-L$(PIDGIN_IDLETRACK_TOP) \
			-L$(ASPELL_TOP)/lib

##
##  SOURCES, OBJECTS
##
PIDGIN_C_SRC =	\
			gtkaccount.c \
			gtkblist.c \
			gtkcertmgr.c \
			gtkcellrendererexpander.c \
			gtkcellrendererprogress.c \
			gtkconn.c \
			gtkconv.c \
			gtkdebug.c \
			gtkdialogs.c \
			gtkdnd-hints.c \
			gtkdocklet.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 \
			gtkscrollbook.c \
			gtksmiley.c \
			gtksound.c \
			gtksourceiter.c \
			gtksourceundomanager.c \
			gtkstatusbox.c \
			gtkthemes.c \
			gtkutils.c \
			gtkwhiteboard.c \
			minidialog.c \
			pidginstock.c \
			pidgintooltip.c \
			win32/MinimizeToTray.c \
			win32/gtkdocklet-win32.c \
			win32/gtkwin32dep.c \
			win32/untar.c \
			win32/wspell.c

PIDGIN_RC_SRC = win32/pidgin_dll_rc.rc
PIDGIN_OBJECTS = $(PIDGIN_C_SRC:%.c=%.o) $(PIDGIN_RC_SRC:%.rc=%.o)

EXE_RC_SRC = win32/pidgin_exe_rc.rc
EXE_C_SRC = win32/winpidgin.c
EXE_OBJECTS = $(EXE_C_SRC:%.c=%.o) $(EXE_RC_SRC:%.rc=%.o)

##
## LIBRARIES
##

PIDGIN_LIBS =	\
		-lintl \
		-lglib-2.0 \
		-lgobject-2.0 \
		-lgthread-2.0 \
		-lpurple \
		-lz \
		-lidletrack \
		-lgtk-win32-2.0 \
		-latk-1.0 \
		-lpango-1.0 \
		-lgdk-win32-2.0 \
		-lgdk_pixbuf-2.0 \
		-lgdi32 \
		-lwinmm

include $(PIDGIN_COMMON_RULES)

##
## TARGET DEFINITIONS
##
.PHONY: all install install_shallow clean

all: $(EXE_TARGET).exe $(PIDGIN_TARGET).dll
	$(MAKE) -C $(PIDGIN_PLUGINS_TOP) -f $(MINGW_MAKEFILE)

win32/pidgin_exe_rc.rc: win32/pidgin_exe_rc.rc.in $(PIDGIN_TREE_TOP)/VERSION
	sed -e 's/@PIDGIN_VERSION@/$(PIDGIN_VERSION)/g' \
	    -e 's/@ORIGINAL_FILENAME@/$(EXE_NAME)/' \
	    $@.in > $@

install_shallow: $(PIDGIN_INSTALL_DIR) $(EXE_TARGET).exe $(PIDGIN_TARGET).dll
	cp $(EXE_TARGET).exe $(PIDGIN_TARGET).dll $(PIDGIN_INSTALL_DIR)
	cp $(NEEDED_DLLS) $(PIDGIN_INSTALL_DIR)

install: install_shallow all
	$(MAKE) -C $(PIDGIN_PLUGINS_TOP) -f $(MINGW_MAKEFILE) install
	$(MAKE) -C $(PIDGIN_PIXMAPS_TOP) -f $(MINGW_MAKEFILE) install
	$(MAKE) -C $(PIDGIN_IDLETRACK_TOP) -f $(MINGW_MAKEFILE) install

win32/pidgin_dll_rc.rc: win32/pidgin_dll_rc.rc.in $(PIDGIN_TREE_TOP)/VERSION
	sed -e 's/@PIDGIN_VERSION@/$(PIDGIN_VERSION)/g' \
	    $@.in > $@

$(EXE_OBJECTS) $(PIDGIN_OBJECTS): $(PIDGIN_CONFIG_H)

$(PIDGIN_TARGET).dll $(PIDGIN_TARGET).dll.a: $(PURPLE_DLL).a $(PIDGIN_IDLETRACK_DLL).a $(PIDGIN_OBJECTS)
	$(CC) -shared $(PIDGIN_OBJECTS) $(LIB_PATHS) $(PIDGIN_LIBS) $(DLL_LD_FLAGS) -Wl,--output-def,$(PIDGIN_TARGET).def,--out-implib,$(PIDGIN_TARGET).dll.a -o $(PIDGIN_TARGET).dll

$(EXE_TARGET).exe: $(PIDGIN_CONFIG_H) $(PIDGIN_DLL).a $(PIDGIN_IDLETRACK_DLL).a $(EXE_OBJECTS)
	$(CC) $(LDFLAGS) $(EXE_OBJECTS) -o $(EXE_TARGET).exe

##
## CLEAN RULES
##
clean:
	$(MAKE) -C $(PIDGIN_IDLETRACK_TOP) -f $(MINGW_MAKEFILE) clean
	$(MAKE) -C $(PIDGIN_PLUGINS_TOP) -f $(MINGW_MAKEFILE) clean
	$(MAKE) -C $(PIDGIN_PIXMAPS_TOP) -f $(MINGW_MAKEFILE) clean
	rm -f $(PIDGIN_OBJECTS) $(PIDGIN_RC_SRC) $(EXE_OBJECTS) $(EXE_RC_SRC)
	rm -f $(PIDGIN_TARGET).dll $(PIDGIN_TARGET).dll.a $(PIDGIN_TARGET).def
	rm -f $(EXE_TARGET).exe

include $(PIDGIN_COMMON_TARGETS)
