2
votes

Make updates object files if one or more of its dependencies is out-of-date.

However, it's really a pain to write down the right dependency tree.

  1. You may simply forget to add a header file to dependencies when you put an extra #include.

  2. What if one of the headers in the dependencies list included another header?

  3. What if ...

So I am looking for automatic method to generate the 'correct' dependency tree for the makefile.

Thanks!

2

2 Answers

3
votes

There are various methods. One is described in the GNU make manual.

A better one is the one used by the automake environment, but you don't need to use automake to use it. You can find it described here.

2
votes

Alternative way were to use CMake. Just look through this tutorial. You just need to specify your sources and add them to the target. CMake will take care of dependencies itself.