
CC = cl.exe
LD = link.exe

O = o$(O)

CFLAGS =  /nologo /c /Zi /D "WIN32" /D "_WIN32" $(CFLAGS)
LDFLAGS = /nologo /DEBUG /RELEASE /opt:ref /opt:icf
LIBS = $(LIBS) kernel32.lib lib\msvcrt_dll.lib lib\ntdll_dll.lib

MICROCRT_OBJS = \
	$(O)\ucrt.obj $(O)\ucrt_asm.obj $(O)\ucrt_math.obj \
	$(O)\ucrt_log.obj $(O)\_wstat64i32.obj $(O)\_stat64i32.obj

MICROCRT_WIN_OBJS = $(MICROCRT_OBJS) $(O)\ucrt_win.obj

MICROCRT_DLL_OBJS = $(MICROCRT_OBJS) $(O)\ucrt_dll.obj

MICROCRT_CONSOLE_OBJS = $(MICROCRT_OBJS) $(O)\ucrt_console.obj

TEST_WIN_APP = $(O)\test_win.exe

TEST_CONSOLE_APP = $(O)\test_console.exe

TEST_DLL = $(O)\test.dll

TEST_DLL_APP = $(O)\test_con_dll.exe

all: $(O) $(TEST_WIN_APP) $(TEST_CONSOLE_APP)

# $(TEST_DLL) $(TEST_DLL_APP)

$(O): force
	@if not exist $(O) mkdir $(O)

$(TEST_WIN_APP): $(O)\test_win.obj $(O)\test.obj $(MICROCRT_WIN_OBJS)
	$(LD) $(LDFLAGS) $** $(LIBS) /PDB:$*.pdb /OUT:$@

$(TEST_CONSOLE_APP): $(O)\test_console.obj $(O)\test.obj $(MICROCRT_CONSOLE_OBJS)
	$(LD) $(LDFLAGS) $** $(LIBS) /PDB:$*.pdb /OUT:$@

# ucrt directory
{src}.cpp{$(S)}.obj::
	$(CC) $(CFLAGS) /Fo$(O)\ /Fd$(O)\vc80.pdb $<

{src\mingw}.c{$(O)}.obj::
	$(CC) $(CFLAGS) /Fo$(O)\ /Fd$(O)\vc80.pdb $<

{test}.cpp{$(S)}.obj::
	$(CC) $(CFLAGS) /Fo$(O)\ /Fd$(O)\vc80.pdb $<

# http://msdn.microsoft.com/en-us/library/s0ksfwcf.aspx
{src}.asm{$(O)}.obj:
	ml /c /coff /Fo$(O)\ $<

force: ;

