Search code examples
linuxmakefilegnu-make

What is the proper way to comment in a makefile recipe?


For years I have lived with this annoying Emacs behavior:

enter image description here

As described in this question

Today I realized that Emacs is actually right: make is not interpreting those lines as comments. It just passes them to the shell and the shell interprets them as comments. Which means that:

  • it is up to shell to decide that those are comments
  • and worse: there is an overhead caused by the comments

What would be the proper way of commenting (with a real makefile comment) within a recipe / target, without visually breaking indentation?


Solution

  • What would be the proper way of commenting (with a real makefile comment) within a recipe / target, without visually breaking indentation?

    Not really.

    • Anything you indent with a leading tab is part of the recipe, and will be sent to the shell. That cannot be a "real makefile comment", as you seem to mean that.

    • If you indent with zero or more spaces instead of a tab then you can have a real makefile comment, but then you will have a visual break in the indentation under at least some circumstances. This will depend on how many spaces, if any, you use to indent, and how widely your particular editor spaces tab stops. You cannot simultaneously satisfy all possible configurations of all editors in this regard.

    • Additionally, if you happen to indent with enough spaces to match your particular editor's tab stop spacing, then your editor may present a visual indication, because that's usually an error in a Makefile. I dunno about emacs, but certainly vim does this.