Last active
September 21, 2018 20:12
-
-
Save seanpianka/caa6c10c188fe45e09ff07c1f507710b to your computer and use it in GitHub Desktop.
C/C++ Makefile Template
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
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice post. Thanks for sharing!
[url=http://jsonformatter-online.com /]json formatter[/url]