3
votes

According to the gnu make documentation, if a rule generates multiple targets by a single invocation (for instance with a recipe executing a tool with multiple output files), you can use the '&:' rule syntax to tell make. I'm getting warnings when using this syntax, about target '&', however, when having multiple (but unique) targets in multiple rules. As if make mistakes the ampersand for a target name instead of being part of the target-prerequisite separator.

In my original project I've got two rules having multiple targets and a recipe generating those targets from a single statement/tool. The targets are unique for each of the two rules. I've created the following simple example to demonstrate the warning generated by make:

all: file_abbc

.PHONY: all clean

clean:
    del /Q file_*

file_abbc: file_ab file_bc
    copy file_ab+file_bc file_abbc

file_ab file_bc &: file_a file_b file_c
    copy file_a+file_b file_ab
    copy file_b+file_c file_bc

file_a file_b file_c &: content
    copy content file_a
    copy content file_b
    copy content file_c

Warnings from running make on Windows on the above:

Makefile:17: warning: overriding recipe for target '&'

Makefile:13: warning: ignoring old recipe for target '&'

Why is make complaining about target '&' ?

1
You're using an old version of GNU make that doesn't understand &: rules, so just treats & as a file name. Use make --version to see which version you are running and upgrade if it is older that 4.3Chris Dodd
@ChrisDodd That's useful. I tried both 3.81 and 4.2.90 and had the same results. I was in fact wondering why the make documentation doesn't state the minimum version for each feature, but I see now that the documentation I linked to is for 4.3. It seems many systems by default have lesser versions, though.Jesper Matthiesen
Well, tough luck that I discovered the '&:' feature 2 weeks ago, which was just released 3 weeks ago in make 4.3.. No wonder it isn't supported by the make versions I already have.Jesper Matthiesen
If this example follows your real Makefile, than there is no need for &:. Each of those can be generated in a separate rule as there is no single statement that generates more than one file.raspy
@raspy true. My real Makefile is using a couple of tools that generate multiple targets from a single recipe statement, which I tried to say in the first sentence of my question. I'll edit to make it clearer.Jesper Matthiesen

1 Answers

5
votes

You're using an old version of GNU make that doesn't understand &: rules, so just treats & as a file name. Use make --version to see which version you are running and upgrade if it is older that 4.3