help-make
[Top][All Lists]
Advanced

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

Re: Proper usage of multiple rules for the same targets


From: Tiphaine Turpin
Subject: Re: Proper usage of multiple rules for the same targets
Date: Thu, 6 Sep 2018 08:05:28 +0000

Hi,

The static pattern solution looks very nice, thanks. It seems to work fine in 
the real Makefile. And there is no visible performance impact, as far as I can 
tell (I'm not sure about how efficiently static pattern rules are implemented). 
So I think I'll go for this one.

I also tried idea suggested by Sébastien to add prerequisites using a 
target-specific variable. It can be made to work using secondary expansion:

foo_prereqs = additional prerequisites specific to foo

.SECONDEXPANSION:

%.t: %.x $$($$*_prereqs)
    ...

But I find this more complex.
Thanks for your help !

Tiphaine


________________________________
From: Help-make <address@hidden> on behalf of Max Gautier <address@hidden>
Sent: Wednesday, September 5, 2018 11:03 AM
To: address@hidden
Subject: Re: Proper usage of multiple rules for the same targets

Hi.

To force the behavior you want, I think you could use a static pattern rule :

The syntax being as follow :

<list_of_target>:<pattern_target>:<prerequisite_pattern>

In your case, that would give :

foo.t: %.t: %.x
    touch $@

foo.t: another_file

That achieves what you want, if I'm testing correctly.
(You'll need to have a way to have all of your concerned target in a variable
for readabilite, of course, something like

$(TARGETS): %.t: %.x

)

The reason for that is that static pattern rules are not really pattern rules,
which act as default when no other rules can be found.
The static pattern rule is in fact more a template, which is applied to
all of the targets listed in the <list_of_target>.
Thus, a static pattern rule is equivalent to write the same rule
for all of your listed targets, and each behave as a normal rule. (aka
: will always apply to that target)

(This is explained more clearly in the Static Pattern section in the
Gnu Make manual).


I'm not sure that this solution will not conflict with your other
requirements, though.
Specifically, you mentions using $^ in recipes : I think the
'another_file' dependency would
end up in it ; although I dont think there is any way to avoid it.
Let me know if you managed to work around it.

Regards,

Max

_______________________________________________
Help-make mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/help-make



reply via email to

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