#**************************************************************************
# Project: Nintendo DS Emulator [dsemu]                                   *
# Author:  Imran Nazar, 2004                                              *
# File:    Makefile, Windows [Makefile.win]                               *
#**************************************************************************

CLPATH = D:\vc7
PSDKPATH = D:\vc7\psdk
INCFILES = /I$(CLPATH)\include /I$(PSDKPATH)\include
LIBFILES = /libpath:$(CLPATH)\lib /libpath:$(PSDKPATH)\lib

CC = cl /c /Ox /Yd /nologo $(INCFILES)
LINK = link /nologo $(LIBFILES)
LINKDBG = link /debug /nologo $(LIBFILES)
RC = rc $(INCFILES)
DELTREE = del /s /q

all: config.h dsemu.exe gba.dll ds.dll log.dll logfile

logfile:
	copy dsemu.ini ..\bin
	copy bioshack.bin ..\bin
	cd ..\bin && del *.lib *.exp *.ilk *.pdb

config.h:
	echo #define __CONFIG_H_ > config.h
	echo #define WORDS_BIGENDIAN 0 >> config.h
	echo #define DSEMU_VERSION_STR "DSemu v0.0.2g" >> config.h
	if not exist ..\bin mkdir ..\bin

dsemu.exe: main.obj main.res plugin.obj win.obj
	$(DELTREE) ..\bin
	$(LINKDBG) /out:..\bin\$@ $** kernel32.lib user32.lib gdi32.lib ole32.lib comdlg32.lib oleaut32.lib comctl32.lib winmm.lib shell32.lib

gba.dll: glgba.obj gba.res arm7x86.obj mmu.obj dma.obj int.obj arm7dasm.obj dbgout.obj gladius-gpu.obj unzip.obj
	$(LINKDBG) /dll /out:..\bin\$@ /def:gba.def $** opengl32.lib glu32.lib glaux.lib kernel32.lib gdi32.lib user32.lib

ds.dll: glds.obj ds.res arm7x86.obj dsmmu.obj dsdma.obj dsint.obj arm7dasm.obj dbgout.obj gladius-dsgpu.obj unzip.obj
	$(LINKDBG) /dll /out:..\bin\$@ /def:ds.def $** opengl32.lib glu32.lib glaux.lib kernel32.lib gdi32.lib user32.lib

log.dll: log.obj log.res
	$(LINKDBG) /dll /out:..\bin\$@ /def:log.def $** kernel32.lib user32.lib


main.obj: main.c log.h vtbl.h
	$(CC) main.c

plugin.obj: plugin.c plugin.h vtbl.h
	$(CC) plugin.c

win.obj: win.c win.h res.h
	$(CC) win.c

main.res: main.rc
	$(RC) main.rc

arm7dasm.obj: arm7dasm.c arm7dasm.h
	$(CC) arm7dasm.c

arm7.obj: arm7.c arm.h arm7.h arm7func.h vtbl.h defs.h cache.h
	$(CC) arm7.c

arm7x86.obj: arm7x86.c thumb7x86.c arm.h arm7.h arm7func.h vtbl.h defs.h cache.h
	$(CC) arm7x86.c

mmu.obj: mmu.c mmu.h vtbl.h defs.h cache.h
	$(CC) mmu.c

dsmmu.obj: dsmmu.c mmu.h vtbl.h defs.h cache.h
	$(CC) dsmmu.c

dma.obj: dma.c dma.h
	$(CC) dma.c

dsdma.obj: dsdma.c dma.h
	$(CC) dsdma.c

int.obj: int.c int.h
	$(CC) int.c

dsint.obj: dsint.c int.h
	$(CC) dsint.c

dbgout.obj: dbgout.c dbgout.h font5x7.h
	$(CC) dbgout.c

gba.obj: gba.c gba.h key.h ioreg.h
	$(CC) gba.c

glgba.obj: glgba.c gba.h key.h ioreg.h
	$(CC) glgba.c

ds.obj: ds.c gba.h key.h ioreg.h
	$(CC) ds.c

glds.obj: glds.c gba.h key.h ioreg.h
	$(CC) glds.c

gpu.obj: gpu.c gpu.h vtbl.h defs.h font5x7.h res.h
	$(CC) gpu.c

dsgpu.obj: dsgpu.c gpu.h vtbl.h defs.h font5x7.h res.h
	$(CC) dsgpu.c

gladius-gpu.obj: gladius-gpu.c gpu.h vtbl.h defs.h font5x7.h res.h
	$(CC) gladius-gpu.c

gladius-dsgpu.obj: gladius-dsgpu.c gpu.h vtbl.h defs.h font5x7.h res.h
	$(CC) gladius-dsgpu.c

unzip.obj: unzip.cpp unzip.h
	$(CC) unzip.cpp

gba.res: gba.rc
	$(RC) gba.rc

ds.res: ds.rc
	$(RC) ds.rc

log.obj: log.c log.h
	$(CC) log.c

log.res: log.rc
	$(RC) log.rc

clean:
	del config.h *.obj *.lib *.exp *.res
	$(DELTREE) ..\bin
	rmdir ..\bin

