Heredoc in a Makefile?

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

    Another GNU Make solution.

    You can do it using the define and export commands as follows:

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

    You have to be careful of make expansions (i.e. $(x)) inside the define block though.

提交回复
热议问题