2

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!

Diaz
  • 957
  • 2
  • 13
  • 22

2 Answers2

3

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.

MadScientist
  • 92,819
  • 9
  • 109
  • 136
2

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.

yegorich
  • 4,653
  • 3
  • 31
  • 37
  • I don't know. If you 'make clean' and 'make' this way will certainly work. But If you update one header and just 'make' will it update all object files that depends on that header? Maybe I'll experiment it out. Thanks! – Diaz Feb 23 '14 at 05:03
  • 1
    This should be working. At least I had no problems so far with my own projects. See this [thread](http://stackoverflow.com/questions/7917112/cmake-auto-header-file-dependency). – yegorich Feb 23 '14 at 09:05