I’m using rake for a C++ project. I’m using gcc -MM -MF to automatically generate dependencies, and “import” to import them. So far, so good.
However, rake is not rebuilding the “depends.mf” file when it should. The example in the Ruby documentation is wrong:
file ".depends.mf" => [SRC_LIST] do |t|
sh "makedepend -f- -- #{CFLAGS} -- #{t.prerequisites} > #{t.name}"
end
import ".depends.mf"
The .depends.mf file needs to be rebuilt when any file included by the SRC_LIST also changes. For example, suppose the SRC_LIST is a single file, a.cpp, and that #includes a.hpp. If we modify a.hpp, we may modify it to #include new files, so we need to remake .depends.mf, but the above line won’t do that.
So we really want .depends.mf to depend on the same things that the source file depends on. And those things are listed in .depends.mf. It’s easy enough to mangle .depends.mf to mention itself (gcc -MT ‘foo.o foo.mf’), but that doesn’t work: rake only decides whether or not to rebuild .depends.mf before reading it. It won’t rebuild it after reading it.
So, what should I do? Switch to SCONS? 😉
The answer is simply: