Heredoc in a Makefile?

前端 未结 7 1067
半阙折子戏
半阙折子戏 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:10

    It depends on how determined you are. It is best to assume it won't work. Write a shell script to be launched instead of a here document in the makefile.

    Fails 1

    heredoc:
        cat - <

    This produces:

    cat - <

    Each line is executed separately - oops.

    Fails 2

    heredoc:
        cat - <

    This generated:

    cat: This: No such file or directory
    cat: is: No such file or directory
    cat: the: No such file or directory
    cat: heredoc.!: No such file or directory
    make: *** [heredoc] Error 1
    

    There may be methods using a specific version of make (GNU make, for example, can execute all commands for an action in a single subshell, I believe), but then you have to specify your portability requirements. For regular (say POSIX-compliant) make, assume here docs do not work.

提交回复
热议问题