title: Specifying build directory in a make file
body: <p>I am relatively new to hand crafted make files. I have put together a basic make file for building a library. I want to keep all the temporary .o files in a build directory and have the built executable stored in a bin directory.</p>
  
  <p>My directory structure looks like this:</p>
  
  <pre><code>root
     src/
     include/
     build/
     bin/
     Makefile
  </code></pre>
  
  <p>and this is what my make file looks like:</p>
  
  <pre><code>SHLIB = pg_extlib
  
  SRC =  src/file1.c \
         src/file2.c
  
  OBJS = build/file1.o \
         build/file2.o
  
  debug_build:
      gcc -g -fPIC -c $(SRC) -I`pg_config --includedir` -I`pg_config --includedir-server` -I/some/required/path/include -Iinclude
      gcc -shared -o bin/$(SHLIB).so $(OBJS) -lm -lpq -lmylib_core
  
  
  clean:
      rm -f $(SHLIB) $(OBJS) 
  </code></pre>
  
  <p>The .o files are placed correctly in the build folder, but they also appear in the root folder (where the Makefile resides). How do I fix this?</p>