File function in makefile takes args prefixed by ‘@’ symbol

make

This code excerpt is from Chapter 8.6 of GNU makefile manual.

What does @$@.in for file function arg in a makefile mean? and why are shell commands like rm prefixed by '@' symbol

program: $(OBJECTS)
     $(file >$@.in,$^)
     $(CMD) $(CMDFLAGS) @$@.in
     @rm $@.in

File function syntax is

$(file op filename[,text])

Best Answer

There are three unrelated uses of @ here.

In $@, the character @ is the name of an automatic variable that can be used in a rule. The value of that variable is the target that the rule is building.

When @ is used at the very beginning of a recipe (command) line, just after the tab character, it causes the command not to be printed when it's about to be executed.

The character @ elsewhere isn't special.

Thus, in your example, to build program:

  1. The file function is invoked. It writes the dependencies of the target ($^ automatic variable) to the file program.in.
  2. Whatever command is stored in the variable CMD is executed, with the parameters stored in the variable CMDFLAGS, plus the extra parameter @program.in. What this does depends on what CMD is.

  3. The command rm program.in is executed, without printing it first.

A few commands treat a parameter starting with @ as indicating a file from which to read more parameters. This is a DOS convention which came about because DOS had a stringent limit on the command line length and no way to interpolate the output of a command into a command line. It is uncommon in the Unix world since Unix doesn't have these limitations. The effect of the recipe is thus likely the same as

$(CMD) $(CMDFLAGS) $(OBJECTS)
Related Question