Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the double "at" (@@) symbol do in a Makefile?

Tags:

bash

makefile

I have often seen Makefiles that start commands with an "@" symbol to suppress normal output.

target: test
    @echo foo

Has this output:

$ make test
foo

But I often encounter Makefiles with @@ in front of commands:

target: test
    @@echo foo

And the output is identical, as far as I can tell, from Makefiles with only one @ before the echo command.

What's the difference?

(The @@ seems to be common practice, as seen by this Google Code search: http://www.google.com/codesearch#search/&q=@@echo%20makefile&type=cs)

like image 621
Chris M Avatar asked Aug 29 '11 17:08

Chris M


People also ask

What is && in makefile?

The ; just separates one command from another. The && says only run the following command if the previous was successful.

What does %O %c mean in makefile?

The simple answer is that %.o is a target that matches any file ending in .o. "%.o: %. c" means that any file ending in .o depends on the same filename ending in . c to be present. The following line, starting with a tab, is the rule to use whenever you are generating a file of the form %.o.

What is at in makefile?

The @ symbol is commonly seen at the beginning of an action lines and means that the action line itself is not be be echoed on the screen as it is executed. Macros are commonly used in makefiles to decrease the amount of typing required.

What is @echo in makefile?

The ' @ ' is discarded before the line is passed to the shell. Typically you would use this for a command whose only effect is to print something, such as an echo command to indicate progress through the makefile: @echo About to make distribution files.


2 Answers

In OpusMake, @@ means, "really, really quiet". It causes OpusMake to suppress printing the commands even when invoked as make -n. Probably somebody, somewhere, had some familiarity with that feature, wrote their makefiles to use it, somebody else saw it and copied it, and since it doesn't break other make variants (at least, not GNU make), it just stuck around.

like image 58
Eric Melski Avatar answered Nov 16 '22 04:11

Eric Melski


Looking at the code, it seems that it just strips all the leading @ (or +/-), but I'm not 100% sure (that is, you can put there as many @ as you wish) - look at job.c in make source code.

while (*p != '\0')
    {
      if (*p == '@')
    flags |= COMMANDS_SILENT;
      else if (*p == '+')
    flags |= COMMANDS_RECURSE;
      else if (*p == '-')
    child->noerror = 1;
      else if (!isblank ((unsigned char)*p))
    break;
      ++p;
    }
like image 22
eran Avatar answered Nov 16 '22 02:11

eran