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

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

DEFINES := $(subst -DWIN32_LEAN_AND_MEAN,,$(DEFINES))

##
## 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_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)/include/gtkspell-2.0

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

##
##  SOURCES, OBJECTS
##
PIDGIN_C_SRC =	\
			gtkaccount.c \
			gtkblist-theme-loader.c \
			gtkblist-theme.c \
			gtkblist.c \
			gtkcellrendererexpander.c \
			gtkcertmgr.c \
			gtkconn.c \
			gtkconv.c \
			gtkconv-theme.c \
			gtkconv-theme-loader.c \
			gtkdebug.c \
			gtkdialogs.c \
			gtkdnd-hints.c \
			gtkdocklet.c \
			gtkeventloop.c \
			gtkft.c \
			gtkicon-theme-loader.c \
			gtkicon-theme.c \
			gtkidle.c \
			gtkimhtml.c \
			gtkimhtmltoolbar.c \
			gtklog.c \
			gtkmain.c \
			gtkmedia.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 \
			gtkstatus-icon-theme.c \
			gtkstatusbox.c \
			gtkthemes.c \
			gtkutils.c \
			gtkwebview.c \
			gtkwebviewtoolbar.c \
			gtkwhiteboard.c \
			minidialog.c \
			pidginstock.c \
			pidgintooltip.c \
			smileyparser.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 \
		-lgtk-win32-2.0 \
		-latk-1.0 \
		-lcairo \
		-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)

install: install_shallow all
	$(MAKE) -C $(PIDGIN_PLUGINS_TOP) -f $(MINGW_MAKEFILE) install
	$(MAKE) -C $(PIDGIN_PIXMAPS_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_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 $(EXE_OBJECTS) $(PIDGIN_TARGET).dll
	$(CC) $(LDFLAGS) $(EXE_OBJECTS) -o $(EXE_TARGET).exe

##
## CLEAN RULES
##
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)
