GNU Make: how to join list and separate it with separator? [duplicate]

雨燕双飞 提交于 2019-11-29 12:25:45

问题


I have this:

FOO = foo1 foo2 ... fooN

and want to get join all these string and separate it with, for instance, colong:

foo1:foo2:foo3:...:fooN

How to do this in GNU Make, without using external UNIX tools?


回答1:


See the code below.

# A literal space.
space :=
space +=

# Joins elements of the list in arg 2 with the given separator.
#   1. Element separator.
#   2. The list.
join-with = $(subst $(space),$1,$(strip $2))

Usage:

FOO = foo1 foo2 ... fooN

COLON_SEPARATED_FOO := $(call join-with,:,$(FOO))



回答2:


You can simply replace spaces with colon:

EMPTY :=
SPACE := $(EMPTY) $(EMPTY)
FOO = foo1 foo2 ... fooN
FOO_LIST = $(subst $(SPACE),:,$(FOO))

FOO_LIST is foo1:foo2:...:fooN.



来源:https://stackoverflow.com/questions/9551416/gnu-make-how-to-join-list-and-separate-it-with-separator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!