234

What does the following do in a Makefile?

rule: $(deps)
    @:

I can't seem to find this in the make manual.

2 Answers 2

315

It means "don't echo this command on the output." So this rule is saying "execute the shell command : and don't echo the output.

Of course the shell command : is a no-op, so this is saying "do nothing, and don't tell."

Why?

The trick here is that you've got an obscure combination of two different syntaxes. The make(1) syntax is the use of an action starting with @, which is simply not to echo the command. So a rule like

always:
       @echo this always happens

won't emit

   echo this always happens
   this always happens

Now, the action part of a rule can be any shell command, including :. Bash help explains this as well as anywhere:

$ help :
:: :
    Null command.

    No effect; the command does nothing.

    Exit Status:
    Always succeeds.
6
  • thanks, is there somewhere that describes this in more detail? I'm not sure what the "out-ut" is.
    – cdwilson
    Commented Dec 22, 2011 at 23:40
  • 73
    Don't make fun of my typing, you'll be old someday too. Commented Dec 22, 2011 at 23:46
  • 10
    This is an excellent explaination of what this does, but do you by any chance know why you would do this in a makefile? Commented Oct 13, 2012 at 20:50
  • 4
    It can be useful in makefiles that call a lot of external programs, and where you want to use echo a lot to make it look nice, like this one
    – dwcoder
    Commented Jul 17, 2015 at 15:04
  • 11
    @charles-keepax if you're asking specifically in reference to @: (not just @) then in addition to @guestolio's answer it could also be a leftover stub from development. It's like writing a function in Python that only contains pass. It can be useful for stubbing blocks of code for copy/paste but they generally shouldn't exist for long. When stubbing this way the file would still compile, pass linting, etc.
    – boweeb
    Commented May 21, 2019 at 18:33
57

For those curious about why you might do this, it is useful if you want to pretend like something was done, so that Make doesn't output "Nothing to be done for" your target.

One example is if you have a phony target that you always execute, and in it you have a bunch of conditionals in the command. You want to have at least something in case those conditions come up false and nothing gets done.

For example (from Linux's scripts/Makefile.clean):

__clean: $(subdir-ymn)
ifneq ($(strip $(__clean-files)),)
    +$(call cmd,clean)
endif
ifneq ($(strip $(__clean-dirs)),)
    +$(call cmd,cleandir)
endif
ifneq ($(strip $(clean-rule)),)
    +$(clean-rule)
endif
    @:
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.