#------------------------------------------------------------
# IDAPython - Python plugin for Interactive Disassembler Pro
#
# Copyright (c) 2004-2005 Gergely Erdelyi <dyce@d-dome.net> 
#
# All rights reserved.
#
# For detailed copyright information see the file COPYING in
# the root of the distribution archive.
#------------------------------------------------------------
# makefile - makefile
#------------------------------------------------------------
VER_MAJOR = 0
VER_MINOR = 8
VER_PATCH = 0
VER_STATUS = beta

VERSION=$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH)

# Define default IDA version
ifndef IDAVERSION
	IDAVERSION=4.9
endif

IDAVERNAME=IDA$(IDAVERSION)
SYSTEM=$(shell uname)

ifeq ($(SYSTEM), WindowsNT)
	# Windows settings
	IDASDK=..\\swigsdk-versions\\$(IDAVERSION)
	IDALIB=$(IDASDK)\\libvc.w32\\ida.lib
	IDASDKINC=$(IDASDK)\\include
	PYTHONINC=c:\\python24\\include
	PYTHONLIB=c:\\python24\\libs\\python24.lib
	SWIG=c:\\tools\\swig\\swig.exe
	PLUGIN=python.plw
	DISTDIR=c:\\tmp\\IDAPython-$(VERSION)_$(IDAVERNAME)-win32
else
	# Linux settings
	IDASDK=../swigsdk-versions/$(IDAVERSION)
	IDASDKINC=$(IDASDK)/include
	PYTHONINC=/usr/include/python2.3
	PYTHONLIB=-lpython2.3
	PYTHONEXT=/usr/lib/python2.3/lib-dynload/*
	SWIG=swig
	PLUGIN=python.plx
	DISTDIR=IDAPython-$(VERSION)_$(IDAVERNAME)-linux
endif

SWIGFILES = \
	swig/bytes.i \
	swig/dbg.i \
	swig/diskio.i \
	swig/enum.i \
	swig/funcs.i \
	swig/idaapi.i \
	swig/ida.i \
	swig/idp.i \
	swig/kernwin.i \
	swig/lines.i \
	swig/loader.i \
	swig/name.i \
	swig/pro.i \
	swig/search.i \
	swig/struct.i \
	swig/typeconv.i \
	swig/ua.i

all: $(PLUGIN)

python.plx: idaapi_wrap.o python.o
	$(CXX) -shared -o $@ $+ $(PYTHONLIB) $(PYTHONEXT)

python.plw: idaapi_wrap.obj python.obj
	link $(IDALIB) $(PYTHONLIB) /nologo /dll /out:"python.plw" /export:PLUGIN $+

idaapi_wrap.cpp: $(SWIGFILES)
	$(SWIG) -Wall -o $@ -python -c++ -shadow -Iswig -I$(IDASDKINC) -D__GNUC__=1 idaapi.i

%.obj: %.cpp
	cl /Fo$@ /c $< /nologo /GX /I $(PYTHONINC) /I $(IDASDKINC) /D "WIN32" /D "_USRDLL" /D "__NT__" /D "__IDP__" /D MAXSTR=1024 /D VER_MAJOR=$(VER_MAJOR) /D VER_MINOR=$(VER_MINOR) /D VER_PATCH=$(VER_PATCH) /D VER_STATUS=\"$(VER_STATUS)\" /D USE_DANGEROUS_FUNCTIONS /D USE_STANDARD_FILE_FUNCTIONS

%.o:   %.cpp
	g++ -o $@ -c $< -I$(IDASDKINC) -I$(PYTHONINC) -D__LINUX__ -D__IDP__ -DMAXSTR=1024 -DVER_MAJOR=$(VER_MAJOR) -DVER_MINOR=$(VER_MINOR) -DVER_PATCH=$(VER_PATCH) -DVER_STATUS=\"$(VER_STATUS)\" -DUSE_DANGEROUS_FUNCTIONS -DUSE_STANDARD_FILE_FUNCTIONS

dist: $(PLUGIN) cleandist
	mkdir $(DISTDIR)
	cp README.txt COPYING.txt $(DISTDIR)
	cp CHANGES*.txt  $(DISTDIR)
	mkdir $(DISTDIR)/plugins
	cp $(PLUGIN) $(DISTDIR)/plugins/$(PLUGIN)
	mkdir $(DISTDIR)/python
	cp init.py idaapi.py idc.py	idautils.py $(DISTDIR)/python
	mkdir $(DISTDIR)/examples
	cp examples/* $(DISTDIR)/examples
	mkdir $(DISTDIR)/docs
	cp docs/* $(DISTDIR)/docs
	find $(DISTDIR) -type f -exec chmod 644 '{}' \; 
	find $(DISTDIR) -type d -exec chmod 755 '{}' \; 

cleandist:
	-rm -rf $(DISTDIR)
	-rmdir $(DISTDIR)


clean:
	-rm -f *.o *.obj
	-rm -f idaapi_wrap.cpp idaapi.py
	-rm -f python.plx python.plw idaapi.pyc
	-rm -f python.exp python.lib
	-rm -f *.pyc

