
#
#      NMAKE makefile for building TRACE32 Remote API sample programs
#
#                 Please use Microsoft Visual Studio NMAKE
#
#  Select e.g. "Start > All Programs > Microsoft Visual Studio 2015 > Visual Studio Tools >
#  Visual Studio Command Prompt(2015)" in order to open a shell for compiling the various
#  demo applications. Recommended lib for linking: \Microsoft SDKs\Windows\v7.0A\Lib\User32.Lib
#
#
#  $Id: makefile 125547 2020-09-03 10:05:51Z irohloff $
#  $LastChangedRevision: 125547 $
#  $LastChangedBy: irohloff $
#
#  (c) Lauterbach GmbH
#


!IF DEFINED(PLATFORM)
! IF "$(PLATFORM)"!="X86"
!  ERROR 64bit Visual Studio Command Shell cannot be used for building demo executables, please use 32bit Visual Studio Command Shell
! ENDIF
!ENDIF

!IF EXIST(release)||EXIST(debug)
CLEAN = rd /S /Q
!IF EXIST(release)
CLEAN = $(CLEAN) release
!ENDIF
!IF EXIST(debug)
CLEAN = $(CLEAN) debug
!ENDIF
!ELSE
CLEAN =	@echo nothing to clean
!ENDIF

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

CC         = cl /c /Gs /w44996 /W3 -I"../src"
SEARCH     = {.;..\src}

help:
	@echo. nmake help ................... show this help
	@echo. nmake rel .................... build all executables (release version)
	@echo. nmake dbg .................... build all executables (debug version)
	@echo. nmake all .................... same as "nmake rel"
	@echo. nmake NETTCP=1 ^<rel^|dbg^|all^> . build executables with RemoteAPI via TCP
	@echo. nmake clean .................. delete working directories .\release and .\debug
	@echo.

!IFNDEF NETTCP
APITARGETS = t32rem.exe t32remtest.exe t32apicmd.exe t32apinotify.exe t32fdxhost.exe
RCLOBJS    = $(OF)\hremote.obj $(OF)\hlinknet.obj
$(OF)\t32rem.exe $(OF)\t32remtest.exe $(OF)\t32apicmd.exe $(OF)\t32apinotify.exe $(OF)\t32fdxhost.exe : $(OF)\$(@B).obj $(RCLOBJS)
	link  $(LFLAGS) /out:"$@" $** ws2_32.lib
!ELSE
APITARGETS = tcp_t32rem.exe tcp_t32remtest.exe tcp_t32apicmd.exe tcp_t32apinotify.exe tcp_t32fdxhost.exe
RCLOBJS    = $(OF)\hremote.obj $(OF)\t32nettcp.obj $(OF)\tcpsimple2.obj
$(OF)\tcp_t32rem.exe $(OF)\tcp_t32remtest.exe $(OF)\tcp_t32apicmd.exe $(OF)\tcp_t32apinotify.exe $(OF)\tcp_t32fdxhost.exe : $(OF)\$(@B:tcp_=).obj $(RCLOBJS)
	link  $(LFLAGS) /out:"$@" $** ws2_32.lib
!ENDIF

clean:
	$(CLEAN)

all:    $(APITARGETS)

rel:    all

dbg:
	nmake DEBUG=1 /NOLOGO all

$(OF):
	md $@

# the next rule allows to build an arbitrary executable also without the ".exe" prefix e.g. "nmake t32rem"
$(APITARGETS:.exe=) : $(@B).exe

$(APITARGETS) : $(OF)\$(@B).exe .phony
	copy $(OF)\$(@B).exe $(@B).exe

$(OF)\t32apicmd.obj $(OF)\t32fdxhost.obj $(OF)\t32rem.obj $(OF)\t32remtest.obj: $(@B).c $(SEARCH)t32.h makefile $(OF)
	$(CC) $(CFLAGS) /Fo$@ %s

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

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

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

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

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

.phony:
