Skip to content

Instantly share code, notes, and snippets.

@Rio6
Last active September 12, 2017 02:59
Show Gist options
  • Save Rio6/13c454043ec5995732d349400d13943b to your computer and use it in GitHub Desktop.
Save Rio6/13c454043ec5995732d349400d13943b to your computer and use it in GitHub Desktop.
makefile template
SRCDIR:=src
BUILDDIR:=build
CXXFLAGS:=-O2 -Wall
LIBS:=-llibs
SRCS:=$(wildcard $(SRCDIR)/*.cpp)
HDRS:=$(wildcard $(SRCDIR)/*.hpp)
OBJS:= $(patsubst $(SRCDIR)/%.cpp,$(BUILDDIR)/%.o,$(SRCS))
TGT:=name
all: $(BUILDDIR) $(TGT)
$(TGT): $(OBJS)
$(CXX) $(CXXFLAGS) $(LIBS) $(OBJS) -o $(TGT)
$(BUILDDIR)/%.o: $(SRCDIR)/%.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@
$(BUILDDIR):
mkdir -p $(BUILDDIR)
clean:
$(RM) -r build
depend: .depend
.depend: $(SRCS) $(HDRS)
$(CXX) $(CXXFLAGS) -MM $^ | sed 's|[a-zA-Z0-9_-]*\.o|$(BUILDDIR)/&|' > .depend
include .depend
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment