# Compiler to use
CC = g++ -std=c++11
# Directories
SRCDIR = src
INCDIR = include
BINDIR = bin
OBJDIR = obj
# Options for the compiler
OPTIONS = -O2 -g -Wall
INCLUDES = -I ./$(INCDIR)
LIBS = -lm -lpthread
PLATFORM = WINDOWS
# Defines for compilation
DEFINES = -DPLATFORM=$(PLATFORM)
debug: DEFINES += -DDEBUG
# Name of target binary
TARGET = app.exe
# List of objects to be build
_OBJS = \
	help.o \
	introduction.o \
	synchronization.o \
	threadpool.o \
	app.o

OBJS = $(patsubst %,$(OBJDIR)/%,$(_OBJS))

# To declare all, clean are not files
.PHONY: all clean
 
# The main targets
all: debug release
 
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp 
	$(CC) -c $(INCLUDES) -o $@ $< $(OPTIONS) $(DEFINES)

# To clean this mess
clean:
	@echo "Cleaning up ..."
	-rm -rf ${OBJDIR}/*.o

# To compile the release version
release: $(OBJS)
	@echo "Building release version ..."
	$(CC) -o ${BINDIR}/release/${TARGET} $^ $(OPTIONS) $(LIBS)
	strip ${BINDIR}/release/${TARGET}

# To compile the debug version
debug: $(OBJS)
	@echo "Building debug version ..."
	$(CC) -o ${BINDIR}/debug/${TARGET} $^ $(OPTIONS) $(LIBS)
