我想用字符串替换其中一个.mak文件中的一个字符串,我的主Makefile包括如下:
/布麦
[...]
LOADLIBES += -lGoo
LOADLIBES += -lBaa -lCov -lDtt // -lDtt to be replaced
[...]
/生成文件
[...]
include $(DIR)/boo.mak
[...]
-lDtt
将被类似于-Wl, --do-something -lDtt -Wl --undo-something
的内容替换你建议怎么做?
我试过这个:
/测试
[...]
replace:= -Wl, --do-something -lDtt -Wl --undo-something
dtt:= -lDtt
boo:= $(DIR)/boo.mak
newboo:= $(subst $(dtt),$(replace),$(boo))
include $(newboo)
[...]
但是没有什么变化,-LDTT仍然存在,并且在我运行之后不需要替换我想要的文本。
编辑:我正在使用gcc和linux。
最佳答案
$(subst
的第三个参数是要替换的实际字符串。它不是字符串所在文件的名称,正如您所相信的那样。
例子:
$ cat Makefile
replace:= -Wl, --do-something -lDtt -Wl --undo-something
dtt:= -lDtt
boo:= This string contains -lDtt which will be replaced
newboo:= $(subst $(dtt),$(replace),$(boo))
testme:
echo $(newboo)
$ make testme
echo This string contains -Wl, --do-something -lDtt -Wl --undo-something which will be replaced
This string contains -Wl, --do-something -lDtt -Wl --undo-something which will be replaced
因此,在您的情况下,需要使用
$(subst
变量上的LOADLIBES
来替换其内容。