Heredoc in a Makefile?

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

    SRCS = (wildcard [a-z]*.c)
    EXES = $(SRCS:.c=)
    GITIGNOREDS = *.o depend
    
    .gitignore: $(SRCS)
            echo $(EXES) | sed 's/ /\n/g' > $@
            echo $(GITIGNOREDS) | sed 's/ /\n/g' > $@
    

    Important is the GITIGNOREDS line. I would have preferred a heredoc like

    GITIGNOREDS = <

    but am also happy with a file list, separated by spaces, and a sed script to translate the space into newlines.

    Edit As proposed by Ryan V. Bissell: Use a separate test subdirectory which you add to gitignore. And everything falls into place. It's simple.

提交回复
热议问题