[英]Append/Substitute string in Makefile from another makefile
我想用这个字符串替换我的主要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
因此,在您的情况下,您将需要使用$(subst
代替LOADLIBES
变量,以替换其内容。
好的,感谢上面的回答。 我设法洞悉出了什么问题以及应该采取的下一步措施。 这是我当前的Makefile:
[...]
include $(DIR)/boo.mak
replace:= -Wl, --do-something -lDtt -Wl --undo-something
dtt:= -lDtt
boo:= $(subst $(dtt),$(replace),$(LOADLIBES))
LOADLIBES = $(boo) //replace old LOADLIBES variable with new modified lib
[...]
我乐于接受任何建议以改善此问题,但目前效果很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.