Search code examples
makefiletarget

Makefile rule with multiple targets for single invocation


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 '&' ?


Solution

  • 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