如何使用Bash的语法。在Makefile目标? [英] How can I use Bash syntax in Makefile targets?

查看:128
本文介绍了如何使用Bash的语法。在Makefile目标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常发现猛砸语法非常有用,例如,在 DIFF&LT进程替换等;(排序文件1)≤(排序文件2)

I often find Bash syntax very helpful, e.g. process substitution like in diff <(sort file1) <(sort file2).

是否有可能使用这种猛砸在一个Makefile命令?我在想是这样的:

Is it possible to use such Bash commands in a Makefile? I'm thinking of something like this:

file-differences:
    diff <(sort file1) <(sort file2) > $@

在我的GNU让3.80这会给出一个错误,因为它使用了而不是庆典执行命令。

In my GNU Make 3.80 this will give an error since it uses the shell instead of bash to execute the commands.

推荐答案

从GNU制作文档,

5.3.1 Choosing the Shell
------------------------

The program used as the shell is taken from the variable `SHELL'.  If
this variable is not set in your makefile, the program `/bin/sh' is
used as the shell.

所以把 SHELL:= /斌/庆典在你的makefile的顶部,你应该是好去。

So put SHELL := /bin/bash at the top of your makefile, and you should be good to go.

BTW:你也可以做到这一点的一个目标,至少在GNU制作。每个目标都可以有自己的变量赋值,如下所示:

BTW: You can also do this for one target, at least for GNU Make. Each target can have its own variable assignments, like this:

all: a b

a:
    @echo "a is $$0"

b: SHELL:=/bin/bash   # HERE: this is setting the shell for b only
b:
    @echo "b is $$0"

这会打印:

a is /bin/sh
b is /bin/bash

请参阅特定目标变量值更多详细信息的文件中。这条线可以在Makefile去任何地方,它没有到目标之前立即

See "Target-specific Variable Values" in the documentation for more details. That line can go anywhere in the Makefile, it doesn't have to be immediately before the target.

这篇关于如何使用Bash的语法。在Makefile目标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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