GCC = i686-w64-mingw32-gcc
DLLTOOL = i686-w64-mingw32-dlltool

GCCFLAGS = -O0 -Wall -fomit-frame-pointer -fpack-struct
LINKFLAGS = -O0 -Wall -fomit-frame-pointer -fpack-struct -s -mdll -mthread

#LIBS = -lwinmm -lopengl32 -lgdi32
LIBS = -lgdi32
OBJS = obj/binkw32.a
OUT = build/binkw32.dll

SRC = src/Daodan.c src/Daodan_BSL.c src/Daodan_Character.c src/Daodan_Cheater.c src/Daodan_Console.c src/Daodan_DLLStubs.c src/daodan_gl.c src/Daodan_Patch.c src/Daodan_Persistence.c src/Daodan_Utility.c src/Daodan_Win32.c src/Daodan_WindowHack.c src/inifile_reader.c src/Oni_Symbols.c
DEST = $(patsubst src/%.c,build/%.o,$(SRC))

ALL: $(FOLDERS) $(DEST) $(OBJS)
	echo "Linking $<"
	$(GCC) $(LINKFLAGS) -o $(OUT) $(DEST) $(OBJS) $(LIBS)

clean:
	rm $(DEST)
	rm $(OUT)

obj/binkw32.a: src/binkw32.def
	echo "Generating binkw32.a"
	$(DLLTOOL) -d $< -l $@

build/%.o: src/%.c
	echo "Compiling $<"
	$(GCC) $(GCCFLAGS) -c -o $@ $<
	echo

$(FOLDERS):
	mkdir $@
