[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Multiple rules for same target: what is the order of prerequisites in $^
From: |
Renaud Pacalet |
Subject: |
Multiple rules for same target: what is the order of prerequisites in $^ and what does $< expand to? |
Date: |
Wed, 27 Sep 2023 12:16:58 +0200 |
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.
- Multiple rules for same target: what is the order of prerequisites in $^ and what does $< expand to?,
Renaud Pacalet <=
Re: Multiple rules for same target: what is the order of prerequisites in $^ and what does $< expand to?, Mark Piffer, 2023/09/27