Makefile中的Heredoc? [英] Heredoc in a Makefile?

查看:99
本文介绍了Makefile中的Heredoc?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这有可能吗?

更新:我需要这样做,因为我是根据动态和静态数据创建文件的.

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 .gitignoreto include the executables.

在那里.

推荐答案

另一个GNU Make解决方案.

Another GNU Make solution.

您可以使用defineexport命令如下进行操作:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