help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Auto-Dependency Generation


From: Игорь Спиридонов
Subject: Auto-Dependency Generation
Date: Sat, 27 Apr 2019 21:11:49 +0300

Hello make experts. I decided to write this letter again since I forgot about
topic.
I'm trying to use Auto-Dependency Generation form this article - Auto-Dependency
GenerationThe article is very nice but i'm stuck. dependencies are generated in
.d folder correctly as written in the article but make doesn't build if i change
a header file.
Here is my Makefile:

# -*- Makefile -*-

DEP_DIR := .d

$(shell mkdir -p $(DEP_DIR) >/dev/null)

DEPFLAGS = -MT $@ -MMD -MP -MF $(DEP_DIR)/$*.Td

POSTCOMPILE = @mv -f $(DEP_DIR)/$*.Td $(DEP_DIR)/$*.d && touch $@

CXX := g++

CXXFLAGS := -std=c++17 -g

LIBS := -lsome_lib

PRODUCT := main

SRC_DIR := src

SRCFILES := $(wildcard $(SRC_DIR)/*.cpp)

OBJFILES := $(patsubst %.cpp,%.o,$(SRCFILES))

all: $(PRODUCT)

$(SRC_DIR)/%.o: $(SRC_DIR)/%.cpp $(DEP_DIR)/%.d

$(CXX) $(DEPFLAGS) $(CXXFLAGS) -o $@ -c $^

$(POSTCOMPILE)

$(PRODUCT): $(OBJFILES)

$(CXX) $^ $(LIBS) -o $@

$(DEP_DIR)/%.d: ;

.PRECIOUS: $(DEP_DIR)/%.d

.PHONY: clean

clean:

find ./src -name '*.o' -delete

find . -name '*.o' -delete

rm $(PRODUCT)

include $(wildcard $(patsubst %,$(DEP_DIR)/%.d,$(basename $(SRCFILES))))


Source files(cpp and hpp) are located in src folder.

I'm using gnu make 4.2.1 for mingw.


Have a wonderful time.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]