Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 756
eold Avatar asked Mar 04 '12 01:03

eold


1 Answers

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))
like image 129
Eldar Abusalimov Avatar answered Oct 03 '22 08:10

Eldar Abusalimov