Skip to content

Instantly share code, notes, and snippets.

@etam
Last active May 8, 2017 09:40
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 etam/e05512a2331a72ad826ff97122208117 to your computer and use it in GitHub Desktop.
Save etam/e05512a2331a72ad826ff97122208117 to your computer and use it in GitHub Desktop.
Makefile for a single c++ binary
CC := gcc
CXX := g++
CPPFLAGS :=
CXXFLAGS := -std=c++14 -O2 -Wall -Wextra
LDFLAGS :=
LDLIBS := -lstdc++
OBJS := main.o
EXE := main
all: $(EXE)
$(EXE): $(OBJS)
DEPS := $(OBJS:.o=.d)
$(DEPS): %.d: %.cpp
@set -e; rm -f $@; \
DIR=`dirname $<`; \
$(CXX) -MM $(CXXFLAGS) $(CPPFLAGS) $< | \
sed "s,^\(.*\)\.o:,$$DIR/\1.d $$DIR/\1.o:," > $@
ifneq ($(MAKECMDGOALS),clean)
-include $(DEPS)
endif
clean:
$(RM) $(EXE) $(OBJS) $(DEPS)
.PHONY: all clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment