#Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com )
#
#This program is free software; you can redistribute it and/or
#modify it under the terms of the GNU General Public License
#as published by the Free Software Foundation; either
#version 2 of the License, or (at your option) any later
#version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

#This file depends on link.win32 so if you modify this makefile, 
#don't forget to update link.win32
#it is quite ugly but without that trick, the compilation didn't
#work for me (command line too long)

#put the correct path to your directx sdk here
DXDIR=c:\mssdk

CHIPDIR=chips
CPUDIR=cpu
DOSDIR=dos
GUIDIR=gui
VIDEODIR=video
WINDIR=win
OBJDIR=obj
ZIPDIR=zip

CHIPSOBJ=${CHIPDIR}/sfxproc.obj ${CHIPDIR}/fxemu2.obj ${CHIPDIR}/dsp1proc.obj\
	 ${CHIPDIR}/fxemu2b.obj ${CHIPDIR}/fxemu2c.obj ${CHIPDIR}/fxtable.obj\
	 ${CHIPDIR}/sa1proc.obj ${CHIPDIR}/sa1regs.obj ${CHIPDIR}/dsp1emu.obj

CPUOBJ=${CPUDIR}/addrni.obj ${CPUDIR}/dma.obj ${CPUDIR}/dsp.obj ${CPUDIR}/dspproc.obj\
	${CPUDIR}/execute.obj ${CPUDIR}/irq.obj ${CPUDIR}/memory.obj\
	${CPUDIR}/spc700.obj ${CPUDIR}/stable.obj ${CPUDIR}/table.obj\
	${CPUDIR}/tableb.obj ${CPUDIR}/tablec.obj 

GUIOBJ=${GUIDIR}/gui.obj ${GUIDIR}/menu.obj

VIDEOBJ=${VIDEODIR}/makev16b.obj ${VIDEODIR}/makev16t.obj ${VIDEODIR}/makevid.obj\
	${VIDEODIR}/mode716.obj ${VIDEODIR}/mode716b.obj ${VIDEODIR}/mode716d.obj\
	${VIDEODIR}/mode716e.obj ${VIDEODIR}/mode716t.obj ${VIDEODIR}/mode7.obj\
	${VIDEODIR}/mode7ext.obj ${VIDEODIR}/mv16tms.obj ${VIDEODIR}/newg162.obj\
	${VIDEODIR}/newgfx16.obj ${VIDEODIR}/newgfx2.obj ${VIDEODIR}/newgfx.obj\
        ${VIDEODIR}/m716text.obj ${VIDEODIR}/2xsaiw.obj\
	${VIDEODIR}/procvid.obj

WINOBJ=${WINDIR}/copyvwin.obj ${WINDIR}/winintrf.obj ${WINDIR}/winlink.obj\
	${WINDIR}/zloaderw.obj ${WINDIR}/ztcp.obj ${WINDIR}/zipxw.obj\
	${WINDIR}/zfilew.obj

WINDOSOBJ=${DOSDIR}/debug.obj ${DOSDIR}/joy.obj ${DOSDIR}/modemrtn.obj ${DOSDIR}/vesa2.obj\
	${DOSDIR}/initvid.obj ${DOSDIR}/sw.obj ${DOSDIR}/gppro.obj ${DOSDIR}/vesa12.obj\
        ${DOSDIR}/zsipx.obj

PREOBJ=

ZIPOBJ=${ZIPDIR}/zzip.obj ${ZIPDIR}/unzip.obj ${ZIPDIR}/zpng.obj

MAINOBJ=cfgload.obj endmem.obj fixsin.obj init.obj ui.obj vcache.obj water.obj

OBJS=${CHIPSOBJ} ${CPUOBJ} ${WINOBJ} ${GUIOBJ} ${VIDEOBJ} ${ZIPOBJ} ${MAINOBJ} ${WINDOSOBJ}
LIBS=
CFLAGS=/O2b2t /G6 /c /D__WIN32__
ASM=nasm
ASMFLAGS=-f win32 -D__WIN32__
CC=cl

