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

后端 未结 19 2001
借酒劲吻你
借酒劲吻你 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:52

    With GNU Make 3.82 and above, the .ONESHELL option is your friend when it comes to multiline shell snippets. Putting together hints from other answers, I get:

    VERSION = 1.2.3
    PACKAGE_NAME = foo-bar
    DOWNLOAD_URL = $(PACKAGE_NAME).somewhere.net
    
    define nwln
    
    endef
    
    define ANNOUNCE_BODY
    Version $(VERSION) of $(PACKAGE_NAME) has been released.
    
    It can be downloaded from $(DOWNLOAD_URL).
    
    etc, etc.
    endef
    
    .ONESHELL:
    
    # mind the *leading*  character
    version:
        @printf "$(subst $(nwln),\n,$(ANNOUNCE_BODY))"
    

    Make sure, when copying and pasting the above example into your editor, that any characters are preserved, else the version target will break!

    Note that .ONESHELL will cause all targets in the Makefile to use a single shell for all their commands.

提交回复
热议问题