Heredoc in a Makefile?

前端 未结 7 1065
半阙折子戏
半阙折子戏 2020-12-25 12:36

Is this possible at all and how?

Update: I need this because I create a file both from dynamic and static data.

Use case:

7条回答
  •  误落风尘
    2020-12-25 13:18

    If you're using Gnu Make, use a 'define' to create a multi-line text variable, and a rule to echo it into your file. See 6.8 Defining Multi-Line Variables of https://www.gnu.org/software/make/manual/make.html#Appending

    Like this:

      define myvar
      # line 1\nline 2\nline 3\n#etc\n
      endef
    
      myfile.txt:
             /bin/echo -e "$(myvar)) >myfile.txt
    

    To create this, it helps to use an editor, create the file you want to have, append "\n" to the end of every line, and then join them all into a single string. Paste that into your makefile.

    Tested with GNU Make 3.81 on linux.

提交回复
热议问题