help-make
[Top][All Lists]
Advanced

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

Re: bug with multiple targets in pattern rules?


From: Mike Gibson
Subject: Re: bug with multiple targets in pattern rules?
Date: Thu, 26 Jun 2003 12:54:41 -0600
User-agent: KMail/1.5.1

The behavior you're getting is correct.  When you list two targets, it isn't 
just for convienience so you don't have to type the rule twice.  If a rule 
creates both targets for some reason, you only want the rule to run once.  
This is for rules that create multiple files.

For example, I have a script that does heavy parsing of a data file and 
produces 4 different outputs.  Each is derived from a single source file, but 
4 output files are created so that the file doesn't have to be parsed 4 
seperate times.

One can assume that if the files have the same pattern for %, then they're 
related and can be made by the same rule.  If different patterns for % need 
to be made, then it seems logical to run two rules to create them.

$@ only represents the filename that caused the rule to execute, hence the 
reason why "touch a.foo a.bar" isn't running.

You need to do this to get the behavior you want:

%.foo :
        touch $@

%.bar :
        touch $@

if the rule is particulary complex, then simply define it as a variable like:

MAKE_FOO_OR_BAR = touch $@

%.foo :
        $(MAKE_FOO_OR_BAR)

%.bar :
        $(MAKE_FOO_OR_BAR)

(note that you *don't* use := to assign since this would expand the $@ 
prematurely)

Mike Gibson




reply via email to

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