2012-03-04 72 views

回答

14

請參閱下面的代碼。

# 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)) 

用法:

FOO = foo1 foo2 ... fooN 

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

你可以簡單的用冒號替換空格:

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

FOO_LISTfoo1:foo2:...:fooN

+1

爲什麼不只是'FOO_LIST = $(subst $(SPACE),:,$(FOO))'? – Beta 2012-03-04 02:03:53

+0

@貝塔好點。糾正。 – 2012-03-04 02:07:31