CFLAGS=$(INCLUDEDDIRS) -O2 -Wall
CXXFLAGS=$(CFLAGS)
LOADLIBES=-rdynamic -L/usr/X11R6/lib -lX11 -lpthread -lGL -lGLU -lglut
TARGET=stereogram

-include Makefile.d


$(TARGET) : $(SRCOBJS)
	$(LINK.cpp) $+ -o $@ $(LOADLIBES)

all: $(TARGET)


.PHONY: run rebuilt clean

run : $(TARGET)
	./$(TARGET)

rebuild: clean $(TARGET)

clean:
	find -name \*.d -o -name \*.o -o -name \*~ -o -name $(TARGET) | xargs rm



# Dependencies of the executable
Makefile.d:
	@echo -n SRCOBJS= > $@
	@find . -iname \*.cpp -o -iname \*.c | sed 's/\(.*\.\)c\(pp\)\?/\1o \\/' >> $@
	@echo >> $@
	@echo INCLUDEDDIRS=-I. \\ >> $@
	@find . -iname \* -type d | sed 's/\(.*\)/-I\1 \\/g' >> $@


# Dependencies of the source files
%.d : %.cpp
	@$(CXX) $(CXXFLAGS) -c $< -MM | sed 's/.*\.o[ :]*/$(subst /,\/,$*).o $(subst /,\/,$*).d : /g' > $@;

%.d : %.c
	@$(CC) $(CFLAGS) -c $< -MM | sed 's/.*\.o[ :]*/$(subst /,\/,$*).o $(subst /,\/,$*).d : /g' > $@;

-include $(SRCOBJS:.o=.d)
