# Generated automatically from Makefile.in by configure.
#ZSNESFX=1
#ZSNESC4=1
#ASMCPU=1
#SPC700ASM=1
#NETPLAY=1
#UNZIP=1
#GLIDE=1
#OPENGL=1
#AIDO=1
#GUI=0
#THREAD_SOUND=1
#ASMKREED=1
SDD1_DECOMP=1
#SDD1_VERIFY=0

#Fairly good and special-char-safe descriptor of the os being built on.
OS=`uname -s -r -m|sed \"s/ /-/g\"|tr \"[A-Z]\" \"[a-z]\"|tr \"/()\" \"___\"`
BUILDDIR=.
#BUILDDIR=build/$(OS)


ifdef ZSNESFX
FXOBJ=i386/fxemu2b.o i386/fxemu2.o i386/fxemu2c.o i386/fxtable.o i386/sfxproc.o i386/ZSNES.O
FXDEFINES=-DZSNES_FX -DEXECUTE_SUPERFX_PER_LINE
FXDEPENDS=zsnes_fx
FXNO_DEPENDS=c_fx
else
FXOBJ=fxinst.o fxemu.o fxdbg.o
FXDEFINES=-DEXECUTE_SUPERFX_PER_LINE
FXDEPENDS=c_fx
FXNO_DEPENDS=zsnes_fx
endif

ifdef ZSNESC4
C4OBJ=i386/C4.O i386/zsnesc4.o c4.o
C4DEFINES=-DZSNES_C4
C4DEPENDS=zsnes_c4
C4NO_DEPENDS=c_c4
else
C4OBJ=c4.o c4emu.o
C4DEFINES=
C4DEPENDS=c_c4
C4NO_DEPENDS=zsnes_c4
endif

ifdef SPC700ASM
SOUNDOBJ=spctool/spc700.o spctool/dsp.o spctool.o spctool/soundmod.o SPC.O
SOUNDDEFINES=-DSPCTOOL
else
SOUNDOBJ=spc700.o soundux.o apu.o 
SOUNDDEFINES=-DSPC700_C
endif

ifdef ASMCPU
CPUOBJ=i386/cpuops.o i386/cpuexec.o i386/sa1ops.o
else
CPUOBJ=cpuops.o cpuexec.o sa1cpu.o
endif

ifdef ASMKREED
KREEDOBJ=i386/2XSAIMMX.O i386/bilinear.o 2xsai.o
KREEDDEFINES=-DMMX
else
KREEDDEFINES=
# KREEDOBJ=2xsai.o
endif

ifdef SDD1_DECOMP
SDD1OBJ=sdd1emu.o
ifdef SDD1_VERIFY
SDD1DEFINES=-DSDD1_DECOMP -DSDD1_VERIFY
else
SDD1DEFINES=-DSDD1_DECOMP
endif
else
SDD1DEFINES=
SDD1OBJ=
endif

SPC7110OBJ=spc7110.o
OBC1OBJ=obc1.o
SETAOBJ=seta.o seta010.o seta011.o seta018.o

OBJECTS=$(CPUOBJ) $(SOUNDOBJ) apudebug.o $(FXOBJ) $(C4OBJ) \
	cpu.o sa1.o debug.o sdd1.o tile.o srtc.o \
	gfx.o memmap.o snaporig.o clip.o dsp1.o \
	movie.o \
	ppu.o dma.o snes9x.o snapshot.o screenshot.o \
        cheats.o cheats2.o data.o unix/unix.o unix/config.o globals.o \
	$(SPC7110OBJ) $(OBC1OBJ) $(SETAOBJ) $(KREEDOBJ) $(SDD1OBJ)

#OBJECTS += ../zlib/libz.a

#FIXME: The gui is bitrotted if it ever worked at all. Remove?
ifdef GUI
GUIOBJS = unix/snes9x_gui.o unix/moc_snes9x_gui.o
GUILIBS = -L$(QTDIR)/lib -lqt
GUIDEFINES = -I$(QTDIR)/include
endif

ifdef NETPLAY
OBJECTS += netplay.o server.o
NETPLAYDEFINES=-DNETPLAY_SUPPORT
SERVER_OBJECTS=server.o
endif

ifdef UNZIP
OBJECTS += loadzip.o unzip/unzip.o unzip/explode.o unzip/unreduce.o unzip/unshrink.o
UNZIPDEFINES=-DUNZIP_SUPPORT
endif

ifdef THREAD_SOUND
CPUDEFINES += -DUSE_THREADS
EXTRALIBS += -lpthread
endif

ifdef GLIDE
GLIDEOBJS = unix/glide.o
GLIDEDEFINES = -DUSE_GLIDE -I/usr/include/glide
GLIDELIBS = -lglide2x
endif

ifdef OPENGL
OPENGLOBJS = unix/opengl.o
OPENGLDEFINES = -DUSE_OPENGL
OPENGLLIBS = -lGL -lGLU -ldl
endif

ifdef AIDO
AIDOOBJS = unix/aido.o
AIDODEFINES = -DUSE_AIDO
endif

JOYDEFINES = 

MOC = $(QTDIR)/bin/moc
CCC = c++  -fno-rtti
GASM = c++
CC = gcc
NASM = /usr/bin/nasm

#INCLUDES = -I../zlib -INONE
INCLUDES = -INONE

#OPTIMISE =  -mcpu=pentiumpro -O6 -fomit-frame-pointer -fno-exceptions -Wall -W -pedantic -Wno-unused-parameter -pipe
OPTIMISE =  -O6 -fomit-frame-pointer -fno-exceptions -Wall -W -pedantic -Wno-unused-parameter -pipe

#OPTIMISE=-g -fno-exceptions

CCFLAGS = $(OPTIMISE) -DMITSHM \
 -I. \
-Iunzip \
-DVAR_CYCLES \
-DCPU_SHUTDOWN \
-DSPC700_SHUTDOWN \
$(FXDEFINES) \
$(C4DEFINES) \
$(CPUDEFINES) \
$(SOUNDDEFINES) \
$(NETPLAYDEFINES) \
$(UNZIPDEFINES) \
$(GLIDEDEFINES) \
$(OPENGLDEFINES) \
$(AIDODEFINES) \
$(GUIDEFINES) \
$(KREEDDEFINES) \
$(SDD1DEFINES) \
$(JOYDEFINES) \
-DNO_INLINE_SET_GET  -DNOASM -DHAVE_MKSTEMP '-DACCEPT_SIZE_T=size_t'

#-DOLD_COLOUR_BLENDING
#-DSOUND
#-DDEBUGGER
#-DNO_INLINE_SET_GET
#-DVAR_CYCLES
#-DCPU_SHUTDOWN
#-DSPC700_SHUTDOWN

CFLAGS=$(CCFLAGS)

.SUFFIXES: .o .cpp .c .cc .h .m .i .S .asm .obj .O .CPP .C .ASM
#FIXME: Why is this set statically?
#LDLIBS = -L/usr/X11R6/lib
# -L../zlib

ifdef GLIDE
all: Makefile configure offsets gsnes9x
else
ifdef OPENGL
all: Makefile configure offsets osnes9x
else
# all: Makefile configure offsets snes9x
all: Makefile configure snes9x  
endif
endif

Makefile: configure Makefile.in
	@echo "Makefile is older than configure or in-file. Run configure or touch Makefile."
	exit 1

configure: configure.in
	@echo "configure is older than in-file. Run autoconf or touch configure."
	exit 1

#ssnes9x
#ggisnes9x
#xf86snes9x

# offsets: offsets.o
# 	$(CCC) $(INCLUDES) -o $@ offsets.o
# 	./offsets >i386/offsets.h

#../zlib/libz.a:
#	cd ../zlib && sh ./configure && make

snes9x: $(OBJECTS) $(AIDOOBJS) $(GUIOBJS)
	$(CCC) $(INCLUDES) -o $@ $(OBJECTS) $(AIDOOBJS) $(GLIDEOBJS) $(OPENGLOBJS) $(GUIOBJS) $(LDLIBS) $(GLIDELIBS) $(OPENGLLIBS) $(GUILIBS)  -lnsl  -lXext -lX11 $(EXTRALIBS) -lm

ssnes9x: $(OBJECTS) unix/svga.o 
	$(CCC) $(INCLUDES) -o $@ $(OBJECTS) $(GLIDEOBJS) unix/svga.o $(LDLIBS) $(GLIDELIBS) -lvga -lvgagl $(EXTRALIBS) -lm

gsnes9x: $(OBJECTS) $(GLIDEOBJS)
	$(CCC) $(INCLUDES) -o $@ $(OBJECTS) $(GLIDEOBJS) $(LDLIBS) -lglide $(EXTRALIBS) -lm

ggisnes9x: $(OBJECTS) unix/ggi.o
	$(CCC) $(INCLUDES) -o $@ $(OBJECTS) unix/ggi.o $(LDLIBS) -lggi $(EXTRALIBS) -lm

osnes9x: $(OBJECTS) $(OPENGLOBJS)
	$(CCC) $(INCLUDES) -o $@ $(OBJECTS) $(OPENGLOBJS) $(LDLIBS) $(OPENGLLIBS)  -lnsl  -lXext -lX11 $(EXTRALIBS) -lm

s9xserver: $(SERVER_OBJECTS)
	$(CCC) $(INCLUDES) -o $@ $(SERVER_OBJECTS) 

.cpp.o:
	$(CCC) $(INCLUDES) -c $(CCFLAGS) $*.cpp -o $@

