Skip to content

Instantly share code, notes, and snippets.

@deciduously
Created July 23, 2019 00:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deciduously/3224c493448c95cf153b2061dd7da02d to your computer and use it in GitHub Desktop.
Save deciduously/3224c493448c95cf153b2061dd7da02d to your computer and use it in GitHub Desktop.
General makefile template for basic CPP projects
CXX=clang++ -std=c++11
FLAGS=-Wall -Wextra -Werror -pedantic -c -g
BUILDDIR=build
SOURCEDIR=src
EXEC=PROJECT-NAME-HERE
SOURCES=$(wildcard $(SOURCEDIR)/*.cpp)
OBJ=$(patsubst $(SOURCEDIR)/%.cpp,$(BUILDDIR)/%.o,$(SOURCES))
all: dir $(BUILDDIR)/$(EXEC)
dir:
mkdir -p $(BUILDDIR)
$(BUILDDIR)/$(EXEC): $(OBJ)
$(CXX) $^ -o $@
$(OBJ): $(BUILDDIR)/%.o : $(SOURCEDIR)/%.cpp
$(CXX) $(FLAGS) $< -o $@
clean:
rm -rf $(BUILDDIR)/*.o $(BUILDDIR)/$(EXEC)
.PHONY: all clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment