title: Makefile auto-dependency generation
body: <p>I am trying to see auto generated dependency the makefile is below:</p>
  
  <pre><code>  OBJS := main.o 
  
    run : $(OBJS)
          $(CC) $(OBJS) -o run -lstdc++
  
    -include $(OBJS:.o=.d)
  
   %.o : %.cpp
        $(CC) -c $(CFLAGS) $*.cpp -o $*.o
  
   %.d : %.cpp
         @set -e; rm -f $@; \
         $(CC) -M $(CPPFLAGS) $&lt; &gt; $@.$$$$; \
         echo "creating dependency file."; \
         sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' &lt; $@.$$$$ &gt; $@; \
         rm -f $@.$$$$
  
    # remove compilation products
    clean :
           rm -f run *.o *.d*
  </code></pre>
  
  <p>But the makefile generate a huge list of dependency in main.d but the actual needed is the first few lines. So where I am getting wrong?</p>