#Copyright (C) 1997-2004 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.

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

CHIPSOBJ=${CHIPDIR}/dsp1emu.o ${CHIPDIR}/fxemu2.o ${CHIPDIR}/sfxproc.o\
	${CHIPDIR}/fxemu2b.o ${CHIPDIR}/fxemu2c.o ${CHIPDIR}/fxtable.o\
        ${CHIPDIR}/sa1proc.o ${CHIPDIR}/sa1regs.o ${CHIPDIR}/dsp1proc.o\
        ${CHIPDIR}/st10proc.o ${CHIPDIR}/seta10.o ${CHIPDIR}/dsp2proc.o\
	${CHIPDIR}/sdd1emu.o

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

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

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

DOSOBJ= ${DOSDIR}/dosintrf.o ${DOSDIR}/gppro.o ${DOSDIR}/debug.o\
	${DOSDIR}/initvid.o ${DOSDIR}/modemrtn.o ${DOSDIR}/sw32.o\
	${DOSDIR}/joy.o ${DOSDIR}/sound.o ${DOSDIR}/sw.o ${DOSDIR}/vesa12.o\
	${DOSDIR}/vesa2.o ${DOSDIR}/zloader.o ${DOSDIR}/zsipx.o\
	${DOSDIR}/zfile.o

WINOBJ=${WINDIR}/copywin.o ${WINDIR}/winintrf.o ${WINDIR}/winlink.o\
	${WINDIR}/zloaderw.o ${WINDIR}/ztcp.o ${WINDIR}/zipxw.o

PREOBJ=${OBJDIR}/dosbuff.o ${OBJDIR}/ipx.o ${OBJDIR}/zipx.o

ZIPOBJ=${ZIPDIR}/unzip.o ${ZIPDIR}/zpng.o

EFFECTSOBJ=${EFFECTSDIR}/burn.o ${EFFECTSDIR}/water.o ${EFFECTSDIR}/smoke.o

JMAOBJ=${JMADIR}/7zlzma.o ${JMADIR}/crc32.o ${JMADIR}/iiostrm.o\
       ${JMADIR}/inbyte.o ${JMADIR}/jma.o ${JMADIR}/lzma.o ${JMADIR}/lzmadec.o\
       ${JMADIR}/winout.o ${JMADIR}/zsnesjma.o
       
MAINOBJ=cfgload.o endmem.o init.o initc.o uic.o patch.o ui.o vcache.o version.o


OBJS=${CHIPSOBJ} ${CPUOBJ} ${DOSOBJ} ${GUIOBJ} ${VIDEOBJ} ${PREOBJ} ${MAINOBJ} ${ZIPOBJ} ${EFFECTSOBJ} ${JMAOBJ}
LIBS=-lz -lm -lpng
CFLAGS=-O3 -march=i586 -fno-exceptions -ffast-math\
-fomit-frame-pointer -fno-unroll-loops -Wall -Wno-unused -D__MSDOS__
ASM=nasm
ASMFLAGS=-O1 -f coff -D__MSDOS__
CC=gcc
PP=gpp


.SUFFIXES: .c .cpp .asm

%.o: %.c
	${CC} ${CFLAGS} -o $@ -c $<

%.o: %.cpp
	${PP} ${CFLAGS} -fexceptions -o $@ -c $<

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

ALL: zsnes.exe

debug: zsnesd.exe

zsnes.exe: ${OBJS}
	${PP} -Ws -s -o zsnes.exe ${OBJS}  ${LIBS}

zsnesd.exe: ${OBJS}
	${PP} -Ws -o zsnesd.exe ${OBJS}  ${LIBS}

${DOSDIR}/zloader.o: ${DOSDIR}/zloader.c

${EFFECTSDIR}/water.o: ${EFFECTSDIR}/water.c ${EFFECTSDIR}/fixsin.h
${EFFECTSDIR}/smoke.o: ${EFFECTSDIR}/smoke.c
${EFFECTSDIR}/burn.o: ${EFFECTSDIR}/burn.c
${DOSDIR}/zfile.o: ${DOSDIR}/zfile.c
${ZIPDIR}/unzip.o: ${ZIPDIR}/unzip.c ${ZIPDIR}/zunzip.h
${ZIPDIR}/zpng.o: ${ZIPDIR}/zpng.c  ${ZIPDIR}/zpng.h
${VIDEODIR}/procvid.o: ${VIDEODIR}/procvid.asm macros.mac ${VIDEODIR}/copyvid.inc ${VIDEODIR}/2xSaImmx.inc
${CHIPDIR}/dsp1proc.o: ${CHIPDIR}/dsp1proc.asm macros.mac
${CHIPDIR}/sa1regs.o: ${CHIPDIR}/sa1regs.asm macros.mac\
	${CPUDIR}/regs.mac ${CPUDIR}/regsw.mac
