On Mon, 2022-07-25 at 09:06 +0000, Edward Welbourne wrote: > On 7/22/22 16:20, Paul Smith wrote: > > > So, after all the "normal" goal targets were completed make would > > > proceed to run any "extra" goal targets that were added as part > > > of the processing of the "normal" goal targets. Then after the > > > those "extra" goal targets were complete, make would proceed to > > > run any "new extra" goal targets that were added as part of THAT > > > processing. > > How would any new targets be added ? Surely make's dependency graph > would ensure that you know what you'll be building before you start, > regardless of whether it's a prerequisite or a postrequisite.
I think I wasn't clear. I wasn't suggesting that "post-requisites" would be represented in the dependency graph in any way at all. When make runs it basically does this: it first generates the DAG. Then it has a list of one or more goal targets (either the default target or one or more targets from the command line) and make starts walking the DAG using each of these goal targets in turn as the starting node. This behavior is already well-understood. What I'm suggesting is that "post-requisites" simply be added to the end of the list of goal targets, as they are encountered while walking the DAG. So if you ran "make foo" and some target that was processed during the walk of the DAG to build "foo" had a post-requisite of "bar", then after "foo" was built make would try to build "bar". It would be essentially exactly the same as if the user had invoked "make foo bar". If some new post-requisite "baz" was found while building either "foo" or "bar", it would be built after those and be as if the user had invoked "make foo bar baz". Etc. If a target was not encountered during the walk, then of course its post-requisites would not be added to the set of goal targets. > Indeed - for example, if a target is specified *both* as a > prerequisite of some target that does get built *and* as a > postrequisite of some rule we do exercise, it has to be built both > before and after, which violates the "only build once" rule above. No. It would be built before as a prerequisite, then when it was attempted to be built after it would be skipped because it was already built. That is _exactly_ the kind situation I was referring to by my statement about "only build things once". In other words, a target "foo" with a post-requisite "bar" does NOT say that make will guarantee that "bar" is always built after "foo". What it ensures is that if "foo" is built, then "bar" will also be tried afterwards. It's possible that make could be taught to detect a situation like this: foo: bar <post> baz bar: baz and give an error. But I'd have to play with it to determine how much work it would be to catch that.