tags:

views:

42

answers:

1

Hello there!

In my makefile I have a variable with a list of directories, like this:

DIRS = /usr /usr/share/ /lib

Now, I need to create PATH variable from it, which is basically the same, but uses semicolon as a separator:

PATH = /usr:/usr/share/:/lib

How do I do that? I mean, how do I join elements of DIRS list with semicolons, instead of spaces?

+3  A: 

You can use the $(subst) command, combined with a little trick to get a variable that has a value of a single space:

p = /usr /usr/share /lib
noop=
space = $(noop) $(noop)

all:
        @echo $(subst $(space),:,$(p))

Hope that helps,

Eric Melski

Eric Melski
Wow, works like a charm, many thanks! Been struggling with it for hours!
maksymko