#Copyright (C) 1997-2005 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
#
#http://www.zsnes.com
#http://sourceforge.net/projects/zsnes
#
#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.

x86-64=@X8664@

CHIPDIR=chips
CPUDIR=cpu
DOSDIR=dos
EFFECTSDIR=effects
GUIDIR=gui
JMADIR=jma
NETDIR=net
TOOLSDIR=tools
VIDEODIR=video
WINDIR=linux
ZIPDIR=zip

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

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

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

GUIOBJ=${GUIDIR}/gui.o ${GUIDIR}/guifuncs.o ${GUIDIR}/menu.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 cfgparse.o endmem.o init.o initc.o uic.o patch.o ui.o vcache.o\
	version.o zmovie.o zstate.o debug.o zloader.o

NETOBJ=
#${NETDIR}/ztcp.o

TOOLSOBJ=${TOOLSDIR}/fileutil.o ${TOOLSDIR}/strutil.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}/2xsaiw.o\
	${VIDEODIR}/procvid.o ${VIDEODIR}/procvidc.o ${VIDEODIR}/sw_draw.o\
	${VIDEODIR}/hq2x16.o ${VIDEODIR}/hq2x32.o\
	${VIDEODIR}/hq3x16.o ${VIDEODIR}/hq3x32.o\
	${VIDEODIR}/hq4x16.o ${VIDEODIR}/hq4x32.o

WINOBJ=${WINDIR}/copyvwin.o ${WINDIR}/sdlintrf.o ${WINDIR}/sdllink.o @GL_DRAW@\
	${WINDIR}/sw_draw.o ${WINDIR}/zfilew.o

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

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

ZOBJS=${MAINOBJ} ${CHIPSOBJ} ${CPUOBJ} ${WINOBJ} ${WINDOSOBJ} ${GUIOBJ} ${VIDEOBJ} ${NETOBJ} ${ZIPOBJ} ${EFFECTSOBJ} ${JMAOBJ}

PSR=parsegen

.SUFFIXES: .cpp .c .asm .psr

%.o: %.cpp
	@CXX@ @CFLAGS@ -o $@ -c $<

%: %.cpp
	@CXX@ @CFLAGS@ -o $@ $<

%.o: %.c
	@CC@ @CFLAGS@ -I. -o $@ -c $<

%.o: %.asm
	@NASMPATH@ @NFLAGS@ -o $@ $<
ifeq (${x86-64},true)
	objcopy --input-target elf32-i386 --output-target elf64-x86-64 $@ $@
endif

%.o: %.psr
	./${PSR} -D__UNIXSDL__ temppsr.c $<
	@CC@ -I. -o $@ -c temppsr.c
	rm -f temppsr.c

ALL: @ZSNESEXE@

@ZSNESEXE@: ${PSR} ${ZOBJS}
	@CXX@ -o @ZSNESEXE@ ${ZOBJS} @CFLAGS@ @LDFLAGS@

${PSR}: parsegen.cpp

ALL:
	rm -f version.o

tools: cutrtype extraext minwhite nreplace sec-test srccount

cutrtype: ${TOOLSOBJ}
	@CXX@ @CFLAGS@ -o ${TOOLSDIR}/cutrtype ${TOOLSDIR}/cutrtype.cpp ${TOOLSOBJ}

extraext: ${TOOLSOBJ}
	@CXX@ @CFLAGS@ -o ${TOOLSDIR}/extraext ${TOOLSDIR}/extraext.cpp ${TOOLSOBJ}

minwhite: ${TOOLSOBJ}
	@CXX@ @CFLAGS@ -o ${TOOLSDIR}/minwhite ${TOOLSDIR}/minwhite.cpp ${TOOLSDIR}/fileutil.o

nreplace: ${TOOLSOBJ}
	@CXX@ @CFLAGS@ -o ${TOOLSDIR}/nreplace ${TOOLSDIR}/nreplace.cpp ${TOOLSDIR}/fileutil.o

sec-test: ${TOOLSOBJ}
	@CXX@ @CFLAGS@ -o ${TOOLSDIR}/sec-test ${TOOLSDIR}/sec-test.cpp ${TOOLSOBJ}

srccount: ${TOOLSOBJ}
	@CXX@ @CFLAGS@ -o ${TOOLSDIR}/srccount ${TOOLSDIR}/srccount.cpp ${TOOLSDIR}/fileutil.o

