Created
February 8, 2015 16:01
-
-
Save a3f/2ce727bbea027cadc87c to your computer and use it in GitHub Desktop.
Simple 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
# hereby released into the public domain (first time; Am I doing this right?) | |
#. | |
#├── Makefile | |
#│ | |
#├── $(SRCDIR) | |
#│ └── $(SRCS) (source files) | |
#│ | |
#├── $(OBJDIR) | |
#│ ├── *.o (automatically generated) | |
#│ └── *.d (automatically generated) | |
#│ | |
#└── $(BIN_NAME) (if everything works out) | |
# features: | |
## different folders for source, objects and binary | |
## changing non-system-header will (only) trigger recompilation of files that include it | |
## make clean removes generated files | |
## works on windows/unix | |
SRCDIR = src | |
OBJDIR = build | |
BIN_NAME = program.exe | |
override FLAGS += -m32 -std=c++11 -Wall -Wextra -fdiagnostics-color=auto | |
LIBS = | |
SRCS = main.cpp a.cc b.cpp | |
# alternative: | |
# SRCS = $(wildcard $(SRCDIR)/*.cpp) | |
SRCEXT = cpp | |
INC += -Iinclude/ -Ilib/ | |
######### Don't touch anything past this | |
OBJS = $(SRCS:%.$(SRCEXT)=$(OBJDIR)/%.o) | |
.DEFAULT: (BIN_NAME) | |
$(BIN_NAME): $(OBJS) | |
$(CXX) $(FLAGS) $(OBJS) -o $@ $(LIBS) | |
$(OBJS): $(OBJDIR)/%.o: $(SRCDIR)/%.cc | |
$(CXX) -MMD $(FLAGS) -c $< -o $@ $(INC) | |
-include $(OBJDIR)/*.d | |
ifeq ($(OS),Windows_NT) | |
RM = del /Q | |
endif | |
.PHONY: clean | |
clean: | |
$(RM) $(BIN_NAME) && cd $(OBJDIR) && $(RM) "*.o" "*.d" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment