Skip to content

Instantly share code, notes, and snippets.

@liberaid2
Last active November 14, 2018 11:56
Show Gist options
  • Save liberaid2/e1a5b35d73648b55c8547887d0a98c6a to your computer and use it in GitHub Desktop.
Save liberaid2/e1a5b35d73648b55c8547887d0a98c6a to your computer and use it in GitHub Desktop.
Common makefile
CC=g++
CFLAGS=-c -Wall -std=c++17 -g -O0
LDFLAGS=
LIBS=
SRCDIR=src
OBJDIR=obj
SOURCES=$(wildcard $(SRCDIR)/*.cpp)
OBJECTS=$(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SOURCES))
EXEC=main
.SILENT:
all: $(SOURCES) $(EXEC)
$(EXEC): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $@ $(LIBS)
@echo LINK $@
$(OBJECTS): $(OBJDIR)/%.o: $(SRCDIR)/%.cpp
mkdir -p $(OBJDIR)
$(CC) $(CFLAGS) -o $@ $^
@echo C $^
clean:
rm -rf $(OBJDIR)
rm $(EXEC)
@echo Cleaned
memcheck: $(EXEC)
valgrind --leak-check=full --show-leak-kinds=all ./$(EXEC)
threadscheck: $(EXEC)
valgrind --tool=helgrind ./$(EXEC)
debug: $(EXEC)
gdb ./$(EXEC)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment