##############################################################################
#
#           Copyright (c)2008 Geovariances, Avon, France.
#
#   In consideration  of payment of  the license fee,  which is a part of
#   the price you  paid for this  product, Geovariances (GV) as licensor,
#   grants you, the licensee, a non-exclusive right to use this copy of a
#   GV software product.
#   GV reserves all rights not  expressly granted to licensee. GV retains
#   titleship and ownership  of software.  This license is not  a sale of
#   the original  software or any  copy. GV also  retains  titleship  and
#   ownership of any modifications or  derivations of this software.  Any
#   modifications of this software  must be clearly marked as such.  This
#   copyright message must  appear in its entirety  in this software,  or
#   any modifications or derivations thereof.
#
#   Geovariances welcomes any comments, suggestions, bug reports, etc. At
#   the discretion  of Geovariances,  any customer  supplied  bug  fixes,
#   enhancements, or utility codes will be distributed in future software
#   releases (the contributor will of course be credited). 
#   
#           Geovariances
#           49bis, Avenue Franklin Roosevelt
#           77210 Avon, FRANCE
#
#            Phone: +33-(0)-160.749.100
#              Fax: +33-(0)-164.228.728
#           e-mail: support@geovariances.fr
#
#                       All Rights Reserved
#
##############################################################################

# This file is a GNU Makefile. Needs GNU make to compile.

ifeq ($(origin GTX_ARCH),undefined)
stop_now:
	@echo "Undefined variable GTX_ARCH (should be winnt or winnt64)"
endif

# Get the list of files
DEPTH = ../..
SOURCES1   = $(wildcard *.cs)
SOURCES2   = $(SOURCES1:AssemblyInfo.cs=)
SOURCES3   = $(SOURCES2:%PINVOKE.cs=)
BASE_SOURCES = $(SOURCES3) AssemblyInfo.cs
RELEASE_SOURCES = $(BASE_SOURCES) GTXClient_ReleaseWrapperPINVOKE.cs
DEBUG_SOURCES = $(BASE_SOURCES) GTXClient_DebugWrapperPINVOKE.cs

LIB_OUT       = $(DEPTH)/lib/$(GTX_ARCH)/shared/GTXClient.Net.dll
LIB_OUT_DEBUG = $(DEPTH)/lib/$(GTX_ARCH)/shared/GTXClient_debug.Net.dll
mywindir=$(subst \,/,$(WINDIR))
CSC=$(subst \,/,$(WINDIR))/Microsoft.NET/Framework/v2.0.50727/csc.exe /unsafe

# Special Geovariances Target
ifneq ($(origin PROJECT_HOME), undefined)
include $(PROJECT_HOME)/config/common.mk
ifeq ($(BUILD_MODE),release)
make-target: $(LIB_OUT)
else
make-target: $(LIB_OUT_DEBUG)
endif
endif

all: $(LIB_OUT)

debug: $(LIB_OUT_DEBUG)

$(LIB_OUT): $(RELEASE_SOURCES) GTXClient.snk
	echo "Building $(LIB_OUT)..."
	$(CSC) /t:library /out:$(LIB_OUT) $(RELEASE_SOURCES)

$(LIB_OUT_DEBUG): $(DEBUG_SOURCES) GTXClient.snk
	echo "Building $(LIB_OUT_DEBUG)..."
	$(CSC) /debug /t:library /optimize+ /out:$(LIB_OUT_DEBUG) $(DEBUG_SOURCES)

# Special Geovariances Target
ifneq ($(origin PROJECT_HOME), undefined)

# Special Geovariances Target
AssemblyInfo.cs: AssemblyInfo.cs.template $(DEPTH)/module.mk
	sed -e 's/X\.X\.X\./$(MODULE_VERSION).$(MODULE_REVISION).$(MODULE_PATCH)./' < $< > $@

GTXClient_ReleaseWrapperPINVOKE.cs: GTXClientWrapperPINVOKE.cs
	sed -e 's/XXGTXClientXX/GTXClient/' < $< > $@

GTXClient_DebugWrapperPINVOKE.cs: GTXClientWrapperPINVOKE.cs
	sed -e 's/XXGTXClientXX/GTXClient_debug/' < $< > $@

endif