${CHIPDIR}/sfxproc.o: ${CHIPDIR}/sfxproc.asm macros.mac\
	${CPUDIR}/regs.mac ${CPUDIR}/regsw.mac
${CHIPDIR}/dsp1emu.o: ${CHIPDIR}/dsp1emu.c
${CHIPDIR}/st10proc.o: ${CHIPDIR}/st10proc.asm
${CHIPDIR}/seta10.o: ${CHIPDIR}/seta10.c
${CHIPDIR}/sdd1emu.o: ${CHIPDIR}/sdd1emu.c
ui.o: ui.asm macros.mac
cfgload.o:cfgload.asm macros.mac
init.o:init.asm macros.mac
initc.o:initc.c ${JMADIR}/zsnesjma.h
uic.o:uic.c
patch.o:patch.c

ALL:
	del version.o
version.o:version.c

${DOSDIR}/debug.o: ${DOSDIR}/debug.asm macros.mac
${CPUDIR}/execute.o: ${CPUDIR}/execute.asm macros.mac
${CPUDIR}/table.o: ${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.o: ${CPUDIR}/tableb.asm ${CPUDIR}/65816db.inc\
	${CPUDIR}/address.inc ${CPUDIR}/addrni.inc ${CPUDIR}/e65816b.inc\
	${CPUDIR}/regs.mac macros.mac
${CPUDIR}/tablec.o: ${CPUDIR}/tablec.asm ${CPUDIR}/65816dc.inc\
	${CPUDIR}/address.inc ${CPUDIR}/addrni.inc ${CPUDIR}/e65816c.inc\
	${CPUDIR}/regs.mac macros.mac
${CPUDIR}/stable.o: ${CPUDIR}/stable.asm ${CPUDIR}/s65816d.inc\
	${CPUDIR}/saddress.inc ${CPUDIR}/saddrni.inc ${CPUDIR}/se65816.inc\
	macros.mac
${CPUDIR}/memory.o: ${CPUDIR}/memory.asm macros.mac
${CPUDIR}/dma.o: ${CPUDIR}/dma.asm macros.mac
${DOSDIR}/dosintrf.o: ${DOSDIR}/dosintrf.asm macros.mac
vcache.o:vcache.asm macros.mac
${DOSDIR}/initvid.o:${DOSDIR}/initvid.asm macros.mac ${DOSDIR}/vga.inc
${VIDEODIR}/makevid.o: ${VIDEODIR}/makevid.asm ${VIDEODIR}/vidmacro.mac\
	macros.mac
${VIDEODIR}/makev16b.o: ${VIDEODIR}/makev16b.asm ${VIDEODIR}/vidmacro.mac\
	macros.mac
${VIDEODIR}/makev16t.o: ${VIDEODIR}/makev16t.asm ${VIDEODIR}/vidmacro.mac\
	macros.mac
${VIDEODIR}/mv16tms.o: ${VIDEODIR}/mv16tms.asm ${VIDEODIR}/vidmacro.mac\
	macros.mac
${VIDEODIR}/mode7.o: ${VIDEODIR}/mode7.asm ${VIDEODIR}/mode7.mac\
	macros.mac
${VIDEODIR}/mode716.o: ${VIDEODIR}/mode716.asm ${VIDEODIR}/mode716.mac\
	macros.mac
${VIDEODIR}/mode716b.o:${VIDEODIR}/mode716b.asm ${VIDEODIR}/mode7.mac\
	macros.mac
${VIDEODIR}/mode716t.o:${VIDEODIR}/mode716t.asm ${VIDEODIR}/mode7.mac\
	macros.mac
${VIDEODIR}/mode716d.o:${VIDEODIR}/mode716d.asm ${VIDEODIR}/mode7.mac\
	macros.mac
${VIDEODIR}/mode7ext.o:${VIDEODIR}/mode7ext.asm macros.mac
${VIDEODIR}/mode716e.o:${VIDEODIR}/mode716e.asm macros.mac
${VIDEODIR}/m716text.o:${VIDEODIR}/m716text.asm ${VIDEODIR}/mode7.mac\
	macros.mac
${CPUDIR}/irq.o: ${CPUDIR}/irq.asm macros.mac
${CPUDIR}/dspproc.o: ${CPUDIR}/dspproc.asm macros.mac
${CPUDIR}/spc700.o:${CPUDIR}/spc700.asm macros.mac\
	${CPUDIR}/regsw.mac ${CPUDIR}/spcdef.inc ${CPUDIR}/spcaddr.inc
${CPUDIR}/dsp.o: ${CPUDIR}/dsp.asm macros.mac
${DOSDIR}/vesa2.o: ${DOSDIR}/vesa2.asm macros.mac
${DOSDIR}/vesa12.o: ${DOSDIR}/vesa12.asm macros.mac
${DOSDIR}/joy.o: ${DOSDIR}/joy.asm macros.mac
${DOSDIR}/sw.o: ${DOSDIR}/sw.asm macros.mac
${GUIDIR}/gui.o: ${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.o: ${GUIDIR}/menu.asm macros.mac
${VIDEODIR}/newgfx.o:${VIDEODIR}/newgfx.asm ${VIDEODIR}/vidmacro.mac\
	${VIDEODIR}/newgfx2.mac ${VIDEODIR}/newgfx.mac macros.mac
${VIDEODIR}/newgfx2.o:${VIDEODIR}/newgfx2.asm ${VIDEODIR}/newgfxwn.mac\
	${VIDEODIR}/newgfx.mac macros.mac
${VIDEODIR}/newgfx16.o: ${VIDEODIR}/newgfx16.asm macros.mac ${VIDEODIR}/vidmacro.mac\
	${VIDEODIR}/newgfx16.mac ${VIDEODIR}/newg162.mac
${VIDEODIR}/newg162.o: macros.mac ${VIDEODIR}/newg162.asm ${VIDEODIR}/newg162.mac\
	${VIDEODIR}/vidmacro.mac ${VIDEODIR}/newg16wn.mac
${CHIPDIR}/fxemu2.o: ${CHIPDIR}/fxemu2.asm ${CHIPDIR}/fxemu2.mac\
	macros.mac
${CHIPSDIR}/fxemu2b.o: ${CHIPDIR}/fxemu2b.asm ${CHIPDIR}/fxemu2.mac\
	${CHIPDIR}/fxemu2b.mac
${CHIPSDIR}/fxemu2c.o: ${CHIPDIR}/fxemu2c.asm macros.mac ${CHIPDIR}/fxemu2.mac\
	${CHIPDIR}/fxemu2b.mac ${CHIPDIR}/fxemu2c.mac
${CHIPDIR}/fxtable.o: ${CHIPDIR}/fxtable.asm macros.mac
${DOSDIR}/gppro.o: ${DOSDIR}/gppro.asm macros.mac
${DOSDIR}/zsipx.o: ${DOSDIR}/zsipx.asm
${CHIPDIR}/sa1proc.o: ${CHIPDIR}/sa1proc.asm macros.mac
endmem.o: endmem.asm macros.mac
${DOSDIR}/modemrtn.o: ${DOSDIR}/modemrtn.asm macros.mac

${JMADIR}/7zlzma.o: ${JMADIR}/7zlzma.cpp
${JMADIR}/crc32.o: ${JMADIR}/crc32.cpp ${JMADIR}/crc32.h
${JMADIR}/iiostrm.o: ${JMADIR}/iiostrm.cpp
${JMADIR}/inbyte.o: ${JMADIR}/inbyte.cpp
${JMADIR}/jma.o: ${JMADIR}/jma.cpp ${JMADIR}/jma.h ${JMADIR}/crc32.h ${JMADIR}/portable.h
${JMADIR}/lzma.o: ${JMADIR}/lzma.cpp
${JMADIR}/lzmadec.o: ${JMADIR}/lzmadec.cpp
${JMADIR}/winout.o: ${JMADIR}/winout.cpp
${JMADIR}/zsnesjma.o: ${JMADIR}/zsnesjma.cpp ${JMADIR}/zsnesjma.h ${JMADIR}/jma.h

clean:
	del *.o
	del ${CHIPDIR}\*.o
	del ${CPUDIR}\*.o
	del ${VIDEODIR}\*.o
	del ${GUIDIR}\*.o
	del ${DOSDIR}\*.o
	del ${ZIPDIR}\*.o
	del ${EFFECTSDIR}\*.o
	del ${JMADIR}\*.o
	del zsnes.exe



