title: How to extend makefile to compose library?
body: <p>I have a makefile which does what I want with the compilation but I want it also to make a library instead of only object files.</p>
  
  <pre><code>CC=gcc
  CFLAGS=-g -Wall
  DEPS = tree.h
  OBJ = main.o tree.o 
  
  %.o: %.c $(DEPS)
      $(CC) -c -o $@ $&lt; $(CFLAGS)
  
  tree: $(OBJ)
      $(CC) -o $@ $^ $(CFLAGS)
  
  clean:
      rm -f *.o tree
  </code></pre>
  
  <p>Now I want the makefile to be something like this:</p>
  
  <pre><code>gcc -Wall -g -c tree.c
  ar -r libtree.a tree.o
  gcc main.c -o main -ltree -L.
  ./main
  </code></pre>
  
  <p>What I have to add to my existing makefile?</p>