[英]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.