title: $(file < $@) expands to nothing but it should not
body: <p>I wrote this make rule</p>
  
  <pre><code>$(COMPDIR)/%.d: $(COMPDIR)/%.cpp
  # other code...
      $(file &gt; $@,$(foreach path,$(file &lt; $@),$(shell echo "$(path)" | sed 's!$(SRCDIR)/!$(COMPDIR)/!')))
  # other code...
  </code></pre>
  
  <p>This should read the target file $@, tokenize its contents in the usual way of make ( whitespace separated words ), pass the tokens to sed and then save the result back into the same file.</p>
  
  <p>If i put a literal file path in place of $@ the code works as intended, but if i leave it as it is it does just nothing.</p>
  
  <p>I traced the root problem to be what i wrote in the title because i have verified that</p>
  
  <pre><code>    echo '$(file &lt; $@)'
  </code></pre>
  
  <p>prints nothing.</p>
  
  <p>The file is guaranteed to be populated because the only command that precedes the one i showed is the one that creates and populates it.</p>
  
  <p>Any thoughts ?</p>
  
  <p>EDIT 1: Some additional info</p>
  
  <p>Software running on my system:</p>
  
  <ul>
  <li>GNU Make 4.2.1</li>
  <li>Bash 5.0.007 in POSIX mode ( invoked via /bin/sh )</li>
  </ul>
  
  <p>Relevant variables defined in the makefile:</p>
  
  <pre><code>SHELL   ?= /bin/sh
  SRCDIR  := src
  COMPDIR := build/files
  </code></pre>
  
  <p>To respond to comments, here is the full rule with added test code:</p>
  
  <pre><code>$(COMPDIR)/%.d: $(COMPDIR)/%.cpp
      @ mkdir -p $(dir $@)
      @ echo "Generating make rule for $(subst .d,.o,$@)"
  
  # Generate recipe dependencies
      $(CXX) -o $@ $(subst $(COMPDIR),$(SRCDIR),$&lt;) -MM -MT $(subst .d,.o,$@) $(ALL_CPPFLAGS) $(ALL_CXXFLAGS)
  
  # Patch the generated recipe to request source files from $(COMPDIR)
      $(file &gt; $(@),$(foreach path,$(file &lt; $(@)),$(shell echo "$(path)" | sed 's!$(SRCDIR)/!$(COMPDIR)/!')))
  
  # Inject compilation instructions
      @ echo -e "\t$(CXX) -c -o $(subst .d,.o,$@) $^ $(ALL_CPPFLAGS) $(ALL_CXXFLAGS)" &gt;&gt; $@
  
  # Tests
      @ echo -e "\n\n"
      @ echo -------------
  
      @ echo TARGET: $@
  
      @ echo -e "\n\n"
  
      ls -R $(COMPDIR)
  
      @ echo -e "\n\n"
  
      cat $@
  
      @ echo -------------
      @ echo -e "\n\n"
  </code></pre>
  
  <p>and the output it produces when make is called</p>
  
  <pre><code>ln -sf /home/qub1750ul/work/studentIngegneria/AssociateManager.BACKEND/src/auth/auth.cpp build/files/auth/auth.cpp
  Generating make rule for build/files/auth/auth.o
  g++ -o build/files/auth/auth.d src/auth/auth.cpp -MM -MT build/files/auth/auth.o -DDEBUG -I/usr/local/include -Ilib/json/single_include -Ilib/pistache/include -g -std=c++17
  
  
  
  -------------
  TARGET: build/files/auth/auth.d
  
  
  
  ls -R build/files
  build/files:
  auth
  
  build/files/auth:
  auth.cpp  auth.d
  
  
  
  cat build/files/auth/auth.d
  build/files/auth/auth.o: src/auth/auth.cpp src/auth/auth.hpp \
   lib/json/single_include/nlohmann/json.hpp \
   src/auth/../database/interface.hpp
  -------------
  
  
  
  ln -sf /home/qub1750ul/work/studentIngegneria/AssociateManager.BACKEND/src/server/server.cpp build/files/server/server.cpp
  Generating make rule for build/files/server/server.o
  g++ -o build/files/server/server.d src/server/server.cpp -MM -MT build/files/server/server.o -DDEBUG -I/usr/local/include -Ilib/json/single_include -Ilib/pistache/include -g -std=c++17
  
  
  
  -------------
  TARGET: build/files/server/server.d
  
  
  
  ls -R build/files
  build/files:
  auth  server
  
  build/files/auth:
  auth.cpp  auth.d
  
  build/files/server:
  server.cpp  server.d
  
  
  
  cat build/files/server/server.d
  build/files/server/server.o: src/server/server.cpp src/server/server.hpp \
   lib/pistache/include/pistache/endpoint.h \
   lib/pistache/include/pistache/listener.h \
   lib/pistache/include/pistache/tcp.h \
   lib/pistache/include/pistache/flags.h \
   lib/pistache/include/pistache/prototype.h \
   lib/pistache/include/pistache/common.h \
   lib/pistache/include/pistache/net.h lib/pistache/include/pistache/os.h \
   lib/pistache/include/pistache/config.h \
   lib/pistache/include/pistache/async.h \
   lib/pistache/include/pistache/typeid.h \
   lib/pistache/include/pistache/reactor.h \
   lib/pistache/include/pistache/http.h \
   lib/pistache/include/pistache/http_headers.h \
   lib/pistache/include/pistache/http_header.h \
   lib/pistache/include/pistache/mime.h \
   lib/pistache/include/pistache/optional.h \
   lib/pistache/include/pistache/http_defs.h \
   lib/pistache/include/pistache/type_checkers.h \
   lib/pistache/include/pistache/cookie.h \
   lib/pistache/include/pistache/stream.h \
   lib/pistache/include/pistache/peer.h \
   lib/pistache/include/pistache/transport.h \
   lib/pistache/include/pistache/mailbox.h \
   lib/pistache/include/pistache/view.h \
   lib/json/single_include/nlohmann/json.hpp src/server/../auth/auth.hpp \
   src/server/../auth/../database/interface.hpp
  -------------
  
  
  
  ln -sf /home/qub1750ul/work/studentIngegneria/AssociateManager.BACKEND/src/main.cpp build/files/main.cpp
  Generating make rule for build/files/main.o
  g++ -o build/files/main.d src/main.cpp -MM -MT build/files/main.o -DDEBUG -I/usr/local/include -Ilib/json/single_include -Ilib/pistache/include -g -std=c++17
  
  
  
  -------------
  TARGET: build/files/main.d
  
  
  
  ls -R build/files
  build/files:
  auth  main.cpp  main.d  server
  
  build/files/auth:
  auth.cpp  auth.d
  
  build/files/server:
  server.cpp  server.d
  
  
  
  cat build/files/main.d
  build/files/main.o: src/main.cpp src/auth/auth.hpp \
   lib/json/single_include/nlohmann/json.hpp \
   src/auth/../database/interface.hpp
  -------------
  
  
  
  rm build/files/server/server.cpp build/files/main.cpp build/files/auth/auth.cpp
  g++ -c -o build/files/auth/auth.o build/files/auth/auth.cpp -DDEBUG -I/usr/local/include -Ilib/json/single_include -Ilib/pistache/include -g -std=c++17
  g++: error: build/files/auth/auth.cpp: No such file or directory
  g++: fatal error: no input files
  compilation terminated.
  make: *** [build/files/auth/auth.d:4: build/files/auth/auth.o] Error 1
  </code></pre>