# MakeFile to compile via a Visual Studio 2010 environment
# Open a "Visual Studio Command Prompt" and compile with
#
#    nmake -f makefile.vs
#

COPTS = /c /W3 /Z7 /O2

DLL1 = {stm_print.dll
APPL2 = {create_fake_tpiu.exe
APPL3 = {pipe_read.exe
DLL4 = {itm_print.dll
DLL5 = {stpv1_print.dll

OBJECTS1 = {pipeproto} {stm_print} {mypipe}
OBJECTS2 = {create_fake_tpiu} {twp}
OBJECTS3 = {pipe_read} {mypipe}
OBJECTS4 = {pipeproto} {itm_print} {mypipe}
OBJECTS5 = {pipeproto} {stpv1_print} {mypipe}

# Enclosing the object names in {} means we can now replace 
# "{" with "vs32\" (or "vs64") and "}" with ".obj"

!if [if "%Platform%"=="x64" exit 11] != 11
!message 32 Bit Build
DLL1     = $(DLL1:{=vs32\)
OBJECTS1 = $(OBJECTS1:{=vs32\)

APPL2    = $(APPL2:{=vs32\)
OBJECTS2 = $(OBJECTS2:{=vs32\)

APPL3    = $(APPL3:{=vs32\)
OBJECTS3 = $(OBJECTS3:{=vs32\)

DLL4     = $(DLL4:{=vs32\)
OBJECTS4 = $(OBJECTS4:{=vs32\)

DLL5     = $(DLL5:{=vs32\)
OBJECTS5 = $(OBJECTS5:{=vs32\)

# create build directory if it does not exist
!if [if not exist vs32 mkdir vs32]
!endif

!else
!message 64 Bit Build

DLL1     = $(DLL1:{=vs64\)
OBJECTS1 = $(OBJECTS1:{=vs64\)

APPL2    = $(APPL2:{=vs64\)
OBJECTS2 = $(OBJECTS2:{=vs64\)

APPL3    = $(APPL3:{=vs64\)
OBJECTS3 = $(OBJECTS3:{=vs64\)

DLL4     = $(DLL4:{=vs64\)
OBJECTS4 = $(OBJECTS4:{=vs64\)

DLL5     = $(DLL5:{=vs64\)
OBJECTS5 = $(OBJECTS5:{=vs64\)

# create build directory if it does not exist
!if [if not exist vs64 mkdir vs64]
!endif

!endif

OBJECTS1 = $(OBJECTS1:}=.obj)
OBJECTS2 = $(OBJECTS2:}=.obj)
OBJECTS3 = $(OBJECTS3:}=.obj)
OBJECTS4 = $(OBJECTS4:}=.obj)
OBJECTS5 = $(OBJECTS5:}=.obj)

all: $(DLL1) $(APPL2) $(APPL3) $(DLL4) $(DLL5)

$(DLL1): $(OBJECTS1)
	link -dll -out:$@ $**

$(APPL2): $(OBJECTS2)
	link -out:$@ $**

$(APPL3): $(OBJECTS3)
	link -out:$@ $**

$(DLL4): $(OBJECTS4)
	link -dll -out:$@ $**

$(DLL5): $(OBJECTS5)
	link -dll -out:$@ $**

{src}.c{vs32}.obj:
	cl $(COPTS) /Fo$@ $<

{src}.c{vs64}.obj:
	cl $(COPTS) /Fo$@ $<

clean:
	rmdir /S /Q vs32 vs64

cleanmost:
	del /Q vs32\*.obj vs32\*.lib vs32\*.exp vs64\*.obj vs64\*.lib vs64\*.exp
