src = $(wildcard src/*.c)
obj = $(src:.c=.o)
dep = $(obj:.o=.d)
bin = view3d

CFLAGS = -pedantic -Wall -g $(incdir)
LDFLAGS = $(libdir) $(libgl) -lassimp -lm -limago

ifeq ($(shell uname -s), Darwin)
	libgl = -framework OpenGL -framework GLUT -lGLEW
	incdir = -I/opt/local/include
	libdir = -L/opt/local/lib
else
	libgl = -lGL -lGLU -lglut -lGLEW
endif

$(bin): $(obj)
	$(CC) -o $@ $(obj) $(LDFLAGS)

-include $(dep)

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

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

.PHONY: install
install: $(bin)
	mkdir -p $(INSTDIR)$(PREFIX)/bin
	cp $(bin) $(INSTDIR)$(PREFIX)/bin/$(bin)

.PHONY: uninstall
uninstall:
	rm -f $(INSTDIR)$(PREFIX)/bin/$(bin)
