ifneq ("$(shell grep GTK2 config.h)","\#define GTK2_SUPPORT 1")
GTK_FLAGS = `gtk-config --cflags`
GTK_LIBS = `gtk-config --libs`
else
GTK_FLAGS = `pkg-config gtk+-2.0 --cflags` -D_GTK2
GTK_LIBS = `pkg-config gtk+-2.0 --libs`
endif

CC = gcc
#CFLAGS = -DUSE_GTK `sdl-config --cflags` $(GTK_FLAGS) -Iwrapper/ -g -mmmx -msse
#CFLAGS = -DUSE_GTK `sdl-config --cflags` $(GTK_FLAGS) -Iwrapper/ -O3 -mcpu=athlon -ffast-math -funroll-loops -fomit-frame-pointer -msse -mmmx
#CFLAGS = -DUSE_GTK `sdl-config --cflags` $(GTK_FLAGS) -Iwrapper/ -O3 -mcpu=athlon -ffast-math -funroll-loops -fomit-frame-pointer -msse -mmmx
#CFLAGS = -DUSE_GTK `sdl-config --cflags` $(GTK_FLAGS) -Iwrapper/ -g -Wall
#CFLAGS = -DUSE_GTK `sdl-config --cflags` $(GTK_FLAGS) -Iwrapper/ -O3 -mcpu=athlon -ffast-math -funroll-loops -fomit-frame-pointer
CFLAGS = -DUSE_GTK `sdl-config --cflags` $(GTK_FLAGS) -Iwrapper/ -O3 -mcpu=athlon -ffast-math -funroll-loops -fomit-frame-pointer
CXX = g++
CPPFLAGS = $(CFLAGS)
LD = g++
LDFLAGS = -lGL -lGLU -L/usr/X11R6/lib `sdl-config --libs`

OBJECTS = Main.o \
	rdp.o \
	Ini.o \
	wrapper/textures.o \
	wrapper/main.o \
	messagebox.o \
	wrapper/geometry.o \
	TexCache.o \
	Debugger.o \
	Util.o \
	CRC.o \
	Combine.o \
	wrapper/combiner.o \
	TexBuffer.o \
	Tmem_nasm.o \
	wrapper/config.o \
	wrapper/filter.o \
	support.o \
	wrapper/2xsai.o \
	wrapper/hq2x.o \
	wrapper/hq4x.o \
	Config.o

all: Glide64.so instruction

Glide64.so: font.h cursor.h $(OBJECTS)
	$(LD) -shared -Wl,-Bsymbolic $(GTK_LIBS) $(LDFLAGS) -o $@ $(OBJECTS)
	strip --strip-all $@

font.h:	compiletex
	./compiletex font.tex font.h font

cursor.h: compiletex
	./compiletex cursor.tex cursor.h cursor

compiletex: compiletex.o
	$(LD) -o $@ compiletex.o

Tmem_nasm.o: Tmem_nasm.asm
	    nasm -f elf $<

instruction:
	$(warning please copy Glide64.so AND Glide64.ini in the plugins/ folder of the emulator)

clean:
	rm -rf $(OBJECTS) $(ALL) compiletex compiletex.o font.h cursor.h

rebuild: clean $(ALL)
