# (C) 2003 XDA Developers  itsme@xs4all.nl
#
# $Header$
#
out=../build
obj=../build/w32
DEBUG=1
include ../local.mak

ccdefs=/D WIN32 /D NDEBUG /D _CONSOLE /D _WIN32 /D _WIN32_WINNT=0x501
ccdefs+=/D _CRT_SECURE_NO_WARNINGS /D _SECURE_SCL=0 /D _HAS_ITERATOR_DEBUGGING=0
# _WIN32  is needed by commctrl.h to define the correct system window classnames
# _WIN32_WINNT  is needed by commctrl.h to get various defines

ccincs=/I "$(mssdk)\include" /I "$(vc8)/include" /I "$(ActiveSyncSupport)/inc" /I "../dll" /I "../include" /I "../common"

ccincs+=/I c:/local/wtl80beta1/include
ccincs+=/I "$(vc8)/atlmfc/include"
ccincs+=/I $(BOOST)

#   - add '/Zi' when debugging is needed
#   vc8:  /analyze
cflags=/nologo /Wall /EHsc
cflags+=/wd4060 /wd4100 /wd4217 /wd4265 /wd4505 /wd4512 /wd4514 /wd4548 /wd4619 /wd4625 /wd4626 /wd4668 /wd4702 /wd4710 /wd4820
#  4127 : conditional expression is constant
#  4061 : enumerate .. in switch not explicitly handled
#  4711 : function selected for automatic inline expansion
#   - add '/debug' when debugging is needed
ldflags=/nologo /incremental:no
ifdef DEBUG
#ccdefs+=/D _DEBUG
ldflags+=/debug /map
cflags+=/Zi
else
cflags+=/O2
endif

libpaths= /libpath:"$(mssdk)/lib" /libpath:"$(vc8)/lib" /libpath:"$(ActiveSyncSupport)/lib"
extralibs=rapi.lib user32.lib  advapi32.lib crypt32.lib

libpaths+= /libpath:"$(vc8)\atlmfc\lib"

.SUFFIXES:
.SUFFIXES: .cpp .obj .exe
vpath .cpp ../common ../src .

$(obj)/%.obj: %.cpp
	@"$(w32cc)" $(cflags) /c $(ccdefs) $(ccincs) $< /Fo"$(obj)/"
$(obj)/%.obj: ../common/%.cpp
	@"$(w32cc)" $(cflags) /c $(ccdefs) $(ccincs) $< /Fo"$(obj)/"
$(obj)/%.obj: ../src/%.cpp
	@"$(w32cc)" $(cflags) /c $(ccdefs) $(ccincs) $< /Fo"$(obj)/"

$(out)/%.exe: $(obj)/%.obj
	@"$(w32ld)" $(ldflags) $(libpaths) $(extralibs) $^ /out:$@

all: $(obj) all2

debug:
	make DEBUG=1

$(obj):
	mkdir -p $(obj)

#################################

define buildtarget

APPLIST+=$1
CLEANLIST+=$(out)/$1
CLEANLIST+=$(basename $(out)/$1).pdb
CLEANLIST+=$(basename $(out)/$1).map
CLEANLIST+=$(addprefix $(obj)/,$2)

$(out)/$1: $(addprefix $(obj)/,$2)

endef

define buildrules

$(call buildtarget,testgrammar.exe,testgrammar.obj checkdll.obj debug.obj stringutils.obj)
$(call buildtarget,kernelbrowser.exe,kernelbrowser.obj checkdll.obj debug.obj stringutils.obj cinfomap.obj tvn_debug.obj typeinfo.obj)

endef

$(eval $(buildrules))

all2:  $(addprefix $(out)/,$(APPLIST))


clean:
	rm -f $(CLEANLIST)

test:
	-rm kernelbrowser.log
	-pskill kernelbrowser.exe
	../build/kernelbrowser.exe
