Skip to content

Instantly share code, notes, and snippets.

@seanpianka
Last active September 21, 2018 20:12
Show Gist options
  • Save seanpianka/caa6c10c188fe45e09ff07c1f507710b to your computer and use it in GitHub Desktop.
Save seanpianka/caa6c10c188fe45e09ff07c1f507710b to your computer and use it in GitHub Desktop.
C/C++ Makefile Template
# if there is a clock skew detected, run:
# find /your/dir -type f -exec touch {} +
CXX := g++
CXXSTD := -std=c++11
CXXFLAGS := -Wall -Wextra -O2
SRCDIR := src
BUILDDIR := build
TARGET := bin/a.out
LIB_IDS :=
INCDIR := include/
INC := -I$(INCDIR)
LIBS_DIRS :=
LIBS :=
SRCEXT := cpp
SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT))
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o))
HDREXT := hpp
HEADERS := $(shell find $(INCDIR) -type f -name *.$(HDREXT))
.PRECIOUS: $(TARGET) $(OBJECTS)
default: $(TARGET)
all: default
$(TARGET): $(OBJECTS)
@echo "Linking...";
mkdir -p bin/
$(CXX) $^ -o $(TARGET) $(LIBS_DIRS) $(LIBS);
$(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT)
@mkdir -p $(BUILDDIR);
@echo "Compiling...";
$(CXX) $(CXXSTD) $(CXXFLAGS) $(INC) -c -o $@ $<;
clean:
@echo " Cleaning...";
rm -r $(BUILDDIR) $(TARGET)
.PHONY: clean
@Vickygibbs
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment