Created
April 8, 2017 07:15
-
-
Save vsee/227ff0817856420da8636e1a2b8deb97 to your computer and use it in GitHub Desktop.
Out of Source Build Makefile Template for C++ Projects
This file contains hidden or 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
APP=appname | |
SRC_DIR=src | |
INC_DIR=inc | |
OBJ_DIR=obj | |
BIN_DIR=bin | |
CC=g++ | |
LD=g++ | |
CFLAGS=-O2 -c -Wall -std=c++11 | |
LFLGAS= | |
DFLAGS=-g3 -O0 -DDEBUG | |
INCFLAGS=-I$(INC_DIR) | |
SOURCES=$(wildcard $(SRC_DIR)/*.cpp) | |
HEADERS=$(wildcard $(INC_DIR)/*.hpp) | |
OBJECTS=$(SOURCES:$(SRC_DIR)/%.cpp=$(OBJ_DIR)/%.o) | |
DEPENDS=$(OBJ_DIR)/.depends | |
.PHONY: all | |
all: $(BIN_DIR)/$(APP) | |
.PHONY: debug | |
debug: CFLAGS+=$(DFLAGS) | |
debug: all | |
$(BIN_DIR)/$(APP): $(OBJECTS) | $(BIN_DIR) | |
$(LD) $(LFLGAS) -o $@ $^ | |
$(OBJ_DIR)/%.o: | $(OBJ_DIR) | |
$(CC) $(CFLAGS) $(INCFLAGS) -o $@ $< | |
$(DEPENDS): $(SOURCES) | $(OBJ_DIR) | |
$(CC) $(INCFLAGS) -MM $(SOURCES) | sed -e 's!^!$(OBJ_DIR)/!' >$@ | |
ifneq ($(MAKECMDGOALS),clean) | |
-include $(DEPENDS) | |
endif | |
$(BIN_DIR): | |
mkdir -p $@ | |
$(OBJ_DIR): | |
mkdir -p $@ | |
.PHONY: clean | |
clean: | |
rm -rf $(BIN_DIR) $(OBJ_DIR) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on a post by elpato.
Thanks!