在 GNU Make 中创建逗号分隔列表
我有一个带有一组布尔值的 Makefile,必须使用它们来控制外部应用程序的标志。问题是该标志必须作为逗号分隔的字符串传递。
像这样的东西(非工作伪代码):
WITH_LIST = ""
WITHOUT_LIST = ""
ifeq ($(BOOL_A),y)
# Append A to list "WITH_LIST"
else
# Append A to list "WITHOUT_LIST"
endif
ifeq ($(BOOL_B),y)
# Append B to list "WITH_LIST"
else
# Append B to list "WITHOUT_LIST"
endif
ifeq ($(BOOL_C),y)
# Append C to list "WITH_LIST"
else
# Append C to list "WITHOUT_LIST"
endif
现在假设 BOOL_A == y、BOOL_B == n 和 BOOL_C == y,我需要运行以下命令:
./app --with=A,C --with-out=B
如何使用 Gnu Make 生成这些字符串?
I have a Makefile with a set of booleans which must be used to control the flags for an external application. The problem is that the flag must be passed as a comma-separated string.
Something like this (non-working pseudo code):
WITH_LIST = ""
WITHOUT_LIST = ""
ifeq ($(BOOL_A),y)
# Append A to list "WITH_LIST"
else
# Append A to list "WITHOUT_LIST"
endif
ifeq ($(BOOL_B),y)
# Append B to list "WITH_LIST"
else
# Append B to list "WITHOUT_LIST"
endif
ifeq ($(BOOL_C),y)
# Append C to list "WITH_LIST"
else
# Append C to list "WITHOUT_LIST"
endif
Now assuming BOOL_A == y, BOOL_B == n and BOOL_C == y, I need to run the following command:
./app --with=A,C --with-out=B
How can I generate these string using Gnu Make?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先,使用您的方法或 thiton 的方法创建两个空格分隔的列表。
然后使用 GNU make 手册第 6.2 节末尾的小技巧 创建一个包含单个空格的变量和一个包含逗号的变量。然后,您可以在
$(subst ...)
中使用它们将两个列表更改为逗号分隔。First you create the two white-space separated lists, either using your method, or thiton's.
Then you use the little trick from the end of section 6.2 of the GNU make manual to create a variable holding a single space, and one holding a comma. You can then use these in
$(subst ...)
to change the two lists to comma-separated.像这样的构造
应该可以工作。
编辑:抱歉,忽略了必要的整理。
这个想法是检查每个可能的部分 X 是否设置为“是”,如果是,则将其插入列表中。该列表以空格分隔,很难用 make 进行逗号分隔,但在 shell 中很容易做到这一点。
A construct like
should work.
Edit: Sorry, overlooked the necessary collation.
The idea is to check for each possible part X whether it's set to yes and insert it into a list if it is yes. This list is whitespace-separated and hard to comma-separate with make, but easy to do this in shell.
或者只使用 sed:丑陋(且未经测试)但简单
Or just use
sed
: ugly (and untested) but straightforward