title: Makefile automatic dependency not working with GNU Make 4.0 or later
body: <p>I have created the following makefile with reference to <a href="http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/" rel="nofollow noreferrer">this site</a> to try out automatic dependency generation. My makefile works fine when I run it with GNU Make 3.81(the one that comes with macOS). However, if I run it with the newer version of GNU Make(4.3, installed via Homebrew), all the objects and dependency files get recreated every single time when I run make, even though there is no change in the source files.</p>
  <pre><code>CXX          := clang++
  CXXFLAGS     := -Wall -Werror -std=c++11
  ICUROOT      := ${HOME}/opt/icu4c
  XERCESCROOT  := ${HOME}/opt/xercesc
  CPPFLAGS     := -I$(ICUROOT)/include -I$(XERCESCROOT)/include
  LDFLAGS      := -lxerces-c -licuuc
  LDLIBS       := -L$(ICUROOT)/lib -L$(XERCESCROOT)/lib
  OBJDIR       := obj
  DEPDIR       := $(OBJDIR)/.deps
  DEPFLAGS      = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.d
  
  SRCS = $(wildcard *.cpp)
  
  
  .PHONY: all
  all: DOMPrint
  
  COMPILE.cc = $(CXX) $(DEPFLAGS) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
  
  $(OBJDIR)/%.o: %.cpp
  $(OBJDIR)/%.o: %.cpp $(DEPDIR)/%.d | $(DEPDIR)
      $(COMPILE.cc) $(OUTPUT_OPTION) $&lt;
  
  $(DEPDIR): ; @mkdir -p $@
  
  DEPFILES := $(SRCS:%.cpp=$(DEPDIR)/%.d)
  $(DEPFILES): ;
  
  DOMPrint: $(addprefix $(OBJDIR)/,DOMPrint.o DOMPrintFilter.o DOMPrintErrorHandler.o DOMTreeErrorReporter.o)
      $(CXX) $(CXXFLAGS) $(LDLIBS) $(LDFLAGS) -o $@ $^
  
  
  -include $(wildcard $(DEPFILES))
  </code></pre>
  <p>Debugging information printed from <code>make --debug</code>(partial), it shows that the dependency file is newer than the target, and the object file is rebuilt:</p>
  <pre><code>GNU Make 4.3
  Built for arm-apple-darwin21.1.0
  Copyright (C) 1988-2020 Free Software Foundation, Inc.
  License GPLv3+: GNU GPL version 3 or later &lt;http://gnu.org/licenses/gpl.html&gt;
  This is free software: you are free to change and redistribute it.
  There is NO WARRANTY, to the extent permitted by law.
  Reading makefiles...
  Updating makefiles....
  Updating goal targets....
   File 'all' does not exist.
       Prerequisite 'obj/.deps/DOMPrintErrorHandler.d' is newer than target 'obj/DOMPrintErrorHandler.o'.
      Must remake target 'obj/DOMPrintErrorHandler.o'.
  clang++ -MT obj/DOMPrintErrorHandler.o -MMD -MP -MF obj/.deps/DOMPrintErrorHandler.d -Wall -Werror -std=c++11 -I/Users/chunwaichan/opt/icu4c/include -I/Users/chunwaichan/opt/xercesc/include  -c -o obj/DOMPrintErrorHandler.o DOMPrintErrorHandler.cpp
      Successfully remade target file 'obj/DOMPrintErrorHandler.o'.
  ...
  </code></pre>
  <p>However, looking at the last modified time in <code>make -p</code> output below(partial), the dependency file isn't newer than the object file, but the automatic variable <code>?</code> does show that it is newer.</p>
  <pre><code>obj/DOMPrintErrorHandler.o: DOMPrintErrorHandler.cpp obj/.deps/DOMPrintErrorHandler.d ...
  #  Implicit rule search has been done.
  #  Implicit/static pattern stem: 'DOMPrintErrorHandler'
  #  Last modified 2022-01-08 10:50:25.517904773
  #  File has been updated.
  #  Successfully updated.
  # automatic
  # ? := obj/.deps/DOMPrintErrorHandler.d
  
  obj/.deps/DOMPrintErrorHandler.d:
  #  Implicit rule search has not been done.
  #  Last modified 2022-01-08 09:45:13.890973263
  #  File has been updated.
  #  Successfully updated.
  #  recipe to execute (from 'Makefile', line 32):
  </code></pre>
  <p>I have tested this makefile with GNU Make 3.81 till 4.3, starting from version 4.0, this issue happens. I would like to know what change/enhancement in the newer version of GNU Make has caused this issue and how can I fix my makefile to make it compatible.</p>