.SUFFIXES: .c .cpp .asm 
	
%.obj : %.c
	${CC} ${CFLAGS} /Fo$@ $<

%.obj: %.cpp
	${CC} ${CFLAGS} /Fo$@ $<

%.obj: %.asm
	${ASM} ${ASMFLAGS} -o $@ $<

ALL: zsnesw.exe

zsnesw.exe: ${OBJS} ${WINDIR}/zsnes.res
	cl @link.win32 ${WINDIR}/zsnes.res /link /libpath:${DXDIR}\lib

${WINDIR}/zsnes.res: ${WINDIR}/zsnes.rc
	rc ${WINDIR}/zsnes.rc
${WINDIR}/copyvwin.obj: ${WINDIR}/copyvwin.asm macros.mac
${WINDIR}/winintrf.obj: ${WINDIR}/winintrf.asm macros.mac
${WINDIR}/zfilew.obj: ${WINDIR}/zfilew.c
${WINDIR}/zipxw.obj: ${WINDIR}/zipxw.c
${WINDIR}/zloaderw.obj: ${WINDIR}/zloaderw.c
${WINDIR}/ztcp.obj: ${WINDIR}/ztcp.c
${WINDIR}/winlink.obj: ${WINDIR}/winlink.cpp ${WINDIR}/resource.h
${ZIPDIR}/unzip.obj: ${ZIPDIR}/unzip.c ${ZIPDIR}/unzip.h 
${ZIPDIR}/zzip.obj: ${ZIPDIR}/zzip.c ${ZIPDIR}/unzip.h
${ZIPDIR}/zpng.obj: ${ZIPDIR}/zpng.c  ${ZIPDIR}/zpng.h ${ZIPDIR}/png.h
${DOSDIR}/initvid.o:${DOSDIR}/initvid.asm macros.mac
${DOSDIR}/modemrtn.o: ${DOSDIR}/modemrtn.asm macros.mac
${DOSDIR}/zsipx.o: ${DOSDIR}/zsipx.asm
${DOSDIR}/debug.obj: ${DOSDIR}/debug.asm macros.mac
${DOSDIR}/joy.obj: ${DOSDIR}/joy.asm macros.mac
${DOSDIR}/vesa2.obj: ${DOSDIR}/vesa2.asm macros.mac
${DOSDIR}/gppro.o: ${DOSDIR}/gppro.asm macros.mac
${DOSDIR}/sw.o: ${DOSDIR}/sw.asm macros.mac
${DOSDIR}/vesa12.o: ${DOSDIR}/vesa12.asm macros.mac
fixsin.obj: fixsin.c
water.obj: water.c
${VIDEODIR}/2xsaiw.obj: ${VIDEODIR}/2xsaiw.asm macros.mac
${VIDEODIR}/procvid.obj: ${VIDEODIR}/procvid.asm macros.mac ${VIDEODIR}/copyvid.inc ${VIDEODIR}/2xSaImmx.inc
${CHIPDIR}/sa1regs.obj: ${CHIPDIR}/sa1regs.asm macros.mac\
	${CPUDIR}/regs.mac ${CPUDIR}/regsw.mac
${CHIPDIR}/sfxproc.obj: ${CHIPDIR}/sfxproc.asm macros.mac\
	${CPUDIR}/regs.mac ${CPUDIR}/regsw.mac

${CHIPDIR}/dsp1emu.obj: ${CHIPDIR}/dsp1emu.c betauser.mac
	${CC} ${CFLAGS} /Fo$@ $<
${CHIPDIR}/dsp1proc.obj: ${CHIPDIR}/dsp1proc.asm macros.mac
ui.obj: ui.asm macros.mac betauser.mac
cfgload.obj:cfgload.asm macros.mac
init.obj:init.asm macros.mac
${DOSDIR}/debug.obj: ${DOSDIR}/debug.asm macros.mac
${CPUDIR}/addrni.obj: ${CPUDIR}/addrni.asm
${CPUDIR}/execute.obj: ${CPUDIR}/execute.asm macros.mac
${CPUDIR}/table.obj: ${CPUDIR}/table.asm ${CPUDIR}/65816d.inc\
	${CPUDIR}/address.inc ${CPUDIR}/addrni.inc ${CPUDIR}/e65816.inc\
	${CPUDIR}/regs.mac ${CPUDIR}/regs.inc ${CPUDIR}/regsw.mac\
	${CPUDIR}/regsw.inc macros.mac
${CPUDIR}/tableb.obj: ${CPUDIR}/tableb.asm ${CPUDIR}/65816db.inc\
	${CPUDIR}/address.inc ${CPUDIR}/addrni.inc ${CPUDIR}/e65816b.inc\
	${CPUDIR}/regs.mac macros.mac
${CPUDIR}/tablec.obj: ${CPUDIR}/tablec.asm ${CPUDIR}/65816dc.inc\
	${CPUDIR}/address.inc ${CPUDIR}/addrni.inc ${CPUDIR}/e65816c.inc\
	${CPUDIR}/regs.mac macros.mac
${CPUDIR}/stable.obj: ${CPUDIR}/stable.asm ${CPUDIR}/s65816d.inc\
	${CPUDIR}/saddress.inc ${CPUDIR}/saddrni.inc ${CPUDIR}/se65816.inc\
	macros.mac
${CPUDIR}/memory.obj: ${CPUDIR}/memory.asm macros.mac
${CPUDIR}/dma.obj: ${CPUDIR}/dma.asm macros.mac
${DOSDIR}/dosintrf.obj: ${DOSDIR}/dosintrf.asm macros.mac
vcache.obj:vcache.asm macros.mac
${DOSDIR}/initvid.obj:${DOSDIR}/initvid.asm macros.mac
${VIDEODIR}/makevid.obj: ${VIDEODIR}/makevid.asm ${VIDEODIR}/vidmacro.mac\
	macros.mac
${VIDEODIR}/makev16b.obj: ${VIDEODIR}/makev16b.asm ${VIDEODIR}/vidmacro.mac\
	macros.mac
${VIDEODIR}/makev16t.obj: ${VIDEODIR}/makev16t.asm ${VIDEODIR}/vidmacro.mac\
	macros.mac
${VIDEODIR}/mv16tms.obj: ${VIDEODIR}/mv16tms.asm ${VIDEODIR}/vidmacro.mac\
	macros.mac
${VIDEODIR}/mode7.obj: ${VIDEODIR}/mode7.asm ${VIDEODIR}/mode7.mac\
	macros.mac
${VIDEODIR}/mode716.obj: ${VIDEODIR}/mode716.asm ${VIDEODIR}/mode716.mac\
	macros.mac
${VIDEODIR}/mode716b.obj:${VIDEODIR}/mode716b.asm ${VIDEODIR}/mode7.mac\
	macros.mac
${VIDEODIR}/mode716t.obj:${VIDEODIR}/mode716t.asm ${VIDEODIR}/mode7.mac\
	macros.mac
${VIDEODIR}/mode716d.obj:${VIDEODIR}/mode716d.asm ${VIDEODIR}/mode7.mac\
	macros.mac
${VIDEODIR}/mode7ext.obj:${VIDEODIR}/mode7ext.asm macros.mac
${VIDEODIR}/mode716e.obj:${VIDEODIR}/mode716e.asm macros.mac
${VIDEODIR}/m716text.obj:${VIDEODIR}/m716text.asm ${VIDEODIR}/mode7.mac\
	macros.mac