release:
	$(DELTREE) ..\bin
	$(LINK) /out:..\bin\dsemu.exe main.obj main.res plugin.obj win.obj kernel32.lib user32.lib gdi32.lib ole32.lib comdlg32.lib oleaut32.lib comctl32.lib winmm.lib shell32.lib
	$(LINK) /dll /def:gba.def /out:..\bin\gba.dll glgba.obj gba.res arm7x86.obj mmu.obj dma.obj int.obj arm7dasm.obj dbgout.obj gladius-gpu.obj unzip.obj opengl32.lib glu32.lib glaux.lib kernel32.lib gdi32.lib user32.lib
	$(LINK) /dll /def:ds.def  /out:..\bin\ds.dll glds.obj ds.res arm7x86.obj dsmmu.obj dsdma.obj dsint.obj arm7dasm.obj dbgout.obj gladius-dsgpu.obj unzip.obj opengl32.lib glu32.lib glaux.lib kernel32.lib gdi32.lib user32.lib
	$(LINK) /dll /def:log.def /out:..\bin\log.dll log.obj log.res kernel32.lib user32.lib
	copy dsemu.ini ..\bin
	copy bioshack.bin ..\bin

dist:
	rm -rf ../dsemu-0.0.2g ../dsemu-0.0.2g.zip
	mkdir -p ../dsemu-0.0.2g/src
	rm -f config.h
	cp arm.h arm7.h arm7func.h arm7.c arm7x86.c ../dsemu-0.0.2g/src
	cp defs.h mmu.c mmu.h log.c log.h main.c vtbl.h ../dsemu-0.0.2g/src
	cp Licence-BSD Makefile cache.h ../dsemu-0.0.2g/src
	cp unzip.cpp unzip.h unziplib.h ../dsemu-0.0.2g/src
	cp arm7dasm.c arm7dasm.h main.h ioreg.h dsioreg.h ../dsemu-0.0.2g/src
	cp gpu.c gpu.h gba.def gba.rc bioshack.asm ../dsemu-0.0.2g/src
	cp dbgout.c dbgout.h font5x7.h gba.c gba.h ../dsemu-0.0.2g/src
	cp win.c win.h res.h main.rc err.h emu.h ../dsemu-0.0.2g/src
	cp plugin.h plugin.c int.c dsint.c int.h bkpt.h ../dsemu-0.0.2g/src
	cp dma.c dma.h dsdma.c key.h log.rc log.def ../dsemu-0.0.2g/src
	cp dsabout.bmp ds16.ico ds32.ico ../dsemu-0.0.2g/src
	cp glgba.c glds.c ds.c ds.rc ds.def dsmmu.c dsgpu.c ../dsemu-0.0.2g/src
	cp gladius-gpu.c gladius-dsgpu.c thumb7x86.c ../dsemu-0.0.2g/src
	cp ../bin/dsemu.exe ../bin/dsemu.ini ../bin/gba.dll ../dsemu-0.0.2g
	cp ../bin/log.dll ../bin/bioshack.bin ../dsemu-0.0.2g
	cp ../bin/ds.dll README.txt ../dsemu-0.0.2g
	cd .. && zip -r dsemu-0.0.2g.zip dsemu-0.0.2g/
	cd .. && tar czvf dsemu-0.0.2g.tar.gz dsemu-0.0.2g/
	mkdir -p ../htmlfiles
	cp ../index.cgi ../shots.cgi ../code.html ../compat.html ../errors/err404.html ../htmlfiles
	sed s/dsemu-0.0.2f.zip/dsemu-0.0.2g.zip/g ../htmlfiles/index.cgi > ../index.cgi
	sed s/dsemu-0.0.2f.zip/dsemu-0.0.2g.zip/g ../htmlfiles/shots.cgi > ../shots.cgi
	sed s/dsemu-0.0.2f.zip/dsemu-0.0.2g.zip/g ../htmlfiles/code.html > ../code.html
	sed s/dsemu-0.0.2f.zip/dsemu-0.0.2g.zip/g ../htmlfiles/compat.html > ../compat.html
	sed s/dsemu-0.0.2f.zip/dsemu-0.0.2g.zip/g ../htmlfiles/err404.html > ../errors/err404.html
	rm -rf ../htmlfiles
	rm -rf ../dsemu-0.0.2g

demos:
	rm -rf ../dsemu-demos ../dsemu-demos.zip
	mkdir -p ../dsemu-demos/GBA ../dsemu-demos/DS
	cp ../fill1.bin ../sg_bump.bin ../copperbars.bin ../armwrestler.bin ../dsemu-demos/GBA
	cp ../leonard.gba ../lgtron.gba ../m5bump.gba ../walk3d.gba ../dsemu-demos/GBA
	cp ../sgtunnel/tunnel.bin ../oamtest.bin ../fontdisp.bin ../dsemu-demos/GBA
	cp ../testromz/afire.gba ../testromz/wstein.gba ../dsemu-demos/GBA
	cp ../dstests/2D_emu.bin ../dstests/TetrisARM9-TwoPlayer.bin ../dsemu-demos/DS
	cp ../dstests/PongDS.bin ../dstests/davr-arm9.bin ../dsemu-demos/DS
	cp ../dstests/0325/mines-arm9.bin ../dstests/0329/armwrestler.nds.arm9.bin ../dsemu-demos/DS
	cd .. && zip -r dsemu-demos.zip dsemu-demos/
	rm -rf ../dsemu-demos

#***EOF********************************************************************