cfgload.o: cfgload.c gblhdr.h
cfgparse.o: cfgparse.psr
debug.o: debug.c gblhdr.h gblvars.h
endmem.o: endmem.asm macros.mac
init.o: init.asm macros.mac
initc.o: initc.c asm_call.h gblhdr.h ${CPUDIR}/memtable.h ${JMADIR}/zsnesjma.h\
	${ZIPDIR}/zunzip.h
patch.o: patch.c gblhdr.h ${ZIPDIR}/zunzip.h
ui.o: ui.asm macros.mac
uic.o: uic.c asm_call.h gblhdr.h
vcache.o: vcache.asm macros.mac
version.o: version.c
zloader.o: zloader.c gblhdr.h
zmovie.o: zmovie.c asm_call.h gblhdr.h gblvars.h numconv.h
zstate.o: zstate.c asm_call.h gblhdr.h gblvars.h numconv.h

${CHIPDIR}/c4emu.o: ${CHIPDIR}/c4emu.c gblhdr.h
${CHIPDIR}/dsp1emu.o: ${CHIPDIR}/dsp1emu.c gblhdr.h
${CHIPDIR}/dsp1proc.o: ${CHIPDIR}/dsp1proc.asm macros.mac
${CHIPDIR}/dsp2proc.o: ${CHIPDIR}/dsp2proc.asm macros.mac
${CHIPDIR}/dsp4emu.o: ${CHIPDIR}/dsp4emu.c
${CHIPDIR}/dsp4proc.o: ${CHIPDIR}/dsp4proc.asm macros.mac
${CHIPDIR}/fxemu2.o: ${CHIPDIR}/fxemu2.asm macros.mac ${CHIPDIR}/fxemu2.mac
${CHIPDIR}/fxemu2b.o: ${CHIPDIR}/fxemu2b.asm macros.mac ${CHIPDIR}/fxemu2.mac\
	${CHIPDIR}/fxemu2b.mac
${CHIPDIR}/fxemu2c.o: ${CHIPDIR}/fxemu2c.asm macros.mac ${CHIPDIR}/fxemu2.mac\
	${CHIPDIR}/fxemu2c.mac
${CHIPDIR}/fxtable.o: ${CHIPDIR}/fxtable.asm macros.mac
${CHIPDIR}/sa1proc.o: ${CHIPDIR}/sa1proc.asm macros.mac
${CHIPDIR}/sa1regs.o: ${CHIPDIR}/sa1regs.asm macros.mac\
	${CPUDIR}/regs.mac ${CPUDIR}/regsw.mac
${CHIPDIR}/sdd1emu.o: ${CHIPDIR}/sdd1emu.c
${CHIPDIR}/seta10.o: ${CHIPDIR}/seta10.c gblhdr.h
${CHIPDIR}/sfxproc.o: ${CHIPDIR}/sfxproc.asm macros.mac\
	${CPUDIR}/regs.mac ${CPUDIR}/regsw.mac
${CHIPDIR}/st10proc.o: ${CHIPDIR}/st10proc.asm macros.mac

${CPUDIR}/dma.o: ${CPUDIR}/dma.asm macros.mac
${CPUDIR}/dsp.o: ${CPUDIR}/dsp.asm macros.mac
${CPUDIR}/dspproc.o: ${CPUDIR}/dspproc.asm macros.mac ${CPUDIR}/fir_tables.inc
${CPUDIR}/execute.o: ${CPUDIR}/execute.asm macros.mac
${CPUDIR}/executec.o: ${CPUDIR}/executec.c gblhdr.h gblvars.h
${CPUDIR}/irq.o: ${CPUDIR}/irq.asm macros.mac
${CPUDIR}/memory.o: ${CPUDIR}/memory.asm macros.mac
${CPUDIR}/memtable.o: ${CPUDIR}/memtable.c gblhdr.h gblvars.h ${CPUDIR}/memtable.h
${CPUDIR}/spc700.o: ${CPUDIR}/spc700.asm macros.mac ${CPUDIR}/regsw.mac\
	${CPUDIR}/spcaddr.inc ${CPUDIR}/spcdef.inc
${CPUDIR}/stable.o: ${CPUDIR}/stable.asm macros.mac ${CPUDIR}/s65816d.inc\
	${CPUDIR}/saddress.inc ${CPUDIR}/saddrni.inc ${CPUDIR}/se65816.inc
${CPUDIR}/table.o: ${CPUDIR}/table.asm macros.mac ${CPUDIR}/65816d.inc\
	${CPUDIR}/address.inc ${CPUDIR}/addrni.inc ${CPUDIR}/e65816.inc\
	${CPUDIR}/regs.inc ${CPUDIR}/regs.mac ${CPUDIR}/regsw.inc ${CPUDIR}/regsw.mac
