Created
May 17, 2021 17:33
-
-
Save hrlou/cee369c277854c144fe94776473071d9 to your computer and use it in GitHub Desktop.
Basic Makefile for most 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
CXX=c++ | |
CXXFLAGS=-std=c++11 -pipe -pedantic -O3 -Wall | |
PREFIX=/usr/local | |
INCLUDE=-I. -I./include | |
LDFLAGS= | |
BIN=bin | |
BUILD_DIR=./build | |
CPP=$(wildcard src/*.cpp) | |
OBJ=$(CPP:%.cpp=$(BUILD_DIR)/%.o) | |
DEP=$(OBJ:%.o=%.d) | |
.PHONY: all clean | |
all: post-build | |
pre-build: | |
@mkdir $(BUILD_DIR) | |
post-build: main-build | |
main-build: pre-build | |
@$(MAKE) --no-print-directory $(BIN) | |
$(BIN) : $(BUILD_DIR)/$(BIN) | |
$(BUILD_DIR)/$(BIN) : $(OBJ) | |
@mkdir -p $(@D) | |
$(CXX) $(CXXFLAGS) $(INCLUDE) $^ -o $@ $(LDFLAGS) | |
-include $(DEP) | |
$(BUILD_DIR)/%.o : %.cpp | |
@mkdir -p $(@D) | |
$(CXX) $(CXXFLAGS) $(INCLUDE) -MMD -c $< -o $@ | |
clean: | |
-rm -rf $(OBJ) $(DEP) $(BUILD_DIR) | |
install: all | |
install -m 775 $(BIN) $(PREFIX)/bin/$(BIN) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment