csrc = $(wildcard src/*.c) $(wildcard vmath/*.c) $(wildcard drawtext/*.c)
ccsrc = $(wildcard src/*.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. -Ivmath -Idrawtext `pkg-config --cflags freetype2`

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

ifeq ($(shell uname -s), Darwin)
	libgl = -framework OpenGL -framework GLUT -lglew
else
	libgl = -lGL -lGLU -lglut -lGLEW
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