${CPUDIR}/tableb.o: ${CPUDIR}/tableb.asm macros.mac ${CPUDIR}/65816db.inc\
	${CPUDIR}/address.inc ${CPUDIR}/addrni.inc ${CPUDIR}/e65816b.inc
${CPUDIR}/tablec.o: ${CPUDIR}/tablec.asm macros.mac ${CPUDIR}/65816dc.inc\
	${CPUDIR}/address.inc ${CPUDIR}/addrni.inc ${CPUDIR}/e65816c.inc

${DOSDIR}/debug.o: ${DOSDIR}/debug.asm macros.mac
${DOSDIR}/gppro.o: ${DOSDIR}/gppro.asm macros.mac
${DOSDIR}/initvid.o: ${DOSDIR}/initvid.asm macros.mac ${DOSDIR}/vga.inc
${DOSDIR}/joy.o: ${DOSDIR}/joy.asm macros.mac
${DOSDIR}/sw.o: ${DOSDIR}/sw.asm macros.mac
${DOSDIR}/vesa12.o: ${DOSDIR}/vesa12.asm macros.mac
${DOSDIR}/vesa2.o: ${DOSDIR}/vesa2.asm macros.mac

${EFFECTSDIR}/burn.o: ${EFFECTSDIR}/burn.c
${EFFECTSDIR}/smoke.o: ${EFFECTSDIR}/smoke.c
${EFFECTSDIR}/water.o: ${EFFECTSDIR}/water.c gblhdr.h ${EFFECTSDIR}/fixsin.h

${GUIDIR}/gui.o: ${GUIDIR}/gui.asm macros.mac ${GUIDIR}/guicheat.inc\
	${GUIDIR}/guicombo.inc ${GUIDIR}/guikeys.inc ${GUIDIR}/guiload.inc\
	${GUIDIR}/guimisc.inc ${GUIDIR}/guimouse.inc ${GUIDIR}/guitools.inc\
	${GUIDIR}/guiwindp.inc
${GUIDIR}/guifuncs.o: ${GUIDIR}/guifuncs.c gblhdr.h
${GUIDIR}/menu.o: ${GUIDIR}/menu.asm macros.mac

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

${TOOLSDIR}/fileutil.o: ${TOOLSDIR}/fileutil.cpp ${TOOLSDIR}/fileutil.h
${TOOLSDIR}/strutil.o: ${TOOLSDIR}/strutil.cpp ${TOOLSDIR}/strutil.h

${VIDEODIR}/2xsaiw.o: ${VIDEODIR}/2xsaiw.asm macros.mac
${VIDEODIR}/hq2x16.o: ${VIDEODIR}/hq2x16.asm macros.mac
${VIDEODIR}/hq2x32.o: ${VIDEODIR}/hq2x32.asm macros.mac
${VIDEODIR}/hq3x16.o: ${VIDEODIR}/hq3x16.asm macros.mac
${VIDEODIR}/hq3x32.o: ${VIDEODIR}/hq3x32.asm macros.mac
${VIDEODIR}/hq4x16.o: ${VIDEODIR}/hq4x16.asm macros.mac
${VIDEODIR}/hq4x32.o: ${VIDEODIR}/hq4x32.asm macros.mac
${VIDEODIR}/m716text.o: ${VIDEODIR}/m716text.asm macros.mac
${VIDEODIR}/makev16b.o: ${VIDEODIR}/makev16b.asm macros.mac\
	${VIDEODIR}/vidmacro.mac
${VIDEODIR}/makev16t.o: ${VIDEODIR}/makev16t.asm macros.mac\
	${VIDEODIR}/vidmacro.mac
${VIDEODIR}/makevid.o: ${VIDEODIR}/makevid.asm macros.mac\
	${VIDEODIR}/vidmacro.mac
${VIDEODIR}/mode7.o: ${VIDEODIR}/mode7.asm macros.mac ${VIDEODIR}/mode7.mac
${VIDEODIR}/mode716.o: ${VIDEODIR}/mode716.asm macros.mac ${VIDEODIR}/mode716.mac
${VIDEODIR}/mode716b.o: ${VIDEODIR}/mode716b.asm macros.mac ${VIDEODIR}/mode7.mac
${VIDEODIR}/mode716d.o: ${VIDEODIR}/mode716d.asm macros.mac ${VIDEODIR}/mode7.mac
${VIDEODIR}/mode716e.o: ${VIDEODIR}/mode716e.asm macros.mac
${VIDEODIR}/mode716t.o: ${VIDEODIR}/mode716t.asm macros.mac ${VIDEODIR}/mode7.mac
${VIDEODIR}/mode7ext.o: ${VIDEODIR}/mode7ext.asm macros.mac ${VIDEODIR}/mode7.mac
${VIDEODIR}/mv16tms.o: ${VIDEODIR}/mv16tms.asm macros.mac\
	${VIDEODIR}/vidmacro.mac
