Makefile中的Heredoc? [英] Heredoc in a Makefile?
问题描述
这有可能吗?
更新:我需要这样做,因为我是根据动态和静态数据创建文件的.
Update: I need this because I create a file both from dynamic and static data.
用例:我有一个测试目录.每个C文件都生成一个测试可执行文件.与
Use case: I have a test directory. Each C file produces a test executable. With
SRCS = $(wildcard [a-z]*.c)
我可以根据需要添加新测试,并进行查找,编译,运行和验证这些新测试.我也使用git.我希望.gitignore
包含可执行文件.
I can add new tests as needed and make will find the new tests, compile, run and valgrind them. I also use git. I would like .gitignore
to include the executables.
在那里.
推荐答案
另一个GNU Make解决方案.
Another GNU Make solution.
您可以使用define
和export
命令如下进行操作:
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" >> $@
不过,您必须注意在define块内进行扩展(即$(x)
).
You have to be careful of make expansions (i.e. $(x)
) inside the define block though.
这篇关于Makefile中的Heredoc?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!