# makefile for gnu/cygwin make, using msvc compiler,
# needs environment setup with 'vcvars32.bat' ( from vstudio )
#
# author: Willem Hengeveld <itsme@xs4all.nl>
# web: http://www.xs4all.nl/~itsme/projects/disassemblers/ida/idp-Makefile
#

idasdk=c:/local/ida570/idasdk

.SUFFIXES:
.SUFFIXES: .cpp .obj .plw

#   microsoft's headers are loaded with warnings:
#C4514: 'uint128::uint128' : unreferenced inline function has been removed
#C4710: function 'int __stdcall getreg(unsigned long,int)' not inlined
#C4244: '+=' : conversion from 'int' to 'unsigned short', possible loss of data
#C4242: '=' : conversion from 'int' to 'ushort', possible loss of data
#C4127: conditional expression is constant
#C4146: unary minus operator applied to unsigned type, result still unsigned
#C4820: '__stat64' : '4' bytes padding added after member '__stat64::st_rdev'
#C4217: member template functions cannot be used for copy-assignment or copy-construction
#C4668: '_MT' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'
#C4619: #pragma warning : there is no warning number '4284'
#C4511: copy constructor could not be generated
#C4512: assignment operator could not generated
#C4201: nonstandard extension used : nameless struct/union

# disabling them all, to get a more readable compiler output.
NOWARN=-wd4619 -wd4514 -wd4710 -wd4244 -wd4242 -wd4127 -wd4668 -wd4146 -wd4820 -wd4217 -wd4511 -wd4512 -wd4201

CDEFS=-DWIN32 -D_USRDLL -D__NT__ -D__IDP__ -DMAXSTR=1024
CINCS=-I $(idasdk)\include -I $(BOOST)
COPTS=-EHsc -GR -Gz -nologo  -Zi

LDLIBS=/libpath:$(idasdk)/lib/vc.w32  $(idasdk)/lib/vc.w32/ida.lib
LDFLAGS=/nologo /dll /export:PLUGIN  /debug /machine:x86 /subsystem:windows

# msvc 12.00 does not support -Wall yet -> use -W4.
# msvc 13.10 does support it.
#
%.obj: %.cpp
	@CL -c -Wall $(NOWARN) $(COPTS) $(CINCS) $(CDEFS) -Fo$@ $<

all: idcext.plw

idcext.plw: pluginreg.obj idcextensions.obj
	@LINK $(LDFLAGS) $(LDLIBS) $^ /out:$@ /map:idcext.map

pluginreg.obj: pluginreg.cpp
idcextensions.obj: idcextensions.cpp

clean:
	-rm *.lib *.exp *.obj *.exe *.dll *.plw *.pdb *.ilk *.map

install: idcext.plw
	@cp idcext.plw $(idasdk)/../plugins

test: install
	$(idasdk)/../idag.exe testcode/winhello.idb

zip:
	zip ida-idcext.zip idcextensions.h idcextensions.cpp Makefile pluginreg.cpp README.txt
