bug-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Static multiple target rules


From: tom honermann
Subject: Re: Static multiple target rules
Date: Mon, 29 Mar 2010 14:18:07 -0700
User-agent: Thunderbird 2.0.0.24 (Windows/20100228)

On 3/3/2010 2:03 AM, Edward Welbourne wrote:
Another possibility crossed my mind over-night, with which I haven't
experimented, but that seems like it theoretically should work.
Replace the touch-file with a phony rule:

    yacc.ts: grammar.y
        yacc -d -v $^

    y.tab.h y.tab.c y.output .PHONY: yacc.ts

Because it's phony, and we never create it, it'll never exist and make
shouldn't care that no such file exists; because the three real
targets depend on it, any need for any of them shall force it to be
made (causing them to all exist); but if more than one of them needs
made, an individual run of make shall only make the phony once yet
still know that it's made it, so not need to run yacc again for the
sake of the others that depend on it.

But I may be confused about proper use of .PHONY - please experiment
and report your results !

        Eddy.
You're a genius!  .PHONY didn't do the trick, but .INTERMEDIATE did:

   .INTERMEDIATE: yacc.ts

   all: y.tab.h y.tab.c y.output y.tab.o

   clean:
           rm -f y.tab.h y.tab.c y.output y.tab.o

   grammar.y:
           @touch $@

   yacc.ts: grammar.y
           @echo "Running yacc..."
           @sleep 1
           @touch y.tab.h y.tab.c y.output

   y.tab.h y.tab.c y.output: yacc.ts

   y.tab.o: y.tab.c y.tab.h
           @echo "Compiling y.tab.c..."
           @sleep 1
           @touch $@

The only problem I could find with this approach is that downstream targets might not get rebuilt as expected. For example, run gmake once to build everything, then remove y.output and run gmake again. Using make 3.81 on Linux, y.output is rebuilt which also rebuilds y.tab.c and y.tab.h, but y.tab.o is not rebuilt (as might be expected since y.tab.h and y.tab.c were regenerated). This makes sense because gmake has no way of knowing that rebuilding y.output would also regenerate y.tab.h and y.tab.c. A full solution for static multiple target rules would recognize that these files had been regenerated and would also rebuild y.tab.o. But, I think this is good enough for my use cases.

Thanks Eddy!
Tom.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]