OS = $(shell uname)
CC = g++
CFLAGS = -std=c++0x -Wall -pedantic -rdynamic
# -rdynamic is to generate debug info for dynamic symbols on debian-based 
# systems (tested on Linux Mint)
# for OSX, using -g generates a newgame.dSYS directory which has debug symbols.
# However, this has no effect on the stack trace, so there must be a way to specify a *.dSYS directory when running ./newgame
# or to instead put thos symbols directly into the executable, like -rdynamic does for Linux
#-Wextra -fno-inline

ifeq ($(OS),Darwin)
	DEP = -framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo -lglfw -lglew
endif
ifeq ($(OS),Linux)
	DEP = -lglfw3 -lGLEW -lGL -ldl -lX11 -lXrandr -lXxf86vm -lXinerama -lXcursor  -pthread
endif

IMGUI_FILES = IMGUI/imgui_demo.cpp IMGUI/imgui_draw.cpp IMGUI/imgui.cpp

# If I were generating .o files as well, I should use $? instead of $^
# as this well prevent regenerating .o files for unchanged .cpp files

newgame: new-game.cpp logger.cpp utils.cpp CrashLogger.cpp stb_image.cpp imgui_impl_glfw_gl3.cpp $(IMGUI_FILES)
	$(CC) $^ $(DEP) $(CFLAGS) -o $@

pong: pong.cpp logger.cpp
	$(CC) $^ $(DEP) $(CFLAGS) -o $@

mygame: mygame.cpp common/shader.cpp common/texture.cpp common/controls-new.cpp
	$(CC) $^ $(DEP) $(CFLAGS) -o $@

demo: game06.cpp common/shader.cpp common/texture.cpp common/controls.cpp
	$(CC) $^ $(DEP) $(CFLAGS) -o $@

clean:
	rm -f newgame
	rm -f pong
	rm -f mygame
	rm -f demo
