Skip to content

Instantly share code, notes, and snippets.

@simonwagner
Created June 22, 2013 15:07
Show Gist options
  • Save simonwagner/5841223 to your computer and use it in GitHub Desktop.
Save simonwagner/5841223 to your computer and use it in GitHub Desktop.
Nearly perfect automatic Makefile for C++11. Simply drop it into your source folder and you are done.
TARGET = program
CXXFLAGS += -g -std=c++11
.PHONY: default all clean
default: $(TARGET)
all: default
SOURCES = $(wildcard **/*.cpp) $(wildcard *.cpp)
OBJECTS = $(patsubst %.cpp, %.o, $(SOURCES))
DEPENDENCIES := $(OBJECTS:.o=.d)
-include $(DEPENDENCIES)
%.o: %.cpp
$(CXX) $(CXXFLAGS) -MMD -c -o $@ $<
.PRECIOUS: $(TARGET) $(OBJECTS)
$(TARGET): $(OBJECTS)
$(CXX) $(CXXFLAGS) $(OBJECTS) -Wall -o $@
clean:
rm -f $(OBJECTS)
rm -f $(TARGET)
rm -f $(DEPENDENCIES)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment