#Makefile MUPEN64 for QNX


CC = gcc -O3 -fomit-frame-pointer -funroll-loops -ffast-math -mcpu=pentium -DEMU64_DEBUG -DREF_HARD_LINKED -I/usr/local/include -Wall
#CC = gcc -g -fomit-frame-pointer -funroll-loops -ffast-math -mcpu=pentium -DEMU64_DEBUG -DREF_HARD_LINKED -I/usr/local/include -Wall

CCPLG=gcc -g -O2  -I/usr/local/include

LIB=-lz -lm -L/usr/lib -lSDL -lGL -lGLU -lasound -lph
LIBS=-lz -lm -L/usr/lib  -lGL -lSDL -lasound  

OBJ		=main/rom.o \
		r4300/r4300.o \
		r4300/cop0.o \
		r4300/special.o \
		r4300/regimm.o \
		r4300/exception.o \
		memory/tlb.o \
		memory/memory.o \
		memory/dma.o \
		r4300/interupt.o \
		r4300/cop1.o \
		r4300/tlb.o \
		r4300/cop1_w.o \
		r4300/cop1_s.o \
		r4300/cop1_d.o \
		r4300/recomp.o \
		memory/pif.o \
		r4300/bc.o \
		r4300/cop1_l.o \
		r4300/pure_interp.o \
		r4300/compare_core.o \
		main/plugin.o \
     	sound/sdl/sound.o
		
OBJ_INPUT = 			plugins/mupen64_input/main.o

OBJ_GFX_MUPEN64 = 		plugins/mupen64_gfx/main.o \
		plugins/mupen64_gfx/rdp.o \
		plugins/mupen64_gfx/hle00.o \
		plugins/mupen64_gfx/texture.o 

OBJ_TINYGL =  	plugins/tinygl/api.o \
	plugins/tinygl/list.o \
	plugins/tinygl/vertex.o \
	plugins/tinygl/init.o \
	plugins/tinygl/matrix.o \
	plugins/tinygl/texture.o \
     plugins/tinygl/misc.o \
    plugins/tinygl/clear.o \
     plugins/tinygl/light.o \
    plugins/tinygl/clip.o \
    plugins/tinygl/select.o \
    plugins/tinygl/get.o \
    plugins/tinygl/error.o \
   plugins/tinygl/zbuffer.o \
   plugins/tinygl/zline.o \
   plugins/tinygl/zdither.o \
   plugins/tinygl/ztriangle.o \
   plugins/tinygl/zmath.o \
   plugins/tinygl/image_util.o \
   plugins/tinygl/oscontext.o \
  plugins/tinygl/msghandling.o \
   plugins/tinygl/arrays.o \
  plugins/tinygl/specbuf.o \
  plugins/tinygl/memory.o \
  plugins/tinygl/nglx.o
		
OBJ_GFX_MUPEN64_SOFT = 		plugins/mupen64_gfx_soft/main.o \
		plugins/mupen64_gfx_soft/rdp.o \
		plugins/mupen64_gfx_soft/hle00.o \
		plugins/mupen64_gfx_soft/texture.o \

					
OBJ_GFX_TR64 = plugins/mupen64_tr/Driver.o \
		plugins/mupen64_tr/crc_ucode.o \
		plugins/mupen64_tr/wingl.o \
		plugins/mupen64_tr/rdp.o \
		plugins/mupen64_tr/Combine.o \
		plugins/mupen64_tr/Texture.o \
		plugins/mupen64_tr/rdp_gl.o \
		plugins/mupen64_tr/lighting.o \
		plugins/mupen64_tr/Render.o \
		plugins/mupen64_tr/3dmath.o \
		plugins/mupen64_tr/hleGetMatrix.o \
		plugins/mupen64_tr/iniapi.o \
		plugins/mupen64_tr/debug.o				

		
OBJ_GFX_TR64_SOFT = plugins/mupen64_tr_soft/Driver.o \
		plugins/mupen64_tr_soft/crc_ucode.o \
		plugins/mupen64_tr_soft/wingl.o \
		plugins/mupen64_tr_soft/rdp.o \
		plugins/mupen64_tr_soft/Combine.o \
		plugins/mupen64_tr_soft/Texture.o \
		plugins/mupen64_tr_soft/rdp_gl.o \
		plugins/mupen64_tr_soft/lighting.o \
		plugins/mupen64_tr_soft/Render.o \
		plugins/mupen64_tr_soft/3dmath.o \
		plugins/mupen64_tr_soft/hleGetMatrix.o \
		plugins/mupen64_tr_soft/iniapi.o \
		plugins/mupen64_tr_soft/debug.o	 \

OBJ_X86         =r4300/x86/gr4300.o \
		r4300/x86/gcop0.o \
		r4300/x86/assemble.o \
		r4300/x86/gcop1.o \
		r4300/x86/gcop1_s.o \
		r4300/x86/gcop1_d.o \
		r4300/x86/gtlb.o \
		r4300/x86/gregimm.o \
		r4300/x86/gspecial.o \
		r4300/x86/gcop1_w.o \
		r4300/x86/debug.o \
		r4300/x86/rjump.o \
		r4300/x86/gbc.o \
		r4300/x86/gcop1_l.o

HEADER		=main/rom.h \
		r4300/r4300.h \
		r4300/ops.h \
		r4300/macros.h \
		r4300/exception.h \
		memory/memory.h \
		memory/tlb.h \
		memory/dma.h \
		r4300/interupt.h \
		r4300/recomp.h \
		memory/pif.h \
		sound/sound.h



all:	mupen64 mupen64_tr mupen64_soft mupen64_tr_soft

main/main.o:	main/main.c
		$(CC)  -c -o main/main.o main/main.c

main/main_gtk.o:	main/main_gtk.c
			$(CC) -c -o main/main_gtk.o main/main_gtk.c `gtk-config --cflags`

mupen64:	$(OBJ) $(OBJ_X86) $(HEADER) $(OBJ_INPUT) $(OBJ_GFX_MUPEN64) main/main.o
		$(CC)  $(OBJ) $(OBJ_X86) $(OBJ_INPUT) $(OBJ_GFX_MUPEN64) $(LIB) -Wl,-E main/main.o  -o $@
		strip --strip-all $@
		
mupen64_soft:	$(OBJ) $(OBJ_X86) $(HEADER) $(OBJ_INPUT) $(OBJ_TINYGL)  $(OBJ_GFX_MUPEN64_SOFT) main/main.o
		$(CC)  $(OBJ) $(OBJ_X86) $(OBJ_INPUT) $(OBJ_TINYGL) $(OBJ_GFX_MUPEN64_SOFT) $(LIBS) main/main.o  -o $@
		strip --strip-all $@		
		
mupen64_tr:	$(OBJ) $(OBJ_X86) $(HEADER) $(OBJ_INPUT) $(OBJ_GFX_TR64) main/main.o
		$(CC)  $(OBJ) $(OBJ_X86) $(OBJ_INPUT) $(OBJ_GFX_TR64) $(LIB) -Wl,-E main/main.o  -o $@
		strip --strip-all $@		

mupen64_tr_soft:	$(OBJ) $(OBJ_X86) $(HEADER) $(OBJ_INPUT) $(OBJ_TINYGL) $(OBJ_GFX_TR64_SOFT) main/main.o
		$(CC)  $(OBJ) $(OBJ_X86) $(OBJ_INPUT) $(OBJ_TINYGL) $(OBJ_GFX_TR64_SOFT) $(LIB) -Wl,-E main/main.o  -o $@
		strip --strip-all $@	

plugins/mupen64_tr/hleGetMatrix.o: plugins/mupen64_tr/hleGetMatrix.asm
		nasm -f elf -o plugins/mupen64_tr/hleGetMatrix.o 	plugins/mupen64_tr/hleGetMatrix.asm
		
plugins/mupen64_tr_soft/hleGetMatrix.o: plugins/mupen64_tr_soft/hleGetMatrix.asm
		nasm -f elf -o plugins/mupen64_tr_soft/hleGetMatrix.o 	plugins/mupen64_tr_soft/hleGetMatrix.asm		

# mupen64_gfx TinyGL Lib
	
plugins/tinygl/ztriangle.o: plugins/tinygl/ztriangle.c
	$(CC)  -Wno-uninitialized   -o $@ -c $<
	
clean:
	find . -name '*.o' -print0 | xargs  rm -f
	rm mupen64 mupen64_soft mupen64_tr mupen64_tr_soft
	
clean_jed:
	find . -name '*~' -print0 | xargs -0r rm -f

gprof:
	gprof mupen64_nogui > stat.txt	
	
	
	