${CPUDIR}/irq.obj: ${CPUDIR}/irq.asm macros.mac
${CPUDIR}/dspproc.obj: ${CPUDIR}/dspproc.asm macros.mac
${CPUDIR}/spc700.obj:${CPUDIR}/spc700.asm macros.mac\
	${CPUDIR}/regsw.mac ${CPUDIR}/spcdef.inc ${CPUDIR}/spcaddr.inc
${CPUDIR}/dsp.obj: ${CPUDIR}/dsp.asm macros.mac
${DOSDIR}/vesa2.obj: ${DOSDIR}/vesa2.asm macros.mac
${DOSDIR}/vesa12.obj: ${DOSDIR}/vesa12.asm macros.mac
${DOSDIR}/joy.obj: ${DOSDIR}/joy.asm macros.mac
${DOSDIR}/sw.obj: ${DOSDIR}/sw.asm macros.mac
${GUIDIR}/gui.obj: ${GUIDIR}/gui.asm ${GUIDIR}/guitools.inc\
	${GUIDIR}/guimisc.inc ${GUIDIR}/guimouse.inc ${GUIDIR}/guiwindp.inc\
	${GUIDIR}/guinetpl.inc ${GUIDIR}/guikeys.inc ${GUIDIR}/guicheat.inc\
	${GUIDIR}/guicombo.inc ${GUIDIR}/guiload.inc macros.mac
${GUIDIR}/menu.obj: ${GUIDIR}/menu.asm macros.mac
${VIDEODIR}/newgfx.obj:${VIDEODIR}/newgfx.asm ${VIDEODIR}/vidmacro.mac\
	${VIDEODIR}/newgfx2.mac ${VIDEODIR}/newgfx.mac macros.mac
${VIDEODIR}/newgfx2.obj:${VIDEODIR}/newgfx2.asm ${VIDEODIR}/newgfxwn.mac\
	${VIDEODIR}/newgfx.mac macros.mac
${VIDEODIR}/newgfx16.obj: ${VIDEODIR}/newgfx16.asm macros.mac ${VIDEODIR}/vidmacro.mac\
	${VIDEODIR}/newgfx16.mac ${VIDEODIR}/newg162.mac
${VIDEODIR}/newg162.obj: macros.mac ${VIDEODIR}/newg162.asm ${VIDEODIR}/newg162.mac\
	${VIDEODIR}/vidmacro.mac ${VIDEODIR}/newg16wn.mac
${CHIPDIR}/fxemu2.obj: ${CHIPDIR}/fxemu2.asm ${CHIPDIR}/fxemu2.mac\
	macros.mac
${CHIPDIR}/fxemu2b.obj: ${CHIPDIR}/fxemu2b.asm ${CHIPDIR}/fxemu2.mac\
	${CHIPDIR}/fxemu2b.mac
${CHIPDIR}/fxemu2c.obj: ${CHIPDIR}/fxemu2c.asm macros.mac ${CHIPDIR}/fxemu2.mac\
	${CHIPDIR}/fxemu2b.mac ${CHIPDIR}/fxemu2c.mac
${CHIPDIR}/fxtable.obj: ${CHIPDIR}/fxtable.asm macros.mac
${DOSDIR}/gppro.obj: ${DOSDIR}/gppro.asm macros.mac
${DOSDIR}/zsipx.obj: ${DOSDIR}/zsipx.asm
${CHIPDIR}/sa1proc.obj: ${CHIPDIR}/sa1proc.asm macros.mac
endmem.obj: endmem.asm macros.mac
${DOSDIR}/modemrtn.obj: ${DOSDIR}/modemrtn.asm macros.mac

clean:
	del *.obj
	del ${CHIPDIR}\*.obj
	del ${CPUDIR}\*.obj
	del ${VIDEODIR}\*.obj
	del ${GUIDIR}\*.obj
	del ${WINDIR}\*.obj
	del ${WINDIR}\zsnes.res
	del ${ZIPDIR}\*.obj
	del ${DOSDIR}\*.obj
	del zsnesw.exe
	


