【发布时间】:2012-02-02 16:46:53
【问题描述】:
Makefile:
#there is a whitespace after "/my/path/to"
FOO = "/my/path/to"
BAR = "dir"
INCLUDE_DIRS = $(FOO)/$(BAR) "/another/path"
INCLUDES = $(foreach dir,$(INCLUDE_DIRS),-I$(dir))
all:
@echo $(INCLUDES)
使用 Gnu make 我希望我的 $(INCLUDES) 是:
-I/my/path/to/dir -I/another/path
但是,如果行
FOO = "/my/path/to"
以空格结尾(这是一个常见的“错误”),变量 FOO 将包含空格,生成的 INCLUDES 将包含三个目录(两个第一个比第一个拆分):
-I/my/path/to -I/dir -I/another/path
我找到的唯一解决方案是使用strip函数:
FOO = $(strip "/my/path/to" )
但是没有更自然的语法,或者有什么方法可以避免这个陷阱吗?
【问题讨论】:
标签: makefile