I know that This thread is very old but this link is viewed by many makefile newbies so adding some useful info.
Thanks to ntubski for useful link, most be code is modified from above link.
Here is goal,
- All source code is arranged in different meaningful directories.
- Makefile should be non recursive
- Adding new file in compilation process should be of minimum change in makefile
- All dependences of header and c source should be calculated correctly
- There should be option to customize each target compilation
- common things should be kept in one place
- whenever I do vi filena<tab> it should not ask me about non source file, this really sucks while editing source
- This template should be on internet so after next six months there should be no need for me to do same R&D
I had attached sample template project with this thread, following things are incomplete / or unknown to me,
- Unable to create separate build directory [so I used . as prefix for intermediate object and dep files]
- Install option is missing
- For loop in main Makefile is not working
Don't know why
- sometime clean creates dep files.
Please feel free to update share or report bugs in above template.