GNU makefile 中的 $(shell) 函数导致 'unterminated call to function shell: missing )'

$(shell) function in GNU makefile results in 'unterminated call to function shell: missing )'

描述:

我的 GNU makefile 中有以下片段:

test:=$(shell grep '#pragma' test_types.h)
$(info test:$(test))

以上导致以下错误消息:

*** 未终止的函数调用 'shell':缺少“)”。停止

但是,如果我从上面的代码片段中删除“#”

test:=$(shell grep 'pragma' test_types.h)
$(info test:$(test))

输出为:

测试:#pragma pack(push, 1) #pragma pack(pop)

如果我 运行 直接从命令行执行以下操作:grep '#pragma' test_types.h。输出又是:

#pragma pack(push, 1) #pragma pack(pop)

问题:

在 GNU makefile 中将 grep 与搜索 # 结合使用时,导致 shell 函数行为的原因是什么?

它将 # 解释为注释的开头,因此不再显示该行的其余部分。

将字符转义为 \#,它将起作用。