title: how to write a make file with a project : source in multi-level sub dir , keep obj file in separate folder?
body: <p>i have a C project , all source file (C and H files)in src directory , have lots of subdirectories</p>
  <p>now I want to</p>
  <p>1  copy all h files to .\header, without folder struct<br />
  2  complier all c files to .\obj, without folder stuct<br />
  3  myproject.exe in .\bin</p>
  <pre><code>D:\myproject
  +---bin
  +---header
  +---obj
  \---src
      |   main.c
      |   main.h
      |
      +---sub1
      |   |   1.c
      |   |   1.h
      |   |
      |   \---sub11
      |       |   11.c
      |       |   11.h
      |       |
      |       \---sub111
      |               111.c
      |               111.h
      |
      \---sub2
          |   2.c
          |   2.h
          |
          \---sub22
              |   22.c
              |   22.h
              |
              \---sub221
                      221.c
                      221.h
  </code></pre>
  <p>the expected output as follows:</p>
  <pre><code>D:.
  +---bin
  |       myproject.exe
  |
  +---header
  |       1.h
  |       11.h
  |       111.h
  |       2.h
  |       22.h
  |       221.h
  |       main.h
  |
  +---obj
  |       1.o
  |       11.o
  |       111.o
  |       2.o
  |       22.o
  |       221.o
  |       main.o
  |
  \---src
      |   main.c
      |
      +---sub1
      |   |   1.c
      |   |   1.h
      |   |
      |   \---sub11
      |       |   11.c
      |       |   11.h
      |       |
      |       \---sub111
      |               111.c
      |               111.h
      |
      \---sub2
          |   2.c
          |   2.h
          |
          \---sub22
              |   22.c
              |   22.h
              |
              \---sub221
                      221.c
                      221.h
  </code></pre>
  <p>the follows posts give a good reference , but this post can not support if the source in multiple directory , all obj files is in the same directory as c file
  <a href="https://stackoverflow.com/questions/40621451/makefile-automatically-compile-all-c-files-keeping-o-files-in-separate-folde">Makefile : Automatically compile all c files, keeping .o files in separate folder</a><br />
  <a href="https://stackoverflow.com/questions/7004702/how-can-i-create-a-makefile-for-c-projects-with-src-obj-and-bin-subdirectories">How can I create a Makefile for C projects with SRC, OBJ, and BIN subdirectories?</a></p>
  <p>can any give some example makefile?</p>