How do you specify where to start in a dependency graph that does not have a fixed starting point?

advertisements

I'm using a tool chain that is more like a web. There are lotys of alternate start points, all resulting in a single final output.

I typically use make or scons - actually, I prefer scons, but my team highly prefers make. I'm open to other build tools.

E.g. final_result depends on penultimate

final_result: penultimate

penultimate may be made in any of several different ways:

If starting from file1, then

penultimate: file1 ; rule1

If starting from file2, then

penultimate: file2 ; rule2

Q: how do I specify to start with file2, not file1?

I suppose that I could use a command line switch and ifdeffing. But I would prefer to have make or scons figure out "Hey, there's a file2 around, so I should use rule2, not fil1/rule1". In part because the web is much more complex than this...

Worse, sometimes an intermediate on one path may be a start on another. Let's see:

A .s produces a .diag

foo.diag: foo.s

But sometimes there is no .s, and I just have a .diag that somebody else gave me already built.

A .diag produces a .heximg, and a .hwresult

foo.hwresult: hwsim foo.heximg

foo.heximg: foo.diag

But sometimes I am given a .img directly

Etc.

I just want to write the overall dependency graph, and say "OK, now here's what I have been given - now how do you get to the final result?"

With what I have now, when I am given, say, a foo.img, I get told (by make in this case) "foo.s not dfound". Because make wants to go all the way back in the dependency graph to tell if foo.img is out of date, whereas I want to say "assume foo.img is up to date, and work forwrads for stuff that depends on foo.img, instead of going back for stuff that foo.img depends on."


You have to do it all with pattern rules (implicit rules). If you specify an explicit rule then make considers that a hard dependency and if some portion of the dependency is not met, make will fail.

If you use an implicit rule then make will consider that a POSSIBLE way to build the target. If that way doesn't work (because some prerequisite does not exist and make doesn't know how to build it) make will try another way. If no way works, and the target already exists, make will just use that target without having to update it.

Also you say "a .diag produces a .heximg and a .hwresult" then gave a strange example makefile syntax that I didn't recognize, but FYI with pattern rules you can specify that a single command generates multiple outputs (you can't do this with explicit rules):

%.heximg %.hwresult: %.diag

Here's the bad news: the only way to define an implicit rule in GNU make is if there is a common "stem" in the filename. That is, you can write an implicit rule that converts foo.diag to foo.heximg by writing a pattern rule "%.heximg: %.diag", because they have a common stem "foo", but there's no way to create a pattern rule for a compilation from "foo1" to "penultimate", because they don't share a common stem.