
#                TRACE32 Remote API
#      Copyright (c) 1998-2015 Lauterbach GmbH
#                All rights reserved
#
#              Visual Studio Makefile


#
#    Please use Microsoft Visual Studio  nmake
#
#
#    Select e.g. Start>All Programs>Microsoft Visual Studio 2010>Visual Studio Tools>Visual Studio Command Prompt(2010)
#    in order to open a shell for compiling the 32bit library version (t32tclapi.dll).
#
#    Select e.g. Start>All Programs>Microsoft Visual Studio 2010>Visual Studio Tools>Visual Studio x64 Win64 Command Prompt(2010)
#    in order to open a shell for compiling the 64bit library version (t32tclapi64.dll).
#
#
#    Remarks:
#      - recommended libs for 32bit build:
#        ....\Microsoft SDKs\Windows\v7.0A\Lib\User32.Lib
#        ....\Microsoft SDKs\Windows\v7.0A\Lib\ws2_32.Lib
#
#      - recommended libs for 64bit build:
#        ....\Microsoft SDKs\Windows\v7.0A\Lib\x64\User32.Lib
#        ....\Microsoft SDKs\Windows\v7.0A\Lib\x64\ws2_32.Lib
#
#      - This file needs the SWIG application. It can be obtained from http://prdownloads.sourceforge.net/swig/swigwin-3.0.5.zip
#      - You may need to adapt the SWIG path (SWIG)
#
#      - This file needs the TCL lib (TCLLIB) and headers (TCL_INCLUDES).
#      - TCL source can be obtained from http://www.tcl.tk/software/tcltk/download.html
#      - To compile TCL lib, follow instruction under <TCL directory>\win\README
#      - You may need to adapt the TCLPATH
#      - Current DLL are compiled with TCL version 8.6.4 (corresponding headers and lib included under this directory)
#
#
#

CC = cl /W3 /D_CRT_SECURE_NO_WARNINGS /Gs

!IFDEF DEBUG
OF     = debug
CFLAGS = /Od /Zi /Fd"$(OF)\vc80.pdb" /DDEBUG
LFLAGS = /DEBUG
!ELSE
OF     = release
CFLAGS = /Gd /Ot
LFLAGS =
!ENDIF

!IF "$(T32VC32BUILD)"!=""||"$(T32VC64BUILD)"!=""
# if called by compile.bat or compile64.bat
REMOVERECURSIVELY = RM -rf
!ELSE
REMOVERECURSIVELY = RMDIR /S /Q
!ENDIF

!IF EXIST(release)||EXIST(debug)||EXIST(t32_wrap.c)||EXIST(t32tclapi.dll)||EXIST(t32tclapi64.dll)
CLEAN = $(REMOVERECURSIVELY)
!IF EXIST(release)
CLEAN = $(CLEAN) release
!ENDIF
!IF EXIST(debug)
CLEAN = $(CLEAN) debug
!ENDIF
!IF EXIST(t32_wrap.c)
CLEAN = $(CLEAN) t32_wrap.c
!ENDIF
!IF EXIST(t32tclapi.dll)
CLEAN = $(CLEAN) t32tclapi.dll
!ENDIF
!IF EXIST(t32tclapi64.dll)
CLEAN = $(CLEAN) t32tclapi64.dll
!ENDIF
!ELSE
CLEAN = @echo nothing to clean
!ENDIF

TCLPATH  = .\tcl8.6.4
TCL_INCLUDES  = -I "$(TCLPATH)\generic"
!IF "$(PLATFORM)"=="x64"||"$(PLATFORM)"=="X64"
NAME                = t32tclapi64
TCLLIB        = $(TCLPATH)\win\release_amd64_vc10\tcl86t.lib
!ELSE
NAME                = t32tclapi
TCLLIB        = $(TCLPATH)\win\release_vc10\tcl86t.lib
!ENDIF
SEARCH = {.;..\capi\src\}

IFILE         = t32
INTERFACE     = $(IFILE).i
WRAPFILE      = $(IFILE)_wrap.c
SRCS          = hremote.c t32util.c hlinknet.c
SWIG          = C:\swigwin

# C compiler flags

CFLAGS    = /Z7 /Od /c /nologo

help:
	@echo.
	@echo. nmake help ... show this help
	@echo.
	@echo. nmake all .... same as "nmake rel"
	@echo.
	@echo. nmake rel .... build t32tclapi/t32tclapi64.dll depending on VS 32bit/64bit shell
	@echo.
	@echo. nmake dbg .... build t32tclapi/t32tclapi64.dll (with debug info)
	@echo.
	@echo. nmake clean .. delete all generated files (t32tclapi.dll, t32tclapi64.dll, t32_wrap.c) and working directories (.\release\ .\debug\)
	@echo.
	@echo.

rel: all

dbg:
	nmake DEBUG=1 /NOLOGO all

all: $(OF) $(OF)\$(NAME).dll
	copy $(OF)\$(NAME).dll $(NAME).dll
	copy $(OF)\$(NAME).lib $(NAME).lib
	copy $(OF)\$(NAME).exp $(NAME).exp
	$(REMOVERECURSIVELY) $(OF)
	$(REMOVERECURSIVELY) t32_wrap.c

$(OF):
	@if exist release $(REMOVERECURSIVELY) release
	@if exist debug   $(REMOVERECURSIVELY) debug
	MKDIR $@

$(OF)\$(NAME).dll:  $(OF)\hremote.obj $(OF)\hlinknet.obj $(OF)\t32util.obj $(OF)\t32_wrap.obj
	link  $(LFLAGS) /dll /out:"$@" $** user32.lib ws2_32.lib $(TCLLIB)

$(OF)\hremote.obj:  $(SEARCH)$$(@B).c $(SEARCH)t32.h makefile
	$(CC)  $(CFLAGS)  $(TCL_INCLUDES) /Fo$@ %s /DENABLE_NOTIFICATION /DDLL_BUILD

$(OF)\hlinknet.obj: $(SEARCH)$$(@B).c $(SEARCH)t32.h makefile
	$(CC) $(CFLAGS)  $(TCL_INCLUDES) /Fo$@ %s /DENABLE_NOTIFICATION /DDLL_BUILD

$(OF)\t32util.obj: $(SEARCH)$$(@B).c $(SEARCH)t32.h makefile
	$(CC) $(CFLAGS)  $(TCL_INCLUDES) /Fo$@ %s /DENABLE_NOTIFICATION /DDLL_BUILD

$(OF)\$(IFILE)_wrap.obj: $(IFILE)_wrap.c $(SEARCH)t32.h makefile
	$(CC) $(CFLAGS)  $(TCL_INCLUDES) /Fo$@ %s /DENABLE_NOTIFICATION /DDLL_BUILD

$(IFILE)_wrap.c:
	$(SWIG)\swig.exe -tcl  $(INTERFACE)

clean: extraclean

extraclean:
	$(CLEAN)
