# VC makefile for ANSICON.
# Jason Hood, 15 November, 2010.

# I've used Visual C++ 2008 Express for the 32-bit version and the 2003 R2
# Platform SDK for the 64-bit version.	Since these are entirely separate
# environments, define BITS to decide which should be built.  Note that the
# 64-bit version still requires the 32-bit ANSI32.dll, so both environments
# are required and you should build the 32-bit version before the 64-bit.

#BITS = 32
#BITS = 64

!IFNDEF BITS
BITS = 32
!ENDIF

!IF $(BITS) == 32
DIR = x86
!ELSE
!IF $(BITS) == 64
DIR = x64
!ELSE
!ERROR BITS should be defined to 32 or 64.
!ENDIF
!ENDIF

CC = cl
CFLAGS = /nologo /W3 /Ox /GF /D_CRT_SECURE_NO_WARNINGS
LIBS = advapi32.lib shell32.lib user32.lib

X86OBJS = x86\proctype.obj x86\injdll32.obj x86\debugstr.obj
X64OBJS = x64\proctype.obj x64\injdll64.obj x64\injdll32.obj x64\debugstr.obj

{}.c{$(DIR)}.obj:
	$(CC) /c $(CFLAGS) /Fo$@ $<

{}.rc{$(DIR)}.res:
	rc /fo$@ $<

all: ansicon$(BITS)

ansicon32: x86 x86\ansicon.exe x86\ANSI32.dll

ansicon64: x64 x64\ansicon.exe x64\ANSI64.dll x64\ANSI32.dll x64\ANSI-LLW.exe

x86:
	mkdir x86

x86\ansicon.exe: x86\ansicon.obj $(X86OBJS) x86\ansicon.res
	$(CC) /nologo /Fe$@ $** $(LIBS)

x86\ANSI32.dll: x86\ANSI.obj $(X86OBJS) x86\ansi.res
!IF $(BITS) == 32
	$(CC) /nologo /LD /Fe$@ $** $(LIBS)
!ENDIF

x64:
	mkdir x64

x64\ansicon.exe: x64\ansicon.obj $(X64OBJS) x64\ansicon.res
	$(CC) /nologo /Fe$@ $** $(LIBS) bufferoverflowu.lib

x64\ANSI64.dll: x64\ANSI.obj $(X64OBJS) x64\ansi.res
	$(CC) /nologo /LD /Fe$@ $** $(LIBS) bufferoverflowu.lib

x64\ANSI32.dll: x86\ANSI32.dll
	copy x86\ANSI32.dll x64\ANSI32.dll

x64\ANSI-LLW.exe: ANSI-LLW.c
	$(CC) $(CFLAGS) /Fe$@ /Fo$*.obj $? bufferoverflowu.lib

ansicon.c:  ansicon.h
ANSI.c:     ansicon.h
debugstr.c: ansicon.h
injdll32.c: ansicon.h
injdll64.c: ansicon.h
proctype.c: ansicon.h

clean:
	-del $(DIR)\*.obj $(DIR)\*.res $(DIR)\*.lib $(DIR)\*.exp