Reputation: 25439
Given a colon-delimited list of paths, getting a space-delimited list with GNU Make is straightforward:
CPATHS := /usr/bin/foo:/usr/bin/baz:/usr/bin/baz
SPATHS := $(subst :, ,$(CPATHS))
However, I couldn't find a nice way to go the opposite direction. The following hack does work (at least if sed is installed) but I'm pretty sure there will be a nicer way to solve this just using Make's internal functions.
SPATHS := /usr/bin/foo /usr/bin/baz /usr/bin/baz
CPATHS := $(shell echo $(SPATHS) > tmp; sed 's/ \+/:/g' tmp; rm tmp)
Upvotes: 30
Views: 10970
Reputation: 98485
The shortest way to get a literal space would be via $() $()
. Thus:
$(subst $() $(),:,$(CPATHS))
Or, for brevity:
_=$() $()
$(subst $(_),:,$(CPATHS))
It is perhaps an interesting curiosity that the same trick works with cmake's macros, i.e. that ${}
is a separator but introduces no whitespace by itself.
Upvotes: 25
Reputation: 25523
The only tricky part here is to define a literal space:
space := $(subst ,, )
SPATHS := /usr/bin/foo /usr/bin/baz /usr/bin/baz
CPATHS := $(subst $(space),:,$(SPATHS))
Upvotes: 36