csrc = $(wildcard src/*.c) \
	   $(wildcard vmath/*.c) \
	   $(wildcard drawtext/*.c) \
	   $(wildcard kdtree/*.c)

ccsrc = $(wildcard src/*.cc) \
		$(wildcard src/audio/*.cc) \
		$(wildcard vmath/*.cc)

obj = $(csrc:.c=.o) $(ccsrc:.cc=.o)
dep = $(obj:.o=.d)
bin = proto

warn = -Wall -Wno-format-extra-args -Wno-char-subscripts

inc = -I. -Isrc -Ivmath -Idrawtext -Ikdtree `pkg-config --cflags freetype2`

CFLAGS = -pedantic $(warn) $(dbg) $(prof) $(opt) $(inc)
CXXFLAGS = $(CFLAGS) $(cxx11_cflags)
LDFLAGS = $(cxx11_ldflags) $(prof) $(libgl) $(libal) -lvorbisfile -lm -lassimp -limago -lpsys `pkg-config --libs freetype2`

ifeq ($(shell uname -s), Darwin)
	libgl = -framework OpenGL -framework GLUT -lglew
	libal = -framework OpenAL
else
	libgl = -lGL -lGLU -lglut -lGLEW
	libal = -lopenal
endif

$(bin): $(obj) Makefile
	$(CXX) -o $@ $(obj) $(LDFLAGS)

-include $(dep)

%.d: %.c
	@$(CPP) $(CFLAGS) $< -MM -MT $(@:.d=.o) >$@

%.d: %.cc
	@$(CPP) $(CXXFLAGS) $< -MM -MT $(@:.d=.o) >$@

.PHONY: clean
clean:
	rm -f $(obj) $(bin) $(dep)

include build/macapp.mk
