#
# makefile.vc - MSVC++ makefile for the C#/MapScript extension
#
# This VC++ makefile will build the PHP module CSHARP_MAPSCRIPT.DLL
#
# To use the makefile:
#  - Open a DOS prompt window
#  - Run the VCVARS32.BAT script to initialize the VC++ environment variables
#  - Start the build with:  nmake /f makefile.vc
#
# $Id: Makefile.vc,v 1.6 2006/08/26 19:42:24 tamas Exp $
#


# Flag indicating to the option files that this is the build of C#/MapScript
!INCLUDE ../../nmake.opt

# Be aware when setting different options for libmap.dll and mapscript.dll (Bug 1476)
# To change the options for mapscript.dll uncomment the following line
# otherwise the options of nmake.opt will be used
#OPTFLAGS =	/nologo /Zi /MD $(WARNING_LEVEL) $(DEBUG)
BASE_CFLAGS = 	$(OPTFLAGS) -DWIN32 -D_WIN32
#LDFLAGS =	/NODEFAULTLIB:msvcrt /NODEFAULTLIB:libcd /dll $(LDEBUG)
LDFLAGS =	/dll $(LDEBUG)
CFLAGS = 	$(BASE_CFLAGS) $(MS_CFLAGS) -I../.. 

CC=     cl
LINK=   link

!IFDEF MONO
CSC = mcs
!ELSE
CSC = csc
!ENDIF

#SWIG = swig

!IFDEF DLLBUILD
MS_LIBS = ../../mapserver_i.lib $(EXTERNAL_LIBS)
!ELSE
MS_LIBS = $(EXTERNAL_LIBS) ../../mapserver.lib
!ENDIF

#
# The rest of the file should not have to be edited...
#

MAPSCRIPT_OBJS =  mapscript_wrap.obj  
MAPSCRIPT_DLL =   mapscript.dll
CSHARP_DLL = mapscript_csharp.dll

default: 	all

all:		interface $(MAPSCRIPT_DLL) $(CSHARP_DLL)

interface: ../mapscript.i
	$(SWIG) -csharp $(MS_DEFS) -o mapscript_wrap.c ../mapscript.i

.c.obj:
	$(CC) $(CFLAGS) /DCOMPILE_DL=1 /c $*.c /Fo$*.obj	
		
$(MAPSCRIPT_DLL): $(MAPSCRIPT_OBJS)
	$(LINK) $(LDFLAGS) /out:$(MAPSCRIPT_DLL) $(MAPSCRIPT_OBJS) $(MS_LIBS)

$(CSHARP_DLL)::
	$(CSC) /t:library /out:mapscript_csharp.dll *.cs
	$(CSC) /r:mapscript_csharp.dll /out:shpdump.exe examples\shpdump.cs
	$(CSC) /r:mapscript_csharp.dll /out:drawmap.exe examples\drawmap.cs
	$(CSC) /r:mapscript_csharp.dll /out:shapeinfo.exe examples\shapeinfo.cs

test:
!IFDEF MONO
	mono shpdump.exe ../../tests/point.shp
	mono shapeinfo.exe ../../tests/point.shp
	mono drawmap.exe ../../tests/test.map test_csharp.png
!ELSE
	shpdump ../../tests/point.shp
	shapeinfo ../../tests/point.shp
	drawmap ../../tests/test.map test_csharp.png
!ENDIF
	

clean:
	del *.obj
	del *.dll
	del *.lib
	del *.pdb
	del *.exp
	del *.ilk
	del *.cs
	del *.c
	del *.exe

