From: Daniel Karbach Date: Thu, 5 Mar 2015 14:27:42 +0000 (+0100) Subject: separate build directory for intermediates X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=d5a078a95bb406936e472ba6b22257a442a7b2d4;p=blank.git separate build directory for intermediates --- diff --git a/.gitignore b/.gitignore index 0f9ba43..efe752e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ -*.d -*.o *.swp *.swo blank +build diff --git a/Makefile b/Makefile index 20b02e9..0665d5c 100644 --- a/Makefile +++ b/Makefile @@ -19,22 +19,33 @@ CXXFLAGS += -g3 -O0 # release #CPPFLAGS += -DNDEBUG -SRC = $(wildcard src/*.cpp) -OBJ = $(SRC:.cpp=.o) -DEP = $(SRC:.cpp=.d) +SOURCE_DIR := src +BUILD_DIR := build + +SRC = $(wildcard $(SOURCE_DIR)/*.cpp) +OBJ = $(patsubst $(SOURCE_DIR)/%.cpp, $(BUILD_DIR)/%.o, $(SRC)) +DEP = $(OBJ:.o=.d) BIN = blank all: $(BIN) clean: - rm -f $(BIN) $(OBJ) $(DEP) + rm -df $(OBJ) $(DEP) $(BUILD_DIR) + +distclean: clean + rm -f $(BIN) -.PHONY: all clean +.PHONY: all clean distclean -include $(DEP) $(BIN): $(OBJ) - $(LDXX) -o $@ $(CXXFLAGS) $(LDXXFLAGS) $^ + @echo link: $@ + @$(LDXX) -o $@ $(CXXFLAGS) $(LDXXFLAGS) $^ + +$(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.cpp | $(BUILD_DIR) + @echo compile: $@ + @$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) -o $@ -MMD -MP -MF"$(@:.o=.d)" -MT"$@" $< -%.o: %.cpp - $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) -o $@ -MMD -MP -MF"$*".d -MT"$@" $< +$(BUILD_DIR): + mkdir "$@"