How does GNU make's "file" function work?

875 views Asked by At

I am thinking I may need to use the file function in GNU make, and just can not follow the example they give. I have looked online, but don't see any post with more explanation. Here is the example they give:

program: $(OBJECTS)
$(file >[email protected],$^)
$(CMD) $(CMDFLAGS) @[email protected]
@rm [email protected]

I think I know what it is doing at a high level as it is explained in the manual.

[email protected] 

is a list of all the target files

$^ 

is a list of the source files

I am not sure how @[email protected] is used on the third line or what there is an @ sign at the beginning. What does that mean please? What does it supposed to do?

1

There are 1 answers

0
Etan Reisner On BEST ANSWER

The key to the operation of that recipe is given in the prose immediately preceding it in the manual:

Many commands use the convention that an argument prefixed with an @ specifies a file containing more arguments. Then you might write your recipe in this way:

program: $(OBJECTS)
    $(file >[email protected],$^)
    $(CMD) $(CMDFLAGS) @[email protected]
    @rm [email protected]
  • $@ is the target file (there is only one of those in any given recipe)

  • [email protected] is the target file with .in added to the end of the name.

  • $^ is the "list" of the all the prerequisites of the target.

  • @[email protected] is the name of the target with .in at the end and @ at the start.

So the $(file ...) call in that recipe writes the list of prerequisites of the target into a file called program.in in "overwrite" mode and then passes that file name to the $(CMD) command using the @filename convention that was mentioned.