Created
February 26, 2018 17:30
-
-
Save skulumani/74f10588459973fb7178883f131b2dec to your computer and use it in GitHub Desktop.
Generic Makefile for a single executable
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
PRODUCT := ex6-10 | |
# directories | |
BINDIR := bin | |
INCDIR := include | |
SRCDIR := src | |
BUILDDIR := build | |
# compiler flags | |
CXX := g++ | |
LINKER := g++ | |
INCDIRS := -I$(INCDIR) | |
CXXFLAGS := -std=c++11 -Wall -Wextra -pedantic | |
SRCFILES := $(wildcard $(SRCDIR)/*.cpp) | |
OBJFILES := $(patsubst $(SRCDIR)/%.cpp, $(BUILDDIR)/%.o, $(SRCFILES)) | |
DEPFILES := $(patsubst $(SRCDIR)/%.cpp, $(BUILDDIR)/%.d, $(SRCFILES)) | |
# link the object files | |
$(BINDIR)/$(PRODUCT): $(OBJFILES) | |
$(LINKER) $(CXXFLAGS) $^ -o $@ | |
# compile src to object files | |
$(BUILDDIR)/%.o: $(SRCDIR)/%.cpp | |
$(CXX) $(CXXFLAGS) $(INCDIRS) -c $< -o $@ | |
# build dependencies | |
$(BUILDDIR)/%.d: $(SRCDIR)/%.cpp | |
$(CXX) $(INCDIRS) -MM $< | sed 's/^/$@ /' > $@ | |
$(OBJDIR)/%.d: $(SRCDIR)/%.cpp | |
$(CXX) $(INCDIRS) -MM $< | sed -e 's%^%$@ %' -e 's% % $(OBJDIR)/%' > $@ | |
-include $(DEPFILES) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Expects the following directory structure