help-make
[Top][All Lists]
Advanced

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

Re: Multiple rules for same target: what is the order of prerequisites i


From: Mark Piffer
Subject: Re: Multiple rules for same target: what is the order of prerequisites in $^ and what does $< expand to?
Date: Mon, 2 Oct 2023 09:06:35 +0200

For the sake of reliability I wouldn't use pure `$<` anywhere. And if the
answer to your question "Which one, listed in another rule, becomes $<?"
isn't "All collected prerequisites, with duplicates purged" as I was
believing until now, then I'm close to dropping make alltogether.

Am Mi., 27. Sept. 2023 um 17:05 Uhr schrieb Renaud Pacalet <
renaud.pacalet@telecom-paris.fr>:

>
>
> On 9/27/23 17:01, Mark Piffer wrote:
> > Is there a case (common or rare) where the answer to this question has
> real world consequences?
>
> Yes, I think. If you don't know how $< is expanded you cannot reliably use
> it in your recipe. I strongly suspect that it is expanded to the first
> prerequisite of the rule with a recipe but is this always the case? I
> couldn't find this in the manual. Moreover, what if the rule with a recipe
> has no prerequisites? Which one, listed in another rule, becomes $<?
>
> > regards,
> > Mark
> >
> >> Am 27.09.2023 um 12:17 schrieb Renaud Pacalet <
> renaud.pacalet@telecom-paris.fr>:
> >>
> >> Dear all,
> >>
> >> I read the manual carefully (especially section 4.11 "Multiple Rules
> for One Target") and searched the help-make archives but couldn't find a
> clear description of how $^ and $< are computed when there are several
> rules for the same target and only one has a recipe.
> >>
> >> According the manual "All the prerequisites mentioned in all the rules
> are merged into one list of prerequisites for the target". But when the
> recipe gets expanded what is the order of prerequisites in $^ and, more
> important, what is $<? Does it depend on the order of rules in the
> Makefile(s)? On the type of rules (pattern, static pattern, explicit...)?
> On which rule has a recipe? Is it deterministic? etc.
> >>
> >> I did some tests and came up with the following algorithm for $^ and $<
> computation:
> >>
> >> 0. When the list of prerequisites of a rule is added to $^, the order
> is preserved.
> >>
> >> 1. Initialize $^ with the list of prerequisites of the rule with a
> recipe, implicit or not.
> >>
> >> 2. Consider all other applicable explicit or static pattern rules, in
> their order of appearance in the Makefile(s), and for each of them append
> its list of prerequisites to $^.
> >>
> >> 3. Ignore all other implicit rules (which seems to contradict 4.11).
> >>
> >> 4. Remove duplicates from $^, keeping only the first occurrence.
> >>
> >> 5. Set $< to the first prerequisite in $^.
> >>
> >> Can someone confirm?
> >>
> >> Renaud.
> >>
>
> --
> Renaud Pacalet
> Télécom Paris
> Campus SophiaTech
> 450 Route des Chappes, CS 50193
> 06904 Biot Sophia Antipolis cedex, FRANCE
> Tel : +33 (0) 4 9300 8402
> Web : http://www.telecom-paris.fr/
>


reply via email to

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