我正在尝试执行 make 语句来检查架构。我非常接近让它发挥作用:
test:
ifeq ("$(shell arch)", "armv7l")
echo "This is an arm system"
else
echo "This is not an arm system."
endif
我有一个问题:虽然这似乎解决了 ifeq ("i386", "armv7l")
这应该是错误的,但我收到以下错误:
$ make
ifeq ("i386", "armv7l")
/bin/sh: -c: line 0: syntax error near unexpected token `"i386",'
/bin/sh: -c: line 0: `ifeq ("i386", "armv7l")'
make: *** [test] Error 2
因此,它解析为两个字符串进行比较,但存在语法错误。这里出了什么问题?
最佳答案
您不能在配方中使用像 ifeq
这样的 make 语句。配方(以 TAB 开头的行)将传递到 shell。 shell 不理解 ifeq
;这是一个 make 构造。
您必须在配方中使用 shell if 语句。而且,您不必在配方中使用 $(shell ...)
,因为您已经在 shell 中了。
test:
if [ `arch` = armv7l ]; then \
echo "This is an arm system"; \
else \
echo "This is not an arm system."; \
fi
这可能不是处理此问题的最佳方法,但由于您没有提供任何有关您真正想要做什么的信息,所以我们只能说。
关于Makefile 条件错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17620887/