CXX:=g++
RM:=rm -f
CPPFLAGS:=-g -std=c++11 -Wall -Wpedantic
LDFLAGS=
LDLIBS=
OUTPUT_OPTION=-o $(OBJDIR)$@

TARGET:=cherry
OBJDIR:=obj/
BINDIR:=bin/

required_dirs:=$(OBJDIR) $(BINDIR)

_MKDIRS:=$(shell for d in $(required_dirs); do [ -d $$d ] || mkdir -p $$d; done)

#Assume *all* cpp files in the current directory are part of the project.
sources:=$(wildcard *.cpp)
object_targets:=$(subst .cpp,.o,$(sources))
#Put the generated object files in a seperate subdir.
object_files:=$(patsubst %,$(OBJDIR)%,$(subst ./,,$(object_targets)))

#Build the executable.
$(TARGET): $(object_targets)
	$(CXX) $(LDFLAGS) -o $(BINDIR)$@ $(object_files) $(LDLIBS)

depend: .depend

#Create the file with all the compilation dependencies.
.depend: $(sources)
	@echo Creating dependencies...
	@rm -f ./.depend
	@$(CXX) $(CPPFLAGS) -MM $^ >>./.depend;

#Remove the (generated) object files and executable
clean:
	$(RM) $(object_files)
	$(RM) $(BINDIR)$(TARGET)

#Remove everything that can be regenerated and should not be part of
#a distribution.
dist-clean: clean
	$(RM) *~ .depend

#Silently include all the compilation dependencies.
-include .depend
