Last active
September 23, 2016 11:22
-
-
Save melmi/ad2e3ed3e591b71d6aec20fe2d502497 to your computer and use it in GitHub Desktop.
A general purpose makefile for c++ projects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PROJNAME = your_project_name | |
SRCDIR = src | |
OBJDIR = bin | |
DEPDIR = bin | |
BINDIR = bin | |
CXX = g++ | |
CXXFLAGS = -O3 -std=c++14 | |
LDFLAGS = | |
TARGET = $(BINDIR)/$(PROJNAME) | |
SRCS = $(wildcard $(SRCDIR)/*.cpp) | |
OBJS = $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS)) | |
DEPS = $(patsubst $(SRCDIR)/%.cpp,$(DEPDIR)/%.depends,$(SRCS)) | |
.PHONY: all clean run | |
all: $(TARGET) | |
@echo Done. | |
$(TARGET): $(OBJS) | |
@echo Linking $@ | |
@mkdir -p $(BINDIR) | |
@$(CXX) $(CXXFLAGS) $(OBJS) $(LDFLAGS) -o $(TARGET) | |
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp | |
@echo Compiling $< | |
@mkdir -p $(OBJDIR) | |
@$(CXX) $(CXXFLAGS) -c $< -o $@ | |
$(DEPDIR)/%.depends: $(SRCDIR)/%.cpp | |
@echo Generating dependencies $< | |
@mkdir -p $(DEPDIR) | |
@$(CXX) -MM $(CXXFLAGS) $< -MT $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$<) -MF $@ | |
clean: | |
@rm -f $(OBJS) $(DEPS) $(TARGET) | |
run: all | |
$(TARGET) | |
-include $(DEPS) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment