如何将经过筛选的 Makefile 变量列表转储到文件中?
我想将所有以 MYLIB_ 开头的 Makefile 变量及其值转储到名为 config.h 的文件中作为预处理器定义。这是我尝试过的:
config:
@echo "// AUTO-GENERATED - DO NOT EDIT!" > config.h
$(foreach V, $(filter MYLIB_%, $(.VARIABLES)),
$(shell echo "#define $(V) $($V)" >> config.h))
不幸的是,$(filter)
不返回任何值,即使$(.VARIABLES)
包含以MYLIB_开头的项目
。
我做错了什么?
I'd like to dump all Makefile variables that start with MYLIB_
and their values to a file called config.h
as preprocessor definitions. This is what I have tried:
config:
@echo "// AUTO-GENERATED - DO NOT EDIT!" > config.h
$(foreach V, $(filter MYLIB_%, $(.VARIABLES)),
$(shell echo "#define $(V) $($V)" >> config.h))
Unfortunately, $(filter)
doesn't return any values, even though $(.VARIABLES)
contains items that begin with MYLIB_
.
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的
$(filter)
看起来正确。原因可能是
@echo
命令之间的评估顺序和
$(foreach)
。是否将
@echo
替换为$(shell echo ...)
,如下所示解决问题吗?
Your
$(filter)
looks correct.Possibly the cause may be the evaluation order between
@echo
commandand
$(foreach)
.Does replacing
@echo
with$(shell echo ...)
like the followingsolve the problem?