Question

The gnu manual section 3.8 says:

"During the secondary expansion of explicit rules, $$@ and $$% evaluate, respectively, to the file name of the target and, when the target is an archive member, the target member name. The $$< variable evaluates to the first prerequisite in the first rule for this target. $$^ and $$+ evaluate to the list of all prerequisites of rules that have already appeared for the same target ($$+ with repetitions and $$^ without). The following example will help illustrate these behaviors:

.SECONDEXPANSION:
foo: foo.1 bar.1 $$< $$^ $$+ # line #1
foo: foo.2 bar.2 $$< $$^ $$+ # line #2
foo: foo.3 bar.3 $$< $$^ $$+ # line #3

In the first prerequisite list, all three variables ($$<, $$^, and $$+) expand to the empty string."

My question: Why does the $$< expand to empty string? The paragraph above says the it should evaluate to the first requisite to the first rule for this target. Wouldn't that be foo.1 ?

Was it helpful?

Solution

The manual is misleading, possibly due to a typo. The first of the two sentences:

The $$< variable evaluates to the first prerequisite in the first rule for this target. $$^ and $$+ evaluate to the list of all prerequisites of rules that have already appeared for the same target ($$+ with repetitions and $$^ without).

should be be qualified, like the second, by appending the words: "that has already appeared".

You can verify that this correctly describes the behaviour by running two makefiles:

Make 1

.SECONDEXPANSION:
foo: foo.1 $$<
    @echo $+

The output is:

foo.1

showing that $$< has expanded to the empty string. Then:

Make 2

.SECONDEXPANSION:
foo: foo.1
foo: foo.2 $$<
    @echo $+

Now the output is:

foo.2 foo.1 foo.1

Here, the explicit prerequisites foo.1 and foo.2 from the first and second rules for target foo are combined, which accounts for the initial foo.2 foo.1 of the output. And in addition, $$< in the second rule is expanded to the first prerequisite foo.1 of the previous rule, which accounts or the final foo.1 of the output.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top