PROGRAM = cchess SOURCE := $(wildcard $(patsubst %,%/*.cpp,src)) OBJECTS = $(patsubst %.cpp,%.o,$(SOURCE)) dependencies = $(subst .o,.d,$(OBJECTS)) # implementation .SUFFIXES: .o .cpp all: $(PROGRAM) CFLAGS+= -Isrc `allegro-config --cflags` -Wall -g ifneq "$(MAKECMDGOALS)" "clean" -include $(dependencies) endif define make-depend @$(CXX) $(CFLAGS) -MM -MF $(subst .o,.d,$@) -MP -MT $2 $1 endef %.o: %.cpp $(call make-depend,$<,$@) $(CXX) -c $(CFLAGS) -o $@ $< $(PROGRAM):$(OBJECTS) $(CXX) -o $(PROGRAM) $(LIBS) `allegro-config --libs` -llirc_client $(OBJECTS) clean: rm -f *.o $(PROGRAM) $(OBJECTS) $(dependencies)