################################### tell Emacs this is a -*- makefile-gmake -*-
#
# Copyright (C) 2012-2014 SIPE Project <http://sipe.sourceforge.net/>
#
# Makefile.mingw
#
# Author: pier11@operamail.com
# Author: zup@sbox.tugraz.at
# Date 11 Nov 2009
# Description: Top Makefile for win32 (mingw) port of LCS protocol plugin
#
###############################################################################

ifndef PIDGIN_TREE_TOP
# standalone MinGW build
export PIDGIN_TREE_TOP := ../pidgin-2.10.0
endif
include $(PIDGIN_TREE_TOP)/libpurple/win32/global.mak

export CFLAGS=-Werror

WIX3_HOME := /cygdrive/c/Program\ Files/Windows\ Installer\ XML\ v3
WXS_NAME := pidgin-sipe
export VERSION := $(shell cat VERSION)
PIDGIN_VERSION := $(shell cat $(PIDGIN_TREE_TOP)/VERSION)

.PHONY: all clean install msi dev devinst nsis

all:
	$(MAKE) -C src -f $(MINGW_MAKEFILE)
	$(MAKE) -C po -f $(MINGW_MAKEFILE)

dev:
	$(MAKE) -C src -f $(MINGW_MAKEFILE)

clean:
	$(MAKE) -C src -f $(MINGW_MAKEFILE) clean
	$(MAKE) -C po -f $(MINGW_MAKEFILE) clean
	rm -f $(WXS_NAME).wix*
	rm -f $(WXS_NAME)-$(VERSION).msi
	rm -f pidgin-sipe-$(VERSION).exe

rmbak:
	rm -f *~
	$(MAKE) -C src -f $(MINGW_MAKEFILE) rmbak

install: all
	$(MAKE) -C src -f $(MINGW_MAKEFILE) install
	$(MAKE) -C po -f $(MINGW_MAKEFILE) install
	$(MAKE) -C pixmaps -f $(MINGW_MAKEFILE) install

devinst: dev
	$(MAKE) -C src -f $(MINGW_MAKEFILE) install

tests: dev
	$(MAKE) -C src -f $(MINGW_MAKEFILE) tests

msi: all
	PACKAGE_VERSION=$(VERSION) $(WIX3_HOME)/bin/candle $(WXS_NAME).wxs
	$(WIX3_HOME)/bin/light $(WXS_NAME).wixobj
	mv $(WXS_NAME).msi $(WXS_NAME)-$(VERSION).msi

nsis: install
	makensis -DTREETOP=..\\pidgin-2.10.0 -DVERSION=$(VERSION) pidgin-sipe.nsi

# MinGW cross-compile build (see contrib/mingw-cross-compile/README.txt)
.PHONY: cross-compile-nsis
cross-compile-nsis:
	$(MAKE) -f Makefile.mingw install
	mv $(PIDGIN_INSTALL_DIR)/plugins $(PIDGIN_INSTALL_DIR)/purple-2
	perl contrib/opensuse-build-service/generate_nsi.pl po/LINGUAS \
		<contrib/opensuse-build-service/pidgin-sipe.nsi.template \
		>$(PIDGIN_INSTALL_DIR)/pidgin-sipe.nsi
	set -e; cd $(PIDGIN_INSTALL_DIR); \
	makensis \
		-DPIDGIN_VERSION=$(PIDGIN_VERSION) \
		-DVERSION=$(VERSION) \
		-DMINGW_LIBDIR=. \
		-DMINGW_DATADIR=. \
		pidgin-sipe.nsi
	mv $(PIDGIN_INSTALL_DIR)/pidgin-sipe-$(VERSION).exe $(PIDGIN_TREE_TOP)
	rm -rf $(PIDGIN_INSTALL_DIR)
