Skip to content

Instantly share code, notes, and snippets.

@kiarina
Created April 30, 2019 13:39
Show Gist options
  • Save kiarina/9ca0b76640bf77c3b777e09998a36e57 to your computer and use it in GitHub Desktop.
Save kiarina/9ca0b76640bf77c3b777e09998a36e57 to your computer and use it in GitHub Desktop.
CXX = g++
CXXFLAGS = -std=c++11 -g -MMD -MP
SRC_DIR = ./src
OBJ_DIR = ./build
SOURCES = $(shell ls $(SRC_DIR)/*.cpp)
OBJS = $(subst $(SRC_DIR), $(OBJ_DIR), $(SOURCES:.cpp=.o))
TARGET = build/main
DEPENDS = $(OBJS:.o=.d)
.PHONY: all
all: $(TARGET)
$(TARGET): $(OBJS)
$(CXX) $(CXXFLAGS) -o $@ $(OBJS)
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
@if [ ! -d $(OBJ_DIR) ]; then mkdir -p $(OBJ_DIR); fi
$(CXX) $(CXXFLAGS) -o $@ -c $<
.PHONY: clean
clean:
rm $(OBJS) $(TARGET) $(DEPENDS)
-include $(DEPENDS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment