help-make
[Top][All Lists]
Advanced

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

Re: Change behaviour of a multiple target rule


From: Paul Smith
Subject: Re: Change behaviour of a multiple target rule
Date: Wed, 08 Sep 2010 07:25:33 -0400

On Wed, 2010-09-08 at 13:06 +0200, Gerald Lutter wrote:
> I'm using make (3.81) from cygwin and I encountered the following "problem"
> with a rule that looks like this:
> 
> $(targetlist): $(sourcelist)
>         do something that generates $(targetlist) from $(sourcelist)
> 
> Now in my case the receipe is executed several times (number of entries
> inside the target list). I think this depends on the evaluation of multiple
> target rules described inside the gnu make manual. But the receipe builds
> all three files together and therefore the command does not have to be
> executed more than one time.

According to the GNU make manual, and the POSIX definition of make, and
30+ years of implementations, when you write:

        foo bar: baz
                recipe

that is exactly identical to writing:

        foo: baz
                recipe
        bar: baz
                recipe

which is why you see the behavior you do ("recipe" is executed for each
target in the list).

> My question is now, is there a possibility to change this behaviour or do I
> have to reduce the number of targets to prevent this?

GNU make supports this capability but ONLY for pattern rules.  So if
your $(targetlist) can be expressed as a pattern rule (that is, there's
some commonality between the target names) then it can work.  For
example:

        %.x %.y %.z : %.q
                recipe

Only one instance of "recipe" will be invoked, and it will be expected
to build all of the targets.

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.mad-scientist.net
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist




reply via email to

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