Adding comments to Makefile

前端 未结 5 922
时光取名叫无心
时光取名叫无心 2021-02-13 19:15

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

相关标签:
5条回答
  • 2021-02-13 19:30

    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!
    
    0 讨论(0)
  • 2021-02-13 19:33

    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.

    0 讨论(0)
  • 2021-02-13 19:35

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

    0 讨论(0)
  • 2021-02-13 19:41

    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
    
    0 讨论(0)
  • 2021-02-13 19:43
    all :
        echo "Building!"
        $(CC) $(OBJECTS) $(LPATH) $(LIBS) -o $(PROGRAM)
    
    0 讨论(0)
提交回复
热议问题