title: How to write a makefile to generate object files and executable in different directory?
body: <p>Now to proceed further I need to change the presentation of existing Makefile.</p>
  
  <p>Presently I am using:</p>
  
  <pre><code>~/Linuz/src: 1.c, 2.c, 3.c ...
  
  ~/Linuz/inc: abc.h, xyz.h
  </code></pre>
  
  <p>and makefile is in: <code>~/Linuz/some_other_dir/</code></p>
  
  <p>But need to change the structure.</p>
  
  <ol>
  <li>Want to create a library from (<code>~/Linuz/src/</code> and <code>~/linuz/inc</code>)</li>
  <li>Library will be used to get executable. Application source files(.c files) are in <code>~/Linuz/app/</code></li>
  <li><code>~/Linuz/bin/</code> should be created during compilation to store all the object files and executable file.</li>
  </ol>
  
  <p>Any suggestions ??</p>
  
  <p><strong>My makefile looks like this:</strong></p>
  
  <pre class="lang-none prettyprint-override"><code>all: Library.a
  
  %.o: ../src/%.c
  
      $(CC) $(CFLAGS) -I../inc/ -c -o $@ $^
  
  Library.a:  $(SRC_DIR)/1.c $(SRC_DIR)/2.c $(SRC_DIR)/3.c $(SRC_DIR)/4.c $(SRC_DIR)/5.c
  
      $(CC) $(LDFLAGS) -o $@ $^
  
  all: prog
  
  %.o: ./*.c
  
      $(CC) $(CFLAGS) -ILibrary.a -c -o $@ $^
  
  
  prog:   $(APP_DIR)/app1.c $(APP_DIR)/app2.c $(APP_DIR)/app3.c
  
  clean:
      rm -f *.o my_program
  </code></pre>