我有一个Makefile变量,如下所示
L_PATH_INCLUDE = c:\dir1\include C:\dir2\include C:\dir3\include
我需要将其移交给其他需要此工具的工具
tool.exe add-include-dir "c:\dir1\include" "C:\dir2\include" "C:\dir3\include"
我尝试了以下方式,但工具报告错误,不应该使用单个字符变量,我使用了$(space)
$(subst $(space)," ",$(strip $(L_PATH_INCLUDE)))
如果不使用$(空格)或单个字符变量
,可以以任何其他方式实现答案 0 :(得分:4)
放置引号没有问题,它不是解释符号。但是你需要在L_PATH_INCLUDE中的所有路径周围加上引号,为了达到这个目的,我就这样做了:
L_PATH_INCLUDE = c:\dir1\include C:\dir2\include C:\dir3\include
all:
echo $(addprefix ",$(addsuffix ",$(L_PATH_INCLUDE)))
使用make all
输出此内容:
echo" c:\ dir1 \ include" " C:\ DIR2 \包括" " C:\ DIR3 \包括"
c:\ dir1 \ include C:\ dir2 \ include C:\ dir3 \ include
你可以用你的命令替换echo,它就可以做到。
基本上,我们的想法是使用addprefix和addsuffix在L_PATH_INCLUDE中的每个单词的开头和结尾添加引号。
如果您在Makefile中复制/粘贴我的答案,请注意用适当的表格替换这四个空格。
答案 1 :(得分:0)
L_PATH_INCLUDE = c:\dir1\include C:\dir2\include C:\dir3\include
L_PATH_INCLUDE_QUOTED := $(patsubst %,"%",$(L_PATH_INCLUDE))
$(info L_PATH_INCLUDE_QUOTED=$(L_PATH_INCLUDE_QUOTED))