${VIDEODIR}/newg162.o: ${VIDEODIR}/newg162.asm macros.mac\
	${VIDEODIR}/newg162.mac ${VIDEODIR}/newg16wn.mac ${VIDEODIR}/newgfx16.mac\
	${VIDEODIR}/vidmacro.mac
${VIDEODIR}/newfgx.o: ${VIDEODIR}/newfgx.asm macros.mac ${VIDEODIR}/newgfx.mac\
	${VIDEODIR}/newgfx2.mac ${VIDEODIR}/vidmacro.mac
${VIDEODIR}/newgfx16.o: ${VIDEODIR}/newgfx16.asm macros.mac\
	${VIDEODIR}/newg162.mac ${VIDEODIR}/newgfx16.mac ${VIDEODIR}/vidmacro.mac
${VIDEODIR}/newgfx2.o: ${VIDEODIR}/newgfx2.asm macros.mac ${VIDEODIR}/newgfx.mac\
	${VIDEODIR}/newgfx2.mac ${VIDEODIR}/newgfxwn.mac ${VIDEODIR}/vidmacro.mac
${VIDEODIR}/procvid.o: ${VIDEODIR}/procvid.asm macros.mac\
	${VIDEODIR}/2xsaimmx.inc ${VIDEODIR}/copyvid.inc
${VIDEODIR}/procvidc.o: ${VIDEODIR}/procvidc.c gblhdr.h
${VIDEODIR}/sw_draw.o: ${VIDEODIR}/sw_draw.asm macros.mac

${WINDIR}/copyvwin.o: ${WINDIR}/copyvwin.asm macros.mac
${WINDIR}/gl_draw.o: ${WINDIR}/gl_draw.c gblhdr.h
${WINDIR}/sdlintrf.o: ${WINDIR}/sdlintrf.asm macros.mac
${WINDIR}/sdllink.o: ${WINDIR}/sdllink.c gblhdr.h ${WINDIR}/sw_draw.h\
	${WINDIR}/gl_draw.h
${WINDIR}/sw_draw.o: ${WINDIR}/sw_draw.c gblhdr.h
${WINDIR}/zfilew.o: ${WINDIR}/zfilew.c

${ZIPDIR}/unzip.o: ${ZIPDIR}/unzip.c gblhdr.h ${ZIPDIR}/zunzip.h
${ZIPDIR}/zpng.o: ${ZIPDIR}/zpng.c gblhdr.h ${ZIPDIR}/zpng.h

install:
	@INSTALL@ -d -m 0755 ${DESTDIR}/@prefix@/bin
	@INSTALL@ -m 0755 @ZSNESEXE@ ${DESTDIR}/@prefix@/bin
	@INSTALL@ -d -m 0755 ${DESTDIR}/@prefix@/man/man1
	@INSTALL@ -m 0644 linux/zsnes.1 ${DESTDIR}/@prefix@/man/man1

uninstall:
	rm -f @prefix@/bin/$(notdir @ZSNESEXE@) @prefix@/man/man5/zsnes.5

clean:
	rm -f *.o ${CHIPDIR}/*.o ${CPUDIR}/*.o ${DOSDIR}/*.o ${EFFECTSDIR}/*.o ${GUIDIR}/*.o ${JMADIR}/*.o ${NETDIR}/*.o ${TOOLSDIR}/*.o ${VIDEODIR}/*.o ${WINDIR}/*.o ${ZIPDIR}/*.o ${PSR} temppsr.c @ZSNESEXE@

distclean:
	rm -f *.o ${CHIPDIR}/*.o ${CPUDIR}/*.o ${DOSDIR}/*.o ${EFFECTSDIR}/*.o ${GUIDIR}/*.o ${JMADIR}/*.o ${NETDIR}/*.o ${TOOLSDIR}/*.o ${VIDEODIR}/*.o ${WINDIR}/*.o ${ZIPDIR}/*.o ${PSR} temppsr.c @ZSNESEXE@ Makefile config.cache config.log config.status config.h
