Here is the Makefile that I use in many projects:
CC = g++
OPTS = -std=c++11
PROJECT = foo_example_program
LIBS = -lpthread
INCS = -I./src/include
SRCS = $(shell find src -name '*.cpp')
DIRS = $(shell find src -type d | sed 's/src/./g' )
OBJS = $(patsubst src/%.cpp,out/%.o,$(SRCS))
$(PROJECT): buildrepo $(OBJS)
$(CC) $(OPTS) $(OBJS) $(LIBS) $(INCS) -o $@
out/%.o: src/%.cpp
$(CC) $(OPTS) -c $< $(INCS) -o $@
clean:
rm $(PROJECT) out -Rf
buildrepo:
mkdir -p out
for dir in $(DIRS); do mkdir -p out/$$dir; done
. , , src - , , . . , . , "object.1.o" "object.2.o" - .