在Makefile中多行的bash命令 [英] Multiline bash commands in makefile

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

问题描述

我有一个非常舒适的方式通过的bash命令的几行编译我的项目。但现在我需要通过makefile编译它。考虑到,每一个命令,在自己的shell中运行,我的问题是,什么是运行多行bash命令的最佳方式,相依为命,在生成文件?
例如,像这样的:

I have a very comfortable way to compile my project via a few lines of bash commands. But now I need to compile it via makefile. Considering, that every command is run in its own shell, my question is what is the best way to run multi-line bash command, depended on each other, in makefile? For example, like this:

for i in `find`
do
    all="$all $i"
done
gcc $all

此外,有人可以解释,为什么即使是单行命令的bash -c'A = 3;回声$ A>文件工作正确的终端,但在生成文件的情况下创建空文件?

Also, can someone explain why even single-line command bash -c 'a=3; echo $a > file' works correct in terminal, but create empty file in makefile case?

推荐答案

我会用反斜杠换行:

foo:
    for i in `find`;     \
    do                   \
        all="$$all $$i"; \
    done;                \
    gcc $$all

UPD

或者,在情况下,如果只是想通过按返回整个列表找到 GCC

foo:
    gcc `find`

这篇关于在Makefile中多行的bash命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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