Is it possible to create a multi-line string variable in a Makefile

后端 未结 19 2075
借酒劲吻你
借酒劲吻你 2020-11-28 20:27

I want to create a makefile variable that is a multi-line string (e.g. the body of an email release announcement). something like

ANNOUNCE_BODY=\"
Version $         


        
19条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-28 20:43

    This doesn't give a here document, but it does display a multi-line message in a way that's suitable for pipes.

    =====

    MSG = this is a\\n\
    multi-line\\n\
    message
    
    method1:
         @$(SHELL) -c "echo '$(MSG)'" | sed -e 's/^ //'
    

    =====

    You can also use Gnu's callable macros:

    =====

    MSG = this is a\\n\
    multi-line\\n\
    message
    
    method1:
            @echo "Method 1:"
            @$(SHELL) -c "echo '$(MSG)'" | sed -e 's/^ //'
            @echo "---"
    
    SHOW = $(SHELL) -c "echo '$1'" | sed -e 's/^ //'
    
    method2:
            @echo "Method 2:"
            @$(call SHOW,$(MSG))
            @echo "---"
    

    =====

    Here's the output:

    =====

    $ make method1 method2
    Method 1:
    this is a
    multi-line
    message
    ---
    Method 2:
    this is a
    multi-line
    message
    ---
    $
    

    =====

提交回复
热议问题