makefile - GNU make 4.1 : Missing separator when $(if . ..) 在定义的函数中为真

标签 makefile gnu-make

当在 shell 命令的输出中找不到字符串时,我试图在 Makefile 中生成错误。 shell 命令依赖于一个参数,因此整个事情都在一个定义的函数中。这是一个极简主义的例子:

define check_in_abcdefg
$(eval TMP := $(shell echo abcdefg))
$(if $(findstring $(1),$(TMP)),,$(error $(1) not in $(TMP)))
endef

$(call check_in_abcdefg,def)

all:
    @echo Hello, world!

我希望这个 Makefile 输出 Hello, world!在这种情况下,但我希望它输出 xyz not in abcdefg如果我用这个替换调用线:
$(call check_in_abcdefg,xyz)

问题在于 def检查我有这个输出:

Makefile:6: *** missing separator. Stop.



其中第 6 行是 $(call check_in_abcdefg,def)
为什么在$(if ...) 时语法检查失败条件为真,因为它实际上是空的?

注意虚拟目标中的echo 命令all正确地前面有一个制表符,而不是四个空格。我在运行 GNU make 4.1.90 built for Windows32 ,而对于较新版本的 GNU make 似乎不会发生这种情况。 .我正在寻找任何可以帮助我使其与 GNU make 4.1.90 一起使用的答案

最佳答案

我不知道为什么旧 make版本在这里窒息,但你可以让它与一个大 $(eval ) 一起工作像这样:

define check_in_abcdefg
$(eval
  TMP := $$(shell echo abcdefg)
  ifeq ($$(findstring $$(1),$$(TMP)),)
      $$(error $$(1) not in $$(TMP))
  endif
)
endef

$(call check_in_abcdefg,def)

all:
        @echo Hello, world!

关于makefile - GNU make 4.1 : Missing separator when $(if . ..) 在定义的函数中为真,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47429909/

相关文章:

makefile - Makefile 中 TARGET_ARCH 变量的用途是什么

makefile - 在 Makefile 变量中使用 `date`

makefile - 同一配方的多个隐式(或模式)规则

c - autoconf configure 导致 C std lib header 相关的编译错误

c - "make target"在 "make clean"之后不工作

c++ - 无法从源代码构建 OpenCV

build-process - 指定为对多个规则的依赖时重新执行目标

windows-10 - 为什么 make.exe 尝试在 Windows 上运行/usr/bin/sh?

linux - .c 文件旁边带有 .s 文件的 makefile

c - C 标准库中 mergesort() 的链接错误