# 
# example Makefile
# 

deps = .deps

CXX = g++
CXXFLAGS = -I.

PREPHEADERS = test.h

SOURCES = test.cpp

OBJECTS = $(SOURCES:%.cpp=%.o)

PREPOUTPUT = $(PREPHEADERS:%.h=%.prep.cpp) $(PREPHEADERS:%.h=%.prep.h) 

all: $(OBJECTS)

%.prep.cpp %.prep.h: %.h
	echo "/* cpp */" > $(<:%.h=%.prep.cpp) 
	echo "/* h   */" > $(<:%.h=%.prep.h) 

$(deps)/%.d: %.cpp $(PREPOUTPUT)
	[ -d $(deps) ] || mkdir $(deps)
	echo -n "$@ " > $@ 
	$(CXX) -M $(CXXFLAGS) $< >> $@
	mv -f $@ $(@:%.d=%.D)
	echo timestamp > $@

-include $(SOURCES:%.cpp=$(deps)/%.D)

%.o: %.cpp 

%.o: %.cpp $(deps)/%.d
	$(CXX) $(CXXFLAGS) -c $< -o $@

.PHONY: all
