title: How to delete intermediate object files in makefile
body: <p>I want to know how to force make to delete .o files after building the library in a correct way.</p>
  
  <pre><code>all: libtest.a
  
  libtest.a: foo.o bar.o
      ar r $@ $?
  
  %.o : %.c
      gcc -o $@ -c $&lt;
  </code></pre>
  
  <p>The problem with marking the .o files as <code>.INTERMEDIATE</code> is that all the .o files are being recompiled if even one source file changes, even though they are already present in the archive. Is there a way to achieve this. Have the object files deleted and not recompile unchanged source files to update the library.</p>