Jimmy
Jimmy

Reputation:

Adding comments to Makefile

How do I add comments (with echo) in a Makefile so that they're printed when ran?

Upvotes: 22

Views: 39527

Answers (6)

Christoph Thiede
Christoph Thiede

Reputation: 1060

An imperfect but simple workaround is to add your comments outside the target:

Rule:  Dependencies
    Command
# Your Comment

Upvotes: 1

FrankieTheKneeMan
FrankieTheKneeMan

Reputation: 6800

Or, since Make just pushes whatever is in a rule to bash, you could just use a pound to have bash treat it as a comment.

Rule:  Dependencies
    # Your Comment
    Command

Will output

$ make Rule
    # Your Comment
    Command

Upvotes: 11

Alnitak
Alnitak

Reputation: 339786

You should use

target:
     @echo "Building!"

Note the @, which tells Make not to display the command itself. Without this the output would look like:

echo "Building!"
Building!

Upvotes: 33

Joey
Joey

Reputation: 354356

Since a makefile mostly contains commands to be run when building specific targets, I'd say you use just that: echo.

Upvotes: 2

Franci Penov
Franci Penov

Reputation: 75982

Visual C++ nmake has the !message text... preprocessing directive. I have not used GNU make, so I don't if it has it as weel, but quick search shows it has the $(info text...) function.

And inside command blocks you can use echo.

Upvotes: 2

BenB
BenB

Reputation: 10620

all :
    echo "Building!"
    $(CC) $(OBJECTS) $(LPATH) $(LIBS) -o $(PROGRAM)

Upvotes: 2

Related Questions