为 ifeq 出错:意外标记附近出现语法错误
我正在编写一个在一个地方进行字符串匹配的 Makefile,代码如下:
if test ...; \
then \
shell scripts... \
fi
ifeq ($(DIST_TYPE),nightly)
shell scripts ...
endif
这里第一个 if
是 shell 脚本,第二个 ifeq
是 GNU Make 的条件。但是会生成以下错误:
ifeq(每晚,每晚)
/bin/sh: -c: 第 0 行:意外标记“nightly,nightly”附近出现语法错误
/bin/sh: -c: 第 0 行:`ifeq(每晚,每晚)'
这里发生了什么?看起来Make正在尝试调用shell。
I'm writing a Makefile that does string matching at one place, the code is like:
if test ...; \
then \
shell scripts... \
fi
ifeq ($(DIST_TYPE),nightly)
shell scripts ...
endif
Here the first if
is shell script, the second ifeq
is GNU Make's conditional. However the following error generates:
ifeq (nightly,nightly)
/bin/sh: -c: line 0: syntax error near unexpected token `nightly,nightly'
/bin/sh: -c: line 0: `ifeq (nightly,nightly)'
What's happening here? It seems that Make is trying to call the shell.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我研究了代码,发现条件语句应该不缩进编写,这解决了我的问题。
如果没有缩进,Make 会将其视为自身的指令;否则,它被视为 shell 脚本。
示例代码
错误:
正确:
I played around the code and found that the conditional statements should be written without indentation, and this solved my problem.
If there is no indentation, Make will treat it as a directive for itself; otherwise, it's regarded as a shell script.
Example code
Wrong:
Correct:
另外,如果在define函数中使用了条件语句,如:
这种情况下,Make也会将其视为shell脚本。
这个问题可以通过使用 if 函数来解决:
In addition, if the conditional statements is used in define functions, like:
In this case, Make will also treat it as a shell script.
This problem can be solved by using if-function instead: