本题类似于Defining Variables inside macro.
我在 v3.82 和 v4.3 上都试过了。在下面的代码片段中,当我使用宏中的 shell 语句的输出初始化变量时,出现错误。在我的系统上,__LINUX_GCC_MAIN_VERSION 应该初始化为 11,然后我希望在 __LINUX_GCC_V7_OR_LATER 的初始化中使用它。这似乎没有发生,导致 expr.
的语法错误我添加了 $(info) 语句来帮助调试。
LINUX_CC = gcc -m32
define __DECLARE_VERSION_FLAGS_GCC
$(info [1])
__$(2)_GCC_MAIN_VERSION = $(shell $($(2)_CC) -dumpversion | sed -e 's/\..*//')
__$(2)_GCC_V7_OR_LATER = $(shell expr $(__$(2)_GCC_MAIN_VERSION) \>= 7)
$(info [5])
endef
$(info [6])
$(eval $(call __DECLARE_VERSION_FLAGS_GCC,linux,LINUX))
$(info [7])
# This outputs '11' as expected
$(info $(__LINUX_GCC_MAIN_VERSION))
$(info [8])
# This should be the result of "expr 11 >= 7", but the result is "FALSE"
ifeq ($(__LINUX_GCC_V7_OR_LATER),1)
V7 = "TRUE"
else
V7 = "FALSE"
endif
$(info $(V7))
$(info [9])
.PHONY: all
all:
@echo Done
~/temp/tmp$ make -f Makefile3
[6]
[1]
expr: syntax error: unexpected argument ‘7’
[5]
[7]
11
[8]
"FALSE"
[9]
Done
我希望看到的是:
~/temp/tmp$ make -f Makefile3
[6]
[1]
[5]
[7]
11
[8]
"TRUE"
[9]
Done
为什么这没有按预期工作,我需要做什么来纠正它?