在我的makefile中,我有一个带有目录列表的变量,如下所示:
DIRS = /usr /usr/share/ /lib
现在,我需要从中创建PATH变量,它基本相同,但使用分号作为分隔符:
PATH = /usr:/usr/share/:/lib
我该怎么做?我的意思是,如何用分号而不是空格加入DIRS列表的元素?
答案 0 :(得分:34)
您可以使用$(subst)
命令,结合一个小技巧来获取具有单个空格值的变量:
p = /usr /usr/share /lib
noop=
space = $(noop) $(noop)
all:
@echo $(subst $(space),:,$(p))
希望有所帮助,
Eric Melski答案 1 :(得分:9)
最干净的表格(我能找到):
classpathify = $(subst $(eval) ,:,$(wildcard $1))
cp = a b c d/*.jar
target:
echo $(call classpathify,$(cp))
# prints a:b:c:d/1.jar:d/2.jar
注意:
答案 2 :(得分:0)
您使用':'作为分隔符,因此您在Linux上。考虑使用bash工具链用单个冒号代替连续空格
PATH := $(shell echo $(DIRS) | sed "s/ \+/:/g")