我想用字符串替换我的主 Makefile 包含的 .mak 文件之一中的这个字符串,如下所示:
/boo.mak
[...]
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
因此,在您的情况下,您需要在 LOADLIBES
变量上使用 $(subst
来替换其内容。
关于c++ - 从另一个 makefile 追加/替换 Makefile 中的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38088766/