.c.o:
	$(CC) $(INCLUDES) -c $(CCFLAGS) $*.c -o $@

.cpp.S:
	$(GASM) $(INCLUDES) -S $(CCFLAGS) $*.cpp -o $@

.cpp.i:
	$(GASM) $(INCLUDES) -E $(CCFLAGS) $*.cpp -o $@

.S.o:
	$(GASM) $(INCLUDES) -c $(CCFLAGS) $*.S -o $@

.S.i:
	$(GASM) $(INCLUDES) -c -E $(CCFLAGS) $*.S -o $@

.asm.o:
	$(NASM) -f elf $(FXDEFINES) -i. -ii386 -o $@ $*.asm

.obj.o:
	cp $*.obj $*.o

.CPP.O:
	$(CCC) $(INCLUDES) -c $(CCFLAGS) -x c++ $*.CPP -o $@

.C.O:
	$(CC) $(INCLUDES) -c $(CCFLAGS) $*.C -o $@

.ASM.O:
	$(NASM) -f elf $(FXDEFINES) -i . -i i386 $*.ASM -o $@

unix/moc_snes9x_gui.cpp: unix/snes9x_gui.h
	$(MOC) unix/snes9x_gui.h -o $@

clean:
	rm -f $(OBJECTS) offsets.o unix/svga.o unix/aido.o unix/ggi.o unix/xf86.o unix/glide.o

#release: CCFLAGS += -DNO_DEBUGGER

_bin-package:
	RELNR=`grep "#define VERSION" snes9x.h | sed -e 's/"//g' | awk '{ print $$3 }'` && \
	echo $$RELNR && \
	RELNAME=snes9x-$${RELNR} && export RELNAME && \
	test \! -f $${RELNAME}.tar.gz && \
	DISTDIR=disttmp/$${RELNAME}/ && \
	rm -rf disttmp && \
	mkdir disttmp && \
	mkdir $${DISTDIR} && \
	cp snes9x $${DISTDIR} && \
	cp config.info hardware.txt problems.txt changes.txt ../faqs.txt ../readme.txt ../readme.unix $${DISTDIR} && \
	(cd disttmp && tar cvf - $${RELNAME}) | gzip -c > $${RELNAME}.tar.gz &&\
	rm -rf disttmp

#FIXME: Should possibly have clean, but not in xenofarm build
bin-release: snes9x _bin-package

#FIXME: Intelligent messages when bailing out.
#FIXME: See those ls:s? Don't look to closely at the statements...
_src-package:
	RELNR=`grep "#define VERSION" snes9x.h | sed -e 's/"//g' | awk '{ print $$3 }'` && \
	echo $$RELNR && \
	RELNAME=snes9x-$${RELNR}-src && \
	test \! -f $${RELNAME}.tar.gz && \
	test \! `ls *~` && \
	test \! `ls *.o` && \
	test \! -f snes9x && \
	export RELNR && export RELNAME && \
	(cd .. && PWD=`pwd` && SNESDIR=`basename $$PWD` && cd .. && \
	 DISTDIR=disttmp/$${RELNAME} && \
	 rm -rf disttmp && \
	 mkdir disttmp && \
	 cp -r $${SNESDIR} $${DISTDIR} && \
	 rm -f $${DISTDIR}/snes9x/config.* 2>/dev/null && \
	 rm -f $${DISTDIR}/snes9x/conftezt.out.* 2>/dev/null && \
	 rm -rf $${DISTDIR}/snes9x/autom4te.cache 2>/dev/null && \
	 rm $${DISTDIR}/snes9x/Makefile && \
	 find disttmp -name CVS -type f -exec rm "{}" \; && \
	 find disttmp -name CVS -type d -exec rm "{}" \; && \
	 (cd disttmp && tar cvf - $${RELNAME}) | gzip -c > $${RELNAME}.tar.gz  && \
	mv $${RELNAME}.tar.gz $${SNESDIR}/snes9x/ ) && \
	rm -rf disttmp

#Requires:
# 1. Prestine checkout
# 2. `autoconf`
# 3. `./configure`
src-release: depend _src-package

xenofarm:
	./xenofarm.sh
	cd build/xenofarm && tar cf - . > ../../../xenofarm_result.tar
	gzip -f9 ../xenofarm_result.tar

# And now for the impressive testsuite:
verify: snes9x
	./snes9x --selftest

#FIXME: Make a auto-self-reference.
depend:
	$(CC) $(CFLAGS) -MM -MG \
	  `find . '(' -name '*.c' -o -name '*.cpp' -o -name '*.S' ')' -print -o -name msdos -prune` \
	  | sed -e 's@^[^ :]*: *\([^ ]*/\)[^ /]*@\1&@' \
	  >dependencies

include dependencies