Menu

#1153 Makefile continued comments (backslash) not highlighted as comment

Completed
accepted
5
2016-08-19
2016-08-19
b2f9h203
No

Minimal example

# Comment 1 \
PROJECT_PATH := ../test

The second line should be highlighted as a comment, but it is not (SciTE 3.6.2) which cost me quite some time to find.

‘#’ in a line of a makefile starts a comment. It and the rest of the line are ignored, except that a trailing backslash not escaped by another backslash will continue the comment across multiple lines.
https://www.gnu.org/software/make/manual/html_node/Makefile-Contents.html

Discussion

  • Colomban Wendling

    This is highly subtle because it has different meaning inside a rule and outside, and accross Make implementations. Given the following example:

        # Comment 1 \
    PROJECT_PATH := ../test
    
    all:
        echo $(PROJECT_PATH)
        # echo hello \
        echo bye
    
    .PHONY: all
    

    With GNU make you get:

    $ make -f /tmp/a.mk
    echo 
    
    # echo hello \
    echo bye
    bye
    

    Note that you see bye in the output: L7 is not commented out, despite of the backslash on L6. This is because the comment is handled by the shell, which doesn't continue comments with backslashes (which Scintilla apparently actually also gets wrong, funnily enough).

    OTOH, with BSD make you get:

    $ pmake -f /tmp/a.mk
    echo 
    

    which suggests the comment inside the rule is handled by Make itself here, not the shell.

     
    • Neil Hodgson

      Neil Hodgson - 2016-08-19

      The GNU versus BSD difference is unfortunate. There could be a property to choose between these.

       
  • Neil Hodgson

    Neil Hodgson - 2016-08-19

    The makefile lexer is currently very simple and looks at each line separately with no inter-line state. Fixing this would require detecting or remembering comment state between lines.

     
  • Neil Hodgson

    Neil Hodgson - 2016-08-19
    • labels: --> scintilla, lexer, makefile
    • status: open --> accepted
    • assigned_to: Neil Hodgson
     

Log in to post a comment.