ONESHELL Makefile中的if语句不起作用
我得到下面makefile中if语句的ONESHELL Makefile中的if语句不起作用,makefile,Makefile,我得到下面makefile中if语句的/bin/sh:-c:第1行:语法错误:意外的文件结尾-怎么了?(我的提示是/tmp>) 我使用的是GNU Make 3.81。使用GNU Make 3.81,该功能显然不受支持-您展示了这一点,我也展示了这一点。我在MacOSX10.11.5上进行了测试,提供的/usr/bin/make为GNUMake3.81。我通过在set-e之前、之后添加策略性放置的echo PID=$$$$$$行,以及观察不同的PID值,证明了我的满意。GNU Make版本3.81
/bin/sh:-c:第1行:语法错误:意外的文件结尾
-怎么了?(我的提示是/tmp>
)
我使用的是GNU Make 3.81。使用GNU Make 3.81,该功能显然不受支持-您展示了这一点,我也展示了这一点。我在MacOSX10.11.5上进行了测试,提供的/usr/bin/make
为GNUMake3.81。我通过在set-e
之前、之后添加策略性放置的echo PID=$$$$$$
行,以及观察不同的PID值,证明了我的满意。GNU Make版本3.81是从2006年开始的(2010年也有版本3.82,在版本4.x发布之前,从2013年的4.0开始)
GNU Make的当前版本为4.2.1(2016年6月)。该版本确实支持该功能;当使用足够新版本的GNU Make时,您的脚本可以正常工作。这是一个已经存在了一段时间的功能-您可能不必升级到最新版本以获得支持,但是如果您仍要升级,为什么还要使用下一个版本呢
如果您希望使用.ONSHELL:
功能,您必须确保使用的GNU Make版本足够新(比3.81版更新)。如果不可行,请不要使用该功能
阅读4.2.1中的新闻文件,很明显,
ONESHELL
已添加到GNU Make版本3.82中:
乔纳森3.81有一个外壳,只是没有“如果”的条件,我猜是这样的。因为echo和其他bash命令似乎有效。@Victor:我不知道你的意思。使用ONESHELL意味着配方的所有操作都在单个shell中执行,而不管使用了多少行。在本例中,
集合
和三行如果
/那么
/`else都在一个shell中运行。发行说明(新闻文件)明确指出,ONESHELL被添加到了3.82中,而不是3.81中。如果您有一个GNU Make的变体声称是3.81,但支持ONESHELL,那么它不是GNU AFAICT发布的版本。也许某个发行版出于某种原因对该功能进行了后端口移植,而不是发布3.82。也请注意,失败的if
是纯shell代码;它不是GNU的Make条件。
/tmp > make test
set -e
if [[ -f /tmp/device ]] ; then
/bin/sh: -c: line 1: syntax error: unexpected end of file
make: *** [test] Error 2
/tmp > cat Makefile
.ONESHELL:
test:
set -e
if [[ -f /tmp/device ]] ; then
echo 'Do something'
fi
Version 3.82 (28 Jul 2010)
…
* New special target: .ONESHELL instructs make to invoke a single instance
of the shell and provide it with the entire recipe, regardless of how many
lines it contains. As a special feature to allow more straightforward
conversion of makefiles to use .ONESHELL, any recipe line control
characters ('@', '+', or '-') will be removed from the second and
subsequent recipe lines. This happens _only_ if the SHELL value is deemed
to be a standard POSIX-style shell. If not, then no interior line control
characters are removed (as they may be part of the scripting language used
with the alternate SHELL).