Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add multi line comments in makefiles

Tags:

makefile

People also ask

Which is used to create multi line comments?

To write multiline comments in Python, prepend a # to each line to block comments. That means writing consecutive single-line comments. Start every line with the # sign consecutively, and you will achieve multiline comments. If you work with Java, C, or C++, you can write multiline codes.

What is the syntax of multi line comments?

Unlike other programming languages such as JavaScript, Java, and C++ which use /*... */ for multi-line comments, there's no built-in mechanism for multi-line comments in Python. To comment out multiple lines in Python, you can prepend each line with a hash ( # ).

What is $@ in makefile?

The variable $@ represents the name of the target and $< represents the first prerequisite required to create the output file.


No, there is nothing like C-style /* */ comments in makefiles. As somebody else suggested, you can make a multi-line comment by using line continuations. For example:

# This is the first line of a comment \
and this is still part of the comment \
as is this, since I keep ending each line \
with a backslash character

However, I imagine that you are probably looking to temporarily comment out a chunk of your makefile for debugging reasons, and adding a backslash on every line is not really practical. If you are using GNU make, I suggest you use the ifeq directive with a deliberately false expression. For example:

ifeq ("x","y")
# here's all your 'commented' makefile content...
endif

Hope that helps.


I believe the answer is no. The only comment styling I can find is # for each line, or use \ to wrap the first line.


A note about the idea of using ifeq to do multi-line comments in make(1). They don't work very well since if you write the following:

ifeq (0,1)
    do not risk ifeq comments
    else trouble will find you
    ifeq is even worse
endif

The text between the ifeq and endif will still be parsed by make which means that you cannot write whatever you want in that section. And if you want to write a long comment and write whatever you want in the comment (including $ signs, colons and more which all have a meaning for make) then you must comment every single line. So why the ifeq...:)


define BOGUS
lines
.....
endef

Not exactly what you're looking for, but similar in spirit. I don't expect it to be the accepted answer, but maybe it can help someone.

Assuming you're editing your makefiles in VIM:
Either decide which lines you want to comment or select them with 'v'.

Then you can use the regex s/^/#/ to comment out the lines
and s/^#// to revert them.

--Notes--

  • To open the vim command line, press : (colon)
  • To prep the command for the next 'n' lines, use .,+n
  • A sample line using "v" looks like: '<,'>s/^/#/